1*d57664e9SAndroid Build Coastguard Worker /*
2*d57664e9SAndroid Build Coastguard Worker * Copyright 2018 The Android Open Source Project
3*d57664e9SAndroid Build Coastguard Worker *
4*d57664e9SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*d57664e9SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*d57664e9SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*d57664e9SAndroid Build Coastguard Worker *
8*d57664e9SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*d57664e9SAndroid Build Coastguard Worker *
10*d57664e9SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*d57664e9SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*d57664e9SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*d57664e9SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*d57664e9SAndroid Build Coastguard Worker * limitations under the License.
15*d57664e9SAndroid Build Coastguard Worker */
16*d57664e9SAndroid Build Coastguard Worker
17*d57664e9SAndroid Build Coastguard Worker #include <android/gui/LutProperties.h>
18*d57664e9SAndroid Build Coastguard Worker #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
19*d57664e9SAndroid Build Coastguard Worker #include <android/native_window.h>
20*d57664e9SAndroid Build Coastguard Worker #include <android/surface_control.h>
21*d57664e9SAndroid Build Coastguard Worker #include <android/surface_control_jni.h>
22*d57664e9SAndroid Build Coastguard Worker #include <android_runtime/android_view_SurfaceControl.h>
23*d57664e9SAndroid Build Coastguard Worker #include <configstore/Utils.h>
24*d57664e9SAndroid Build Coastguard Worker #include <cutils/ashmem.h>
25*d57664e9SAndroid Build Coastguard Worker #include <display_luts_private.h>
26*d57664e9SAndroid Build Coastguard Worker #include <gui/HdrMetadata.h>
27*d57664e9SAndroid Build Coastguard Worker #include <gui/ISurfaceComposer.h>
28*d57664e9SAndroid Build Coastguard Worker #include <gui/Surface.h>
29*d57664e9SAndroid Build Coastguard Worker #include <gui/SurfaceComposerClient.h>
30*d57664e9SAndroid Build Coastguard Worker #include <gui/SurfaceControl.h>
31*d57664e9SAndroid Build Coastguard Worker #include <private/android/choreographer.h>
32*d57664e9SAndroid Build Coastguard Worker #include <surface_control_private.h>
33*d57664e9SAndroid Build Coastguard Worker #include <ui/DynamicDisplayInfo.h>
34*d57664e9SAndroid Build Coastguard Worker #include <utils/Timers.h>
35*d57664e9SAndroid Build Coastguard Worker
36*d57664e9SAndroid Build Coastguard Worker #include <utility>
37*d57664e9SAndroid Build Coastguard Worker
38*d57664e9SAndroid Build Coastguard Worker using namespace android::hardware::configstore;
39*d57664e9SAndroid Build Coastguard Worker using namespace android::hardware::configstore::V1_0;
40*d57664e9SAndroid Build Coastguard Worker using namespace android;
41*d57664e9SAndroid Build Coastguard Worker
42*d57664e9SAndroid Build Coastguard Worker using Transaction = SurfaceComposerClient::Transaction;
43*d57664e9SAndroid Build Coastguard Worker
44*d57664e9SAndroid Build Coastguard Worker #define CHECK_NOT_NULL(name) \
45*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(name == nullptr, "nullptr passed as " #name " argument");
46*d57664e9SAndroid Build Coastguard Worker
47*d57664e9SAndroid Build Coastguard Worker #define CHECK_VALID_RECT(name) \
48*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!static_cast<const Rect&>(name).isValid(), \
49*d57664e9SAndroid Build Coastguard Worker "invalid arg passed as " #name " argument");
50*d57664e9SAndroid Build Coastguard Worker
51*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN));
52*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_SCRGB_LINEAR) ==
53*d57664e9SAndroid Build Coastguard Worker static_cast<int>(HAL_DATASPACE_V0_SCRGB_LINEAR));
54*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB));
55*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
56*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) ==
57*d57664e9SAndroid Build Coastguard Worker static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
58*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
59*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADISPLAYLUTS_ONE_DIMENSION) ==
60*d57664e9SAndroid Build Coastguard Worker static_cast<int>(android::gui::LutProperties::Dimension::ONE_D));
61*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADISPLAYLUTS_THREE_DIMENSION) ==
62*d57664e9SAndroid Build Coastguard Worker static_cast<int>(android::gui::LutProperties::Dimension::THREE_D));
63*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADISPLAYLUTS_SAMPLINGKEY_RGB) ==
64*d57664e9SAndroid Build Coastguard Worker static_cast<int>(android::gui::LutProperties::SamplingKey::RGB));
65*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB) ==
66*d57664e9SAndroid Build Coastguard Worker static_cast<int>(android::gui::LutProperties::SamplingKey::MAX_RGB));
67*d57664e9SAndroid Build Coastguard Worker static_assert(static_cast<int>(ADISPLAYLUTS_SAMPLINGKEY_CIE_Y) ==
68*d57664e9SAndroid Build Coastguard Worker static_cast<int>(android::gui::LutProperties::SamplingKey::CIE_Y));
69*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_to_Transaction(ASurfaceTransaction * aSurfaceTransaction)70*d57664e9SAndroid Build Coastguard Worker Transaction* ASurfaceTransaction_to_Transaction(ASurfaceTransaction* aSurfaceTransaction) {
71*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<Transaction*>(aSurfaceTransaction);
72*d57664e9SAndroid Build Coastguard Worker }
73*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_to_SurfaceControl(ASurfaceControl * aSurfaceControl)74*d57664e9SAndroid Build Coastguard Worker SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) {
75*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<SurfaceControl*>(aSurfaceControl);
76*d57664e9SAndroid Build Coastguard Worker }
77*d57664e9SAndroid Build Coastguard Worker
SurfaceControl_acquire(SurfaceControl * surfaceControl)78*d57664e9SAndroid Build Coastguard Worker void SurfaceControl_acquire(SurfaceControl* surfaceControl) {
79*d57664e9SAndroid Build Coastguard Worker // incStrong/decStrong token must be the same, doesn't matter what it is
80*d57664e9SAndroid Build Coastguard Worker surfaceControl->incStrong((void*)SurfaceControl_acquire);
81*d57664e9SAndroid Build Coastguard Worker }
82*d57664e9SAndroid Build Coastguard Worker
SurfaceControl_release(SurfaceControl * surfaceControl)83*d57664e9SAndroid Build Coastguard Worker void SurfaceControl_release(SurfaceControl* surfaceControl) {
84*d57664e9SAndroid Build Coastguard Worker // incStrong/decStrong token must be the same, doesn't matter what it is
85*d57664e9SAndroid Build Coastguard Worker surfaceControl->decStrong((void*)SurfaceControl_acquire);
86*d57664e9SAndroid Build Coastguard Worker }
87*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_createFromWindow(ANativeWindow * window,const char * debug_name)88*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) {
89*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(window);
90*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(debug_name);
91*d57664e9SAndroid Build Coastguard Worker
92*d57664e9SAndroid Build Coastguard Worker sp<SurfaceComposerClient> client = new SurfaceComposerClient();
93*d57664e9SAndroid Build Coastguard Worker if (client->initCheck() != NO_ERROR) {
94*d57664e9SAndroid Build Coastguard Worker return nullptr;
95*d57664e9SAndroid Build Coastguard Worker }
96*d57664e9SAndroid Build Coastguard Worker
97*d57664e9SAndroid Build Coastguard Worker Surface* surface = static_cast<Surface*>(window);
98*d57664e9SAndroid Build Coastguard Worker sp<IBinder> parentHandle = surface->getSurfaceControlHandle();
99*d57664e9SAndroid Build Coastguard Worker
100*d57664e9SAndroid Build Coastguard Worker int32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
101*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl;
102*d57664e9SAndroid Build Coastguard Worker if (parentHandle) {
103*d57664e9SAndroid Build Coastguard Worker surfaceControl =
104*d57664e9SAndroid Build Coastguard Worker client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
105*d57664e9SAndroid Build Coastguard Worker // Format is only relevant for buffer queue layers.
106*d57664e9SAndroid Build Coastguard Worker PIXEL_FORMAT_UNKNOWN /* format */, flags, parentHandle);
107*d57664e9SAndroid Build Coastguard Worker } else {
108*d57664e9SAndroid Build Coastguard Worker // deprecated, this should no longer be used
109*d57664e9SAndroid Build Coastguard Worker surfaceControl = nullptr;
110*d57664e9SAndroid Build Coastguard Worker }
111*d57664e9SAndroid Build Coastguard Worker
112*d57664e9SAndroid Build Coastguard Worker if (!surfaceControl) {
113*d57664e9SAndroid Build Coastguard Worker return nullptr;
114*d57664e9SAndroid Build Coastguard Worker }
115*d57664e9SAndroid Build Coastguard Worker
116*d57664e9SAndroid Build Coastguard Worker SurfaceControl_acquire(surfaceControl.get());
117*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
118*d57664e9SAndroid Build Coastguard Worker }
119*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_create(ASurfaceControl * parent,const char * debug_name)120*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) {
121*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(parent);
122*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(debug_name);
123*d57664e9SAndroid Build Coastguard Worker
124*d57664e9SAndroid Build Coastguard Worker SurfaceComposerClient* client = ASurfaceControl_to_SurfaceControl(parent)->getClient().get();
125*d57664e9SAndroid Build Coastguard Worker
126*d57664e9SAndroid Build Coastguard Worker SurfaceControl* surfaceControlParent = ASurfaceControl_to_SurfaceControl(parent);
127*d57664e9SAndroid Build Coastguard Worker
128*d57664e9SAndroid Build Coastguard Worker uint32_t flags = ISurfaceComposerClient::eFXSurfaceBufferState;
129*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl =
130*d57664e9SAndroid Build Coastguard Worker client->createSurface(String8(debug_name), 0 /* width */, 0 /* height */,
131*d57664e9SAndroid Build Coastguard Worker // Format is only relevant for buffer queue layers.
132*d57664e9SAndroid Build Coastguard Worker PIXEL_FORMAT_UNKNOWN /* format */, flags,
133*d57664e9SAndroid Build Coastguard Worker surfaceControlParent->getHandle());
134*d57664e9SAndroid Build Coastguard Worker if (!surfaceControl) {
135*d57664e9SAndroid Build Coastguard Worker return nullptr;
136*d57664e9SAndroid Build Coastguard Worker }
137*d57664e9SAndroid Build Coastguard Worker
138*d57664e9SAndroid Build Coastguard Worker SurfaceControl_acquire(surfaceControl.get());
139*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
140*d57664e9SAndroid Build Coastguard Worker }
141*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_acquire(ASurfaceControl * aSurfaceControl)142*d57664e9SAndroid Build Coastguard Worker void ASurfaceControl_acquire(ASurfaceControl* aSurfaceControl) {
143*d57664e9SAndroid Build Coastguard Worker SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
144*d57664e9SAndroid Build Coastguard Worker
145*d57664e9SAndroid Build Coastguard Worker SurfaceControl_acquire(surfaceControl);
146*d57664e9SAndroid Build Coastguard Worker }
147*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_release(ASurfaceControl * aSurfaceControl)148*d57664e9SAndroid Build Coastguard Worker void ASurfaceControl_release(ASurfaceControl* aSurfaceControl) {
149*d57664e9SAndroid Build Coastguard Worker SurfaceControl* surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
150*d57664e9SAndroid Build Coastguard Worker
151*d57664e9SAndroid Build Coastguard Worker SurfaceControl_release(surfaceControl);
152*d57664e9SAndroid Build Coastguard Worker }
153*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_fromJava(JNIEnv * env,jobject surfaceControlObj)154*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* ASurfaceControl_fromJava(JNIEnv* env, jobject surfaceControlObj) {
155*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!env, "nullptr passed to ASurfaceControl_fromJava as env argument");
156*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!surfaceControlObj,
157*d57664e9SAndroid Build Coastguard Worker "nullptr passed to ASurfaceControl_fromJava as surfaceControlObj argument");
158*d57664e9SAndroid Build Coastguard Worker SurfaceControl* surfaceControl =
159*d57664e9SAndroid Build Coastguard Worker android_view_SurfaceControl_getNativeSurfaceControl(env, surfaceControlObj);
160*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!surfaceControl,
161*d57664e9SAndroid Build Coastguard Worker "surfaceControlObj passed to ASurfaceControl_fromJava is not valid");
162*d57664e9SAndroid Build Coastguard Worker SurfaceControl_acquire(surfaceControl);
163*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<ASurfaceControl*>(surfaceControl);
164*d57664e9SAndroid Build Coastguard Worker }
165*d57664e9SAndroid Build Coastguard Worker
166*d57664e9SAndroid Build Coastguard Worker struct ASurfaceControlStats {
167*d57664e9SAndroid Build Coastguard Worker std::variant<int64_t, sp<Fence>> acquireTimeOrFence;
168*d57664e9SAndroid Build Coastguard Worker sp<Fence> previousReleaseFence;
169*d57664e9SAndroid Build Coastguard Worker uint64_t frameNumber;
170*d57664e9SAndroid Build Coastguard Worker };
171*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl * control,int32_t id,void * context,ASurfaceControl_SurfaceStatsListener func)172*d57664e9SAndroid Build Coastguard Worker void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, int32_t id,
173*d57664e9SAndroid Build Coastguard Worker void* context,
174*d57664e9SAndroid Build Coastguard Worker ASurfaceControl_SurfaceStatsListener func) {
175*d57664e9SAndroid Build Coastguard Worker SurfaceStatsCallback callback = [func, id](void* callback_context, nsecs_t, const sp<Fence>&,
176*d57664e9SAndroid Build Coastguard Worker const SurfaceStats& surfaceStats) {
177*d57664e9SAndroid Build Coastguard Worker ASurfaceControlStats aSurfaceControlStats;
178*d57664e9SAndroid Build Coastguard Worker
179*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats.acquireTimeOrFence = surfaceStats.acquireTimeOrFence;
180*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats.previousReleaseFence = surfaceStats.previousReleaseFence;
181*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats.frameNumber = surfaceStats.eventStats.frameNumber;
182*d57664e9SAndroid Build Coastguard Worker
183*d57664e9SAndroid Build Coastguard Worker (*func)(callback_context, id, &aSurfaceControlStats);
184*d57664e9SAndroid Build Coastguard Worker };
185*d57664e9SAndroid Build Coastguard Worker
186*d57664e9SAndroid Build Coastguard Worker TransactionCompletedListener::getInstance()->addSurfaceStatsListener(context,
187*d57664e9SAndroid Build Coastguard Worker reinterpret_cast<void*>(func), ASurfaceControl_to_SurfaceControl(control), callback);
188*d57664e9SAndroid Build Coastguard Worker }
189*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_unregisterSurfaceStatsListener(void * context,ASurfaceControl_SurfaceStatsListener func)190*d57664e9SAndroid Build Coastguard Worker void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
191*d57664e9SAndroid Build Coastguard Worker ASurfaceControl_SurfaceStatsListener func) {
192*d57664e9SAndroid Build Coastguard Worker TransactionCompletedListener::getInstance()->removeSurfaceStatsListener(context,
193*d57664e9SAndroid Build Coastguard Worker reinterpret_cast<void*>(func));
194*d57664e9SAndroid Build Coastguard Worker }
195*d57664e9SAndroid Build Coastguard Worker
ASurfaceControl_getChoreographer(ASurfaceControl * aSurfaceControl)196*d57664e9SAndroid Build Coastguard Worker AChoreographer* ASurfaceControl_getChoreographer(ASurfaceControl* aSurfaceControl) {
197*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(aSurfaceControl == nullptr, "aSurfaceControl should not be nullptr");
198*d57664e9SAndroid Build Coastguard Worker SurfaceControl* surfaceControl =
199*d57664e9SAndroid Build Coastguard Worker ASurfaceControl_to_SurfaceControl(reinterpret_cast<ASurfaceControl*>(aSurfaceControl));
200*d57664e9SAndroid Build Coastguard Worker if (!surfaceControl->isValid()) {
201*d57664e9SAndroid Build Coastguard Worker ALOGE("Attempted to get choreographer from invalid surface control");
202*d57664e9SAndroid Build Coastguard Worker return nullptr;
203*d57664e9SAndroid Build Coastguard Worker }
204*d57664e9SAndroid Build Coastguard Worker SurfaceControl_acquire(surfaceControl);
205*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<AChoreographer*>(surfaceControl->getChoreographer().get());
206*d57664e9SAndroid Build Coastguard Worker }
207*d57664e9SAndroid Build Coastguard Worker
ASurfaceControlStats_getAcquireTime(ASurfaceControlStats * stats)208*d57664e9SAndroid Build Coastguard Worker int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
209*d57664e9SAndroid Build Coastguard Worker if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
210*d57664e9SAndroid Build Coastguard Worker // We got a fence instead of the acquire time due to latch unsignaled.
211*d57664e9SAndroid Build Coastguard Worker // Ideally the client could just get the acquire time dericly from
212*d57664e9SAndroid Build Coastguard Worker // the fence instead of calling this function which needs to block.
213*d57664e9SAndroid Build Coastguard Worker (*fence)->waitForever("ASurfaceControlStats_getAcquireTime");
214*d57664e9SAndroid Build Coastguard Worker return (*fence)->getSignalTime();
215*d57664e9SAndroid Build Coastguard Worker }
216*d57664e9SAndroid Build Coastguard Worker
217*d57664e9SAndroid Build Coastguard Worker return std::get<int64_t>(stats->acquireTimeOrFence);
218*d57664e9SAndroid Build Coastguard Worker }
219*d57664e9SAndroid Build Coastguard Worker
ASurfaceControlStats_getFrameNumber(ASurfaceControlStats * stats)220*d57664e9SAndroid Build Coastguard Worker uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats) {
221*d57664e9SAndroid Build Coastguard Worker return stats->frameNumber;
222*d57664e9SAndroid Build Coastguard Worker }
223*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_create()224*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction* ASurfaceTransaction_create() {
225*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = new Transaction;
226*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<ASurfaceTransaction*>(transaction);
227*d57664e9SAndroid Build Coastguard Worker }
228*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_delete(ASurfaceTransaction * aSurfaceTransaction)229*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_delete(ASurfaceTransaction* aSurfaceTransaction) {
230*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
231*d57664e9SAndroid Build Coastguard Worker delete transaction;
232*d57664e9SAndroid Build Coastguard Worker }
233*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_fromJava(JNIEnv * env,jobject transactionObj)234*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction* ASurfaceTransaction_fromJava(JNIEnv* env, jobject transactionObj) {
235*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!env, "nullptr passed to ASurfaceTransaction_fromJava as env argument");
236*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!transactionObj,
237*d57664e9SAndroid Build Coastguard Worker "nullptr passed to ASurfaceTransaction_fromJava as transactionObj "
238*d57664e9SAndroid Build Coastguard Worker "argument");
239*d57664e9SAndroid Build Coastguard Worker Transaction* transaction =
240*d57664e9SAndroid Build Coastguard Worker android_view_SurfaceTransaction_getNativeSurfaceTransaction(env, transactionObj);
241*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!transaction,
242*d57664e9SAndroid Build Coastguard Worker "surfaceControlObj passed to ASurfaceTransaction_fromJava is not valid");
243*d57664e9SAndroid Build Coastguard Worker return reinterpret_cast<ASurfaceTransaction*>(transaction);
244*d57664e9SAndroid Build Coastguard Worker }
245*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_apply(ASurfaceTransaction * aSurfaceTransaction)246*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_apply(ASurfaceTransaction* aSurfaceTransaction) {
247*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
248*d57664e9SAndroid Build Coastguard Worker
249*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
250*d57664e9SAndroid Build Coastguard Worker
251*d57664e9SAndroid Build Coastguard Worker transaction->apply();
252*d57664e9SAndroid Build Coastguard Worker }
253*d57664e9SAndroid Build Coastguard Worker
254*d57664e9SAndroid Build Coastguard Worker struct ASurfaceTransactionStats {
255*d57664e9SAndroid Build Coastguard Worker std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats;
256*d57664e9SAndroid Build Coastguard Worker int64_t latchTime;
257*d57664e9SAndroid Build Coastguard Worker sp<Fence> presentFence;
258*d57664e9SAndroid Build Coastguard Worker bool transactionCompleted;
259*d57664e9SAndroid Build Coastguard Worker };
260*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats * aSurfaceTransactionStats)261*d57664e9SAndroid Build Coastguard Worker int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) {
262*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransactionStats);
263*d57664e9SAndroid Build Coastguard Worker return aSurfaceTransactionStats->latchTime;
264*d57664e9SAndroid Build Coastguard Worker }
265*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats * aSurfaceTransactionStats)266*d57664e9SAndroid Build Coastguard Worker int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) {
267*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransactionStats);
268*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
269*d57664e9SAndroid Build Coastguard Worker "ASurfaceTransactionStats queried from an incomplete transaction callback");
270*d57664e9SAndroid Build Coastguard Worker
271*d57664e9SAndroid Build Coastguard Worker auto& presentFence = aSurfaceTransactionStats->presentFence;
272*d57664e9SAndroid Build Coastguard Worker return (presentFence) ? presentFence->dup() : -1;
273*d57664e9SAndroid Build Coastguard Worker }
274*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats * aSurfaceTransactionStats,ASurfaceControl *** outASurfaceControls,size_t * outASurfaceControlsSize)275*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* aSurfaceTransactionStats,
276*d57664e9SAndroid Build Coastguard Worker ASurfaceControl*** outASurfaceControls,
277*d57664e9SAndroid Build Coastguard Worker size_t* outASurfaceControlsSize) {
278*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransactionStats);
279*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(outASurfaceControls);
280*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(outASurfaceControlsSize);
281*d57664e9SAndroid Build Coastguard Worker
282*d57664e9SAndroid Build Coastguard Worker size_t size = aSurfaceTransactionStats->aSurfaceControlStats.size();
283*d57664e9SAndroid Build Coastguard Worker
284*d57664e9SAndroid Build Coastguard Worker SurfaceControl** surfaceControls = new SurfaceControl*[size];
285*d57664e9SAndroid Build Coastguard Worker ASurfaceControl** aSurfaceControls = reinterpret_cast<ASurfaceControl**>(surfaceControls);
286*d57664e9SAndroid Build Coastguard Worker
287*d57664e9SAndroid Build Coastguard Worker size_t i = 0;
288*d57664e9SAndroid Build Coastguard Worker for (auto& [aSurfaceControl, aSurfaceControlStats] : aSurfaceTransactionStats->aSurfaceControlStats) {
289*d57664e9SAndroid Build Coastguard Worker aSurfaceControls[i] = aSurfaceControl;
290*d57664e9SAndroid Build Coastguard Worker i++;
291*d57664e9SAndroid Build Coastguard Worker }
292*d57664e9SAndroid Build Coastguard Worker
293*d57664e9SAndroid Build Coastguard Worker *outASurfaceControls = aSurfaceControls;
294*d57664e9SAndroid Build Coastguard Worker *outASurfaceControlsSize = size;
295*d57664e9SAndroid Build Coastguard Worker }
296*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats * aSurfaceTransactionStats,ASurfaceControl * aSurfaceControl)297*d57664e9SAndroid Build Coastguard Worker int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* aSurfaceTransactionStats,
298*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl) {
299*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransactionStats);
300*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
301*d57664e9SAndroid Build Coastguard Worker
302*d57664e9SAndroid Build Coastguard Worker const auto& aSurfaceControlStats =
303*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
304*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(
305*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
306*d57664e9SAndroid Build Coastguard Worker "ASurfaceControl not found");
307*d57664e9SAndroid Build Coastguard Worker
308*d57664e9SAndroid Build Coastguard Worker return ASurfaceControlStats_getAcquireTime(&aSurfaceControlStats->second);
309*d57664e9SAndroid Build Coastguard Worker }
310*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_getPreviousReleaseFenceFd(ASurfaceTransactionStats * aSurfaceTransactionStats,ASurfaceControl * aSurfaceControl)311*d57664e9SAndroid Build Coastguard Worker int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
312*d57664e9SAndroid Build Coastguard Worker ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) {
313*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransactionStats);
314*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
315*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
316*d57664e9SAndroid Build Coastguard Worker "ASurfaceTransactionStats queried from an incomplete transaction callback");
317*d57664e9SAndroid Build Coastguard Worker
318*d57664e9SAndroid Build Coastguard Worker const auto& aSurfaceControlStats =
319*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
320*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(
321*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats == aSurfaceTransactionStats->aSurfaceControlStats.end(),
322*d57664e9SAndroid Build Coastguard Worker "ASurfaceControl not found");
323*d57664e9SAndroid Build Coastguard Worker
324*d57664e9SAndroid Build Coastguard Worker auto& previousReleaseFence = aSurfaceControlStats->second.previousReleaseFence;
325*d57664e9SAndroid Build Coastguard Worker return (previousReleaseFence) ? previousReleaseFence->dup() : -1;
326*d57664e9SAndroid Build Coastguard Worker }
327*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl ** aSurfaceControls)328*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurfaceControls) {
329*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControls);
330*d57664e9SAndroid Build Coastguard Worker
331*d57664e9SAndroid Build Coastguard Worker SurfaceControl** surfaceControls = reinterpret_cast<SurfaceControl**>(aSurfaceControls);
332*d57664e9SAndroid Build Coastguard Worker delete[] surfaceControls;
333*d57664e9SAndroid Build Coastguard Worker }
334*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setOnComplete(ASurfaceTransaction * aSurfaceTransaction,void * context,ASurfaceTransaction_OnComplete func)335*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context,
336*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction_OnComplete func) {
337*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
338*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(func);
339*d57664e9SAndroid Build Coastguard Worker
340*d57664e9SAndroid Build Coastguard Worker TransactionCompletedCallbackTakesContext callback = [func](void* callback_context,
341*d57664e9SAndroid Build Coastguard Worker nsecs_t latchTime,
342*d57664e9SAndroid Build Coastguard Worker const sp<Fence>& presentFence,
343*d57664e9SAndroid Build Coastguard Worker const std::vector<SurfaceControlStats>& surfaceControlStats) {
344*d57664e9SAndroid Build Coastguard Worker ASurfaceTransactionStats aSurfaceTransactionStats;
345*d57664e9SAndroid Build Coastguard Worker
346*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats.latchTime = latchTime;
347*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats.presentFence = presentFence;
348*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats.transactionCompleted = true;
349*d57664e9SAndroid Build Coastguard Worker
350*d57664e9SAndroid Build Coastguard Worker auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
351*d57664e9SAndroid Build Coastguard Worker
352*d57664e9SAndroid Build Coastguard Worker for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
353*d57664e9SAndroid Build Coastguard Worker previousReleaseFence, transformHint, frameEvents, ignore] : surfaceControlStats) {
354*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
355*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
356*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats[aSurfaceControl].previousReleaseFence = previousReleaseFence;
357*d57664e9SAndroid Build Coastguard Worker }
358*d57664e9SAndroid Build Coastguard Worker
359*d57664e9SAndroid Build Coastguard Worker (*func)(callback_context, &aSurfaceTransactionStats);
360*d57664e9SAndroid Build Coastguard Worker };
361*d57664e9SAndroid Build Coastguard Worker
362*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
363*d57664e9SAndroid Build Coastguard Worker
364*d57664e9SAndroid Build Coastguard Worker transaction->addTransactionCompletedCallback(callback, context);
365*d57664e9SAndroid Build Coastguard Worker }
366*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_reparent(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,ASurfaceControl * newParentASurfaceControl)367*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_reparent(ASurfaceTransaction* aSurfaceTransaction,
368*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
369*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* newParentASurfaceControl) {
370*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
371*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
372*d57664e9SAndroid Build Coastguard Worker
373*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
374*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> newParentSurfaceControl = ASurfaceControl_to_SurfaceControl(
375*d57664e9SAndroid Build Coastguard Worker newParentASurfaceControl);
376*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
377*d57664e9SAndroid Build Coastguard Worker
378*d57664e9SAndroid Build Coastguard Worker transaction->reparent(surfaceControl, newParentSurfaceControl);
379*d57664e9SAndroid Build Coastguard Worker }
380*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setVisibility(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,ASurfaceTransactionVisibility visibility)381*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setVisibility(ASurfaceTransaction* aSurfaceTransaction,
382*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
383*d57664e9SAndroid Build Coastguard Worker ASurfaceTransactionVisibility visibility) {
384*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
385*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
386*d57664e9SAndroid Build Coastguard Worker
387*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
388*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
389*d57664e9SAndroid Build Coastguard Worker
390*d57664e9SAndroid Build Coastguard Worker switch (visibility) {
391*d57664e9SAndroid Build Coastguard Worker case ASURFACE_TRANSACTION_VISIBILITY_SHOW:
392*d57664e9SAndroid Build Coastguard Worker transaction->show(surfaceControl);
393*d57664e9SAndroid Build Coastguard Worker break;
394*d57664e9SAndroid Build Coastguard Worker case ASURFACE_TRANSACTION_VISIBILITY_HIDE:
395*d57664e9SAndroid Build Coastguard Worker transaction->hide(surfaceControl);
396*d57664e9SAndroid Build Coastguard Worker break;
397*d57664e9SAndroid Build Coastguard Worker default:
398*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("invalid visibility %d", visibility);
399*d57664e9SAndroid Build Coastguard Worker }
400*d57664e9SAndroid Build Coastguard Worker }
401*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setZOrder(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,int32_t z_order)402*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setZOrder(ASurfaceTransaction* aSurfaceTransaction,
403*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
404*d57664e9SAndroid Build Coastguard Worker int32_t z_order) {
405*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
406*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
407*d57664e9SAndroid Build Coastguard Worker
408*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
409*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
410*d57664e9SAndroid Build Coastguard Worker
411*d57664e9SAndroid Build Coastguard Worker transaction->setLayer(surfaceControl, z_order);
412*d57664e9SAndroid Build Coastguard Worker }
413*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBuffer(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,AHardwareBuffer * buffer,int acquire_fence_fd)414*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBuffer(ASurfaceTransaction* aSurfaceTransaction,
415*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
416*d57664e9SAndroid Build Coastguard Worker AHardwareBuffer* buffer, int acquire_fence_fd) {
417*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
418*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
419*d57664e9SAndroid Build Coastguard Worker
420*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
421*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
422*d57664e9SAndroid Build Coastguard Worker
423*d57664e9SAndroid Build Coastguard Worker sp<GraphicBuffer> graphic_buffer(GraphicBuffer::fromAHardwareBuffer(buffer));
424*d57664e9SAndroid Build Coastguard Worker
425*d57664e9SAndroid Build Coastguard Worker std::optional<sp<Fence>> fence = std::nullopt;
426*d57664e9SAndroid Build Coastguard Worker if (acquire_fence_fd != -1) {
427*d57664e9SAndroid Build Coastguard Worker fence = new Fence(acquire_fence_fd);
428*d57664e9SAndroid Build Coastguard Worker }
429*d57664e9SAndroid Build Coastguard Worker transaction->setBuffer(surfaceControl, graphic_buffer, fence);
430*d57664e9SAndroid Build Coastguard Worker }
431*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBufferWithRelease(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,AHardwareBuffer * buffer,int acquire_fence_fd,void * _Null_unspecified context,ASurfaceTransaction_OnBufferRelease aReleaseCallback)432*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBufferWithRelease(
433*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction* aSurfaceTransaction, ASurfaceControl* aSurfaceControl,
434*d57664e9SAndroid Build Coastguard Worker AHardwareBuffer* buffer, int acquire_fence_fd, void* _Null_unspecified context,
435*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction_OnBufferRelease aReleaseCallback) {
436*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
437*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
438*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aReleaseCallback);
439*d57664e9SAndroid Build Coastguard Worker
440*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
441*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
442*d57664e9SAndroid Build Coastguard Worker
443*d57664e9SAndroid Build Coastguard Worker sp<GraphicBuffer> graphic_buffer(GraphicBuffer::fromAHardwareBuffer(buffer));
444*d57664e9SAndroid Build Coastguard Worker
445*d57664e9SAndroid Build Coastguard Worker std::optional<sp<Fence>> fence = std::nullopt;
446*d57664e9SAndroid Build Coastguard Worker if (acquire_fence_fd != -1) {
447*d57664e9SAndroid Build Coastguard Worker fence = new Fence(acquire_fence_fd);
448*d57664e9SAndroid Build Coastguard Worker }
449*d57664e9SAndroid Build Coastguard Worker
450*d57664e9SAndroid Build Coastguard Worker ReleaseBufferCallback releaseBufferCallback =
451*d57664e9SAndroid Build Coastguard Worker [context,
452*d57664e9SAndroid Build Coastguard Worker aReleaseCallback](const ReleaseCallbackId&, const sp<Fence>& releaseFence,
453*d57664e9SAndroid Build Coastguard Worker std::optional<uint32_t> /* currentMaxAcquiredBufferCount */) {
454*d57664e9SAndroid Build Coastguard Worker (*aReleaseCallback)(context, (releaseFence) ? releaseFence->dup() : -1);
455*d57664e9SAndroid Build Coastguard Worker };
456*d57664e9SAndroid Build Coastguard Worker
457*d57664e9SAndroid Build Coastguard Worker transaction->setBuffer(surfaceControl, graphic_buffer, fence, /* frameNumber */ std::nullopt,
458*d57664e9SAndroid Build Coastguard Worker /* producerId */ 0, releaseBufferCallback);
459*d57664e9SAndroid Build Coastguard Worker }
460*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setGeometry(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,const ARect & source,const ARect & destination,int32_t transform)461*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setGeometry(ASurfaceTransaction* aSurfaceTransaction,
462*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, const ARect& source,
463*d57664e9SAndroid Build Coastguard Worker const ARect& destination, int32_t transform) {
464*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
465*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
466*d57664e9SAndroid Build Coastguard Worker CHECK_VALID_RECT(source);
467*d57664e9SAndroid Build Coastguard Worker CHECK_VALID_RECT(destination);
468*d57664e9SAndroid Build Coastguard Worker
469*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
470*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
471*d57664e9SAndroid Build Coastguard Worker
472*d57664e9SAndroid Build Coastguard Worker Rect sourceRect = static_cast<const Rect&>(source);
473*d57664e9SAndroid Build Coastguard Worker Rect destRect = static_cast<const Rect&>(destination);
474*d57664e9SAndroid Build Coastguard Worker // Adjust the source so its top and left are not negative
475*d57664e9SAndroid Build Coastguard Worker sourceRect.left = std::max(sourceRect.left, 0);
476*d57664e9SAndroid Build Coastguard Worker sourceRect.top = std::max(sourceRect.top, 0);
477*d57664e9SAndroid Build Coastguard Worker
478*d57664e9SAndroid Build Coastguard Worker if (!sourceRect.isValid()) {
479*d57664e9SAndroid Build Coastguard Worker sourceRect.makeInvalid();
480*d57664e9SAndroid Build Coastguard Worker }
481*d57664e9SAndroid Build Coastguard Worker transaction->setBufferCrop(surfaceControl, sourceRect);
482*d57664e9SAndroid Build Coastguard Worker transaction->setDestinationFrame(surfaceControl, destRect);
483*d57664e9SAndroid Build Coastguard Worker transaction->setTransform(surfaceControl, transform);
484*d57664e9SAndroid Build Coastguard Worker bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
485*d57664e9SAndroid Build Coastguard Worker NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
486*d57664e9SAndroid Build Coastguard Worker transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay);
487*d57664e9SAndroid Build Coastguard Worker }
488*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setCrop(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,const ARect & crop)489*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setCrop(ASurfaceTransaction* aSurfaceTransaction,
490*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, const ARect& crop) {
491*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
492*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
493*d57664e9SAndroid Build Coastguard Worker CHECK_VALID_RECT(crop);
494*d57664e9SAndroid Build Coastguard Worker
495*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
496*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
497*d57664e9SAndroid Build Coastguard Worker
498*d57664e9SAndroid Build Coastguard Worker transaction->setCrop(surfaceControl, static_cast<const Rect&>(crop));
499*d57664e9SAndroid Build Coastguard Worker }
500*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setPosition(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,int32_t x,int32_t y)501*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setPosition(ASurfaceTransaction* aSurfaceTransaction,
502*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, int32_t x, int32_t y) {
503*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
504*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
505*d57664e9SAndroid Build Coastguard Worker
506*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
507*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
508*d57664e9SAndroid Build Coastguard Worker
509*d57664e9SAndroid Build Coastguard Worker transaction->setPosition(surfaceControl, x, y);
510*d57664e9SAndroid Build Coastguard Worker }
511*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBufferTransform(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,int32_t transform)512*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* aSurfaceTransaction,
513*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, int32_t transform) {
514*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
515*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
516*d57664e9SAndroid Build Coastguard Worker
517*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
518*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
519*d57664e9SAndroid Build Coastguard Worker
520*d57664e9SAndroid Build Coastguard Worker transaction->setTransform(surfaceControl, transform);
521*d57664e9SAndroid Build Coastguard Worker bool transformToInverseDisplay = (NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY & transform) ==
522*d57664e9SAndroid Build Coastguard Worker NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
523*d57664e9SAndroid Build Coastguard Worker transaction->setTransformToDisplayInverse(surfaceControl, transformToInverseDisplay);
524*d57664e9SAndroid Build Coastguard Worker }
525*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setScale(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float xScale,float yScale)526*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setScale(ASurfaceTransaction* aSurfaceTransaction,
527*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, float xScale, float yScale) {
528*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
529*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
530*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(xScale < 0, "negative value passed in for xScale");
531*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(yScale < 0, "negative value passed in for yScale");
532*d57664e9SAndroid Build Coastguard Worker
533*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
534*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
535*d57664e9SAndroid Build Coastguard Worker
536*d57664e9SAndroid Build Coastguard Worker transaction->setMatrix(surfaceControl, xScale, 0, 0, yScale);
537*d57664e9SAndroid Build Coastguard Worker }
538*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,ASurfaceTransactionTransparency transparency)539*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* aSurfaceTransaction,
540*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
541*d57664e9SAndroid Build Coastguard Worker ASurfaceTransactionTransparency transparency) {
542*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
543*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
544*d57664e9SAndroid Build Coastguard Worker
545*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
546*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
547*d57664e9SAndroid Build Coastguard Worker
548*d57664e9SAndroid Build Coastguard Worker uint32_t flags = (transparency == ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE) ?
549*d57664e9SAndroid Build Coastguard Worker layer_state_t::eLayerOpaque : 0;
550*d57664e9SAndroid Build Coastguard Worker transaction->setFlags(surfaceControl, flags, layer_state_t::eLayerOpaque);
551*d57664e9SAndroid Build Coastguard Worker }
552*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setDamageRegion(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,const ARect rects[],uint32_t count)553*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* aSurfaceTransaction,
554*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
555*d57664e9SAndroid Build Coastguard Worker const ARect rects[], uint32_t count) {
556*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
557*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
558*d57664e9SAndroid Build Coastguard Worker
559*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
560*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
561*d57664e9SAndroid Build Coastguard Worker
562*d57664e9SAndroid Build Coastguard Worker Region region;
563*d57664e9SAndroid Build Coastguard Worker for (uint32_t i = 0; i < count; ++i) {
564*d57664e9SAndroid Build Coastguard Worker region.orSelf(static_cast<const Rect&>(rects[i]));
565*d57664e9SAndroid Build Coastguard Worker }
566*d57664e9SAndroid Build Coastguard Worker
567*d57664e9SAndroid Build Coastguard Worker // Hardware composer interprets a DamageRegion with a single Rect of {0,0,0,0} to be an
568*d57664e9SAndroid Build Coastguard Worker // undamaged region and {0,0,-1,-1} to be a fully damaged buffer. This is a confusing
569*d57664e9SAndroid Build Coastguard Worker // distinction for a public api. Instead, default both cases to be a fully damaged buffer.
570*d57664e9SAndroid Build Coastguard Worker if (count == 1 && region.getBounds().isEmpty()) {
571*d57664e9SAndroid Build Coastguard Worker transaction->setSurfaceDamageRegion(surfaceControl, Region::INVALID_REGION);
572*d57664e9SAndroid Build Coastguard Worker return;
573*d57664e9SAndroid Build Coastguard Worker }
574*d57664e9SAndroid Build Coastguard Worker
575*d57664e9SAndroid Build Coastguard Worker transaction->setSurfaceDamageRegion(surfaceControl, region);
576*d57664e9SAndroid Build Coastguard Worker }
577*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction * aSurfaceTransaction,int64_t desiredPresentTime)578*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* aSurfaceTransaction,
579*d57664e9SAndroid Build Coastguard Worker int64_t desiredPresentTime) {
580*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
581*d57664e9SAndroid Build Coastguard Worker
582*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
583*d57664e9SAndroid Build Coastguard Worker
584*d57664e9SAndroid Build Coastguard Worker transaction->setDesiredPresentTime(static_cast<nsecs_t>(desiredPresentTime));
585*d57664e9SAndroid Build Coastguard Worker }
586*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float alpha)587*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* aSurfaceTransaction,
588*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
589*d57664e9SAndroid Build Coastguard Worker float alpha) {
590*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
591*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
592*d57664e9SAndroid Build Coastguard Worker
593*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(alpha < 0.0 || alpha > 1.0, "invalid alpha");
594*d57664e9SAndroid Build Coastguard Worker
595*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
596*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
597*d57664e9SAndroid Build Coastguard Worker
598*d57664e9SAndroid Build Coastguard Worker transaction->setAlpha(surfaceControl, alpha);
599*d57664e9SAndroid Build Coastguard Worker }
600*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,ADataSpace aDataSpace)601*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* aSurfaceTransaction,
602*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
603*d57664e9SAndroid Build Coastguard Worker ADataSpace aDataSpace) {
604*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
605*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
606*d57664e9SAndroid Build Coastguard Worker
607*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
608*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
609*d57664e9SAndroid Build Coastguard Worker transaction->setDataspace(surfaceControl, static_cast<ui::Dataspace>(aDataSpace));
610*d57664e9SAndroid Build Coastguard Worker }
611*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,struct AHdrMetadata_smpte2086 * metadata)612*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* aSurfaceTransaction,
613*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
614*d57664e9SAndroid Build Coastguard Worker struct AHdrMetadata_smpte2086* metadata) {
615*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
616*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
617*d57664e9SAndroid Build Coastguard Worker
618*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
619*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
620*d57664e9SAndroid Build Coastguard Worker
621*d57664e9SAndroid Build Coastguard Worker HdrMetadata hdrMetadata;
622*d57664e9SAndroid Build Coastguard Worker
623*d57664e9SAndroid Build Coastguard Worker if (metadata) {
624*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryRed.x = metadata->displayPrimaryRed.x;
625*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryRed.y = metadata->displayPrimaryRed.y;
626*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryGreen.x = metadata->displayPrimaryGreen.x;
627*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryGreen.y = metadata->displayPrimaryGreen.y;
628*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryBlue.x = metadata->displayPrimaryBlue.x;
629*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.displayPrimaryBlue.y = metadata->displayPrimaryBlue.y;
630*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.whitePoint.x = metadata->whitePoint.x;
631*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.whitePoint.y = metadata->whitePoint.y;
632*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.minLuminance = metadata->minLuminance;
633*d57664e9SAndroid Build Coastguard Worker hdrMetadata.smpte2086.maxLuminance = metadata->maxLuminance;
634*d57664e9SAndroid Build Coastguard Worker
635*d57664e9SAndroid Build Coastguard Worker hdrMetadata.validTypes |= HdrMetadata::SMPTE2086;
636*d57664e9SAndroid Build Coastguard Worker } else {
637*d57664e9SAndroid Build Coastguard Worker hdrMetadata.validTypes &= ~HdrMetadata::SMPTE2086;
638*d57664e9SAndroid Build Coastguard Worker }
639*d57664e9SAndroid Build Coastguard Worker
640*d57664e9SAndroid Build Coastguard Worker transaction->setHdrMetadata(surfaceControl, hdrMetadata);
641*d57664e9SAndroid Build Coastguard Worker }
642*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,struct AHdrMetadata_cta861_3 * metadata)643*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* aSurfaceTransaction,
644*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
645*d57664e9SAndroid Build Coastguard Worker struct AHdrMetadata_cta861_3* metadata) {
646*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
647*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
648*d57664e9SAndroid Build Coastguard Worker
649*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
650*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
651*d57664e9SAndroid Build Coastguard Worker
652*d57664e9SAndroid Build Coastguard Worker HdrMetadata hdrMetadata;
653*d57664e9SAndroid Build Coastguard Worker
654*d57664e9SAndroid Build Coastguard Worker if (metadata) {
655*d57664e9SAndroid Build Coastguard Worker hdrMetadata.cta8613.maxContentLightLevel = metadata->maxContentLightLevel;
656*d57664e9SAndroid Build Coastguard Worker hdrMetadata.cta8613.maxFrameAverageLightLevel = metadata->maxFrameAverageLightLevel;
657*d57664e9SAndroid Build Coastguard Worker
658*d57664e9SAndroid Build Coastguard Worker hdrMetadata.validTypes |= HdrMetadata::CTA861_3;
659*d57664e9SAndroid Build Coastguard Worker } else {
660*d57664e9SAndroid Build Coastguard Worker hdrMetadata.validTypes &= ~HdrMetadata::CTA861_3;
661*d57664e9SAndroid Build Coastguard Worker }
662*d57664e9SAndroid Build Coastguard Worker
663*d57664e9SAndroid Build Coastguard Worker transaction->setHdrMetadata(surfaceControl, hdrMetadata);
664*d57664e9SAndroid Build Coastguard Worker }
665*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float currentBufferRatio,float desiredRatio)666*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* aSurfaceTransaction,
667*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
668*d57664e9SAndroid Build Coastguard Worker float currentBufferRatio, float desiredRatio) {
669*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
670*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
671*d57664e9SAndroid Build Coastguard Worker
672*d57664e9SAndroid Build Coastguard Worker if (!isfinite(currentBufferRatio) || currentBufferRatio < 1.0f) {
673*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("setExtendedRangeBrightness, currentBufferRatio %f isn't finite or >= "
674*d57664e9SAndroid Build Coastguard Worker "1.0f",
675*d57664e9SAndroid Build Coastguard Worker currentBufferRatio);
676*d57664e9SAndroid Build Coastguard Worker return;
677*d57664e9SAndroid Build Coastguard Worker }
678*d57664e9SAndroid Build Coastguard Worker
679*d57664e9SAndroid Build Coastguard Worker if (!isfinite(desiredRatio) || desiredRatio < 1.0f) {
680*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("setExtendedRangeBrightness, desiredRatio %f isn't finite or >= 1.0f",
681*d57664e9SAndroid Build Coastguard Worker desiredRatio);
682*d57664e9SAndroid Build Coastguard Worker return;
683*d57664e9SAndroid Build Coastguard Worker }
684*d57664e9SAndroid Build Coastguard Worker
685*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
686*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
687*d57664e9SAndroid Build Coastguard Worker
688*d57664e9SAndroid Build Coastguard Worker transaction->setExtendedRangeBrightness(surfaceControl, currentBufferRatio, desiredRatio);
689*d57664e9SAndroid Build Coastguard Worker }
690*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float desiredRatio)691*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* aSurfaceTransaction,
692*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
693*d57664e9SAndroid Build Coastguard Worker float desiredRatio) {
694*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
695*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
696*d57664e9SAndroid Build Coastguard Worker
697*d57664e9SAndroid Build Coastguard Worker if (!isfinite(desiredRatio) || (desiredRatio < 1.0f && desiredRatio > 0.0f)) {
698*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("setDesiredHdrHeadroom, desiredRatio isn't finite && >= 1.0f or 0, got %f",
699*d57664e9SAndroid Build Coastguard Worker desiredRatio);
700*d57664e9SAndroid Build Coastguard Worker return;
701*d57664e9SAndroid Build Coastguard Worker }
702*d57664e9SAndroid Build Coastguard Worker
703*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
704*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
705*d57664e9SAndroid Build Coastguard Worker
706*d57664e9SAndroid Build Coastguard Worker transaction->setDesiredHdrHeadroom(surfaceControl, desiredRatio);
707*d57664e9SAndroid Build Coastguard Worker }
708*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setLuts(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,const struct ADisplayLuts * luts)709*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setLuts(ASurfaceTransaction* aSurfaceTransaction,
710*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
711*d57664e9SAndroid Build Coastguard Worker const struct ADisplayLuts* luts) {
712*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
713*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
714*d57664e9SAndroid Build Coastguard Worker
715*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
716*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
717*d57664e9SAndroid Build Coastguard Worker
718*d57664e9SAndroid Build Coastguard Worker int fd = -1;
719*d57664e9SAndroid Build Coastguard Worker std::vector<int32_t> offsets;
720*d57664e9SAndroid Build Coastguard Worker std::vector<int32_t> dimensions;
721*d57664e9SAndroid Build Coastguard Worker std::vector<int32_t> sizes;
722*d57664e9SAndroid Build Coastguard Worker std::vector<int32_t> samplingKeys;
723*d57664e9SAndroid Build Coastguard Worker
724*d57664e9SAndroid Build Coastguard Worker if (luts) {
725*d57664e9SAndroid Build Coastguard Worker std::vector<float> buffer(luts->totalBufferSize);
726*d57664e9SAndroid Build Coastguard Worker int32_t count = luts->offsets.size();
727*d57664e9SAndroid Build Coastguard Worker offsets = luts->offsets;
728*d57664e9SAndroid Build Coastguard Worker
729*d57664e9SAndroid Build Coastguard Worker dimensions.reserve(count);
730*d57664e9SAndroid Build Coastguard Worker sizes.reserve(count);
731*d57664e9SAndroid Build Coastguard Worker samplingKeys.reserve(count);
732*d57664e9SAndroid Build Coastguard Worker for (int32_t i = 0; i < count; i++) {
733*d57664e9SAndroid Build Coastguard Worker dimensions.emplace_back(luts->entries[i]->properties.dimension);
734*d57664e9SAndroid Build Coastguard Worker sizes.emplace_back(luts->entries[i]->properties.size);
735*d57664e9SAndroid Build Coastguard Worker samplingKeys.emplace_back(luts->entries[i]->properties.samplingKey);
736*d57664e9SAndroid Build Coastguard Worker std::copy(luts->entries[i]->buffer.data.begin(), luts->entries[i]->buffer.data.end(),
737*d57664e9SAndroid Build Coastguard Worker buffer.begin() + offsets[i]);
738*d57664e9SAndroid Build Coastguard Worker }
739*d57664e9SAndroid Build Coastguard Worker
740*d57664e9SAndroid Build Coastguard Worker // mmap
741*d57664e9SAndroid Build Coastguard Worker fd = ashmem_create_region("lut_shared_mem", luts->totalBufferSize * sizeof(float));
742*d57664e9SAndroid Build Coastguard Worker if (fd < 0) {
743*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("setLuts, ashmem_create_region() failed");
744*d57664e9SAndroid Build Coastguard Worker return;
745*d57664e9SAndroid Build Coastguard Worker }
746*d57664e9SAndroid Build Coastguard Worker void* ptr = mmap(nullptr, luts->totalBufferSize * sizeof(float), PROT_READ | PROT_WRITE,
747*d57664e9SAndroid Build Coastguard Worker MAP_SHARED, fd, 0);
748*d57664e9SAndroid Build Coastguard Worker if (ptr == MAP_FAILED) {
749*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL("setLuts, Failed to map the shared memory");
750*d57664e9SAndroid Build Coastguard Worker return;
751*d57664e9SAndroid Build Coastguard Worker }
752*d57664e9SAndroid Build Coastguard Worker
753*d57664e9SAndroid Build Coastguard Worker memcpy(ptr, buffer.data(), luts->totalBufferSize * sizeof(float));
754*d57664e9SAndroid Build Coastguard Worker munmap(ptr, luts->totalBufferSize * sizeof(float));
755*d57664e9SAndroid Build Coastguard Worker }
756*d57664e9SAndroid Build Coastguard Worker
757*d57664e9SAndroid Build Coastguard Worker transaction->setLuts(surfaceControl, base::unique_fd(fd), offsets, dimensions, sizes,
758*d57664e9SAndroid Build Coastguard Worker samplingKeys);
759*d57664e9SAndroid Build Coastguard Worker }
760*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setColor(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float r,float g,float b,float alpha,ADataSpace dataspace)761*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction,
762*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
763*d57664e9SAndroid Build Coastguard Worker float r, float g, float b, float alpha,
764*d57664e9SAndroid Build Coastguard Worker ADataSpace dataspace) {
765*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
766*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
767*d57664e9SAndroid Build Coastguard Worker
768*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
769*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
770*d57664e9SAndroid Build Coastguard Worker
771*d57664e9SAndroid Build Coastguard Worker half3 color;
772*d57664e9SAndroid Build Coastguard Worker color.r = r;
773*d57664e9SAndroid Build Coastguard Worker color.g = g;
774*d57664e9SAndroid Build Coastguard Worker color.b = b;
775*d57664e9SAndroid Build Coastguard Worker
776*d57664e9SAndroid Build Coastguard Worker transaction->setBackgroundColor(surfaceControl, color, alpha,
777*d57664e9SAndroid Build Coastguard Worker static_cast<ui::Dataspace>(dataspace));
778*d57664e9SAndroid Build Coastguard Worker }
779*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setFrameRate(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float frameRate,int8_t compatibility)780*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* aSurfaceTransaction,
781*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl, float frameRate,
782*d57664e9SAndroid Build Coastguard Worker int8_t compatibility) {
783*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction_setFrameRateWithChangeStrategy(
784*d57664e9SAndroid Build Coastguard Worker aSurfaceTransaction, aSurfaceControl, frameRate, compatibility,
785*d57664e9SAndroid Build Coastguard Worker ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
786*d57664e9SAndroid Build Coastguard Worker }
787*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)788*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* aSurfaceTransaction,
789*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
790*d57664e9SAndroid Build Coastguard Worker float frameRate, int8_t compatibility,
791*d57664e9SAndroid Build Coastguard Worker int8_t changeFrameRateStrategy) {
792*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
793*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
794*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
795*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
796*d57664e9SAndroid Build Coastguard Worker transaction->setFrameRate(surfaceControl, frameRate, compatibility, changeFrameRateStrategy);
797*d57664e9SAndroid Build Coastguard Worker }
798*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_clearFrameRate(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl)799*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* aSurfaceTransaction,
800*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl) {
801*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
802*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
803*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
804*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
805*d57664e9SAndroid Build Coastguard Worker transaction->setFrameRate(surfaceControl, 0, ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
806*d57664e9SAndroid Build Coastguard Worker ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
807*d57664e9SAndroid Build Coastguard Worker }
808*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction * aSurfaceTransaction,ASurfaceControl * aSurfaceControl,bool enableBackpressure)809*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* aSurfaceTransaction,
810*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl,
811*d57664e9SAndroid Build Coastguard Worker bool enableBackpressure) {
812*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceControl);
813*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
814*d57664e9SAndroid Build Coastguard Worker
815*d57664e9SAndroid Build Coastguard Worker sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
816*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
817*d57664e9SAndroid Build Coastguard Worker
818*d57664e9SAndroid Build Coastguard Worker const uint32_t flags = enableBackpressure ?
819*d57664e9SAndroid Build Coastguard Worker layer_state_t::eEnableBackpressure : 0;
820*d57664e9SAndroid Build Coastguard Worker transaction->setFlags(surfaceControl, flags, layer_state_t::eEnableBackpressure);
821*d57664e9SAndroid Build Coastguard Worker }
822*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setOnCommit(ASurfaceTransaction * aSurfaceTransaction,void * context,ASurfaceTransaction_OnCommit func)823*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* aSurfaceTransaction, void* context,
824*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction_OnCommit func) {
825*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
826*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(func);
827*d57664e9SAndroid Build Coastguard Worker
828*d57664e9SAndroid Build Coastguard Worker TransactionCompletedCallbackTakesContext callback =
829*d57664e9SAndroid Build Coastguard Worker [func](void* callback_context, nsecs_t latchTime, const sp<Fence>& /* presentFence */,
830*d57664e9SAndroid Build Coastguard Worker const std::vector<SurfaceControlStats>& surfaceControlStats) {
831*d57664e9SAndroid Build Coastguard Worker ASurfaceTransactionStats aSurfaceTransactionStats;
832*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats.latchTime = latchTime;
833*d57664e9SAndroid Build Coastguard Worker aSurfaceTransactionStats.transactionCompleted = false;
834*d57664e9SAndroid Build Coastguard Worker
835*d57664e9SAndroid Build Coastguard Worker auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
836*d57664e9SAndroid Build Coastguard Worker for (const auto& [surfaceControl, latchTime, acquireTimeOrFence, presentFence,
837*d57664e9SAndroid Build Coastguard Worker previousReleaseFence, transformHint, frameEvents, ignore] :
838*d57664e9SAndroid Build Coastguard Worker surfaceControlStats) {
839*d57664e9SAndroid Build Coastguard Worker ASurfaceControl* aSurfaceControl =
840*d57664e9SAndroid Build Coastguard Worker reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
841*d57664e9SAndroid Build Coastguard Worker aSurfaceControlStats[aSurfaceControl].acquireTimeOrFence = acquireTimeOrFence;
842*d57664e9SAndroid Build Coastguard Worker }
843*d57664e9SAndroid Build Coastguard Worker
844*d57664e9SAndroid Build Coastguard Worker (*func)(callback_context, &aSurfaceTransactionStats);
845*d57664e9SAndroid Build Coastguard Worker };
846*d57664e9SAndroid Build Coastguard Worker
847*d57664e9SAndroid Build Coastguard Worker Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
848*d57664e9SAndroid Build Coastguard Worker
849*d57664e9SAndroid Build Coastguard Worker transaction->addTransactionCommittedCallback(callback, context);
850*d57664e9SAndroid Build Coastguard Worker }
851*d57664e9SAndroid Build Coastguard Worker
ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction * aSurfaceTransaction,AVsyncId vsyncId)852*d57664e9SAndroid Build Coastguard Worker void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* aSurfaceTransaction,
853*d57664e9SAndroid Build Coastguard Worker AVsyncId vsyncId) {
854*d57664e9SAndroid Build Coastguard Worker CHECK_NOT_NULL(aSurfaceTransaction);
855*d57664e9SAndroid Build Coastguard Worker const auto startTime = AChoreographer_getStartTimeNanosForVsyncId(vsyncId);
856*d57664e9SAndroid Build Coastguard Worker FrameTimelineInfo ftInfo;
857*d57664e9SAndroid Build Coastguard Worker ftInfo.vsyncId = vsyncId;
858*d57664e9SAndroid Build Coastguard Worker ftInfo.startTimeNanos = startTime;
859*d57664e9SAndroid Build Coastguard Worker ASurfaceTransaction_to_Transaction(aSurfaceTransaction)->setFrameTimelineInfo(ftInfo);
860*d57664e9SAndroid Build Coastguard Worker }
861