blob: c345385839f24afe9c0732e3777e0b852d306b36 [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
Sungtak Lee4b3e4a92022-11-01 23:39:37 +000027#include <log/log.h>
Mathias Agopian453effd2017-04-03 15:34:13 -070028#include <ui/GraphicBuffer.h>
Sungtak Lee4b3e4a92022-11-01 23:39:37 +000029#include <gui/Surface.h>
30#include <gui/view/Surface.h>
31#include <android/binder_libbinder.h>
Mathias Agopian453effd2017-04-03 15:34:13 -070032
Mathias Agopian000879a2017-03-20 18:07:26 -070033using namespace android;
Mathias Agopian89ed4c82017-02-09 18:48:34 -080034
Mathias Agopian000879a2017-03-20 18:07:26 -070035static int32_t query(ANativeWindow* window, int what) {
Mathias Agopian89ed4c82017-02-09 18:48:34 -080036 int value;
37 int res = window->query(window, what, &value);
38 return res < 0 ? res : value;
39}
40
Alec Mouri72670c52019-08-31 01:54:33 -070041static int64_t query64(ANativeWindow* window, int what) {
42 int64_t value;
43 int res = window->perform(window, what, &value);
44 return res < 0 ? res : value;
45}
46
Peiyong Lin654f87b2018-01-30 14:21:33 -080047static bool isDataSpaceValid(ANativeWindow* window, int32_t dataSpace) {
48 bool supported = false;
49 switch (dataSpace) {
50 case HAL_DATASPACE_UNKNOWN:
51 case HAL_DATASPACE_V0_SRGB:
52 return true;
53 // These data space need wide gamut support.
54 case HAL_DATASPACE_V0_SCRGB_LINEAR:
55 case HAL_DATASPACE_V0_SCRGB:
56 case HAL_DATASPACE_DISPLAY_P3:
57 native_window_get_wide_color_support(window, &supported);
58 return supported;
59 // These data space need HDR support.
60 case HAL_DATASPACE_BT2020_PQ:
61 native_window_get_hdr_support(window, &supported);
62 return supported;
63 default:
64 return false;
65 }
66}
Sungtak Lee4b3e4a92022-11-01 23:39:37 +000067static sp<IGraphicBufferProducer> IGraphicBufferProducer_from_ANativeWindow(ANativeWindow* window) {
68 return Surface::getIGraphicBufferProducer(window);
69}
70
71static sp<IBinder> SurfaceControlHandle_from_ANativeWindow(ANativeWindow* window) {
72 return Surface::getSurfaceControlHandle(window);
73}
Peiyong Lin654f87b2018-01-30 14:21:33 -080074
Mathias Agopian000879a2017-03-20 18:07:26 -070075/**************************************************************************************************
76 * NDK
77 **************************************************************************************************/
78
79void ANativeWindow_acquire(ANativeWindow* window) {
80 // incStrong/decStrong token must be the same, doesn't matter what it is
81 window->incStrong((void*)ANativeWindow_acquire);
82}
83
84void ANativeWindow_release(ANativeWindow* window) {
85 // incStrong/decStrong token must be the same, doesn't matter what it is
86 window->decStrong((void*)ANativeWindow_acquire);
87}
88
Mathias Agopian89ed4c82017-02-09 18:48:34 -080089int32_t ANativeWindow_getWidth(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -070090 return query(window, NATIVE_WINDOW_WIDTH);
Mathias Agopian89ed4c82017-02-09 18:48:34 -080091}
92
93int32_t ANativeWindow_getHeight(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -070094 return query(window, NATIVE_WINDOW_HEIGHT);
Mathias Agopian89ed4c82017-02-09 18:48:34 -080095}
96
97int32_t ANativeWindow_getFormat(ANativeWindow* window) {
Mathias Agopian000879a2017-03-20 18:07:26 -070098 return query(window, NATIVE_WINDOW_FORMAT);
Mathias Agopian89ed4c82017-02-09 18:48:34 -080099}
100
Mathias Agopian000879a2017-03-20 18:07:26 -0700101int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
102 int32_t width, int32_t height, int32_t format) {
Mathias Agopian89ed4c82017-02-09 18:48:34 -0800103 int32_t err = native_window_set_buffers_format(window, format);
104 if (!err) {
105 err = native_window_set_buffers_user_dimensions(window, width, height);
106 if (!err) {
107 int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
108 if (width && height) {
109 mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
110 }
111 err = native_window_set_scaling_mode(window, mode);
112 }
113 }
114 return err;
115}
116
117int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
118 ARect* inOutDirtyBounds) {
119 return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds);
120}
121
122int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
123 return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST);
124}
Jesse Hall09932ec2017-03-13 11:36:05 -0700125
126int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) {
127 static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL == NATIVE_WINDOW_TRANSFORM_FLIP_H);
128 static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL == NATIVE_WINDOW_TRANSFORM_FLIP_V);
129 static_assert(ANATIVEWINDOW_TRANSFORM_ROTATE_90 == NATIVE_WINDOW_TRANSFORM_ROT_90);
130
131 constexpr int32_t kAllTransformBits =
132 ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |
133 ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL |
Robert Carr175ed5b2018-04-06 13:59:00 -0700134 ANATIVEWINDOW_TRANSFORM_ROTATE_90 |
135 // We don't expose INVERSE_DISPLAY as an NDK constant, but someone could have read it
136 // from a buffer already set by Camera framework, so we allow it to be forwarded.
137 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
Mathias Agopian000879a2017-03-20 18:07:26 -0700138 if (!window || !query(window, NATIVE_WINDOW_IS_VALID))
Jesse Hall09932ec2017-03-13 11:36:05 -0700139 return -EINVAL;
140 if ((transform & ~kAllTransformBits) != 0)
141 return -EINVAL;
142
143 return native_window_set_buffers_transform(window, transform);
144}
Mathias Agopian000879a2017-03-20 18:07:26 -0700145
Peiyong Lin654f87b2018-01-30 14:21:33 -0800146int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) {
Yi Kong2fe2a082018-05-31 11:47:00 -0700147 static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700148 static_assert(static_cast<int>(STANDARD_MASK) == static_cast<int>(HAL_DATASPACE_STANDARD_MASK));
149 static_assert(static_cast<int>(STANDARD_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_STANDARD_UNSPECIFIED));
150 static_assert(static_cast<int>(STANDARD_BT709) == static_cast<int>(HAL_DATASPACE_STANDARD_BT709));
151 static_assert(static_cast<int>(STANDARD_BT601_625) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625));
152 static_assert(static_cast<int>(STANDARD_BT601_625_UNADJUSTED) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED));
153 static_assert(static_cast<int>(STANDARD_BT601_525) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525));
154 static_assert(static_cast<int>(STANDARD_BT601_525_UNADJUSTED) == static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED));
155 static_assert(static_cast<int>(STANDARD_BT470M) == static_cast<int>(HAL_DATASPACE_STANDARD_BT470M));
156 static_assert(static_cast<int>(STANDARD_FILM) == static_cast<int>(HAL_DATASPACE_STANDARD_FILM));
157 static_assert(static_cast<int>(STANDARD_DCI_P3) == static_cast<int>(HAL_DATASPACE_STANDARD_DCI_P3));
158 static_assert(static_cast<int>(STANDARD_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_STANDARD_ADOBE_RGB));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700159 static_assert(static_cast<int>(TRANSFER_MASK) == static_cast<int>(HAL_DATASPACE_TRANSFER_MASK));
160 static_assert(static_cast<int>(TRANSFER_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_TRANSFER_UNSPECIFIED));
161 static_assert(static_cast<int>(TRANSFER_LINEAR) == static_cast<int>(HAL_DATASPACE_TRANSFER_LINEAR));
162 static_assert(static_cast<int>(TRANSFER_SMPTE_170M) == static_cast<int>(HAL_DATASPACE_TRANSFER_SMPTE_170M));
163 static_assert(static_cast<int>(TRANSFER_GAMMA2_2) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_2));
164 static_assert(static_cast<int>(TRANSFER_GAMMA2_6) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_6));
165 static_assert(static_cast<int>(TRANSFER_GAMMA2_8) == static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_8));
166 static_assert(static_cast<int>(TRANSFER_ST2084) == static_cast<int>(HAL_DATASPACE_TRANSFER_ST2084));
167 static_assert(static_cast<int>(TRANSFER_HLG) == static_cast<int>(HAL_DATASPACE_TRANSFER_HLG));
168 static_assert(static_cast<int>(RANGE_MASK) == static_cast<int>(HAL_DATASPACE_RANGE_MASK));
169 static_assert(static_cast<int>(RANGE_UNSPECIFIED) == static_cast<int>(HAL_DATASPACE_RANGE_UNSPECIFIED));
170 static_assert(static_cast<int>(RANGE_FULL) == static_cast<int>(HAL_DATASPACE_RANGE_FULL));
171 static_assert(static_cast<int>(RANGE_LIMITED) == static_cast<int>(HAL_DATASPACE_RANGE_LIMITED));
172 static_assert(static_cast<int>(RANGE_EXTENDED) == static_cast<int>(HAL_DATASPACE_RANGE_EXTENDED));
Yi Kong2fe2a082018-05-31 11:47:00 -0700173 static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB));
174 static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB));
175 static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3));
176 static_assert(static_cast<int>(ADATASPACE_BT2020_PQ) == static_cast<int>(HAL_DATASPACE_BT2020_PQ));
Sally Qi31c3f572021-11-16 10:14:50 -0800177 static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_PQ) ==
178 static_cast<int>(HAL_DATASPACE_BT2020_ITU_PQ));
Peiyong Lin91a2b3d2019-12-12 21:33:11 -0800179 static_assert(static_cast<int>(ADATASPACE_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_ADOBE_RGB));
Sally Qic4e8a2e2021-09-27 13:11:35 -0700180 static_assert(static_cast<int>(ADATASPACE_JFIF) == static_cast<int>(HAL_DATASPACE_V0_JFIF));
181 static_assert(static_cast<int>(ADATASPACE_BT601_625) == static_cast<int>(HAL_DATASPACE_V0_BT601_625));
182 static_assert(static_cast<int>(ADATASPACE_BT601_525) == static_cast<int>(HAL_DATASPACE_V0_BT601_525));
Peiyong Lin91a2b3d2019-12-12 21:33:11 -0800183 static_assert(static_cast<int>(ADATASPACE_BT2020) == static_cast<int>(HAL_DATASPACE_BT2020));
184 static_assert(static_cast<int>(ADATASPACE_BT709) == static_cast<int>(HAL_DATASPACE_V0_BT709));
185 static_assert(static_cast<int>(ADATASPACE_DCI_P3) == static_cast<int>(HAL_DATASPACE_DCI_P3));
186 static_assert(static_cast<int>(ADATASPACE_SRGB_LINEAR) == static_cast<int>(HAL_DATASPACE_V0_SRGB_LINEAR));
Sally Qi95770602021-11-15 11:16:26 -0800187 static_assert(static_cast<int>(ADATASPACE_BT2020_HLG) ==
188 static_cast<int>(HAL_DATASPACE_BT2020_HLG));
189 static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_HLG) ==
190 static_cast<int>(HAL_DATASPACE_BT2020_ITU_HLG));
Sally Qie77820c2022-06-07 11:01:45 -0700191 static_assert(static_cast<int>(ADATASPACE_DEPTH) == static_cast<int>(HAL_DATASPACE_DEPTH));
192 static_assert(static_cast<int>(ADATASPACE_DYNAMIC_DEPTH) == static_cast<int>(HAL_DATASPACE_DYNAMIC_DEPTH));
Peiyong Lin654f87b2018-01-30 14:21:33 -0800193
194 if (!window || !query(window, NATIVE_WINDOW_IS_VALID) ||
195 !isDataSpaceValid(window, dataSpace)) {
196 return -EINVAL;
197 }
198 return native_window_set_buffers_data_space(window,
199 static_cast<android_dataspace_t>(dataSpace));
200}
201
202int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) {
203 if (!window || !query(window, NATIVE_WINDOW_IS_VALID))
204 return -EINVAL;
205 return query(window, NATIVE_WINDOW_DATASPACE);
206}
207
Jason Macnak78d7fb32022-06-13 10:45:07 -0700208int32_t ANativeWindow_getBuffersDefaultDataSpace(ANativeWindow* window) {
209 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
210 return -EINVAL;
211 }
212 return query(window, NATIVE_WINDOW_DEFAULT_DATASPACE);
213}
214
Steven Thomas62a4cf82020-01-31 12:04:03 -0800215int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100216 return ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility,
217 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
Steven Thomas6d88a482019-12-02 22:00:47 -0800218}
219
Alec Mourid9d85722020-02-13 13:57:19 -0800220void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) {
221 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
222 return;
223 }
224 window->perform(window, NATIVE_WINDOW_ALLOCATE_BUFFERS);
225}
226
Marin Shalamanovc5986772021-03-16 16:09:49 +0100227int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, float frameRate,
228 int8_t compatibility, int8_t changeFrameRateStrategy) {
Marin Shalamanov46084422020-10-13 12:33:42 +0200229 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
230 return -EINVAL;
231 }
Marin Shalamanovc5986772021-03-16 16:09:49 +0100232 return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy);
Marin Shalamanov46084422020-10-13 12:33:42 +0200233}
Alec Mourid9d85722020-02-13 13:57:19 -0800234
Kriti Dang4113fc12022-08-26 16:30:37 +0200235int32_t ANativeWindow_clearFrameRate(ANativeWindow* window) {
236 if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) {
237 return -EINVAL;
238 }
239 return native_window_set_frame_rate(window, 0,
240 ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT,
241 ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS);
242}
243
Mathias Agopian000879a2017-03-20 18:07:26 -0700244/**************************************************************************************************
245 * vndk-stable
246 **************************************************************************************************/
247
Mathias Agopian453effd2017-04-03 15:34:13 -0700248AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) {
249 return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb));
250}
251
Mathias Agopian000879a2017-03-20 18:07:26 -0700252int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value) {
253 if (slot < 4) {
254 window->oem[slot] = value;
255 return 0;
256 }
257 return -EINVAL;
258}
259
260int ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value) {
261 if (slot >= 4) {
262 *value = window->oem[slot];
263 return 0;
264 }
265 return -EINVAL;
266}
267
268
269int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval) {
270 return window->setSwapInterval(window, interval);
271}
272
273int ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery what, int* value) {
274 switch (what) {
275 case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS:
276 case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH:
277 case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT:
278 case ANATIVEWINDOW_QUERY_TRANSFORM_HINT:
Peiyong Lin90a90f12021-06-03 18:11:56 +0000279 case ANATIVEWINDOW_QUERY_BUFFER_AGE:
Mathias Agopian000879a2017-03-20 18:07:26 -0700280 // these are part of the VNDK API
281 break;
282 case ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL:
283 *value = window->minSwapInterval;
284 return 0;
285 case ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL:
286 *value = window->maxSwapInterval;
287 return 0;
288 case ANATIVEWINDOW_QUERY_XDPI:
289 *value = (int)window->xdpi;
290 return 0;
291 case ANATIVEWINDOW_QUERY_YDPI:
292 *value = (int)window->ydpi;
293 return 0;
294 default:
295 // asked for an invalid query(), one that isn't part of the VNDK
296 return -EINVAL;
297 }
298 return window->query(window, int(what), value);
299}
300
301int ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery what, float* value) {
302 switch (what) {
303 case ANATIVEWINDOW_QUERY_XDPI:
304 *value = window->xdpi;
305 return 0;
306 case ANATIVEWINDOW_QUERY_YDPI:
307 *value = window->ydpi;
308 return 0;
309 default:
310 break;
311 }
312
313 int i;
314 int e = ANativeWindow_query(window, what, &i);
315 if (e == 0) {
316 *value = (float)i;
317 }
318 return e;
319}
320
321int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) {
322 return window->dequeueBuffer(window, buffer, fenceFd);
323}
324
325int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
326 return window->queueBuffer(window, buffer, fenceFd);
327}
328
329int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
330 return window->cancelBuffer(window, buffer, fenceFd);
331}
332
Mathias Agopian2c38b562017-04-20 16:35:39 -0700333int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) {
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700334 return native_window_set_usage(window, usage);
Mathias Agopian000879a2017-03-20 18:07:26 -0700335}
336
337int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) {
338 return native_window_set_buffer_count(window, bufferCount);
339}
340
341int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h) {
342 return native_window_set_buffers_dimensions(window, (int)w, (int)h);
343}
344
345int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format) {
346 return native_window_set_buffers_format(window, format);
347}
348
349int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp) {
350 return native_window_set_buffers_timestamp(window, timestamp);
351}
352
Mathias Agopian000879a2017-03-20 18:07:26 -0700353int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode) {
354 return native_window_set_shared_buffer_mode(window, sharedBufferMode);
355}
356
357int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) {
358 return native_window_set_auto_refresh(window, autoRefresh);
359}
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700360
361int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) {
362 return native_window_set_auto_prerotation(window, autoPrerotation);
363}
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700364
Sungtak Lee4b3e4a92022-11-01 23:39:37 +0000365binder_status_t ANativeWindow_readFromParcel(
366 const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) {
367 const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
368
369 // Use a android::view::Surface to unparcel the window
370 std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
371 status_t ret = shimSurface->readFromParcel(nativeParcel);
372 if (ret != OK) {
373 ALOGE("%s: Error: Failed to create android::view::Surface from AParcel", __FUNCTION__);
374 return STATUS_BAD_VALUE;
375 }
376 sp<Surface> surface = sp<Surface>::make(
377 shimSurface->graphicBufferProducer, false, shimSurface->surfaceControlHandle);
378 ANativeWindow* anw = surface.get();
379 ANativeWindow_acquire(anw);
380 *outWindow = anw;
381 return STATUS_OK;
382}
383
384binder_status_t ANativeWindow_writeToParcel(
385 ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) {
386 int value;
387 int err = (*window->query)(window, NATIVE_WINDOW_CONCRETE_TYPE, &value);
388 if (err != OK || value != NATIVE_WINDOW_SURFACE) {
389 ALOGE("Error: ANativeWindow is not backed by Surface");
390 return STATUS_BAD_VALUE;
391 }
392 // Use a android::view::Surface to parcelize the window
393 std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
394 shimSurface->graphicBufferProducer = IGraphicBufferProducer_from_ANativeWindow(window);
395 shimSurface->surfaceControlHandle = SurfaceControlHandle_from_ANativeWindow(window);
396
397 Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
398 return shimSurface->writeToParcel(nativeParcel);
399}
400
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700401/**************************************************************************************************
402 * apex-stable
403 **************************************************************************************************/
404
Alec Mouri72670c52019-08-31 01:54:33 -0700405int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) {
406 return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION);
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700407}
Alec Mouri0d1398b2019-08-14 10:53:50 -0700408
Alec Mouri72670c52019-08-31 01:54:33 -0700409int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) {
410 return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION);
Alec Mouri0d1398b2019-08-14 10:53:50 -0700411}
Alec Mouria1619662019-08-21 19:30:48 -0700412
413int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) {
Alec Mouri72670c52019-08-31 01:54:33 -0700414 return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START);
Alec Mouria1619662019-08-21 19:30:48 -0700415}
Alec Mouri04fdb602019-08-23 19:41:43 -0700416
417int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) {
418 return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout);
419}
Alec Mouri09d122a2019-11-25 10:00:53 -0800420
421int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window,
422 ANativeWindow_cancelBufferInterceptor interceptor,
423 void* data) {
424 return window->perform(window, NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR, interceptor, data);
425}
426
427int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window,
428 ANativeWindow_dequeueBufferInterceptor interceptor,
429 void* data) {
430 return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR, interceptor, data);
431}
432
433int ANativeWindow_setPerformInterceptor(ANativeWindow* window,
434 ANativeWindow_performInterceptor interceptor, void* data) {
435 return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data);
436}
437
438int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window,
439 ANativeWindow_queueBufferInterceptor interceptor,
440 void* data) {
441 return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data);
442}