blob: 4130d4abe09e6ee00cdc8fa86016cfa68fbf11fc [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
Bo Liu2b739bb2021-11-10 19:20:03 -050023#include <optional>
24#include <vector>
John Reck668f0e32014-03-26 15:10:40 -070025
John Reckba6adf62015-02-19 14:36:50 -080026#include "../FrameInfo.h"
John Reck1bcacfd2017-11-03 10:12:19 -070027#include "../Rect.h"
John Recka5dda642014-05-22 15:43:54 -070028#include "../TreeInfo.h"
Bo Liu2b739bb2021-11-10 19:20:03 -050029#include "RenderTask.h"
Nader Jawada3521852023-01-30 20:23:46 -080030#include "SkColorSpace.h"
31#include "SwapBehavior.h"
32#include "utils/TimeUtils.h"
33#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
34#include <android/hardware_buffer.h>
35#endif
36#include "HardwareBufferRenderParams.h"
John Reck668f0e32014-03-26 15:10:40 -070037
38namespace android {
Nader Jawada3521852023-01-30 20:23:46 -080039
John Reck668f0e32014-03-26 15:10:40 -070040namespace uirenderer {
41
42class DeferredLayerUpdater;
John Reck668f0e32014-03-26 15:10:40 -070043class RenderNode;
44
45namespace renderthread {
46
47class CanvasContext;
48class RenderThread;
49
John Reck9a17da82016-04-18 11:17:52 -070050namespace SyncResult {
51enum {
52 OK = 0,
53 UIRedrawRequired = 1 << 0,
54 LostSurfaceRewardIfFound = 1 << 1,
55 ContextIsStopped = 1 << 2,
John Reckcc2eee82018-05-17 10:44:00 -070056 FrameDropped = 1 << 3,
John Reckf9be7792014-05-02 18:21:16 -070057};
John Reck9a17da82016-04-18 11:17:52 -070058}
John Reckf9be7792014-05-02 18:21:16 -070059
John Reck668f0e32014-03-26 15:10:40 -070060/*
61 * This is a special Super Task. It is re-used multiple times by RenderProxy,
Chris Craik003cc3d2015-10-16 10:24:55 -070062 * and contains state (such as layer updaters & new DisplayLists) that is
John Reck668f0e32014-03-26 15:10:40 -070063 * tracked across many frames not just a single frame.
64 * It is the sync-state task, and will kick off the post-sync draw
65 */
John Reckf8441e62017-10-23 13:10:41 -070066class DrawFrameTask {
John Reck668f0e32014-03-26 15:10:40 -070067public:
68 DrawFrameTask();
69 virtual ~DrawFrameTask();
70
Matt Buckleye9023cf2022-11-23 22:39:25 +000071 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
John Reckf138b172017-09-08 11:00:42 -070072 void setContentDrawBounds(int left, int top, int right, int bottom) {
73 mContentDrawBounds.set(left, top, right, bottom);
74 }
John Reck668f0e32014-03-26 15:10:40 -070075
John Reckd72e0a32014-05-29 18:56:11 -070076 void pushLayerUpdate(DeferredLayerUpdater* layer);
77 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070078
John Reck2de950d2017-01-25 10:58:30 -080079 int drawFrame();
John Reckba6adf62015-02-19 14:36:50 -080080
81 int64_t* frameInfo() { return mFrameInfo; }
John Reck668f0e32014-03-26 15:10:40 -070082
John Reckf8441e62017-10-23 13:10:41 -070083 void run();
John Reck668f0e32014-03-26 15:10:40 -070084
chaviwb6803712021-12-13 15:46:29 -060085 void setFrameCallback(std::function<std::function<void(bool)>(int32_t, int64_t)>&& callback) {
Mihai Popa95688002018-02-23 16:10:11 +000086 mFrameCallback = std::move(callback);
87 }
88
chaviw9c137532021-08-20 12:15:48 -050089 void setFrameCommitCallback(std::function<void(bool)>&& callback) {
90 mFrameCommitCallback = std::move(callback);
91 }
92
93 void setFrameCompleteCallback(std::function<void()>&& callback) {
John Reckcc2eee82018-05-17 10:44:00 -070094 mFrameCompleteCallback = std::move(callback);
95 }
96
chaviwadba0b12022-03-18 17:42:15 -050097 void forceDrawNextFrame() { mForceDrawFrame = true; }
98
Nader Jawada3521852023-01-30 20:23:46 -080099 void setHardwareBufferRenderParams(const HardwareBufferRenderParams& params) {
100 mHardwareBufferParams = params;
101 }
102
John Reck55887762023-01-25 16:51:18 -0500103 void setRenderSdrHdrRatio(float ratio) { mRenderSdrHdrRatio = ratio; }
104
John Reck668f0e32014-03-26 15:10:40 -0700105private:
John Reck18f16e62014-05-02 16:46:41 -0700106 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -0700107 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -0700108 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -0700109
John Reck668f0e32014-03-26 15:10:40 -0700110 Mutex mLock;
111 Condition mSignal;
112
John Reck18f16e62014-05-02 16:46:41 -0700113 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -0700114 CanvasContext* mContext;
Skuhneea7a7fb2015-08-28 07:10:31 -0700115 RenderNode* mTargetNode = nullptr;
John Reckf138b172017-09-08 11:00:42 -0700116 Rect mContentDrawBounds;
John Reck55887762023-01-25 16:51:18 -0500117 float mRenderSdrHdrRatio = 1.f;
John Reck668f0e32014-03-26 15:10:40 -0700118
119 /*********************************************
120 * Single frame data
121 *********************************************/
John Reck1bcacfd2017-11-03 10:12:19 -0700122 std::vector<sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -0700123
John Reckf9be7792014-05-02 18:21:16 -0700124 int mSyncResult;
John Reckbe3fba02015-07-06 13:49:58 -0700125 int64_t mSyncQueued;
John Reckba6adf62015-02-19 14:36:50 -0800126
127 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
Mihai Popa95688002018-02-23 16:10:11 +0000128
Nader Jawada3521852023-01-30 20:23:46 -0800129 HardwareBufferRenderParams mHardwareBufferParams;
chaviwb6803712021-12-13 15:46:29 -0600130 std::function<std::function<void(bool)>(int32_t, int64_t)> mFrameCallback;
chaviw9c137532021-08-20 12:15:48 -0500131 std::function<void(bool)> mFrameCommitCallback;
132 std::function<void()> mFrameCompleteCallback;
Bo Liu027b2182021-03-18 16:50:38 -0400133
chaviwadba0b12022-03-18 17:42:15 -0500134 bool mForceDrawFrame = false;
John Reck668f0e32014-03-26 15:10:40 -0700135};
136
137} /* namespace renderthread */
138} /* namespace uirenderer */
139} /* namespace android */
140
141#endif /* DRAWFRAMETASK_H */