Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 1 | /* |
| 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 Hall | 7992781 | 2017-03-23 11:03:23 -0700 | [diff] [blame] | 19 | #include <grallocusage/GrallocUsageConversion.h> |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 20 | // from nativewindow/includes/system/window.h |
| 21 | // (not to be confused with the compatibility-only window.h from system/core/includes) |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 22 | #include <system/window.h> |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame^] | 23 | #include <android/native_window_aidl.h> |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 24 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 25 | #include <private/android/AHardwareBufferHelpers.h> |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 26 | |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame^] | 27 | #include <log/log.h> |
Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 28 | #include <ui/GraphicBuffer.h> |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame^] | 29 | #include <gui/Surface.h> |
| 30 | #include <gui/view/Surface.h> |
| 31 | #include <android/binder_libbinder.h> |
Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 32 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 33 | using namespace android; |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 34 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 35 | static int32_t query(ANativeWindow* window, int what) { |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 36 | int value; |
| 37 | int res = window->query(window, what, &value); |
| 38 | return res < 0 ? res : value; |
| 39 | } |
| 40 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 41 | static 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 Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 47 | static 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 Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame^] | 67 | static sp<IGraphicBufferProducer> IGraphicBufferProducer_from_ANativeWindow(ANativeWindow* window) { |
| 68 | return Surface::getIGraphicBufferProducer(window); |
| 69 | } |
| 70 | |
| 71 | static sp<IBinder> SurfaceControlHandle_from_ANativeWindow(ANativeWindow* window) { |
| 72 | return Surface::getSurfaceControlHandle(window); |
| 73 | } |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 74 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 75 | /************************************************************************************************** |
| 76 | * NDK |
| 77 | **************************************************************************************************/ |
| 78 | |
| 79 | void 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 | |
| 84 | void 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 Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 89 | int32_t ANativeWindow_getWidth(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 90 | return query(window, NATIVE_WINDOW_WIDTH); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int32_t ANativeWindow_getHeight(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 94 | return query(window, NATIVE_WINDOW_HEIGHT); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | int32_t ANativeWindow_getFormat(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 98 | return query(window, NATIVE_WINDOW_FORMAT); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 101 | int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, |
| 102 | int32_t width, int32_t height, int32_t format) { |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 103 | 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 | |
| 117 | int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, |
| 118 | ARect* inOutDirtyBounds) { |
| 119 | return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds); |
| 120 | } |
| 121 | |
| 122 | int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) { |
| 123 | return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST); |
| 124 | } |
Jesse Hall | 09932ec | 2017-03-13 11:36:05 -0700 | [diff] [blame] | 125 | |
| 126 | int32_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 Carr | 175ed5b | 2018-04-06 13:59:00 -0700 | [diff] [blame] | 134 | 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 Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 138 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) |
Jesse Hall | 09932ec | 2017-03-13 11:36:05 -0700 | [diff] [blame] | 139 | return -EINVAL; |
| 140 | if ((transform & ~kAllTransformBits) != 0) |
| 141 | return -EINVAL; |
| 142 | |
| 143 | return native_window_set_buffers_transform(window, transform); |
| 144 | } |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 145 | |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 146 | int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) { |
Yi Kong | 2fe2a08 | 2018-05-31 11:47:00 -0700 | [diff] [blame] | 147 | static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN)); |
Sally Qi | c4e8a2e | 2021-09-27 13:11:35 -0700 | [diff] [blame] | 148 | 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 Qi | c4e8a2e | 2021-09-27 13:11:35 -0700 | [diff] [blame] | 159 | 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 Kong | 2fe2a08 | 2018-05-31 11:47:00 -0700 | [diff] [blame] | 173 | 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 Qi | 31c3f57 | 2021-11-16 10:14:50 -0800 | [diff] [blame] | 177 | static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_PQ) == |
| 178 | static_cast<int>(HAL_DATASPACE_BT2020_ITU_PQ)); |
Peiyong Lin | 91a2b3d | 2019-12-12 21:33:11 -0800 | [diff] [blame] | 179 | static_assert(static_cast<int>(ADATASPACE_ADOBE_RGB) == static_cast<int>(HAL_DATASPACE_ADOBE_RGB)); |
Sally Qi | c4e8a2e | 2021-09-27 13:11:35 -0700 | [diff] [blame] | 180 | 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 Lin | 91a2b3d | 2019-12-12 21:33:11 -0800 | [diff] [blame] | 183 | 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 Qi | 9577060 | 2021-11-15 11:16:26 -0800 | [diff] [blame] | 187 | 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 Qi | e77820c | 2022-06-07 11:01:45 -0700 | [diff] [blame] | 191 | 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 Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 193 | |
| 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 | |
| 202 | int32_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 Macnak | 78d7fb3 | 2022-06-13 10:45:07 -0700 | [diff] [blame] | 208 | int32_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 Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 215 | int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) { |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 216 | return ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility, |
| 217 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS); |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 220 | void 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 Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 227 | int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, float frameRate, |
| 228 | int8_t compatibility, int8_t changeFrameRateStrategy) { |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 229 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { |
| 230 | return -EINVAL; |
| 231 | } |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 232 | return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy); |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 233 | } |
Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 234 | |
Kriti Dang | 4113fc1 | 2022-08-26 16:30:37 +0200 | [diff] [blame] | 235 | int32_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 Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 244 | /************************************************************************************************** |
| 245 | * vndk-stable |
| 246 | **************************************************************************************************/ |
| 247 | |
Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 248 | AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) { |
| 249 | return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb)); |
| 250 | } |
| 251 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 252 | int 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 | |
| 260 | int 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 | |
| 269 | int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval) { |
| 270 | return window->setSwapInterval(window, interval); |
| 271 | } |
| 272 | |
| 273 | int 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 Lin | 90a90f1 | 2021-06-03 18:11:56 +0000 | [diff] [blame] | 279 | case ANATIVEWINDOW_QUERY_BUFFER_AGE: |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 280 | // 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 | |
| 301 | int 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 | |
| 321 | int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) { |
| 322 | return window->dequeueBuffer(window, buffer, fenceFd); |
| 323 | } |
| 324 | |
| 325 | int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { |
| 326 | return window->queueBuffer(window, buffer, fenceFd); |
| 327 | } |
| 328 | |
| 329 | int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { |
| 330 | return window->cancelBuffer(window, buffer, fenceFd); |
| 331 | } |
| 332 | |
Mathias Agopian | 2c38b56 | 2017-04-20 16:35:39 -0700 | [diff] [blame] | 333 | int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) { |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 334 | return native_window_set_usage(window, usage); |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) { |
| 338 | return native_window_set_buffer_count(window, bufferCount); |
| 339 | } |
| 340 | |
| 341 | int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h) { |
| 342 | return native_window_set_buffers_dimensions(window, (int)w, (int)h); |
| 343 | } |
| 344 | |
| 345 | int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format) { |
| 346 | return native_window_set_buffers_format(window, format); |
| 347 | } |
| 348 | |
| 349 | int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp) { |
| 350 | return native_window_set_buffers_timestamp(window, timestamp); |
| 351 | } |
| 352 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 353 | int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode) { |
| 354 | return native_window_set_shared_buffer_mode(window, sharedBufferMode); |
| 355 | } |
| 356 | |
| 357 | int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) { |
| 358 | return native_window_set_auto_refresh(window, autoRefresh); |
| 359 | } |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 360 | |
| 361 | int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) { |
| 362 | return native_window_set_auto_prerotation(window, autoPrerotation); |
| 363 | } |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 364 | |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame^] | 365 | binder_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 | |
| 384 | binder_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 Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 401 | /************************************************************************************************** |
| 402 | * apex-stable |
| 403 | **************************************************************************************************/ |
| 404 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 405 | int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) { |
| 406 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION); |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 407 | } |
Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 408 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 409 | int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) { |
| 410 | return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION); |
Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 411 | } |
Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 412 | |
| 413 | int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) { |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 414 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START); |
Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 415 | } |
Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 416 | |
| 417 | int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) { |
| 418 | return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout); |
| 419 | } |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 420 | |
| 421 | int 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 | |
| 427 | int 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 | |
| 433 | int ANativeWindow_setPerformInterceptor(ANativeWindow* window, |
| 434 | ANativeWindow_performInterceptor interceptor, void* data) { |
| 435 | return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data); |
| 436 | } |
| 437 | |
| 438 | int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window, |
| 439 | ANativeWindow_queueBufferInterceptor interceptor, |
| 440 | void* data) { |
| 441 | return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data); |
| 442 | } |