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