blob: 4e9b24487b47a0aa6dbc2dd361e14dcd47b6b850 [file] [log] [blame]
John Reck668f0e32014-03-26 15:10:40 -07001/*
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 <utils/Condition.h>
20#include <utils/Mutex.h>
John Reck087bc0c2014-04-04 16:20:08 -070021#include <utils/StrongPointer.h>
John Reck668f0e32014-03-26 15:10:40 -070022#include <utils/Vector.h>
23
24#include "RenderTask.h"
25
26#include "../Rect.h"
27
28namespace android {
29namespace uirenderer {
30
31class DeferredLayerUpdater;
32class DisplayListData;
33class RenderNode;
34
35namespace renderthread {
36
37class CanvasContext;
38class RenderThread;
39
John Reck087bc0c2014-04-04 16:20:08 -070040class SetDisplayListData {
41public:
42 // This ctor exists for Vector's usage
43 SetDisplayListData();
44 SetDisplayListData(RenderNode* node, DisplayListData* newData);
45 ~SetDisplayListData();
46 void apply() const;
47private:
48 sp<RenderNode> mTargetNode;
49 DisplayListData* mNewData;
John Reck668f0e32014-03-26 15:10:40 -070050};
51
52/*
53 * This is a special Super Task. It is re-used multiple times by RenderProxy,
54 * and contains state (such as layer updaters & new DisplayListDatas) that is
55 * tracked across many frames not just a single frame.
56 * It is the sync-state task, and will kick off the post-sync draw
57 */
58class DrawFrameTask : public RenderTask {
59public:
60 DrawFrameTask();
61 virtual ~DrawFrameTask();
62
63 void setContext(CanvasContext* context);
64
65 void setDisplayListData(RenderNode* renderNode, DisplayListData* newData);
66 void addLayer(DeferredLayerUpdater* layer);
67 void removeLayer(DeferredLayerUpdater* layer);
68
69 void setRenderNode(RenderNode* renderNode);
70 void setDirty(int left, int top, int right, int bottom);
71 void drawFrame(RenderThread* renderThread);
John Reck087bc0c2014-04-04 16:20:08 -070072 void flushStateChanges(RenderThread* renderThread);
John Reck668f0e32014-03-26 15:10:40 -070073
74 virtual void run();
75
76private:
John Reck087bc0c2014-04-04 16:20:08 -070077 enum TaskMode {
78 MODE_INVALID,
79 MODE_FULL,
80 MODE_STATE_ONLY,
81 };
82
83 void postAndWait(RenderThread* renderThread, TaskMode mode);
John Reck668f0e32014-03-26 15:10:40 -070084 void syncFrameState();
85 void unblockUiThread();
86 static void drawRenderNode(CanvasContext* context, RenderNode* renderNode, Rect* dirty);
87
88 // This checks to see if there are any drawGlFunctors which would require
89 // a synchronous drawRenderNode()
90 static bool requiresSynchronousDraw(RenderNode* renderNode);
91
92 Mutex mLock;
93 Condition mSignal;
94
95 CanvasContext* mContext;
96
97 /*********************************************
98 * Single frame data
99 *********************************************/
John Reck087bc0c2014-04-04 16:20:08 -0700100 TaskMode mTaskMode;
101 sp<RenderNode> mRenderNode;
John Reck668f0e32014-03-26 15:10:40 -0700102 Rect mDirty;
103 Vector<SetDisplayListData> mDisplayListDataUpdates;
104
105 /*********************************************
106 * Multi frame data
107 *********************************************/
108 Vector<DeferredLayerUpdater*> mLayers;
109};
110
111} /* namespace renderthread */
112} /* namespace uirenderer */
113} /* namespace android */
114
115#endif /* DRAWFRAMETASK_H */