blob: 4b63fbf14d4c196e43b7ad58e8a639ad10e5cd59 [file] [log] [blame]
Marissa Wallf6a73fa2018-12-10 10:41:08 -08001/*
2 * Copyright 2018 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
Marissa Wall1be5a102019-01-18 16:14:04 -080017#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
Marissa Wallf6a73fa2018-12-10 10:41:08 -080018#include <android/native_window.h>
19#include <android/surface_control.h>
Bo Liu789103b2022-09-15 16:24:31 -040020#include <android/surface_control_jni.h>
21#include <android_runtime/android_view_SurfaceControl.h>
Marissa Wall1be5a102019-01-18 16:14:04 -080022#include <configstore/Utils.h>
Marissa Wall1be5a102019-01-18 16:14:04 -080023#include <gui/HdrMetadata.h>
24#include <gui/ISurfaceComposer.h>
Marissa Wallf6a73fa2018-12-10 10:41:08 -080025#include <gui/Surface.h>
26#include <gui/SurfaceComposerClient.h>
27#include <gui/SurfaceControl.h>
Rachel Leeb6c93aa2022-02-22 15:48:28 -080028#include <private/android/choreographer.h>
29#include <surface_control_private.h>
Marin Shalamanov463ad8e2021-01-28 22:58:37 +010030#include <ui/DynamicDisplayInfo.h>
Marissa Wall1be5a102019-01-18 16:14:04 -080031#include <utils/Timers.h>
32
Bo Liu789103b2022-09-15 16:24:31 -040033#include <utility>
34
Marissa Wall1be5a102019-01-18 16:14:04 -080035using namespace android::hardware::configstore;
36using namespace android::hardware::configstore::V1_0;
Marissa Wallf6a73fa2018-12-10 10:41:08 -080037using namespace android;
38
39using Transaction = SurfaceComposerClient::Transaction;
40
41#define CHECK_NOT_NULL(name) \
42 LOG_ALWAYS_FATAL_IF(name == nullptr, "nullptr passed as " #name " argument");
43
44#define CHECK_VALID_RECT(name) \
45 LOG_ALWAYS_FATAL_IF(!static_cast<const Rect&>(name).isValid(), \
46 "invalid arg passed as " #name " argument");
47
John Reck2b2ba932021-07-12 21:51:09 -040048static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN));
49static_assert(static_cast<int>(ADATASPACE_SCRGB_LINEAR) ==
50 static_cast<int>(HAL_DATASPACE_V0_SCRGB_LINEAR));
51static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB));
52static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
53static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) ==
54 static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
55static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
Valerie Hau5bbfd512019-01-22 17:39:43 -080056
Marissa Wallf6a73fa2018-12-10 10:41:08 -080057Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) {
58 return reinterpret_cast<Transaction*>(aSurfaceTransaction);
59}
60
61SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) {
62 return reinterpret_cast<SurfaceControl*>(aSurfaceControl);
63}
64
65void SurfaceControl_acquire(SurfaceControl* surfaceControl) {
66 // incStrong/decStrong token must be the same, doesn't matter what it is
67 surfaceControl->incStrong((void*)SurfaceControl_acquire);
68}
69
70void SurfaceControl_release(SurfaceControl* surfaceControl) {
71 // incStrong/decStrong token must be the same, doesn't matter what it is
72 surfaceControl->decStrong((void*)SurfaceControl_acquire);
73}
74
75ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) {
76 CHECK_NOT_NULL(window);
77 CHECK_NOT_NULL(debug_name);
78
79 sp<SurfaceComposerClient> client = new SurfaceComposerClient();
80 if (client->initCheck() != NO_ERROR) {
81 return nullptr;
82 }
83
Vishnu Nairce1a6482020-10-22 17:41:30 -070084 Surface* surface = static_cast<Surface*>(window);
85 sp<IBinder> parentHandle = surface->getSurfaceControlHandle();
86
Huihong Luo36b55bc2022-03-08 14:50:45 -080087 int32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
Vishnu Nairce1a6482020-10-22 17:41:30 -070088 sp<SurfaceControl> surfaceControl;
89 if (parentHandle) {
90 surfaceControl =
91 client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
92 // Format is only relevant for buffer queue layers.
93 PIXEL_FORMAT_UNKNOWN /* format */, flags, parentHandle);
94 } else {
Huihong Luo36b55bc2022-03-08 14:50:45 -080095 // deprecated, this should no longer be used
96 surfaceControl = nullptr;
Vishnu Nairce1a6482020-10-22 17:41:30 -070097 }
98
Marissa Wallf6a73fa2018-12-10 10:41:08 -080099 if (!surfaceControl) {
100 return nullptr;
101 }
102
103 SurfaceControl_acquire(surfaceControl.get());
104 return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
105}
106
107ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) {
108 CHECK_NOT_NULL(parent);
109 CHECK_NOT_NULL(debug_name);
110
111 SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get();
112
113 SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent);
114
115 uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
116 sp<SurfaceControl> surfaceControl =
117 client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
118 // Format is only relevant for buffer queue layers.
119 PIXEL_FORMAT_UNKNOWN /* format */, flags,
Vishnu Nairce1a6482020-10-22 17:41:30 -0700120 surfaceControlParent->getHandle());
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800121 if (!surfaceControl) {
122 return nullptr;
123 }
124
125 SurfaceControl_acquire(surfaceControl.get());
126 return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
127}
128
Huihong Luo91697e12021-01-28 15:24:19 -0800129void ASurfaceControl_acquire(ASurfaceControl* aSurfaceControl) {
130 SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800131
Huihong Luo91697e12021-01-28 15:24:19 -0800132 SurfaceControl_acquire(surfaceControl);
133}
134
135void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) {
136 SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
137
138 SurfaceControl_release(surfaceControl);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800139}
140
Bo Liu23af7022022-11-11 15:00:19 -0500141ASurfaceControl* ASurfaceControl_fromJava(JNIEnv* env, jobject surfaceControlObj) {
142 LOG_ALWAYS_FATAL_IF(!env, "nullptr passed to ASurfaceControl_fromJava as env argument");
Bo Liudd89c3b2022-10-11 20:26:31 -0400143 LOG_ALWAYS_FATAL_IF(!surfaceControlObj,
Bo Liu23af7022022-11-11 15:00:19 -0500144 "nullptr passed to ASurfaceControl_fromJava as surfaceControlObj argument");
Bo Liudd89c3b2022-10-11 20:26:31 -0400145 SurfaceControl* surfaceControl =
146 android_view_SurfaceControl_getNativeSurfaceControl(env, surfaceControlObj);
147 LOG_ALWAYS_FATAL_IF(!surfaceControl,
Bo Liu23af7022022-11-11 15:00:19 -0500148 "surfaceControlObj passed to ASurfaceControl_fromJava is not valid");
Bo Liudd89c3b2022-10-11 20:26:31 -0400149 SurfaceControl_acquire(surfaceControl);
150 return reinterpret_cast<ASurfaceControl*>(surfaceControl);
Bo Liu789103b2022-09-15 16:24:31 -0400151}
152
Jorim Jaggi71db8892021-02-03 23:19:29 +0100153struct ASurfaceControlStats {
Ady Abraham62e15f02022-01-21 17:00:50 -0800154 std::variant<int64_t, sp<Fence>> acquireTimeOrFence;
Jorim Jaggi71db8892021-02-03 23:19:29 +0100155 sp<Fence> previousReleaseFence;
156 uint64_t frameNumber;
157};
158
Pablo Gamitobc9e5292021-08-23 17:12:29 +0200159void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, int32_t id,
160 void* context,
161 ASurfaceControl_SurfaceStatsListener func) {
Pablo Gamito14b28ce9c2021-09-06 16:33:23 +0000162 SurfaceStatsCallback callback = [func, id](void* callback_context, nsecs_t, const sp<Fence>&,
163 const SurfaceStats& surfaceStats) {
Jorim Jaggi71db8892021-02-03 23:19:29 +0100164 ASurfaceControlStats aSurfaceControlStats;
165
Ady Abraham62e15f02022-01-21 17:00:50 -0800166 aSurfaceControlStats.acquireTimeOrFence = surfaceStats.acquireTimeOrFence;
Jorim Jaggi71db8892021-02-03 23:19:29 +0100167 aSurfaceControlStats.previousReleaseFence = surfaceStats.previousReleaseFence;
168 aSurfaceControlStats.frameNumber = surfaceStats.eventStats.frameNumber;
169
Pablo Gamito14b28ce9c2021-09-06 16:33:23 +0000170 (*func)(callback_context, id, &aSurfaceControlStats);
Jorim Jaggi71db8892021-02-03 23:19:29 +0100171 };
Pablo Gamitobc9e5292021-08-23 17:12:29 +0200172
Jorim Jaggi71db8892021-02-03 23:19:29 +0100173 TransactionCompletedListener::getInstance()->addSurfaceStatsListener(context,
174 reinterpret_cast<void*>(func), ASurfaceControl_to_SurfaceControl(control), callback);
175}
176
Jorim Jaggi71db8892021-02-03 23:19:29 +0100177void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
178 ASurfaceControl_SurfaceStatsListener func) {
179 TransactionCompletedListener::getInstance()->removeSurfaceStatsListener(context,
180 reinterpret_cast<void*>(func));
181}
182
Rachel Lee93d2d0b2023-01-06 14:06:29 -0800183AChoreographer* ASurfaceControl_getChoreographer(ASurfaceControl* aSurfaceControl) {
184 LOG_ALWAYS_FATAL_IF(aSurfaceControl == nullptr, "aSurfaceControl should not be nullptr");
185 SurfaceControl* surfaceControl =
186 ASurfaceControl_to_SurfaceControl(reinterpret_cast<ASurfaceControl*>(aSurfaceControl));
187 if (!surfaceControl->isValid()) {
188 ALOGE("Attempted to get choreographer from invalid surface control");
189 return nullptr;
190 }
191 SurfaceControl_acquire(surfaceControl);
192 return reinterpret_cast<AChoreographer*>(surfaceControl->getChoreographer().get());
193}
194
Jorim Jaggi71db8892021-02-03 23:19:29 +0100195int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
Ady Abraham62e15f02022-01-21 17:00:50 -0800196 if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
197 // We got a fence instead of the acquire time due to latch unsignaled.
198 // Ideally the client could just get the acquire time dericly from
199 // the fence instead of calling this function which needs to block.
200 (*fence)->waitForever("ASurfaceControlStats_getAcquireTime");
201 return (*fence)->getSignalTime();
202 }
203
204 return std::get<int64_t>(stats->acquireTimeOrFence);
Jorim Jaggi71db8892021-02-03 23:19:29 +0100205}
206
207uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats) {
208 return stats->frameNumber;
209}
210
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800211ASurfaceTransaction* ASurfaceTransaction_create() {
212 Transaction* transaction = new Transaction;
213 return reinterpret_cast<ASurfaceTransaction*>(transaction);
214}
215
216void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) {
217 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
218 delete transaction;
219}
220
Bo Liu23af7022022-11-11 15:00:19 -0500221ASurfaceTransaction* ASurfaceTransaction_fromJava(JNIEnv* env, jobject transactionObj) {
222 LOG_ALWAYS_FATAL_IF(!env, "nullptr passed to ASurfaceTransaction_fromJava as env argument");
Bo Liudd89c3b2022-10-11 20:26:31 -0400223 LOG_ALWAYS_FATAL_IF(!transactionObj,
Bo Liu23af7022022-11-11 15:00:19 -0500224 "nullptr passed to ASurfaceTransaction_fromJava as transactionObj "
Bo Liudd89c3b2022-10-11 20:26:31 -0400225 "argument");
226 Transaction* transaction =
227 android_view_SurfaceTransaction_getNativeSurfaceTransaction(env, transactionObj);
228 LOG_ALWAYS_FATAL_IF(!transaction,
Bo Liu23af7022022-11-11 15:00:19 -0500229 "surfaceControlObj passed to ASurfaceTransaction_fromJava is not valid");
Bo Liudd89c3b2022-10-11 20:26:31 -0400230 return reinterpret_cast<ASurfaceTransaction*>(transaction);
Bo Liu789103b2022-09-15 16:24:31 -0400231}
232
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800233void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) {
234 CHECK_NOT_NULL(aSurfaceTransaction);
235
236 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
237
238 transaction->apply();
239}
240
Marissa Wall1be5a102019-01-18 16:14:04 -0800241struct ASurfaceTransactionStats {
242 std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats;
243 int64_t latchTime;
244 sp<Fence> presentFence;
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700245 bool transactionCompleted;
Marissa Wall1be5a102019-01-18 16:14:04 -0800246};
247
248int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) {
249 CHECK_NOT_NULL(aSurfaceTransactionStats);
250 return aSurfaceTransactionStats->latchTime;
251}
252
253int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) {
254 CHECK_NOT_NULL(aSurfaceTransactionStats);
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700255 LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
256 "ASurfaceTransactionStats queried from an incomplete transaction callback");
257
Marissa Wall1be5a102019-01-18 16:14:04 -0800258 auto& presentFence = aSurfaceTransactionStats->presentFence;
259 return (presentFence) ? presentFence->dup() : -1;
260}
261
262void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats,
263 ASurfaceControl*** outASurfaceControls,
264 size_t* outASurfaceControlsSize) {
265 CHECK_NOT_NULL(aSurfaceTransactionStats);
266 CHECK_NOT_NULL(outASurfaceControls);
267 CHECK_NOT_NULL(outASurfaceControlsSize);
268
269 size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size();
270
271 SurfaceControl** surfaceControls = new SurfaceControl*[size];
272 ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls);
273
274 size_t i = 0;
275 for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) {
276 aSurfaceControls[i] = aSurfaceControl;
277 i++;
278 }
279
280 *outASurfaceControls = aSurfaceControls;
281 *outASurfaceControlsSize = size;
282}
283
284int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats,
285 ASurfaceControl* aSurfaceControl) {
286 CHECK_NOT_NULL(aSurfaceTransactionStats);
287 CHECK_NOT_NULL(aSurfaceControl);
288
289 const auto& aSurfaceControlStats =
290 aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
291 LOG_ALWAYS_FATAL_IF(
292 aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
293 "ASurfaceControl not found");
294
Ady Abraham62e15f02022-01-21 17:00:50 -0800295 return ASurfaceControlStats_getAcquireTime(&aSurfaceControlStats->second);
Marissa Wall1be5a102019-01-18 16:14:04 -0800296}
297
298int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
299 ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) {
300 CHECK_NOT_NULL(aSurfaceTransactionStats);
301 CHECK_NOT_NULL(aSurfaceControl);
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700302 LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
303 "ASurfaceTransactionStats queried from an incomplete transaction callback");
Marissa Wall1be5a102019-01-18 16:14:04 -0800304
305 const auto& aSurfaceControlStats =
306 aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
307 LOG_ALWAYS_FATAL_IF(
308 aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
309 "ASurfaceControl not found");
310
311 auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence;
312 return (previousReleaseFence) ? previousReleaseFence->dup() : -1;
313}
314
315void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) {
316 CHECK_NOT_NULL(aSurfaceControls);
317
318 SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls);
319 delete[] surfaceControls;
320}
321
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800322void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context,
323 ASurfaceTransaction_OnComplete func) {
324 CHECK_NOT_NULL(aSurfaceTransaction);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800325 CHECK_NOT_NULL(func);
326
327 TransactionCompletedCallbackTakesContext callback = [func](void* callback_context,
Marissa Wall1be5a102019-01-18 16:14:04 -0800328 nsecs_t latchTime,
329 const sp<Fence>& presentFence,
330 const std::vector<SurfaceControlStats>& surfaceControlStats) {
331 ASurfaceTransactionStats aSurfaceTransactionStats;
332
333 aSurfaceTransactionStats.latchTime = latchTime;
334 aSurfaceTransactionStats.presentFence = presentFence;
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700335 aSurfaceTransactionStats.transactionCompleted = true;
Marissa Wall1be5a102019-01-18 16:14:04 -0800336
337 auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
338
Ady Abraham62e15f02022-01-21 17:00:50 -0800339 for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
Rob Carr7c703732022-09-27 00:57:27 +0000340 previousReleaseFence, transformHint, frameEvents, ignore] : surfaceControlStats) {
Marissa Wall1be5a102019-01-18 16:14:04 -0800341 ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
Ady Abraham62e15f02022-01-21 17:00:50 -0800342 aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
Marissa Wall1be5a102019-01-18 16:14:04 -0800343 aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence;
344 }
345
346 (*func)(callback_context, &aSurfaceTransactionStats);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800347 };
348
349 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
350
351 transaction->addTransactionCompletedCallback(callback, context);
352}
353
Marissa Wall1be5a102019-01-18 16:14:04 -0800354void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction,
355 ASurfaceControl* aSurfaceControl,
356 ASurfaceControl* newParentASurfaceControl) {
357 CHECK_NOT_NULL(aSurfaceTransaction);
358 CHECK_NOT_NULL(aSurfaceControl);
359
360 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
361 sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl(
362 newParentASurfaceControl);
Marissa Wall1be5a102019-01-18 16:14:04 -0800363 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
364
Pablo Gamito117040c2020-09-14 08:24:41 +0000365 transaction->reparent(surfaceControl, newParentSurfaceControl);
Marissa Wall1be5a102019-01-18 16:14:04 -0800366}
367
368void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction,
369 ASurfaceControl* aSurfaceControl,
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800370 int8_t visibility) {
371 CHECK_NOT_NULL(aSurfaceTransaction);
372 CHECK_NOT_NULL(aSurfaceControl);
373
374 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
375 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
376
377 switch (visibility) {
378 case ASURFACE_TRANSACTION_VISIBILITY_SHOW:
379 transaction->show(surfaceControl);
380 break;
381 case ASURFACE_TRANSACTION_VISIBILITY_HIDE:
382 transaction->hide(surfaceControl);
383 break;
384 default:
385 LOG_ALWAYS_FATAL("invalid visibility %d", visibility);
386 }
387}
388
Marissa Wall1be5a102019-01-18 16:14:04 -0800389void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction,
390 ASurfaceControl* aSurfaceControl,
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800391 int32_t z_order) {
392 CHECK_NOT_NULL(aSurfaceTransaction);
393 CHECK_NOT_NULL(aSurfaceControl);
394
395 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
396 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
397
398 transaction->setLayer(surfaceControl, z_order);
399}
400
Marissa Wall1be5a102019-01-18 16:14:04 -0800401void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction,
402 ASurfaceControl* aSurfaceControl,
403 AHardwareBuffer* buffer, int acquire_fence_fd) {
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800404 CHECK_NOT_NULL(aSurfaceTransaction);
405 CHECK_NOT_NULL(aSurfaceControl);
406
407 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
408 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
409
John Reck7f55b132021-09-20 14:42:29 -0400410 sp<GraphicBuffer> graphic_buffer(GraphicBuffer::fromAHardwareBuffer(buffer));
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800411
chaviw5513c612021-09-15 15:26:23 -0500412 std::optional<sp<Fence>> fence = std::nullopt;
Marissa Wall1be5a102019-01-18 16:14:04 -0800413 if (acquire_fence_fd != -1) {
chaviw5513c612021-09-15 15:26:23 -0500414 fence = new Fence(acquire_fence_fd);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800415 }
chaviw5513c612021-09-15 15:26:23 -0500416 transaction->setBuffer(surfaceControl, graphic_buffer, fence);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800417}
418
419void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction,
420 ASurfaceControl* aSurfaceControl, const ARect& source,
421 const ARect& destination, int32_t transform) {
422 CHECK_NOT_NULL(aSurfaceTransaction);
423 CHECK_NOT_NULL(aSurfaceControl);
chaviw87a07ea2021-04-29 09:04:41 -0500424 CHECK_VALID_RECT(source);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800425 CHECK_VALID_RECT(destination);
426
427 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
428 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
429
chaviw87a07ea2021-04-29 09:04:41 -0500430 Rect sourceRect = static_cast<const Rect&>(source);
431 Rect destRect = static_cast<const Rect&>(destination);
432 // Adjust the source so its top and left are not negative
433 sourceRect.left = std::max(sourceRect.left, 0);
434 sourceRect.top = std::max(sourceRect.top, 0);
435
436 if (!sourceRect.isValid()) {
437 sourceRect.makeInvalid();
438 }
chaviw9b2ac242021-04-27 15:52:09 -0500439 transaction->setBufferCrop(surfaceControl, sourceRect);
Vishnu Nair0d7aff72021-05-10 15:01:20 -0700440 transaction->setDestinationFrame(surfaceControl, destRect);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800441 transaction->setTransform(surfaceControl, transform);
Vishnu Nair1ad69542019-05-23 16:27:45 +0800442 bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
443 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
444 transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay);
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800445}
446
chaviwccf3e8b2021-03-25 15:28:44 -0500447void ASurfaceTransaction_setCrop(ASurfaceTransaction* aSurfaceTransaction,
448 ASurfaceControl* aSurfaceControl, const ARect& crop) {
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500449 CHECK_NOT_NULL(aSurfaceTransaction);
450 CHECK_NOT_NULL(aSurfaceControl);
chaviwccf3e8b2021-03-25 15:28:44 -0500451 CHECK_VALID_RECT(crop);
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500452
453 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
454 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
455
chaviwccf3e8b2021-03-25 15:28:44 -0500456 transaction->setCrop(surfaceControl, static_cast<const Rect&>(crop));
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500457}
458
chaviwccf3e8b2021-03-25 15:28:44 -0500459void ASurfaceTransaction_setPosition(ASurfaceTransaction* aSurfaceTransaction,
460 ASurfaceControl* aSurfaceControl, int32_t x, int32_t y) {
461 CHECK_NOT_NULL(aSurfaceTransaction);
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500462 CHECK_NOT_NULL(aSurfaceControl);
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500463
464 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
465 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
466
chaviwccf3e8b2021-03-25 15:28:44 -0500467 transaction->setPosition(surfaceControl, x, y);
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500468}
469
chaviwccf3e8b2021-03-25 15:28:44 -0500470void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* aSurfaceTransaction,
471 ASurfaceControl* aSurfaceControl, int32_t transform) {
Vasiliy Telezhnikov5ead3aa2021-03-13 19:55:00 -0500472 CHECK_NOT_NULL(aSurfaceTransaction);
473 CHECK_NOT_NULL(aSurfaceControl);
474
475 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
476 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
477
478 transaction->setTransform(surfaceControl, transform);
479 bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
480 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
481 transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay);
482}
483
chaviwccf3e8b2021-03-25 15:28:44 -0500484void ASurfaceTransaction_setScale(ASurfaceTransaction* aSurfaceTransaction,
485 ASurfaceControl* aSurfaceControl, float xScale, float yScale) {
486 CHECK_NOT_NULL(aSurfaceTransaction);
487 CHECK_NOT_NULL(aSurfaceControl);
488 LOG_ALWAYS_FATAL_IF(xScale < 0, "negative value passed in for xScale");
489 LOG_ALWAYS_FATAL_IF(yScale < 0, "negative value passed in for yScale");
490
491 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
492 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
493
494 transaction->setMatrix(surfaceControl, xScale, 0, 0, yScale);
495}
496
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800497void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction,
498 ASurfaceControl* aSurfaceControl,
499 int8_t transparency) {
500 CHECK_NOT_NULL(aSurfaceTransaction);
501 CHECK_NOT_NULL(aSurfaceControl);
502
503 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
504 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
505
506 uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ?
507 layer_state_t::eLayerOpaque : 0;
508 transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque);
509}
510
Marissa Wall1be5a102019-01-18 16:14:04 -0800511void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction,
512 ASurfaceControl* aSurfaceControl,
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800513 const ARect rects[], uint32_t count) {
514 CHECK_NOT_NULL(aSurfaceTransaction);
515 CHECK_NOT_NULL(aSurfaceControl);
516
517 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
518 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
519
520 Region region;
521 for (uint32_t i = 0; i < count; ++i) {
Marissa Wallbb9b14f2019-04-23 14:10:15 -0700522 region.orSelf(static_cast<const Rect&>(rects[i]));
523 }
524
525 // Hardware composer interprets a DamageRegion with a single Rect of {0,0,0,0} to be an
526 // undamaged region and {0,0,-1,-1} to be a fully damaged buffer. This is a confusing
527 // distinction for a public api. Instead, default both cases to be a fully damaged buffer.
528 if (count == 1 && region.getBounds().isEmpty()) {
529 transaction->setSurfaceDamageRegion(surfaceControl, Region::INVALID_REGION);
530 return;
Marissa Wallf6a73fa2018-12-10 10:41:08 -0800531 }
532
533 transaction->setSurfaceDamageRegion(surfaceControl, region);
534}
Marissa Wall1be5a102019-01-18 16:14:04 -0800535
536void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction,
537 int64_t desiredPresentTime) {
538 CHECK_NOT_NULL(aSurfaceTransaction);
539
540 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
541
542 transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime));
543}
544
545void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction,
546 ASurfaceControl* aSurfaceControl,
547 float alpha) {
548 CHECK_NOT_NULL(aSurfaceTransaction);
549 CHECK_NOT_NULL(aSurfaceControl);
550
551 LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha");
552
553 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
554 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
555
556 transaction->setAlpha(surfaceControl, alpha);
557}
558
Marissa Wall7f24f792019-02-07 14:06:04 -0800559void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* aSurfaceTransaction,
560 ASurfaceControl* aSurfaceControl,
561 ADataSpace aDataSpace) {
562 CHECK_NOT_NULL(aSurfaceTransaction);
563 CHECK_NOT_NULL(aSurfaceControl);
564
565 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
Marissa Wall7f24f792019-02-07 14:06:04 -0800566 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
Marissa Wall7f24f792019-02-07 14:06:04 -0800567 transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace));
568}
569
Marissa Wall1be5a102019-01-18 16:14:04 -0800570void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction,
571 ASurfaceControl* aSurfaceControl,
572 struct AHdrMetadata_smpte2086* metadata) {
573 CHECK_NOT_NULL(aSurfaceTransaction);
574 CHECK_NOT_NULL(aSurfaceControl);
575
576 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
577 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
578
579 HdrMetadata hdrMetadata;
580
581 if (metadata) {
582 hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x;
583 hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y;
584 hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x;
585 hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y;
586 hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x;
587 hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y;
588 hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x;
589 hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y;
590 hdrMetadata.smpte2086.minLuminance = metadata->minLuminance;
591 hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance;
592
593 hdrMetadata.validTypes |= HdrMetadata::SMPTE2086;
594 } else {
595 hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086;
596 }
597
598 transaction->setHdrMetadata(surfaceControl, hdrMetadata);
599}
600
601void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction,
602 ASurfaceControl* aSurfaceControl,
603 struct AHdrMetadata_cta861_3* metadata) {
604 CHECK_NOT_NULL(aSurfaceTransaction);
605 CHECK_NOT_NULL(aSurfaceControl);
606
607 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
608 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
609
610 HdrMetadata hdrMetadata;
611
612 if (metadata) {
613 hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel;
614 hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel;
615
616 hdrMetadata.validTypes |= HdrMetadata::CTA861_3;
617 } else {
618 hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3;
619 }
620
621 transaction->setHdrMetadata(surfaceControl, hdrMetadata);
622}
Valerie Hau5bbfd512019-01-22 17:39:43 -0800623
John Recka40ad032023-02-13 10:20:24 -0500624void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* aSurfaceTransaction,
625 ASurfaceControl* aSurfaceControl,
626 float currentBufferRatio, float desiredRatio) {
627 CHECK_NOT_NULL(aSurfaceTransaction);
628 CHECK_NOT_NULL(aSurfaceControl);
629
630 if (!isfinite(currentBufferRatio) || currentBufferRatio < 1.0f) {
John Reck732442f2023-03-16 14:28:50 -0400631 LOG_ALWAYS_FATAL("setExtendedRangeBrightness, currentBufferRatio %f isn't finite or >= "
632 "1.0f",
633 currentBufferRatio);
John Recka40ad032023-02-13 10:20:24 -0500634 return;
635 }
636
637 if (!isfinite(desiredRatio) || desiredRatio < 1.0f) {
John Reck732442f2023-03-16 14:28:50 -0400638 LOG_ALWAYS_FATAL("setExtendedRangeBrightness, desiredRatio %f isn't finite or >= 1.0f",
639 desiredRatio);
John Recka40ad032023-02-13 10:20:24 -0500640 return;
641 }
642
643 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
644 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
645
646 transaction->setExtendedRangeBrightness(surfaceControl, currentBufferRatio, desiredRatio);
647}
648
Valerie Hau5bbfd512019-01-22 17:39:43 -0800649void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction,
650 ASurfaceControl* aSurfaceControl,
651 float r, float g, float b, float alpha,
652 ADataSpace dataspace) {
653 CHECK_NOT_NULL(aSurfaceTransaction);
654 CHECK_NOT_NULL(aSurfaceControl);
655
656 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
Valerie Hau5bbfd512019-01-22 17:39:43 -0800657 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
658
659 half3 color;
660 color.r = r;
661 color.g = g;
662 color.b = b;
663
Marin Shalamanov511f9142021-03-16 18:03:30 +0100664 transaction->setBackgroundColor(surfaceControl, color, alpha,
665 static_cast<ui::Dataspace>(dataspace));
Valerie Hau5bbfd512019-01-22 17:39:43 -0800666}
Steven Thomas6cf051e2020-01-14 11:37:21 -0800667
668void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* aSurfaceTransaction,
Steven Thomasdd7bf2f2020-01-31 18:50:02 -0800669 ASurfaceControl* aSurfaceControl, float frameRate,
670 int8_t compatibility) {
Marin Shalamanov511f9142021-03-16 18:03:30 +0100671 ASurfaceTransaction_setFrameRateWithChangeStrategy(
672 aSurfaceTransaction, aSurfaceControl, frameRate, compatibility,
673 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
Marin Shalamanov41ffa8d2020-10-13 12:35:20 +0200674}
675
Marin Shalamanov511f9142021-03-16 18:03:30 +0100676void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* aSurfaceTransaction,
677 ASurfaceControl* aSurfaceControl,
678 float frameRate, int8_t compatibility,
679 int8_t changeFrameRateStrategy) {
Steven Thomas6cf051e2020-01-14 11:37:21 -0800680 CHECK_NOT_NULL(aSurfaceTransaction);
681 CHECK_NOT_NULL(aSurfaceControl);
Steven Thomas6cf051e2020-01-14 11:37:21 -0800682 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
Steven Thomasdd7bf2f2020-01-31 18:50:02 -0800683 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
Marin Shalamanov511f9142021-03-16 18:03:30 +0100684 transaction->setFrameRate(surfaceControl, frameRate, compatibility, changeFrameRateStrategy);
Steven Thomas6cf051e2020-01-14 11:37:21 -0800685}
Robert Carrf57c0162021-03-24 15:48:25 -0700686
Kriti Dang4bfeeb42022-08-11 15:15:36 +0200687void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* aSurfaceTransaction,
688 ASurfaceControl* aSurfaceControl) {
689 CHECK_NOT_NULL(aSurfaceTransaction);
690 CHECK_NOT_NULL(aSurfaceControl);
691 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
692 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
693 transaction->setFrameRate(surfaceControl, 0, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
694 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
695}
696
Robert Carrf57c0162021-03-24 15:48:25 -0700697void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* aSurfaceTransaction,
698 ASurfaceControl* aSurfaceControl,
699 bool enableBackpressure) {
700 CHECK_NOT_NULL(aSurfaceControl);
701 CHECK_NOT_NULL(aSurfaceTransaction);
702
703 sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
704 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
705
706 const uint32_t flags = enableBackpressure ?
707 layer_state_t::eEnableBackpressure : 0;
708 transaction->setFlags(surfaceControl, flags, layer_state_t::eEnableBackpressure);
709}
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700710
711void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* aSurfaceTransaction, void* context,
712 ASurfaceTransaction_OnCommit func) {
713 CHECK_NOT_NULL(aSurfaceTransaction);
714 CHECK_NOT_NULL(func);
715
716 TransactionCompletedCallbackTakesContext callback =
717 [func](void* callback_context, nsecs_t latchTime, const sp<Fence>& /* presentFence */,
718 const std::vector<SurfaceControlStats>& surfaceControlStats) {
719 ASurfaceTransactionStats aSurfaceTransactionStats;
720 aSurfaceTransactionStats.latchTime = latchTime;
721 aSurfaceTransactionStats.transactionCompleted = false;
722
723 auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
Ady Abraham62e15f02022-01-21 17:00:50 -0800724 for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
Rob Carr7c703732022-09-27 00:57:27 +0000725 previousReleaseFence, transformHint, frameEvents, ignore] :
Ady Abraham62e15f02022-01-21 17:00:50 -0800726 surfaceControlStats) {
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700727 ASurfaceControl* aSurfaceControl =
728 reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
Ady Abraham62e15f02022-01-21 17:00:50 -0800729 aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
Vishnu Nairbeb3b482021-04-21 08:31:27 -0700730 }
731
732 (*func)(callback_context, &aSurfaceTransactionStats);
733 };
734
735 Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
736
737 transaction->addTransactionCommittedCallback(callback, context);
Pablo Gamito88660d72021-08-09 14:37:56 +0000738}
Rachel Leee1e77cc2021-10-19 16:40:41 -0700739
740void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* aSurfaceTransaction,
Rachel Lee7e47b3d2022-01-12 14:28:26 -0800741 AVsyncId vsyncId) {
Rachel Leee1e77cc2021-10-19 16:40:41 -0700742 CHECK_NOT_NULL(aSurfaceTransaction);
Rachel Leeb6c93aa2022-02-22 15:48:28 -0800743 const auto startTime = AChoreographer_getStartTimeNanosForVsyncId(vsyncId);
Huihong Luo4fed9b42022-03-03 15:10:33 -0800744 FrameTimelineInfo ftInfo;
745 ftInfo.vsyncId = vsyncId;
746 ftInfo.startTimeNanos = startTime;
747 ASurfaceTransaction_to_Transaction(aSurfaceTransaction)->setFrameTimelineInfo(ftInfo);
Rachel Leee1e77cc2021-10-19 16:40:41 -0700748}