blob: 0037a0f4306d095685dacca187798cf24bb781e3 [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
John Reckba6adf62015-02-19 14:36:50 -080027#include "../FrameInfo.h"
John Reck1bcacfd2017-11-03 10:12:19 -070028#include "../Rect.h"
John Recka5dda642014-05-22 15:43:54 -070029#include "../TreeInfo.h"
John Reck668f0e32014-03-26 15:10:40 -070030
31namespace android {
32namespace uirenderer {
33
34class DeferredLayerUpdater;
John Reck668f0e32014-03-26 15:10:40 -070035class RenderNode;
36
37namespace renderthread {
38
39class CanvasContext;
40class RenderThread;
41
John Reck9a17da82016-04-18 11:17:52 -070042namespace SyncResult {
43enum {
44 OK = 0,
45 UIRedrawRequired = 1 << 0,
46 LostSurfaceRewardIfFound = 1 << 1,
47 ContextIsStopped = 1 << 2,
John Reckf9be7792014-05-02 18:21:16 -070048};
John Reck9a17da82016-04-18 11:17:52 -070049}
John Reckf9be7792014-05-02 18:21:16 -070050
John Reck668f0e32014-03-26 15:10:40 -070051/*
52 * This is a special Super Task. It is re-used multiple times by RenderProxy,
Chris Craik003cc3d2015-10-16 10:24:55 -070053 * and contains state (such as layer updaters & new DisplayLists) that is
John Reck668f0e32014-03-26 15:10:40 -070054 * tracked across many frames not just a single frame.
55 * It is the sync-state task, and will kick off the post-sync draw
56 */
John Reckf8441e62017-10-23 13:10:41 -070057class DrawFrameTask {
John Reck668f0e32014-03-26 15:10:40 -070058public:
59 DrawFrameTask();
60 virtual ~DrawFrameTask();
61
Skuhneea7a7fb2015-08-28 07:10:31 -070062 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
John Reckf138b172017-09-08 11:00:42 -070063 void setContentDrawBounds(int left, int top, int right, int bottom) {
64 mContentDrawBounds.set(left, top, right, bottom);
65 }
John Reck668f0e32014-03-26 15:10:40 -070066
John Reckd72e0a32014-05-29 18:56:11 -070067 void pushLayerUpdate(DeferredLayerUpdater* layer);
68 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070069
John Reck2de950d2017-01-25 10:58:30 -080070 int drawFrame();
John Reckba6adf62015-02-19 14:36:50 -080071
72 int64_t* frameInfo() { return mFrameInfo; }
John Reck668f0e32014-03-26 15:10:40 -070073
John Reckf8441e62017-10-23 13:10:41 -070074 void run();
John Reck668f0e32014-03-26 15:10:40 -070075
Mihai Popa95688002018-02-23 16:10:11 +000076 void setFrameCallback(std::function<void(int64_t)>&& callback) {
77 mFrameCallback = std::move(callback);
78 }
79
John Reck668f0e32014-03-26 15:10:40 -070080private:
John Reck18f16e62014-05-02 16:46:41 -070081 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070082 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070083 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070084
John Reck668f0e32014-03-26 15:10:40 -070085 Mutex mLock;
86 Condition mSignal;
87
John Reck18f16e62014-05-02 16:46:41 -070088 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070089 CanvasContext* mContext;
Skuhneea7a7fb2015-08-28 07:10:31 -070090 RenderNode* mTargetNode = nullptr;
John Reckf138b172017-09-08 11:00:42 -070091 Rect mContentDrawBounds;
John Reck668f0e32014-03-26 15:10:40 -070092
93 /*********************************************
94 * Single frame data
95 *********************************************/
John Reck1bcacfd2017-11-03 10:12:19 -070096 std::vector<sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -070097
John Reckf9be7792014-05-02 18:21:16 -070098 int mSyncResult;
John Reckbe3fba02015-07-06 13:49:58 -070099 int64_t mSyncQueued;
John Reckba6adf62015-02-19 14:36:50 -0800100
101 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
Mihai Popa95688002018-02-23 16:10:11 +0000102
103 std::function<void(int64_t)> mFrameCallback;
John Reck668f0e32014-03-26 15:10:40 -0700104};
105
106} /* namespace renderthread */
107} /* namespace uirenderer */
108} /* namespace android */
109
110#endif /* DRAWFRAMETASK_H */