TreeInfo.h revision 998a6d81896df8b662cc10ddeb35087b78b38d72
151769a68a5cb34e9564740c6a854fcb93018789dRomain Guy/* 251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * Copyright (C) 2014 The Android Open Source Project 351769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * 451769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 551769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * you may not use this file except in compliance with the License. 651769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * You may obtain a copy of the License at 751769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * 851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * http://www.apache.org/licenses/LICENSE-2.0 951769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * 1051769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * Unless required by applicable law or agreed to in writing, software 1151769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * distributed under the License is distributed on an "AS IS" BASIS, 1251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1351769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * See the License for the specific language governing permissions and 1451769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * limitations under the License. 1551769a68a5cb34e9564740c6a854fcb93018789dRomain Guy */ 1651769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#ifndef TREEINFO_H 175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define TREEINFO_H 185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 1951769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include <string> 20fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy 21e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy#include <utils/Timers.h> 222507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik 23fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "DamageAccumulator.h" 2451769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "utils/Macros.h" 2551769a68a5cb34e9564740c6a854fcb93018789dRomain Guy 2651769a68a5cb34e9564740c6a854fcb93018789dRomain Guynamespace android { 2751769a68a5cb34e9564740c6a854fcb93018789dRomain Guynamespace uirenderer { 2851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy 292507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craiknamespace renderthread { 302507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craikclass CanvasContext; 312507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik} 32cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy 33cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guyclass OpenGLRenderer; 34cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guyclass RenderState; 35cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy 36726aeba80ffc6778a9bc3e0ee957b8d644183505Romain Guyclass ErrorHandler { 37726aeba80ffc6778a9bc3e0ee957b8d644183505Romain Guypublic: 38726aeba80ffc6778a9bc3e0ee957b8d644183505Romain Guy virtual void onError(const std::string& message) = 0; 3928d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guyprotected: 4028d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guy ~ErrorHandler() {} 4128d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guy}; 4228d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guy 4328d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guy// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN 4428d8ff6dbcc1b137131c70b72b4dbd211db7fbd9Romain Guyclass TreeInfo { 458d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy PREVENT_COPY_AND_ASSIGN(TreeInfo); 46ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guypublic: 478d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy enum TraversalMode { 487c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy // The full monty - sync, push, run animators, etc... Used by DrawFrameTask 49530041d3191ce817832a0108514617768e43cda6Romain Guy // May only be used if both the UI thread and RT thread are blocked on the 50cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy // prepare 51cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy MODE_FULL, 52cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy // Run only what can be done safely on RT thread. Currently this only means 53cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy // animators, but potentially things like SurfaceTexture updates 54e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy // could be handled by this as well if there are no listeners 554ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy MODE_RT_ONLY, 564ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy }; 57e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy 584ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy explicit TreeInfo(TraversalMode mode, RenderState& renderState) 59e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy : mode(mode) 60e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , prepareTextures(mode == MODE_FULL) 61e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , runAnimations(true) 62e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , damageAccumulator(NULL) 63e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , renderState(renderState) 64e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , renderer(NULL) 65e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy , errorHandler(NULL) 6625dc3a7dbac2f90f5144035e9c8ed99c09cc3132Romain Guy , canvasContext(NULL) 67042f7d64b5ccd7b5b73e7e9814a84576f04fb7d4Kenny Root {} 68e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy 69e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy explicit TreeInfo(TraversalMode mode, const TreeInfo& clone) 704ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy : mode(mode) 717c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy , prepareTextures(mode == MODE_FULL) 724ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy , runAnimations(clone.runAnimations) 734ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy , damageAccumulator(clone.damageAccumulator) 744ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy , renderState(clone.renderState) 754ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy , renderer(clone.renderer) 767c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy , errorHandler(clone.errorHandler) 77627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy , canvasContext(clone.canvasContext) 78627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy {} 79627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy 80627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy const TraversalMode mode; 81627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy // TODO: Remove this? Currently this is used to signal to stop preparing 82627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy // textures if we run out of cache space. 83627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy bool prepareTextures; 84627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy // TODO: buildLayer uses this to suppress running any animations, but this 85627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy // should probably be refactored somehow. The reason this is done is 867c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy // because buildLayer is not setup for injecting the animationHook, as well 8778dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy // as this being otherwise wasted work as all the animators will be 887c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy // re-evaluated when the frame is actually drawn 8987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy bool runAnimations; 9031e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy 9131e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy // Must not be null during actual usage 9231e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy DamageAccumulator* damageAccumulator; 9331e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy RenderState& renderState; 9431e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy // The renderer that will be drawing the next frame. Use this to push any 9531e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy // layer updates or similar. May be NULL. 96fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck OpenGLRenderer* renderer; 97fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck ErrorHandler* errorHandler; 98fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // TODO: Remove this? May be NULL 99fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck renderthread::CanvasContext* canvasContext; 100fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 101fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck struct Out { 102fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck Out() 103fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck : hasFunctors(false) 104fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck , hasAnimations(false) 105fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck , requiresUiRedraw(false) 106fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck , canDrawThisFrame(true) 107fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck {} 108fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck bool hasFunctors; 109fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // This is only updated if evaluateAnimations is true 110fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck bool hasAnimations; 111fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // This is set to true if there is an animation that RenderThread cannot 112fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // animate itself, such as if hasFunctors is true 113fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // This is only set if hasAnimations is true 114fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck bool requiresUiRedraw; 115fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // This is set to true if draw() can be called this frame 116fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // false means that we must delay until the next vsync pulse as frame 117fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // production is outrunning consumption 118fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // NOTE that if this is false CanvasContext will set either requiresUiRedraw 119fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // *OR* will post itself for the next vsync automatically, use this 120fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // only to avoid calling draw() 121fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck bool canDrawThisFrame; 122fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck } out; 123fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 124fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck // TODO: Damage calculations 125fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck}; 1263ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy 1273ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy} /* namespace uirenderer */ 1283ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy} /* namespace android */ 1293ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy 1303ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy#endif /* TREEINFO_H */ 1313ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy