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 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 19 | #include <string> |
| 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 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 23 | #include "utils/Macros.h" |
| 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; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 33 | class OpenGLRenderer; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 34 | class RenderState; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 35 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 36 | class ErrorHandler { |
| 37 | public: |
| 38 | virtual void onError(const std::string& message) = 0; |
| 39 | protected: |
| 40 | ~ErrorHandler() {} |
| 41 | }; |
| 42 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 43 | // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN |
| 44 | class TreeInfo { |
| 45 | PREVENT_COPY_AND_ASSIGN(TreeInfo); |
| 46 | public: |
| 47 | enum TraversalMode { |
| 48 | // The full monty - sync, push, run animators, etc... Used by DrawFrameTask |
| 49 | // May only be used if both the UI thread and RT thread are blocked on the |
| 50 | // prepare |
| 51 | MODE_FULL, |
| 52 | // Run only what can be done safely on RT thread. Currently this only means |
| 53 | // animators, but potentially things like SurfaceTexture updates |
| 54 | // could be handled by this as well if there are no listeners |
| 55 | MODE_RT_ONLY, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 58 | explicit TreeInfo(TraversalMode mode, RenderState& renderState) |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 59 | : mode(mode) |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 60 | , prepareTextures(mode == MODE_FULL) |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 61 | , runAnimations(true) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 62 | , damageAccumulator(nullptr) |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 63 | , renderState(renderState) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 64 | , renderer(nullptr) |
| 65 | , errorHandler(nullptr) |
| 66 | , canvasContext(nullptr) |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 67 | {} |
| 68 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 69 | explicit TreeInfo(TraversalMode mode, const TreeInfo& clone) |
| 70 | : mode(mode) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 71 | , prepareTextures(mode == MODE_FULL) |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 72 | , runAnimations(clone.runAnimations) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 73 | , damageAccumulator(clone.damageAccumulator) |
| 74 | , renderState(clone.renderState) |
| 75 | , renderer(clone.renderer) |
| 76 | , errorHandler(clone.errorHandler) |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 77 | , canvasContext(clone.canvasContext) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 78 | {} |
| 79 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 80 | const TraversalMode mode; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 81 | // TODO: Remove this? Currently this is used to signal to stop preparing |
| 82 | // textures if we run out of cache space. |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 83 | bool prepareTextures; |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 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; |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 90 | |
| 91 | // Must not be null during actual usage |
| 92 | DamageAccumulator* damageAccumulator; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 93 | RenderState& renderState; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 94 | // The renderer that will be drawing the next frame. Use this to push any |
| 95 | // layer updates or similar. May be NULL. |
| 96 | OpenGLRenderer* renderer; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 97 | ErrorHandler* errorHandler; |
John Reck | 00e79c9 | 2015-07-21 10:23:59 -0700 | [diff] [blame] | 98 | // May be NULL (TODO: can it really?) |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 99 | renderthread::CanvasContext* canvasContext; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 100 | |
| 101 | struct Out { |
| 102 | Out() |
| 103 | : hasFunctors(false) |
| 104 | , hasAnimations(false) |
| 105 | , requiresUiRedraw(false) |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 106 | , canDrawThisFrame(true) |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 107 | {} |
| 108 | bool hasFunctors; |
| 109 | // This is only updated if evaluateAnimations is true |
| 110 | bool hasAnimations; |
| 111 | // This is set to true if there is an animation that RenderThread cannot |
| 112 | // animate itself, such as if hasFunctors is true |
| 113 | // This is only set if hasAnimations is true |
| 114 | bool requiresUiRedraw; |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 115 | // This is set to true if draw() can be called this frame |
| 116 | // false means that we must delay until the next vsync pulse as frame |
| 117 | // production is outrunning consumption |
| 118 | // NOTE that if this is false CanvasContext will set either requiresUiRedraw |
| 119 | // *OR* will post itself for the next vsync automatically, use this |
| 120 | // only to avoid calling draw() |
| 121 | bool canDrawThisFrame; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 122 | } out; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 123 | |
| 124 | // TODO: Damage calculations |
| 125 | }; |
| 126 | |
| 127 | } /* namespace uirenderer */ |
| 128 | } /* namespace android */ |
| 129 | |
| 130 | #endif /* TREEINFO_H */ |