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 17 #pragma once 18 19 #include "utils/Macros.h" 20 21 #include <utils/Timers.h> 22 23 #include <string> 24 25 namespace android { 26 namespace uirenderer { 27 28 namespace renderthread { 29 class CanvasContext; 30 } 31 32 class DamageAccumulator; 33 class LayerUpdateQueue; 34 class RenderNode; 35 class RenderState; 36 37 class ErrorHandler { 38 public: 39 virtual void onError(const std::string& message) = 0; 40 protected: ~ErrorHandler()41 ~ErrorHandler() {} 42 }; 43 44 class TreeObserver { 45 public: 46 // Called when a RenderNode's parent count hits 0. 47 // Due to the unordered nature of tree pushes, once prepareTree 48 // is finished it is possible that the node was "resurrected" and has 49 // a non-zero parent count. 50 virtual void onMaybeRemovedFromTree(RenderNode* node) = 0; 51 protected: ~TreeObserver()52 virtual ~TreeObserver() {} 53 }; 54 55 // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 56 class TreeInfo { 57 PREVENT_COPY_AND_ASSIGN(TreeInfo); 58 public: 59 enum TraversalMode { 60 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 61 // May only be used if both the UI thread and RT thread are blocked on the 62 // prepare 63 MODE_FULL, 64 // Run only what can be done safely on RT thread. Currently this only means 65 // animators, but potentially things like SurfaceTexture updates 66 // could be handled by this as well if there are no listeners 67 MODE_RT_ONLY, 68 }; 69 TreeInfo(TraversalMode mode,renderthread::CanvasContext & canvasContext)70 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext) 71 : mode(mode) 72 , prepareTextures(mode == MODE_FULL) 73 , canvasContext(canvasContext) 74 {} 75 76 TraversalMode mode; 77 // TODO: Remove this? Currently this is used to signal to stop preparing 78 // textures if we run out of cache space. 79 bool prepareTextures; 80 renderthread::CanvasContext& canvasContext; 81 // TODO: buildLayer uses this to suppress running any animations, but this 82 // should probably be refactored somehow. The reason this is done is 83 // because buildLayer is not setup for injecting the animationHook, as well 84 // as this being otherwise wasted work as all the animators will be 85 // re-evaluated when the frame is actually drawn 86 bool runAnimations = true; 87 88 // Must not be null during actual usage 89 DamageAccumulator* damageAccumulator = nullptr; 90 91 LayerUpdateQueue* layerUpdateQueue = nullptr; 92 ErrorHandler* errorHandler = nullptr; 93 94 bool updateWindowPositions = false; 95 96 struct Out { 97 bool hasFunctors = false; 98 // This is only updated if evaluateAnimations is true 99 bool hasAnimations = false; 100 // This is set to true if there is an animation that RenderThread cannot 101 // animate itself, such as if hasFunctors is true 102 // This is only set if hasAnimations is true 103 bool requiresUiRedraw = false; 104 // This is set to true if draw() can be called this frame 105 // false means that we must delay until the next vsync pulse as frame 106 // production is outrunning consumption 107 // NOTE that if this is false CanvasContext will set either requiresUiRedraw 108 // *OR* will post itself for the next vsync automatically, use this 109 // only to avoid calling draw() 110 bool canDrawThisFrame = true; 111 } out; 112 113 // This flag helps to disable projection for receiver nodes that do not have any backward 114 // projected children. 115 bool hasBackwardProjectedNodes = false; 116 // TODO: Damage calculations 117 }; 118 119 } /* namespace uirenderer */ 120 } /* namespace android */ 121