TreeInfo.h revision 3b20251a355c88193c439f928a84ae69483fb488
1e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/* 2e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Copyright (C) 2014 The Android Open Source Project 3e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 4e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 5e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * you may not use this file except in compliance with the License. 6e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * You may obtain a copy of the License at 7e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 8e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 9e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * 10e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Unless required by applicable law or agreed to in writing, software 11e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 12e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * See the License for the specific language governing permissions and 14e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * limitations under the License. 15e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck */ 16e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#ifndef TREEINFO_H 17e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#define TREEINFO_H 18e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 19c25e506f7fc08790c0532f927f31310a2ca778b7John Reck#include <string> 20c25e506f7fc08790c0532f927f31310a2ca778b7John Reck 21e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <utils/Timers.h> 22e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 23a447d29c65fb811cd184775a3476101a1cede929John Reck#include "DamageAccumulator.h" 24e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck#include "utils/Macros.h" 25e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 26e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace android { 27e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace uirenderer { 28e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 29ff941dcd815021bb20d6504eb486acb1e50592c3John Reckclass BaseRenderNodeAnimator; 3052244fff29042926e21fa897ef5ab11148e35299John Reckclass AnimationListener; 3125fbb3fa1138675379102a44405852555cefccbdJohn Reckclass OpenGLRenderer; 323b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState; 33e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 3452244fff29042926e21fa897ef5ab11148e35299John Reckclass AnimationHook { 35e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckpublic: 36ff941dcd815021bb20d6504eb486acb1e50592c3John Reck virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0; 37e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckprotected: 3852244fff29042926e21fa897ef5ab11148e35299John Reck ~AnimationHook() {} 39e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}; 40e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 41c25e506f7fc08790c0532f927f31310a2ca778b7John Reckclass ErrorHandler { 42c25e506f7fc08790c0532f927f31310a2ca778b7John Reckpublic: 43c25e506f7fc08790c0532f927f31310a2ca778b7John Reck virtual void onError(const std::string& message) = 0; 44c25e506f7fc08790c0532f927f31310a2ca778b7John Reckprotected: 45c25e506f7fc08790c0532f927f31310a2ca778b7John Reck ~ErrorHandler() {} 46c25e506f7fc08790c0532f927f31310a2ca778b7John Reck}; 47c25e506f7fc08790c0532f927f31310a2ca778b7John Reck 48e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 49e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckclass TreeInfo { 50e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck PREVENT_COPY_AND_ASSIGN(TreeInfo); 51e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckpublic: 52e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck enum TraversalMode { 53e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 54e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // May only be used if both the UI thread and RT thread are blocked on the 55e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // prepare 56e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck MODE_FULL, 57e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // Run only what can be done safely on RT thread. Currently this only means 58e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // animators, but potentially things like SurfaceTexture updates 59e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // could be handled by this as well if there are no listeners 60e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck MODE_RT_ONLY, 61e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // The subtree is being detached. Maybe. If the RenderNode is present 62e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // in both the old and new display list's children then it will get a 63e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL. 64e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // Push any pending display list changes in case it is detached, 65e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // but don't evaluate animators and such as if it isn't detached as a 66e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // MODE_FULL will follow shortly. 67e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck MODE_MAYBE_DETACHING, 68e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // TODO: TRIM_MEMORY? 69e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck }; 70e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck 713b20251a355c88193c439f928a84ae69483fb488John Reck explicit TreeInfo(TraversalMode mode, RenderState& renderState) 72e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck : mode(mode) 73e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck , frameTimeMs(0) 74f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck , animationHook(NULL) 75e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck , prepareTextures(mode == MODE_FULL) 76a447d29c65fb811cd184775a3476101a1cede929John Reck , damageAccumulator(NullDamageAccumulator::instance()) 773b20251a355c88193c439f928a84ae69483fb488John Reck , renderState(renderState) 783b20251a355c88193c439f928a84ae69483fb488John Reck , renderer(NULL) 793b20251a355c88193c439f928a84ae69483fb488John Reck , errorHandler(NULL) 80e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck {} 81e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 82e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck const TraversalMode mode; 83f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck nsecs_t frameTimeMs; 84f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck AnimationHook* animationHook; 85e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // TODO: Remove this? Currently this is used to signal to stop preparing 86e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck // textures if we run out of cache space. 87e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck bool prepareTextures; 88a447d29c65fb811cd184775a3476101a1cede929John Reck // Must not be null 89a447d29c65fb811cd184775a3476101a1cede929John Reck IDamageAccumulator* damageAccumulator; 903b20251a355c88193c439f928a84ae69483fb488John Reck RenderState& renderState; 9125fbb3fa1138675379102a44405852555cefccbdJohn Reck // The renderer that will be drawing the next frame. Use this to push any 9225fbb3fa1138675379102a44405852555cefccbdJohn Reck // layer updates or similar. May be NULL. 9325fbb3fa1138675379102a44405852555cefccbdJohn Reck OpenGLRenderer* renderer; 94c25e506f7fc08790c0532f927f31310a2ca778b7John Reck ErrorHandler* errorHandler; 95f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck 96f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck struct Out { 97f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck Out() 98f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck : hasFunctors(false) 99f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck , hasAnimations(false) 100f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck , requiresUiRedraw(false) 101a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck , canDrawThisFrame(true) 102f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck {} 103f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck bool hasFunctors; 104f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // This is only updated if evaluateAnimations is true 105f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck bool hasAnimations; 106f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // This is set to true if there is an animation that RenderThread cannot 107f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // animate itself, such as if hasFunctors is true 108f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // This is only set if hasAnimations is true 109f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck bool requiresUiRedraw; 110a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // This is set to true if draw() can be called this frame 111a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // false means that we must delay until the next vsync pulse as frame 112a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // production is outrunning consumption 113a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // NOTE that if this is false CanvasContext will set either requiresUiRedraw 114a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // *OR* will post itself for the next vsync automatically, use this 115a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck // only to avoid calling draw() 116a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck bool canDrawThisFrame; 117f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck } out; 118e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 119e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck // TODO: Damage calculations 120e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck}; 121e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 122e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */ 123e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */ 124e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck 125e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#endif /* TREEINFO_H */ 126