John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 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 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 19 | #include "utils/Macros.h" |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 20 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 21 | #include <utils/Timers.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 22 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 23 | #include <string> |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 24 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 28 | namespace renderthread { |
| 29 | class CanvasContext; |
| 30 | } |
| 31 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 32 | class DamageAccumulator; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 33 | class LayerUpdateQueue; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 34 | class OpenGLRenderer; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 35 | class RenderNode; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 36 | class RenderState; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 37 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 38 | class ErrorHandler { |
| 39 | public: |
| 40 | virtual void onError(const std::string& message) = 0; |
| 41 | protected: |
| 42 | ~ErrorHandler() {} |
| 43 | }; |
| 44 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 45 | class TreeObserver { |
| 46 | public: |
| 47 | // Called when a RenderNode's parent count hits 0. |
| 48 | // Due to the unordered nature of tree pushes, once prepareTree |
| 49 | // is finished it is possible that the node was "resurrected" and has |
| 50 | // a non-zero parent count. |
| 51 | virtual void onMaybeRemovedFromTree(RenderNode* node) {} |
| 52 | protected: |
| 53 | ~TreeObserver() {} |
| 54 | }; |
| 55 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 56 | // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN |
| 57 | class TreeInfo { |
| 58 | PREVENT_COPY_AND_ASSIGN(TreeInfo); |
| 59 | public: |
| 60 | enum TraversalMode { |
| 61 | // The full monty - sync, push, run animators, etc... Used by DrawFrameTask |
| 62 | // May only be used if both the UI thread and RT thread are blocked on the |
| 63 | // prepare |
| 64 | MODE_FULL, |
| 65 | // Run only what can be done safely on RT thread. Currently this only means |
| 66 | // animators, but potentially things like SurfaceTexture updates |
| 67 | // could be handled by this as well if there are no listeners |
| 68 | MODE_RT_ONLY, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 71 | TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext) |
| 72 | : mode(mode) |
| 73 | , prepareTextures(mode == MODE_FULL) |
| 74 | , canvasContext(canvasContext) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 75 | {} |
| 76 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 77 | TraversalMode mode; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 78 | // TODO: Remove this? Currently this is used to signal to stop preparing |
| 79 | // textures if we run out of cache space. |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 80 | bool prepareTextures; |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 81 | renderthread::CanvasContext& canvasContext; |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 82 | // TODO: buildLayer uses this to suppress running any animations, but this |
| 83 | // should probably be refactored somehow. The reason this is done is |
| 84 | // because buildLayer is not setup for injecting the animationHook, as well |
| 85 | // as this being otherwise wasted work as all the animators will be |
| 86 | // re-evaluated when the frame is actually drawn |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 87 | bool runAnimations = true; |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 88 | |
| 89 | // Must not be null during actual usage |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 90 | DamageAccumulator* damageAccumulator = nullptr; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 91 | |
| 92 | #if HWUI_NEW_OPS |
| 93 | LayerUpdateQueue* layerUpdateQueue = nullptr; |
| 94 | #else |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 95 | // The renderer that will be drawing the next frame. Use this to push any |
| 96 | // layer updates or similar. May be NULL. |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 97 | OpenGLRenderer* renderer = nullptr; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 98 | #endif |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 99 | ErrorHandler* errorHandler = nullptr; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 100 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 101 | // Optional, may be nullptr. Used to allow things to observe interesting |
| 102 | // tree state changes |
| 103 | TreeObserver* observer = nullptr; |
| 104 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 105 | int32_t windowInsetLeft = 0; |
| 106 | int32_t windowInsetTop = 0; |
| 107 | bool updateWindowPositions = false; |
| 108 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 109 | struct Out { |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 110 | bool hasFunctors = false; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 111 | // This is only updated if evaluateAnimations is true |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 112 | bool hasAnimations = false; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 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 |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 116 | bool requiresUiRedraw = false; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 117 | // This is set to true if draw() can be called this frame |
| 118 | // false means that we must delay until the next vsync pulse as frame |
| 119 | // production is outrunning consumption |
| 120 | // NOTE that if this is false CanvasContext will set either requiresUiRedraw |
| 121 | // *OR* will post itself for the next vsync automatically, use this |
| 122 | // only to avoid calling draw() |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 123 | bool canDrawThisFrame = true; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 124 | } out; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 125 | |
| 126 | // TODO: Damage calculations |
| 127 | }; |
| 128 | |
| 129 | } /* namespace uirenderer */ |
| 130 | } /* namespace android */ |
| 131 | |
| 132 | #endif /* TREEINFO_H */ |