DrawFrameTask.h revision 51f2d606dcbfba3cc5b03dfea37c1304b91c232f
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 DRAWFRAMETASK_H 17#define DRAWFRAMETASK_H 18 19#include <vector> 20 21#include <utils/Condition.h> 22#include <utils/Mutex.h> 23#include <utils/StrongPointer.h> 24 25#include "RenderTask.h" 26 27#include "../Rect.h" 28#include "../FrameInfo.h" 29#include "../TreeInfo.h" 30 31namespace android { 32namespace uirenderer { 33 34class DeferredLayerUpdater; 35class DisplayList; 36class RenderNode; 37 38namespace renderthread { 39 40class CanvasContext; 41class RenderThread; 42 43enum SyncResult { 44 kSync_OK = 0, 45 kSync_UIRedrawRequired = 1 << 0, 46 kSync_LostSurfaceRewardIfFound = 1 << 1, 47}; 48 49/* 50 * This is a special Super Task. It is re-used multiple times by RenderProxy, 51 * and contains state (such as layer updaters & new DisplayLists) that is 52 * tracked across many frames not just a single frame. 53 * It is the sync-state task, and will kick off the post-sync draw 54 */ 55class DrawFrameTask : public RenderTask { 56public: 57 DrawFrameTask(); 58 virtual ~DrawFrameTask(); 59 60 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode); 61 62 void pushLayerUpdate(DeferredLayerUpdater* layer); 63 void removeLayerUpdate(DeferredLayerUpdater* layer); 64 65 int drawFrame(TreeObserver* observer); 66 67 int64_t* frameInfo() { return mFrameInfo; } 68 69 virtual void run() override; 70 71private: 72 void postAndWait(); 73 bool syncFrameState(TreeInfo& info); 74 void unblockUiThread(); 75 76 Mutex mLock; 77 Condition mSignal; 78 79 RenderThread* mRenderThread; 80 CanvasContext* mContext; 81 RenderNode* mTargetNode = nullptr; 82 83 /********************************************* 84 * Single frame data 85 *********************************************/ 86 std::vector< sp<DeferredLayerUpdater> > mLayers; 87 88 int mSyncResult; 89 int64_t mSyncQueued; 90 TreeObserver* mObserver; 91 92 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE]; 93}; 94 95} /* namespace renderthread */ 96} /* namespace uirenderer */ 97} /* namespace android */ 98 99#endif /* DRAWFRAMETASK_H */ 100