blob: 3bb574aff59b8f3bed6c7d511fadffea22f4dd83 [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 Reckcc2eee82018-05-17 10:44:00 -070048 FrameDropped = 1 << 3,
John Reckf9be7792014-05-02 18:21:16 -070049};
John Reck9a17da82016-04-18 11:17:52 -070050}
John Reckf9be7792014-05-02 18:21:16 -070051
John Reck668f0e32014-03-26 15:10:40 -070052/*
53 * This is a special Super Task. It is re-used multiple times by RenderProxy,
Chris Craik003cc3d2015-10-16 10:24:55 -070054 * and contains state (such as layer updaters & new DisplayLists) that is
John Reck668f0e32014-03-26 15:10:40 -070055 * 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 */
John Reckf8441e62017-10-23 13:10:41 -070058class DrawFrameTask {
John Reck668f0e32014-03-26 15:10:40 -070059public:
60 DrawFrameTask();
61 virtual ~DrawFrameTask();
62
Skuhneea7a7fb2015-08-28 07:10:31 -070063 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
Bo Liu027b2182021-03-18 16:50:38 -040064 void setHintSessionCallbacks(std::function<void(int64_t)> updateTargetWorkDuration,
65 std::function<void(int64_t)> reportActualWorkDuration);
John Reckf138b172017-09-08 11:00:42 -070066 void setContentDrawBounds(int left, int top, int right, int bottom) {
67 mContentDrawBounds.set(left, top, right, bottom);
68 }
John Reck668f0e32014-03-26 15:10:40 -070069
John Reckd72e0a32014-05-29 18:56:11 -070070 void pushLayerUpdate(DeferredLayerUpdater* layer);
71 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070072
John Reck2de950d2017-01-25 10:58:30 -080073 int drawFrame();
John Reckba6adf62015-02-19 14:36:50 -080074
75 int64_t* frameInfo() { return mFrameInfo; }
John Reck668f0e32014-03-26 15:10:40 -070076
John Reckf8441e62017-10-23 13:10:41 -070077 void run();
John Reck668f0e32014-03-26 15:10:40 -070078
Mihai Popa95688002018-02-23 16:10:11 +000079 void setFrameCallback(std::function<void(int64_t)>&& callback) {
80 mFrameCallback = std::move(callback);
81 }
82
John Reckcc2eee82018-05-17 10:44:00 -070083 void setFrameCompleteCallback(std::function<void(int64_t)>&& callback) {
84 mFrameCompleteCallback = std::move(callback);
85 }
86
John Reck668f0e32014-03-26 15:10:40 -070087private:
John Reck18f16e62014-05-02 16:46:41 -070088 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070089 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070090 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070091
John Reck668f0e32014-03-26 15:10:40 -070092 Mutex mLock;
93 Condition mSignal;
94
John Reck18f16e62014-05-02 16:46:41 -070095 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070096 CanvasContext* mContext;
Skuhneea7a7fb2015-08-28 07:10:31 -070097 RenderNode* mTargetNode = nullptr;
John Reckf138b172017-09-08 11:00:42 -070098 Rect mContentDrawBounds;
John Reck668f0e32014-03-26 15:10:40 -070099
100 /*********************************************
101 * Single frame data
102 *********************************************/
John Reck1bcacfd2017-11-03 10:12:19 -0700103 std::vector<sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -0700104
John Reckf9be7792014-05-02 18:21:16 -0700105 int mSyncResult;
John Reckbe3fba02015-07-06 13:49:58 -0700106 int64_t mSyncQueued;
John Reckba6adf62015-02-19 14:36:50 -0800107
108 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
Mihai Popa95688002018-02-23 16:10:11 +0000109
110 std::function<void(int64_t)> mFrameCallback;
John Reckcc2eee82018-05-17 10:44:00 -0700111 std::function<void(int64_t)> mFrameCompleteCallback;
Bo Liu027b2182021-03-18 16:50:38 -0400112
113 nsecs_t mLastTargetWorkDuration = 0;
114 std::function<void(int64_t)> mUpdateTargetWorkDuration;
115 std::function<void(int64_t)> mReportActualWorkDuration;
John Reck668f0e32014-03-26 15:10:40 -0700116};
117
118} /* namespace renderthread */
119} /* namespace uirenderer */
120} /* namespace android */
121
122#endif /* DRAWFRAMETASK_H */