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/Timers.h> 20 21 #include <optional> 22 #include <string> 23 24 #include "Properties.h" 25 #include "SkSize.h" 26 #include "SkippedFrameInfo.h" 27 #include "utils/ForceDark.h" 28 #include "utils/Macros.h" 29 30 namespace android { 31 namespace uirenderer { 32 33 namespace renderthread { 34 class CanvasContext; 35 } 36 37 class DamageAccumulator; 38 class LayerUpdateQueue; 39 class RenderNode; 40 class RenderState; 41 42 class ErrorHandler { 43 public: 44 virtual void onError(const std::string& message) = 0; 45 46 virtual ~ErrorHandler() = default; 47 }; 48 49 class TreeObserver { 50 public: 51 // Called when a RenderNode's parent count hits 0. 52 // Due to the unordered nature of tree pushes, once prepareTree 53 // is finished it is possible that the node was "resurrected" and has 54 // a non-zero parent count. 55 virtual void onMaybeRemovedFromTree(RenderNode* node) = 0; 56 57 protected: 58 virtual ~TreeObserver() = default; 59 }; 60 61 // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 62 class TreeInfo { 63 PREVENT_COPY_AND_ASSIGN(TreeInfo); 64 65 public: 66 enum TraversalMode { 67 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 68 // May only be used if both the UI thread and RT thread are blocked on the 69 // prepare 70 MODE_FULL, 71 // Run only what can be done safely on RT thread. Currently this only means 72 // animators, but potentially things like SurfaceTexture updates 73 // could be handled by this as well if there are no listeners 74 MODE_RT_ONLY, 75 }; 76 77 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext); 78 79 TraversalMode mode; 80 // TODO: Remove this? Currently this is used to signal to stop preparing 81 // textures if we run out of cache space. 82 bool prepareTextures; 83 renderthread::CanvasContext& canvasContext; 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 = true; 90 91 // Must not be null during actual usage 92 DamageAccumulator* damageAccumulator = nullptr; 93 int64_t damageGenerationId = 0; 94 95 LayerUpdateQueue* layerUpdateQueue = nullptr; 96 ErrorHandler* errorHandler = nullptr; 97 98 bool updateWindowPositions = false; 99 100 int disableForceDark; 101 ForceDarkType forceDarkType = ForceDarkType::NONE; 102 103 const SkISize screenSize; 104 105 int stretchEffectCount = 0; 106 107 bool forceDrawFrame = false; 108 109 struct Out { 110 bool hasFunctors = false; 111 // This is only updated if evaluateAnimations is true 112 bool hasAnimations = false; 113 // This is set to true if there is an animation that RenderThread cannot 114 // animate itself, such as if hasFunctors is true 115 // This is only set if hasAnimations is true 116 bool requiresUiRedraw = false; 117 // This is set to nullopt if draw() can be called this frame 118 // A value means that we must delay until the next vsync pulse as frame 119 // production is outrunning consumption 120 // NOTE that if this has a value CanvasContext will set either requiresUiRedraw 121 // *OR* will post itself for the next vsync automatically, use this 122 // only to avoid calling draw() 123 std::optional<SkippedFrameReason> skippedFrameReason; 124 // Sentinel for animatedImageDelay meaning there is no need to post such 125 // a message. 126 static constexpr nsecs_t kNoAnimatedImageDelay = -1; 127 // This is used to post a message to redraw when it is time to draw the 128 // next frame of an AnimatedImageDrawable. 129 nsecs_t animatedImageDelay = kNoAnimatedImageDelay; 130 // This is used to determine if there were only TextureView updates in this frame. 131 // This info is passed to SurfaceFlinger to determine whether it should use vsyncIds 132 // for refresh rate selection. 133 bool solelyTextureViewUpdates = true; 134 } out; 135 136 // This flag helps to disable projection for receiver nodes that do not have any backward 137 // projected children. 138 bool hasBackwardProjectedNodes = false; 139 // TODO: Damage calculations 140 }; 141 142 } /* namespace uirenderer */ 143 } /* namespace android */ 144