blob: 5306529fcb77283fc2856c65c35facd27b40d386 [file] [log] [blame]
Mathias Agopian89ed4c82017-02-09 18:48:34 -08001/*
2 * Copyright (C) 2010 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
17#define LOG_TAG "ANativeWindow"
18
Jesse Hall79927812017-03-23 11:03:23 -070019#include <grallocusage/GrallocUsageConversion.h>
Mathias Agopian000879a2017-03-20 18:07:26 -070020// from nativewindow/includes/system/window.h
21// (not to be confused with the compatibility-only window.h from system/core/includes)
Mathias Agopian89ed4c82017-02-09 18:48:34 -080022#include <system/window.h>
Sungtak Lee4b3e4a92022-11-01 23:39:37 +000023#include <android/native_window_aidl.h>
Mathias Agopian89ed4c82017-02-09 18:48:34 -080024
Mathias Agopian000879a2017-03-20 18:07:26 -070025#include <private/android/AHardwareBufferHelpers.h>
Mathias Agopian89ed4c82017-02-09 18:48:34 -080026
John Reck42fcb0d2023-02-23 17:55:07 -050027#include <android/binder_libbinder.h>
28#include <dlfcn.h>
Sungtak Lee4b3e4a92022-11-01 23:39:37 +000029#include <log/log.h>
Mathias Agopian453effd2017-04-03 15:34:13 -070030#include <ui/GraphicBuffer.h>
31
Mathias Agopian000879a2017-03-20 18:07:26 -070032using namespace android;
Mathias Agopian89ed4c82017-02-09 18:48:34 -080033
John Reck42fcb0d2023-02-23 17:55:07 -050034#if defined(__ANDROID_APEX__) || defined(__ANDROID_VNDK__)
35#error libnativewindow can only be built for system
36#endif
37
38using android_view_Surface_writeToParcel = status_t (*)(ANativeWindow* _Nonnull window,
39 Parcel* _Nonnull parcel);
40
41using android_view_Surface_readFromParcel =
42 status_t (*)(const Parcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow);
43
44struct SurfaceParcelables {
45 android_view_Surface_writeToParcel write = nullptr;
46 android_view_Surface_readFromParcel read = nullptr;
47};
48
49const SurfaceParcelables* getSurfaceParcelFunctions() {
50 static SurfaceParcelables funcs = []() -> SurfaceParcelables {
51 SurfaceParcelables ret;
52 void* dl = dlopen("libgui.so", RTLD_NOW);
53 LOG_ALWAYS_FATAL_IF(!dl, "Failed to find libgui.so");
54 ret.write =
55 (android_view_Surface_writeToParcel)dlsym(dl, "android_view_Surface_writeToParcel");
56 LOG_ALWAYS_FATAL_IF(!ret.write,
57 "libgui.so missing android_view_Surface_writeToParcel; "
58 "loaded wrong libgui?");
59 ret.read =
60 (android_view_Surface_readFromParcel)dlsym(dl,
61 "android_view_Surface_readFromParcel");
62 LOG_ALWAYS_FATAL_IF(!ret.read,
63 "libgui.so missing android_view_Surface_readFromParcel; "
64 "loaded wrong libgui?");
65 return ret;
66 }();
67 return &funcs;
68}
69
Mathias Agopian000879a2017-03-20 18:07:26 -070070static int32_t query(ANativeWindow* window, int what) {
Mathias Agopian89ed4c82017-02-09 18:48:34 -080071 int value;
72 int res = window->query(window, what, &value);
73 return res < 0 ? res : value;
74}
75
Alec Mouri72670c52019-08-31 01:54:33 -070076static int64_t query64(ANativeWindow* window, int what) {
77 int64_t value;
78 int res = window->perform(window, what, &value);
79 return res < 0 ? res : value;
80}
81
Peiyong Lin654f87b2018-01-30 14:21:33 -080082static bool isDataSpaceValid(ANativeWindow* window, int32_t dataSpace) {
83 bool supported = false;
84 switch (dataSpace) {
85 case HAL_DATASPACE_UNKNOWN:
86 case HAL_DATASPACE_V0_SRGB:
87 return true;
88 // These data space need wide gamut support.
89 case HAL_DATASPACE_V0_SCRGB_LINEAR:
90 case HAL_DATASPACE_V0_SCRGB:
91 case HAL_DATASPACE_DISPLAY_P3:
92 native_window_get_wide_color_support(window, &supported);
93 return supported;
94 // These data space need HDR support.
95 case HAL_DATASPACE_BT2020_PQ:
96 native_window_get_hdr_support(window, &supported);
97 return supported;
98 default:
99 return false;
100 }
101}
102
Mathias Agopian000879a2017-03-20 18:07:26 -0700103/**************************************************************************************************
104 * NDK
105 **************************************************************************************************/
106
107void ANativeWindow_acquire(ANativeWindow* window) {
108 // incStrong/decStrong token must be the same, doesn't matter what it is
109 window->incStrong((void*)ANativeWindow_acquire);
110}
111
112void ANativeWindow_release(ANativeWindow* window) {
113 // incStrong/decStrong token must be the same, doesn't matter what it is
114 window->decStrong((void*)ANativeWindow_acquire);
115}
116
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800117int32_t ANativeWindow_getWidth(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -0700118 return query(window, NATIVE_WINDOW_WIDTH);
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800119}
120
121int32_t ANativeWindow_getHeight(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -0700122 return query(window, NATIVE_WINDOW_HEIGHT);
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800123}
124
125int32_t ANativeWindow_getFormat(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -0700126 return query(window, NATIVE_WINDOW_FORMAT);
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800127}
128
Mathias Agopian000879a2017-03-20 18:07:26 -0700129int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
130 int32_t width, int32_t height, int32_t format) {
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800131 int32_t err = native_window_set_buffers_format(window, format);
132 if (!err) {
133 err = native_window_set_buffers_user_dimensions(window, width, height);
134 if (!err) {
135 int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
136 if (width && height) {
137 mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
138 }
139 err = native_window_set_scaling_mode(window, mode);
140 }
141 }
142 return err;
143}
144
145int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
146 ARect* inOutDirtyBounds) {
147 return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds);
148}
149
150int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
151 return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST);
152}
Jesse Hall09932ec2017-03-13 11:36:05 -0700153
154int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) {
155 static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL == NATIVE_WINDOW_TRANSFORM_FLIP_H);
156 static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL == NATIVE_WINDOW_TRANSFORM_FLIP_V);
157 static_assert(ANATIVEWINDOW_TRANSFORM_ROTATE_90 == NATIVE_WINDOW_TRANSFORM_ROT_90);
158
159 constexpr int32_t kAllTransformBits =
160 ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |
161 ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL |
Robert Carr175ed5b2018-04-06 13:59:00 -0700162 ANATIVEWINDOW_TRANSFORM_ROTATE_90 |
163 // We don't expose INVERSE_DISPLAY as an NDK constant, but someone could have read it
164 // from a buffer already set by Camera framework, so we allow it to be forwarded.
165 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
Mathias Agopian000879a2017-03-20 18:07:26 -0700166 if (!window || !query(window, NATIVE_WINDOW_IS_VALID))
Jesse Hall09932ec2017-03-13 11:36:05 -0700167 return -EINVAL;
168 if ((transform & ~kAllTransformBits) != 0)
169 return -EINVAL;
170
171 return native_window_set_buffers_transform(window, transform);
172}
Mathias Agopian000879a2017-03-20 18:07:26 -0700173
Peiyong Lin654f87b2018-01-30 14:21:33 -0800174int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) {
Yi Kong2fe2a082018-05-31 11:47:00 -0700175 static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700176 static_assert(static_cast<int>(STANDARD_MASK) == static_cast<int>(HAL_DATASPACE_STANDARD_MASK));
177 static_assert(static_cast<int>(STANDARD_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_STANDARD_UNSPECIFIED));
178 static_assert(static_cast<int>(STANDARD_BT709) == static_cast<int>(HAL_DATASPACE_STANDARD_BT709));
179 static_assert(static_cast<int>(STANDARD_BT601_625) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625));
180 static_assert(static_cast<int>(STANDARD_BT601_625_UNADJUSTED) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED));
181 static_assert(static_cast<int>(STANDARD_BT601_525) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525));
182 static_assert(static_cast<int>(STANDARD_BT601_525_UNADJUSTED) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED));
183 static_assert(static_cast<int>(STANDARD_BT470M) == static_cast<int>(HAL_DATASPACE_STANDARD_BT470M));
184 static_assert(static_cast<int>(STANDARD_FILM) == static_cast<int>(HAL_DATASPACE_STANDARD_FILM));
185 static_assert(static_cast<int>(STANDARD_DCI_P3) == static_cast<int>(HAL_DATASPACE_STANDARD_DCI_P3));
186 static_assert(static_cast<int>(STANDARD_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_STANDARD_ADOBE_RGB));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700187 static_assert(static_cast<int>(TRANSFER_MASK) == static_cast<int>(HAL_DATASPACE_TRANSFER_MASK));
188 static_assert(static_cast<int>(TRANSFER_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_TRANSFER_UNSPECIFIED));
189 static_assert(static_cast<int>(TRANSFER_LINEAR) == static_cast<int>(HAL_DATASPACE_TRANSFER_LINEAR));
190 static_assert(static_cast<int>(TRANSFER_SMPTE_170M) == static_cast<int>(HAL_DATASPACE_TRANSFER_SMPTE_170M));
191 static_assert(static_cast<int>(TRANSFER_GAMMA2_2) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_2));
192 static_assert(static_cast<int>(TRANSFER_GAMMA2_6) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_6));
193 static_assert(static_cast<int>(TRANSFER_GAMMA2_8) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_8));
194 static_assert(static_cast<int>(TRANSFER_ST2084) == static_cast<int>(HAL_DATASPACE_TRANSFER_ST2084));
195 static_assert(static_cast<int>(TRANSFER_HLG) == static_cast<int>(HAL_DATASPACE_TRANSFER_HLG));
196 static_assert(static_cast<int>(RANGE_MASK) == static_cast<int>(HAL_DATASPACE_RANGE_MASK));
197 static_assert(static_cast<int>(RANGE_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_RANGE_UNSPECIFIED));
198 static_assert(static_cast<int>(RANGE_FULL) == static_cast<int>(HAL_DATASPACE_RANGE_FULL));
199 static_assert(static_cast<int>(RANGE_LIMITED) == static_cast<int>(HAL_DATASPACE_RANGE_LIMITED));
200 static_assert(static_cast<int>(RANGE_EXTENDED) == static_cast<int>(HAL_DATASPACE_RANGE_EXTENDED));
Yi Kong2fe2a082018-05-31 11:47:00 -0700201 static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB));
202 static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
203 static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
204 static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
Sally Qi31c3f572021-11-16 10:14:50 -0800205 static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_PQ) ==
206 static_cast<int>(HAL_DATASPACE_BT2020_ITU_PQ));
Peiyong Lin91a2b3d2019-12-12 21:33:11 -0800207 static_assert(static_cast<int>(ADATASPACE_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_ADOBE_RGB));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700208 static_assert(static_cast<int>(ADATASPACE_JFIF) == static_cast<int>(HAL_DATASPACE_V0_JFIF));
209 static_assert(static_cast<int>(ADATASPACE_BT601_625) == static_cast<int>(HAL_DATASPACE_V0_BT601_625));
210 static_assert(static_cast<int>(ADATASPACE_BT601_525) == static_cast<int>(HAL_DATASPACE_V0_BT601_525));
Peiyong Lin91a2b3d2019-12-12 21:33:11 -0800211 static_assert(static_cast<int>(ADATASPACE_BT2020) == static_cast<int>(HAL_DATASPACE_BT2020));
212 static_assert(static_cast<int>(ADATASPACE_BT709) == static_cast<int>(HAL_DATASPACE_V0_BT709));
213 static_assert(static_cast<int>(ADATASPACE_DCI_P3) == static_cast<int>(HAL_DATASPACE_DCI_P3));
214 static_assert(static_cast<int>(ADATASPACE_SRGB_LINEAR) == static_cast<int>(HAL_DATASPACE_V0_SRGB_LINEAR));
Sally Qi95770602021-11-15 11:16:26 -0800215 static_assert(static_cast<int>(ADATASPACE_BT2020_HLG) ==
216 static_cast<int>(HAL_DATASPACE_BT2020_HLG));
217 static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_HLG) ==
218 static_cast<int>(HAL_DATASPACE_BT2020_ITU_HLG));
Sally Qie77820c2022-06-07 11:01:45 -0700219 static_assert(static_cast<int>(ADATASPACE_DEPTH) == static_cast<int>(HAL_DATASPACE_DEPTH));
220 static_assert(static_cast<int>(ADATASPACE_DYNAMIC_DEPTH) == static_cast<int>(HAL_DATASPACE_DYNAMIC_DEPTH));
Peiyong Lin654f87b2018-01-30 14:21:33 -0800221
222 if (!window || !query(window, NATIVE_WINDOW_IS_VALID) ||
223 !isDataSpaceValid(window, dataSpace)) {
224 return -EINVAL;
225 }
226 return native_window_set_buffers_data_space(window,
227 static_cast<android_dataspace_t>(dataSpace));
228}
229
230int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) {
231 if (!window || !query(window, NATIVE_WINDOW_IS_VALID))
232 return -EINVAL;
233 return query(window, NATIVE_WINDOW_DATASPACE);
234}
235
Jason Macnak78d7fb32022-06-13 10:45:07 -0700236int32_t ANativeWindow_getBuffersDefaultDataSpace(ANativeWindow* window) {
237 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
238 return -EINVAL;
239 }
240 return query(window, NATIVE_WINDOW_DEFAULT_DATASPACE);
241}
242
Steven Thomas62a4cf82020-01-31 12:04:03 -0800243int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100244 return ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility,
245 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
Steven Thomas6d88a482019-12-02 22:00:47 -0800246}
247
Alec Mourid9d85722020-02-13 13:57:19 -0800248void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) {
249 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
250 return;
251 }
252 window->perform(window, NATIVE_WINDOW_ALLOCATE_BUFFERS);
253}
254
Marin Shalamanovc5986772021-03-16 16:09:49 +0100255int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, float frameRate,
256 int8_t compatibility, int8_t changeFrameRateStrategy) {
Marin Shalamanov46084422020-10-13 12:33:42 +0200257 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
258 return -EINVAL;
259 }
Marin Shalamanovc5986772021-03-16 16:09:49 +0100260 return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy);
Marin Shalamanov46084422020-10-13 12:33:42 +0200261}
Alec Mourid9d85722020-02-13 13:57:19 -0800262
Mathias Agopian000879a2017-03-20 18:07:26 -0700263/**************************************************************************************************
264 * vndk-stable
265 **************************************************************************************************/
266
Mathias Agopian453effd2017-04-03 15:34:13 -0700267AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) {
268 return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb));
269}
270
Mathias Agopian000879a2017-03-20 18:07:26 -0700271int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value) {
272 if (slot < 4) {
273 window->oem[slot] = value;
274 return 0;
275 }
276 return -EINVAL;
277}
278
279int ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value) {
280 if (slot >= 4) {
281 *value = window->oem[slot];
282 return 0;
283 }
284 return -EINVAL;
285}
286
287
288int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval) {
289 return window->setSwapInterval(window, interval);
290}
291
292int ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery what, int* value) {
293 switch (what) {
294 case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS:
295 case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH:
296 case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT:
297 case ANATIVEWINDOW_QUERY_TRANSFORM_HINT:
Peiyong Lin90a90f12021-06-03 18:11:56 +0000298 case ANATIVEWINDOW_QUERY_BUFFER_AGE:
Mathias Agopian000879a2017-03-20 18:07:26 -0700299 // these are part of the VNDK API
300 break;
301 case ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL:
302 *value = window->minSwapInterval;
303 return 0;
304 case ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL:
305 *value = window->maxSwapInterval;
306 return 0;
307 case ANATIVEWINDOW_QUERY_XDPI:
308 *value = (int)window->xdpi;
309 return 0;
310 case ANATIVEWINDOW_QUERY_YDPI:
311 *value = (int)window->ydpi;
312 return 0;
313 default:
314 // asked for an invalid query(), one that isn't part of the VNDK
315 return -EINVAL;
316 }
317 return window->query(window, int(what), value);
318}
319
320int ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery what, float* value) {
321 switch (what) {
322 case ANATIVEWINDOW_QUERY_XDPI:
323 *value = window->xdpi;
324 return 0;
325 case ANATIVEWINDOW_QUERY_YDPI:
326 *value = window->ydpi;
327 return 0;
328 default:
329 break;
330 }
331
332 int i;
333 int e = ANativeWindow_query(window, what, &i);
334 if (e == 0) {
335 *value = (float)i;
336 }
337 return e;
338}
339
340int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) {
341 return window->dequeueBuffer(window, buffer, fenceFd);
342}
343
344int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
345 return window->queueBuffer(window, buffer, fenceFd);
346}
347
348int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
349 return window->cancelBuffer(window, buffer, fenceFd);
350}
351
Mathias Agopian2c38b562017-04-20 16:35:39 -0700352int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) {
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700353 return native_window_set_usage(window, usage);
Mathias Agopian000879a2017-03-20 18:07:26 -0700354}
355
356int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) {
357 return native_window_set_buffer_count(window, bufferCount);
358}
359
360int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h) {
361 return native_window_set_buffers_dimensions(window, (int)w, (int)h);
362}
363
364int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format) {
365 return native_window_set_buffers_format(window, format);
366}
367
368int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp) {
369 return native_window_set_buffers_timestamp(window, timestamp);
370}
371
Mathias Agopian000879a2017-03-20 18:07:26 -0700372int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode) {
373 return native_window_set_shared_buffer_mode(window, sharedBufferMode);
374}
375
376int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) {
377 return native_window_set_auto_refresh(window, autoRefresh);
378}
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700379
380int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) {
381 return native_window_set_auto_prerotation(window, autoPrerotation);
382}
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700383
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000384binder_status_t ANativeWindow_readFromParcel(
385 const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) {
John Reck42fcb0d2023-02-23 17:55:07 -0500386 auto funcs = getSurfaceParcelFunctions();
387 if (funcs->read == nullptr) {
388 ALOGE("Failed to load Surface_readFromParcel implementation");
389 return STATUS_FAILED_TRANSACTION;
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000390 }
John Reck42fcb0d2023-02-23 17:55:07 -0500391 const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
392 return funcs->read(nativeParcel, outWindow);
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000393}
394
395binder_status_t ANativeWindow_writeToParcel(
396 ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) {
John Reck42fcb0d2023-02-23 17:55:07 -0500397 auto funcs = getSurfaceParcelFunctions();
398 if (funcs->write == nullptr) {
399 ALOGE("Failed to load Surface_writeToParcel implementation");
400 return STATUS_FAILED_TRANSACTION;
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000401 }
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000402 Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
John Reck42fcb0d2023-02-23 17:55:07 -0500403 return funcs->write(window, nativeParcel);
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000404}
405
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700406/**************************************************************************************************
407 * apex-stable
408 **************************************************************************************************/
409
Alec Mouri72670c52019-08-31 01:54:33 -0700410int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
411 return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION);
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700412}
Alec Mouri0d1398b2019-08-14 10:53:50 -0700413
Alec Mouri72670c52019-08-31 01:54:33 -0700414int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
415 return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION);
Alec Mouri0d1398b2019-08-14 10:53:50 -0700416}
Alec Mouria1619662019-08-21 19:30:48 -0700417
418int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) {
Alec Mouri72670c52019-08-31 01:54:33 -0700419 return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START);
Alec Mouria1619662019-08-21 19:30:48 -0700420}
Alec Mouri04fdb602019-08-23 19:41:43 -0700421
422int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) {
423 return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout);
424}
Alec Mouri09d122a2019-11-25 10:00:53 -0800425
426int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window,
427 ANativeWindow_cancelBufferInterceptor interceptor,
428 void* data) {
429 return window->perform(window, NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR, interceptor, data);
430}
431
432int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window,
433 ANativeWindow_dequeueBufferInterceptor interceptor,
434 void* data) {
435 return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR, interceptor, data);
436}
437
438int ANativeWindow_setPerformInterceptor(ANativeWindow* window,
439 ANativeWindow_performInterceptor interceptor, void* data) {
440 return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data);
441}
442
443int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window,
444 ANativeWindow_queueBufferInterceptor interceptor,
445 void* data) {
446 return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data);
447}