Debian Codegraph @

libs/hwui/renderthread/DrawFrameTask.h

raw symbols SCIP
1 /*
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 <android/performance_hint.h>
20 #include <utils/Condition.h>
21 #include <utils/Mutex.h>
22 #include <utils/StrongPointer.h>
23
24 #include <optional>
25 #include <vector>
26
27 #include "../FrameInfo.h"
28 #include "../Rect.h"
29 #include "../TreeInfo.h"
30 #include "RenderTask.h"
31
32 namespace android {
33 namespace uirenderer {
34
35 class DeferredLayerUpdater;
36 class RenderNode;
37
38 namespace renderthread {
39
40 class CanvasContext;
41 class RenderThread;
42
43 namespace SyncResult {
44 enum {
45 OK = 0,
46 UIRedrawRequired = 1 << 0,
47 LostSurfaceRewardIfFound = 1 << 1,
48 ContextIsStopped = 1 << 2,
49 FrameDropped = 1 << 3,
50 };
51 }
52
53 /*
54 * This is a special Super Task. It is re-used multiple times by RenderProxy,
55 * and contains state (such as layer updaters & new DisplayLists) that is
56 * 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 */
59 class DrawFrameTask {
60 public:
61 DrawFrameTask();
62 virtual ~DrawFrameTask();
63
64 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode,
65 int32_t uiThreadId, int32_t renderThreadId);
66 void setContentDrawBounds(int left, int top, int right, int bottom) {
67 mContentDrawBounds.set(left, top, right, bottom);
68 }
69
70 void pushLayerUpdate(DeferredLayerUpdater* layer);
71 void removeLayerUpdate(DeferredLayerUpdater* layer);
72
73 int drawFrame();
74
75 int64_t* frameInfo() { return mFrameInfo; }
76
77 void run();
78
79 void setFrameCallback(std::function<std::function<void(bool)>(int32_t, int64_t)>&& callback) {
80 mFrameCallback = std::move(callback);
81 }
82
83 void setFrameCommitCallback(std::function<void(bool)>&& callback) {
84 mFrameCommitCallback = std::move(callback);
85 }
86
87 void setFrameCompleteCallback(std::function<void()>&& callback) {
88 mFrameCompleteCallback = std::move(callback);
89 }
90
91 void forceDrawNextFrame() { mForceDrawFrame = true; }
92
93 private:
94 class HintSessionWrapper {
95 public:
96 HintSessionWrapper(int32_t uiThreadId, int32_t renderThreadId);
97 ~HintSessionWrapper();
98
99 void updateTargetWorkDuration(long targetDurationNanos);
100 void reportActualWorkDuration(long actualDurationNanos);
101
102 private:
103 APerformanceHintSession* mHintSession = nullptr;
104 };
105
106 void postAndWait();
107 bool syncFrameState(TreeInfo& info);
108 void unblockUiThread();
109
110 Mutex mLock;
111 Condition mSignal;
112
113 RenderThread* mRenderThread;
114 CanvasContext* mContext;
115 RenderNode* mTargetNode = nullptr;
116 int32_t mUiThreadId = -1;
117 int32_t mRenderThreadId = -1;
118 Rect mContentDrawBounds;
119
120 /*********************************************
121 * Single frame data
122 *********************************************/
123 std::vector<sp<DeferredLayerUpdater> > mLayers;
124
125 int mSyncResult;
126 int64_t mSyncQueued;
127
128 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
129
130 std::function<std::function<void(bool)>(int32_t, int64_t)> mFrameCallback;
131 std::function<void(bool)> mFrameCommitCallback;
132 std::function<void()> mFrameCompleteCallback;
133
134 nsecs_t mLastDequeueBufferDuration = 0;
135 nsecs_t mLastTargetWorkDuration = 0;
136 std::optional<HintSessionWrapper> mHintSessionWrapper;
137
138 bool mForceDrawFrame = false;
139 };
140
141 } /* namespace renderthread */
142 } /* namespace uirenderer */
143 } /* namespace android */
144
145 #endif /* DRAWFRAMETASK_H */