TreeInfo.h revision 119907cd2575c56b1ebf66348b52e67aaf6a88d8
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#ifndef TREEINFO_H 17#define TREEINFO_H 18 19#include <string> 20 21#include <utils/Timers.h> 22 23#include "DamageAccumulator.h" 24#include "utils/Macros.h" 25 26namespace android { 27namespace uirenderer { 28 29class OpenGLRenderer; 30class RenderState; 31 32class ErrorHandler { 33public: 34 virtual void onError(const std::string& message) = 0; 35protected: 36 ~ErrorHandler() {} 37}; 38 39// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 40class TreeInfo { 41 PREVENT_COPY_AND_ASSIGN(TreeInfo); 42public: 43 enum TraversalMode { 44 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 45 // May only be used if both the UI thread and RT thread are blocked on the 46 // prepare 47 MODE_FULL, 48 // Run only what can be done safely on RT thread. Currently this only means 49 // animators, but potentially things like SurfaceTexture updates 50 // could be handled by this as well if there are no listeners 51 MODE_RT_ONLY, 52 }; 53 54 explicit TreeInfo(TraversalMode mode, RenderState& renderState) 55 : mode(mode) 56 , prepareTextures(mode == MODE_FULL) 57 , runAnimations(true) 58 , damageAccumulator(NULL) 59 , renderState(renderState) 60 , renderer(NULL) 61 , errorHandler(NULL) 62 {} 63 64 explicit TreeInfo(TraversalMode mode, const TreeInfo& clone) 65 : mode(mode) 66 , prepareTextures(mode == MODE_FULL) 67 , runAnimations(clone.runAnimations) 68 , damageAccumulator(clone.damageAccumulator) 69 , renderState(clone.renderState) 70 , renderer(clone.renderer) 71 , errorHandler(clone.errorHandler) 72 {} 73 74 const TraversalMode mode; 75 // TODO: Remove this? Currently this is used to signal to stop preparing 76 // textures if we run out of cache space. 77 bool prepareTextures; 78 // TODO: buildLayer uses this to suppress running any animations, but this 79 // should probably be refactored somehow. The reason this is done is 80 // because buildLayer is not setup for injecting the animationHook, as well 81 // as this being otherwise wasted work as all the animators will be 82 // re-evaluated when the frame is actually drawn 83 bool runAnimations; 84 85 // Must not be null during actual usage 86 DamageAccumulator* damageAccumulator; 87 RenderState& renderState; 88 // The renderer that will be drawing the next frame. Use this to push any 89 // layer updates or similar. May be NULL. 90 OpenGLRenderer* renderer; 91 ErrorHandler* errorHandler; 92 93 struct Out { 94 Out() 95 : hasFunctors(false) 96 , hasAnimations(false) 97 , requiresUiRedraw(false) 98 , canDrawThisFrame(true) 99 {} 100 bool hasFunctors; 101 // This is only updated if evaluateAnimations is true 102 bool hasAnimations; 103 // This is set to true if there is an animation that RenderThread cannot 104 // animate itself, such as if hasFunctors is true 105 // This is only set if hasAnimations is true 106 bool requiresUiRedraw; 107 // This is set to true if draw() can be called this frame 108 // false means that we must delay until the next vsync pulse as frame 109 // production is outrunning consumption 110 // NOTE that if this is false CanvasContext will set either requiresUiRedraw 111 // *OR* will post itself for the next vsync automatically, use this 112 // only to avoid calling draw() 113 bool canDrawThisFrame; 114 } out; 115 116 // TODO: Damage calculations 117}; 118 119} /* namespace uirenderer */ 120} /* namespace android */ 121 122#endif /* TREEINFO_H */ 123