| 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 | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 23 | #include "DamageAccumulator.h" | 
| John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 24 | #include "utils/Macros.h" | 
|  | 25 |  | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 26 | namespace android { | 
|  | 27 | namespace uirenderer { | 
|  | 28 |  | 
| John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 29 | class BaseRenderNodeAnimator; | 
| John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 30 | class AnimationListener; | 
| John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 31 | class OpenGLRenderer; | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 32 |  | 
| John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 33 | class AnimationHook { | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 34 | public: | 
| John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 35 | virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0; | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 36 | protected: | 
| John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 37 | ~AnimationHook() {} | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 38 | }; | 
|  | 39 |  | 
| John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame^] | 40 | class ErrorHandler { | 
|  | 41 | public: | 
|  | 42 | virtual void onError(const std::string& message) = 0; | 
|  | 43 | protected: | 
|  | 44 | ~ErrorHandler() {} | 
|  | 45 | }; | 
|  | 46 |  | 
| John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 47 | // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN | 
|  | 48 | class TreeInfo { | 
|  | 49 | PREVENT_COPY_AND_ASSIGN(TreeInfo); | 
|  | 50 | public: | 
|  | 51 | enum TraversalMode { | 
|  | 52 | // The full monty - sync, push, run animators, etc... Used by DrawFrameTask | 
|  | 53 | // May only be used if both the UI thread and RT thread are blocked on the | 
|  | 54 | // prepare | 
|  | 55 | MODE_FULL, | 
|  | 56 | // Run only what can be done safely on RT thread. Currently this only means | 
|  | 57 | // animators, but potentially things like SurfaceTexture updates | 
|  | 58 | // could be handled by this as well if there are no listeners | 
|  | 59 | MODE_RT_ONLY, | 
|  | 60 | // The subtree is being detached. Maybe. If the RenderNode is present | 
|  | 61 | // in both the old and new display list's children then it will get a | 
|  | 62 | // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL. | 
|  | 63 | // Push any pending display list changes in case it is detached, | 
|  | 64 | // but don't evaluate animators and such as if it isn't detached as a | 
|  | 65 | // MODE_FULL will follow shortly. | 
|  | 66 | MODE_MAYBE_DETACHING, | 
|  | 67 | // TODO: TRIM_MEMORY? | 
|  | 68 | }; | 
|  | 69 |  | 
|  | 70 | explicit TreeInfo(TraversalMode mode) | 
|  | 71 | : mode(mode) | 
|  | 72 | , frameTimeMs(0) | 
| John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 73 | , animationHook(NULL) | 
| John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 74 | , prepareTextures(mode == MODE_FULL) | 
| John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 75 | , damageAccumulator(NullDamageAccumulator::instance()) | 
| John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 76 | , renderer(0) | 
| John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame^] | 77 | , errorHandler(0) | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 78 | {} | 
|  | 79 |  | 
| John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 80 | const TraversalMode mode; | 
| John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 81 | nsecs_t frameTimeMs; | 
|  | 82 | AnimationHook* animationHook; | 
| John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 83 | // TODO: Remove this? Currently this is used to signal to stop preparing | 
|  | 84 | // textures if we run out of cache space. | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 85 | bool prepareTextures; | 
| John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 86 | // Must not be null | 
|  | 87 | IDamageAccumulator* damageAccumulator; | 
| John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 88 | // The renderer that will be drawing the next frame. Use this to push any | 
|  | 89 | // layer updates or similar. May be NULL. | 
|  | 90 | OpenGLRenderer* renderer; | 
| John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame^] | 91 | ErrorHandler* errorHandler; | 
| John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | struct Out { | 
|  | 94 | Out() | 
|  | 95 | : hasFunctors(false) | 
|  | 96 | , hasAnimations(false) | 
|  | 97 | , requiresUiRedraw(false) | 
| John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 98 | , canDrawThisFrame(true) | 
| John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 99 | {} | 
|  | 100 | bool hasFunctors; | 
|  | 101 | // This is only updated if evaluateAnimations is true | 
|  | 102 | bool hasAnimations; | 
|  | 103 | // This is set to true if there is an animation that RenderThread cannot | 
|  | 104 | // animate itself, such as if hasFunctors is true | 
|  | 105 | // This is only set if hasAnimations is true | 
|  | 106 | bool requiresUiRedraw; | 
| John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 107 | // This is set to true if draw() can be called this frame | 
|  | 108 | // false means that we must delay until the next vsync pulse as frame | 
|  | 109 | // production is outrunning consumption | 
|  | 110 | // NOTE that if this is false CanvasContext will set either requiresUiRedraw | 
|  | 111 | // *OR* will post itself for the next vsync automatically, use this | 
|  | 112 | // only to avoid calling draw() | 
|  | 113 | bool canDrawThisFrame; | 
| John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 114 | } out; | 
| John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | // TODO: Damage calculations | 
|  | 117 | }; | 
|  | 118 |  | 
|  | 119 | } /* namespace uirenderer */ | 
|  | 120 | } /* namespace android */ | 
|  | 121 |  | 
|  | 122 | #endif /* TREEINFO_H */ |