TreeInfo.h revision ea7a7fb75acb7305eb774ca7bc7e96103bd49323
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 "utils/Macros.h" 24 25namespace android { 26namespace uirenderer { 27 28namespace renderthread { 29class CanvasContext; 30} 31 32class DamageAccumulator; 33class OpenGLRenderer; 34class RenderState; 35 36class ErrorHandler { 37public: 38 virtual void onError(const std::string& message) = 0; 39protected: 40 ~ErrorHandler() {} 41}; 42 43// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 44class TreeInfo { 45 PREVENT_COPY_AND_ASSIGN(TreeInfo); 46public: 47 enum TraversalMode { 48 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 49 // May only be used if both the UI thread and RT thread are blocked on the 50 // prepare 51 MODE_FULL, 52 // Run only what can be done safely on RT thread. Currently this only means 53 // animators, but potentially things like SurfaceTexture updates 54 // could be handled by this as well if there are no listeners 55 MODE_RT_ONLY, 56 }; 57 58 explicit TreeInfo(TraversalMode mode, RenderState& renderState) 59 : mode(mode) 60 , prepareTextures(mode == MODE_FULL) 61 , runAnimations(true) 62 , damageAccumulator(nullptr) 63 , renderState(renderState) 64 , renderer(nullptr) 65 , errorHandler(nullptr) 66 , canvasContext(nullptr) 67 {} 68 69 explicit TreeInfo(TraversalMode mode, const TreeInfo& clone) 70 : mode(mode) 71 , prepareTextures(mode == MODE_FULL) 72 , runAnimations(clone.runAnimations) 73 , damageAccumulator(clone.damageAccumulator) 74 , renderState(clone.renderState) 75 , renderer(clone.renderer) 76 , errorHandler(clone.errorHandler) 77 , canvasContext(clone.canvasContext) 78 {} 79 80 TraversalMode mode; 81 // TODO: Remove this? Currently this is used to signal to stop preparing 82 // textures if we run out of cache space. 83 bool prepareTextures; 84 // TODO: buildLayer uses this to suppress running any animations, but this 85 // should probably be refactored somehow. The reason this is done is 86 // because buildLayer is not setup for injecting the animationHook, as well 87 // as this being otherwise wasted work as all the animators will be 88 // re-evaluated when the frame is actually drawn 89 bool runAnimations; 90 91 // Must not be null during actual usage 92 DamageAccumulator* damageAccumulator; 93 RenderState& renderState; 94 // The renderer that will be drawing the next frame. Use this to push any 95 // layer updates or similar. May be NULL. 96 OpenGLRenderer* renderer; 97 ErrorHandler* errorHandler; 98 // May be NULL (TODO: can it really?) 99 renderthread::CanvasContext* canvasContext; 100 101 struct Out { 102 Out() 103 : hasFunctors(false) 104 , hasAnimations(false) 105 , requiresUiRedraw(false) 106 , canDrawThisFrame(true) 107 {} 108 bool hasFunctors; 109 // This is only updated if evaluateAnimations is true 110 bool hasAnimations; 111 // This is set to true if there is an animation that RenderThread cannot 112 // animate itself, such as if hasFunctors is true 113 // This is only set if hasAnimations is true 114 bool requiresUiRedraw; 115 // This is set to true if draw() can be called this frame 116 // false means that we must delay until the next vsync pulse as frame 117 // production is outrunning consumption 118 // NOTE that if this is false CanvasContext will set either requiresUiRedraw 119 // *OR* will post itself for the next vsync automatically, use this 120 // only to avoid calling draw() 121 bool canDrawThisFrame; 122 } out; 123 124 // TODO: Damage calculations 125}; 126 127} /* namespace uirenderer */ 128} /* namespace android */ 129 130#endif /* TREEINFO_H */ 131