TreeInfo.h revision 68bfe0a37a0dcef52abd81688d8520c5d16e1a85
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 BaseRenderNodeAnimator; 30class AnimationListener; 31class OpenGLRenderer; 32class RenderState; 33 34class AnimationHook { 35public: 36 virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0; 37protected: 38 ~AnimationHook() {} 39}; 40 41class ErrorHandler { 42public: 43 virtual void onError(const std::string& message) = 0; 44protected: 45 ~ErrorHandler() {} 46}; 47 48// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 49class TreeInfo { 50 PREVENT_COPY_AND_ASSIGN(TreeInfo); 51public: 52 enum TraversalMode { 53 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 54 // May only be used if both the UI thread and RT thread are blocked on the 55 // prepare 56 MODE_FULL, 57 // Run only what can be done safely on RT thread. Currently this only means 58 // animators, but potentially things like SurfaceTexture updates 59 // could be handled by this as well if there are no listeners 60 MODE_RT_ONLY, 61 // The subtree is being detached. Maybe. If the RenderNode is present 62 // in both the old and new display list's children then it will get a 63 // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL. 64 // Push any pending display list changes in case it is detached, 65 // but don't evaluate animators and such as if it isn't detached as a 66 // MODE_FULL will follow shortly. 67 MODE_MAYBE_DETACHING, 68 // TODO: TRIM_MEMORY? 69 }; 70 71 explicit TreeInfo(TraversalMode mode, RenderState& renderState) 72 : mode(mode) 73 , frameTimeMs(0) 74 , animationHook(NULL) 75 , prepareTextures(mode == MODE_FULL) 76 , damageAccumulator(NullDamageAccumulator::instance()) 77 , renderState(renderState) 78 , renderer(NULL) 79 , errorHandler(NULL) 80 {} 81 82 explicit TreeInfo(TraversalMode mode, const TreeInfo& clone) 83 : mode(mode) 84 , frameTimeMs(clone.frameTimeMs) 85 , animationHook(clone.animationHook) 86 , prepareTextures(mode == MODE_FULL) 87 , damageAccumulator(clone.damageAccumulator) 88 , renderState(clone.renderState) 89 , renderer(clone.renderer) 90 , errorHandler(clone.errorHandler) 91 {} 92 93 const TraversalMode mode; 94 nsecs_t frameTimeMs; 95 AnimationHook* animationHook; 96 // TODO: Remove this? Currently this is used to signal to stop preparing 97 // textures if we run out of cache space. 98 bool prepareTextures; 99 // Must not be null 100 IDamageAccumulator* damageAccumulator; 101 RenderState& renderState; 102 // The renderer that will be drawing the next frame. Use this to push any 103 // layer updates or similar. May be NULL. 104 OpenGLRenderer* renderer; 105 ErrorHandler* errorHandler; 106 107 struct Out { 108 Out() 109 : hasFunctors(false) 110 , hasAnimations(false) 111 , requiresUiRedraw(false) 112 , canDrawThisFrame(true) 113 {} 114 bool hasFunctors; 115 // This is only updated if evaluateAnimations is true 116 bool hasAnimations; 117 // This is set to true if there is an animation that RenderThread cannot 118 // animate itself, such as if hasFunctors is true 119 // This is only set if hasAnimations is true 120 bool requiresUiRedraw; 121 // This is set to true if draw() can be called this frame 122 // false means that we must delay until the next vsync pulse as frame 123 // production is outrunning consumption 124 // NOTE that if this is false CanvasContext will set either requiresUiRedraw 125 // *OR* will post itself for the next vsync automatically, use this 126 // only to avoid calling draw() 127 bool canDrawThisFrame; 128 } out; 129 130 // TODO: Damage calculations 131}; 132 133} /* namespace uirenderer */ 134} /* namespace android */ 135 136#endif /* TREEINFO_H */ 137