blob: 30c8880ce54680cae7f5c7d4639a95638d800c51 [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"
John Recka5dda642014-05-22 15:43:54 -070027#include "../TreeInfo.h"
John Reck668f0e32014-03-26 15:10:40 -070028
29namespace android {
30namespace uirenderer {
31
32class DeferredLayerUpdater;
33class DisplayListData;
34class RenderNode;
35
36namespace renderthread {
37
38class CanvasContext;
39class RenderThread;
40
John Reckf9be7792014-05-02 18:21:16 -070041enum SyncResult {
42 kSync_OK = 0,
43 kSync_UIRedrawRequired = 1 << 1,
44};
45
John Reck668f0e32014-03-26 15:10:40 -070046/*
47 * This is a special Super Task. It is re-used multiple times by RenderProxy,
48 * and contains state (such as layer updaters & new DisplayListDatas) that is
49 * tracked across many frames not just a single frame.
50 * It is the sync-state task, and will kick off the post-sync draw
51 */
52class DrawFrameTask : public RenderTask {
53public:
54 DrawFrameTask();
55 virtual ~DrawFrameTask();
56
John Reck18f16e62014-05-02 16:46:41 -070057 void setContext(RenderThread* thread, CanvasContext* context);
John Reck668f0e32014-03-26 15:10:40 -070058
John Reck668f0e32014-03-26 15:10:40 -070059 void addLayer(DeferredLayerUpdater* layer);
60 void removeLayer(DeferredLayerUpdater* layer);
61
John Reck668f0e32014-03-26 15:10:40 -070062 void setDirty(int left, int top, int right, int bottom);
John Reckfe5e7b72014-05-23 17:42:28 -070063 void setDensity(float density) { mDensity = density; }
64 int drawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos);
John Reck668f0e32014-03-26 15:10:40 -070065
66 virtual void run();
67
68private:
John Reck18f16e62014-05-02 16:46:41 -070069 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070070 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070071 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070072
John Reck668f0e32014-03-26 15:10:40 -070073 Mutex mLock;
74 Condition mSignal;
75
John Reck18f16e62014-05-02 16:46:41 -070076 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070077 CanvasContext* mContext;
78
79 /*********************************************
80 * Single frame data
81 *********************************************/
John Reck668f0e32014-03-26 15:10:40 -070082 Rect mDirty;
John Reck18f16e62014-05-02 16:46:41 -070083 nsecs_t mFrameTimeNanos;
John Reckfe5e7b72014-05-23 17:42:28 -070084 nsecs_t mRecordDurationNanos;
85 float mDensity;
John Reck668f0e32014-03-26 15:10:40 -070086
John Reckf9be7792014-05-02 18:21:16 -070087 int mSyncResult;
88
John Reck668f0e32014-03-26 15:10:40 -070089 /*********************************************
90 * Multi frame data
91 *********************************************/
92 Vector<DeferredLayerUpdater*> mLayers;
93};
94
95} /* namespace renderthread */
96} /* namespace uirenderer */
97} /* namespace android */
98
99#endif /* DRAWFRAMETASK_H */