blob: 2c46762fee5c304d3288a39bffe5905ad5cfaecc [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;
Chris Craik003cc3d2015-10-16 10:24:55 -070035class DisplayList;
John Reck668f0e32014-03-26 15:10:40 -070036class RenderNode;
37
38namespace renderthread {
39
40class CanvasContext;
41class RenderThread;
42
John Reck9a17da82016-04-18 11:17:52 -070043namespace SyncResult {
44enum {
45 OK = 0,
46 UIRedrawRequired = 1 << 0,
47 LostSurfaceRewardIfFound = 1 << 1,
48 ContextIsStopped = 1 << 2,
John Reck5b02c622018-05-17 10:44:00 -070049 FrameDropped = 1 << 3,
John Reckf9be7792014-05-02 18:21:16 -070050};
John Reck9a17da82016-04-18 11:17:52 -070051}
John Reckf9be7792014-05-02 18:21:16 -070052
John Reck668f0e32014-03-26 15:10:40 -070053/*
54 * This is a special Super Task. It is re-used multiple times by RenderProxy,
Chris Craik003cc3d2015-10-16 10:24:55 -070055 * and contains state (such as layer updaters & new DisplayLists) that is
John Reck668f0e32014-03-26 15:10:40 -070056 * tracked across many frames not just a single frame.
57 * It is the sync-state task, and will kick off the post-sync draw
58 */
John Reckf8441e62017-10-23 13:10:41 -070059class DrawFrameTask {
John Reck668f0e32014-03-26 15:10:40 -070060public:
61 DrawFrameTask();
62 virtual ~DrawFrameTask();
63
Skuhneea7a7fb2015-08-28 07:10:31 -070064 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
John Reckf138b172017-09-08 11:00:42 -070065 void setContentDrawBounds(int left, int top, int right, int bottom) {
66 mContentDrawBounds.set(left, top, right, bottom);
67 }
John Reck668f0e32014-03-26 15:10:40 -070068
John Reckd72e0a32014-05-29 18:56:11 -070069 void pushLayerUpdate(DeferredLayerUpdater* layer);
70 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070071
John Reck2de950d2017-01-25 10:58:30 -080072 int drawFrame();
John Reckba6adf62015-02-19 14:36:50 -080073
74 int64_t* frameInfo() { return mFrameInfo; }
John Reck668f0e32014-03-26 15:10:40 -070075
John Reckf8441e62017-10-23 13:10:41 -070076 void run();
John Reck668f0e32014-03-26 15:10:40 -070077
Mihai Popa95688002018-02-23 16:10:11 +000078 void setFrameCallback(std::function<void(int64_t)>&& callback) {
79 mFrameCallback = std::move(callback);
80 }
81
John Reck5b02c622018-05-17 10:44:00 -070082 void setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
83 mFrameCompleteCallback = std::move(callback);
84 }
85
John Reck668f0e32014-03-26 15:10:40 -070086private:
John Reck18f16e62014-05-02 16:46:41 -070087 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070088 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070089 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070090
John Reck668f0e32014-03-26 15:10:40 -070091 Mutex mLock;
92 Condition mSignal;
93
John Reck18f16e62014-05-02 16:46:41 -070094 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070095 CanvasContext* mContext;
Skuhneea7a7fb2015-08-28 07:10:31 -070096 RenderNode* mTargetNode = nullptr;
John Reckf138b172017-09-08 11:00:42 -070097 Rect mContentDrawBounds;
John Reck668f0e32014-03-26 15:10:40 -070098
99 /*********************************************
100 * Single frame data
101 *********************************************/
John Reck1bcacfd2017-11-03 10:12:19 -0700102 std::vector<sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -0700103
John Reckf9be7792014-05-02 18:21:16 -0700104 int mSyncResult;
John Reckbe3fba02015-07-06 13:49:58 -0700105 int64_t mSyncQueued;
John Reckba6adf62015-02-19 14:36:50 -0800106
107 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
Mihai Popa95688002018-02-23 16:10:11 +0000108
109 std::function<void(int64_t)> mFrameCallback;
John Reck5b02c622018-05-17 10:44:00 -0700110 std::function<void(int64_t)> mFrameCompleteCallback;
John Reck668f0e32014-03-26 15:10:40 -0700111};
112
113} /* namespace renderthread */
114} /* namespace uirenderer */
115} /* namespace android */
116
117#endif /* DRAWFRAMETASK_H */