blob: 953f012dafbc7ba1a29f2b919fe03715ff457f57 [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
John Reckd72e0a32014-05-29 18:56:11 -070019#include <vector>
20
John Reck668f0e32014-03-26 15:10:40 -070021#include <utils/Condition.h>
22#include <utils/Mutex.h>
John Reck087bc0c2014-04-04 16:20:08 -070023#include <utils/StrongPointer.h>
John Reck668f0e32014-03-26 15:10:40 -070024
25#include "RenderTask.h"
26
27#include "../Rect.h"
John Recka5dda642014-05-22 15:43:54 -070028#include "../TreeInfo.h"
John Reck668f0e32014-03-26 15:10:40 -070029
30namespace android {
31namespace uirenderer {
32
33class DeferredLayerUpdater;
34class DisplayListData;
35class RenderNode;
36
37namespace renderthread {
38
39class CanvasContext;
40class RenderThread;
41
John Reckf9be7792014-05-02 18:21:16 -070042enum SyncResult {
43 kSync_OK = 0,
John Reckcd028f32014-06-24 08:44:29 -070044 kSync_UIRedrawRequired = 1 << 0,
John Reckaa95a882014-11-07 11:02:07 -080045 kSync_LostSurfaceRewardIfFound = 1 << 1,
John Reckf9be7792014-05-02 18:21:16 -070046};
47
John Reck668f0e32014-03-26 15:10:40 -070048/*
49 * This is a special Super Task. It is re-used multiple times by RenderProxy,
50 * and contains state (such as layer updaters & new DisplayListDatas) that is
51 * tracked across many frames not just a single frame.
52 * It is the sync-state task, and will kick off the post-sync draw
53 */
54class DrawFrameTask : public RenderTask {
55public:
56 DrawFrameTask();
57 virtual ~DrawFrameTask();
58
John Reck18f16e62014-05-02 16:46:41 -070059 void setContext(RenderThread* thread, CanvasContext* context);
John Reck668f0e32014-03-26 15:10:40 -070060
John Reckd72e0a32014-05-29 18:56:11 -070061 void pushLayerUpdate(DeferredLayerUpdater* layer);
62 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070063
John Reckfe5e7b72014-05-23 17:42:28 -070064 void setDensity(float density) { mDensity = density; }
65 int drawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos);
John Reck668f0e32014-03-26 15:10:40 -070066
Chris Craikd41c4d82015-01-05 15:51:13 -080067 virtual void run() override;
John Reck668f0e32014-03-26 15:10:40 -070068
69private:
John Reck18f16e62014-05-02 16:46:41 -070070 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070071 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070072 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070073
John Reck668f0e32014-03-26 15:10:40 -070074 Mutex mLock;
75 Condition mSignal;
76
John Reck18f16e62014-05-02 16:46:41 -070077 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070078 CanvasContext* mContext;
79
80 /*********************************************
81 * Single frame data
82 *********************************************/
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 Reckd72e0a32014-05-29 18:56:11 -070086 std::vector< sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -070087
John Reckf9be7792014-05-02 18:21:16 -070088 int mSyncResult;
John Reck668f0e32014-03-26 15:10:40 -070089};
90
91} /* namespace renderthread */
92} /* namespace uirenderer */
93} /* namespace android */
94
95#endif /* DRAWFRAMETASK_H */