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 | |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 27 | #include <android/binder_libbinder.h> |
| 28 | #include <dlfcn.h> |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 29 | #include <log/log.h> |
Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 30 | #include <ui/GraphicBuffer.h> |
| 31 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 32 | using namespace android; |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 33 | |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 34 | #if defined(__ANDROID_APEX__) || defined(__ANDROID_VNDK__) |
| 35 | #error libnativewindow can only be built for system |
| 36 | #endif |
| 37 | |
| 38 | using android_view_Surface_writeToParcel = status_t (*)(ANativeWindow* _Nonnull window, |
| 39 | Parcel* _Nonnull parcel); |
| 40 | |
| 41 | using android_view_Surface_readFromParcel = |
| 42 | status_t (*)(const Parcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow); |
| 43 | |
| 44 | struct SurfaceParcelables { |
| 45 | android_view_Surface_writeToParcel write = nullptr; |
| 46 | android_view_Surface_readFromParcel read = nullptr; |
| 47 | }; |
| 48 | |
| 49 | const 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 Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 70 | static int32_t query(ANativeWindow* window, int what) { |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 71 | int value; |
| 72 | int res = window->query(window, what, &value); |
| 73 | return res < 0 ? res : value; |
| 74 | } |
| 75 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 76 | static 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 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 82 | /************************************************************************************************** |
| 83 | * NDK |
| 84 | **************************************************************************************************/ |
| 85 | |
| 86 | void ANativeWindow_acquire(ANativeWindow* window) { |
| 87 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 88 | window->incStrong((void*)ANativeWindow_acquire); |
| 89 | } |
| 90 | |
| 91 | void ANativeWindow_release(ANativeWindow* window) { |
| 92 | // incStrong/decStrong token must be the same, doesn't matter what it is |
| 93 | window->decStrong((void*)ANativeWindow_acquire); |
| 94 | } |
| 95 | |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 96 | int32_t ANativeWindow_getWidth(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 97 | return query(window, NATIVE_WINDOW_WIDTH); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int32_t ANativeWindow_getHeight(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 101 | return query(window, NATIVE_WINDOW_HEIGHT); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int32_t ANativeWindow_getFormat(ANativeWindow* window) { |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 105 | return query(window, NATIVE_WINDOW_FORMAT); |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 108 | int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, |
| 109 | int32_t width, int32_t height, int32_t format) { |
Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 110 | int32_t err = native_window_set_buffers_format(window, format); |
| 111 | if (!err) { |
| 112 | err = native_window_set_buffers_user_dimensions(window, width, height); |
| 113 | if (!err) { |
| 114 | int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 115 | if (width && height) { |
| 116 | mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; |
| 117 | } |
| 118 | err = native_window_set_scaling_mode(window, mode); |
| 119 | } |
| 120 | } |
| 121 | return err; |
| 122 | } |
| 123 | |
| 124 | int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, |
| 125 | ARect* inOutDirtyBounds) { |
| 126 | return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds); |
| 127 | } |
| 128 | |
| 129 | int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) { |
| 130 | return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST); |
| 131 | } |
Jesse Hall | 09932ec | 2017-03-13 11:36:05 -0700 | [diff] [blame] | 132 | |
| 133 | int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) { |
| 134 | static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL == NATIVE_WINDOW_TRANSFORM_FLIP_H); |
| 135 | static_assert(ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL == NATIVE_WINDOW_TRANSFORM_FLIP_V); |
| 136 | static_assert(ANATIVEWINDOW_TRANSFORM_ROTATE_90 == NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 137 | |
| 138 | constexpr int32_t kAllTransformBits = |
| 139 | ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL | |
| 140 | ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL | |
Robert Carr | 175ed5b | 2018-04-06 13:59:00 -0700 | [diff] [blame] | 141 | ANATIVEWINDOW_TRANSFORM_ROTATE_90 | |
| 142 | // We don't expose INVERSE_DISPLAY as an NDK constant, but someone could have read it |
| 143 | // from a buffer already set by Camera framework, so we allow it to be forwarded. |
| 144 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY; |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 145 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) |
Jesse Hall | 09932ec | 2017-03-13 11:36:05 -0700 | [diff] [blame] | 146 | return -EINVAL; |
| 147 | if ((transform & ~kAllTransformBits) != 0) |
| 148 | return -EINVAL; |
| 149 | |
| 150 | return native_window_set_buffers_transform(window, transform); |
| 151 | } |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 152 | |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 153 | int32_t ANativeWindow_setBuffersDataSpace(ANativeWindow* window, int32_t dataSpace) { |
Yi Kong | 2fe2a08 | 2018-05-31 11:47:00 -0700 | [diff] [blame] | 154 | static_assert(static_cast<int>(ADATASPACE_UNKNOWN) == static_cast<int>(HAL_DATASPACE_UNKNOWN)); |
John Reck | d727e9c | 2023-12-08 11:30:37 -0500 | [diff] [blame] | 155 | static_assert(static_cast<int>(ADATASPACE_STANDARD_MASK) == |
| 156 | static_cast<int>(HAL_DATASPACE_STANDARD_MASK)); |
| 157 | static_assert(static_cast<int>(ADATASPACE_STANDARD_UNSPECIFIED) == |
| 158 | static_cast<int>(HAL_DATASPACE_STANDARD_UNSPECIFIED)); |
| 159 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT709) == |
| 160 | static_cast<int>(HAL_DATASPACE_STANDARD_BT709)); |
| 161 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT601_625) == |
| 162 | static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625)); |
| 163 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT601_625_UNADJUSTED) == |
| 164 | static_cast<int>(HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED)); |
| 165 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT601_525) == |
| 166 | static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525)); |
| 167 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT601_525_UNADJUSTED) == |
| 168 | static_cast<int>(HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED)); |
| 169 | static_assert(static_cast<int>(ADATASPACE_STANDARD_BT470M) == |
| 170 | static_cast<int>(HAL_DATASPACE_STANDARD_BT470M)); |
| 171 | static_assert(static_cast<int>(ADATASPACE_STANDARD_FILM) == |
| 172 | static_cast<int>(HAL_DATASPACE_STANDARD_FILM)); |
| 173 | static_assert(static_cast<int>(ADATASPACE_STANDARD_DCI_P3) == |
| 174 | static_cast<int>(HAL_DATASPACE_STANDARD_DCI_P3)); |
| 175 | static_assert(static_cast<int>(ADATASPACE_STANDARD_ADOBE_RGB) == |
| 176 | static_cast<int>(HAL_DATASPACE_STANDARD_ADOBE_RGB)); |
| 177 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_MASK) == |
| 178 | static_cast<int>(HAL_DATASPACE_TRANSFER_MASK)); |
| 179 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_UNSPECIFIED) == |
| 180 | static_cast<int>(HAL_DATASPACE_TRANSFER_UNSPECIFIED)); |
| 181 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_LINEAR) == |
| 182 | static_cast<int>(HAL_DATASPACE_TRANSFER_LINEAR)); |
| 183 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_SMPTE_170M) == |
| 184 | static_cast<int>(HAL_DATASPACE_TRANSFER_SMPTE_170M)); |
| 185 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_GAMMA2_2) == |
| 186 | static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_2)); |
| 187 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_GAMMA2_6) == |
| 188 | static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_6)); |
| 189 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_GAMMA2_8) == |
| 190 | static_cast<int>(HAL_DATASPACE_TRANSFER_GAMMA2_8)); |
| 191 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_ST2084) == |
| 192 | static_cast<int>(HAL_DATASPACE_TRANSFER_ST2084)); |
| 193 | static_assert(static_cast<int>(ADATASPACE_TRANSFER_HLG) == |
| 194 | static_cast<int>(HAL_DATASPACE_TRANSFER_HLG)); |
| 195 | static_assert(static_cast<int>(ADATASPACE_RANGE_MASK) == |
| 196 | static_cast<int>(HAL_DATASPACE_RANGE_MASK)); |
| 197 | static_assert(static_cast<int>(ADATASPACE_RANGE_UNSPECIFIED) == |
| 198 | static_cast<int>(HAL_DATASPACE_RANGE_UNSPECIFIED)); |
| 199 | static_assert(static_cast<int>(ADATASPACE_RANGE_FULL) == |
| 200 | static_cast<int>(HAL_DATASPACE_RANGE_FULL)); |
| 201 | static_assert(static_cast<int>(ADATASPACE_RANGE_LIMITED) == |
| 202 | static_cast<int>(HAL_DATASPACE_RANGE_LIMITED)); |
| 203 | static_assert(static_cast<int>(ADATASPACE_RANGE_EXTENDED) == |
| 204 | static_cast<int>(HAL_DATASPACE_RANGE_EXTENDED)); |
Yi Kong | 2fe2a08 | 2018-05-31 11:47:00 -0700 | [diff] [blame] | 205 | static_assert(static_cast<int>(ADATASPACE_SRGB) == static_cast<int>(HAL_DATASPACE_V0_SRGB)); |
| 206 | static_assert(static_cast<int>(ADATASPACE_SCRGB) == static_cast<int>(HAL_DATASPACE_V0_SCRGB)); |
| 207 | static_assert(static_cast<int>(ADATASPACE_DISPLAY_P3) == static_cast<int>(HAL_DATASPACE_DISPLAY_P3)); |
| 208 | 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] | 209 | static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_PQ) == |
| 210 | static_cast<int>(HAL_DATASPACE_BT2020_ITU_PQ)); |
Peiyong Lin | 91a2b3d | 2019-12-12 21:33:11 -0800 | [diff] [blame] | 211 | 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] | 212 | static_assert(static_cast<int>(ADATASPACE_JFIF) == static_cast<int>(HAL_DATASPACE_V0_JFIF)); |
| 213 | static_assert(static_cast<int>(ADATASPACE_BT601_625) == static_cast<int>(HAL_DATASPACE_V0_BT601_625)); |
| 214 | 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] | 215 | static_assert(static_cast<int>(ADATASPACE_BT2020) == static_cast<int>(HAL_DATASPACE_BT2020)); |
| 216 | static_assert(static_cast<int>(ADATASPACE_BT709) == static_cast<int>(HAL_DATASPACE_V0_BT709)); |
| 217 | static_assert(static_cast<int>(ADATASPACE_DCI_P3) == static_cast<int>(HAL_DATASPACE_DCI_P3)); |
| 218 | 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] | 219 | static_assert(static_cast<int>(ADATASPACE_BT2020_HLG) == |
| 220 | static_cast<int>(HAL_DATASPACE_BT2020_HLG)); |
| 221 | static_assert(static_cast<int>(ADATASPACE_BT2020_ITU_HLG) == |
| 222 | static_cast<int>(HAL_DATASPACE_BT2020_ITU_HLG)); |
Sally Qi | e77820c | 2022-06-07 11:01:45 -0700 | [diff] [blame] | 223 | static_assert(static_cast<int>(ADATASPACE_DEPTH) == static_cast<int>(HAL_DATASPACE_DEPTH)); |
| 224 | static_assert(static_cast<int>(ADATASPACE_DYNAMIC_DEPTH) == static_cast<int>(HAL_DATASPACE_DYNAMIC_DEPTH)); |
Alec Mouri | 94cd7bf | 2024-10-17 15:24:47 +0000 | [diff] [blame] | 225 | static_assert(static_cast<int>(ADATASPACE_DISPLAY_BT2020) == |
| 226 | static_cast<int>(HAL_DATASPACE_DISPLAY_BT2020)); |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 227 | |
John Reck | cbfd41f | 2023-04-06 17:01:32 +0000 | [diff] [blame] | 228 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 229 | return -EINVAL; |
| 230 | } |
| 231 | return native_window_set_buffers_data_space(window, |
| 232 | static_cast<android_dataspace_t>(dataSpace)); |
| 233 | } |
| 234 | |
| 235 | int32_t ANativeWindow_getBuffersDataSpace(ANativeWindow* window) { |
| 236 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) |
| 237 | return -EINVAL; |
| 238 | return query(window, NATIVE_WINDOW_DATASPACE); |
| 239 | } |
| 240 | |
Jason Macnak | 78d7fb3 | 2022-06-13 10:45:07 -0700 | [diff] [blame] | 241 | int32_t ANativeWindow_getBuffersDefaultDataSpace(ANativeWindow* window) { |
| 242 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | return query(window, NATIVE_WINDOW_DEFAULT_DATASPACE); |
| 246 | } |
| 247 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 248 | int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) { |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 249 | return ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility, |
| 250 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS); |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 253 | void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) { |
| 254 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { |
| 255 | return; |
| 256 | } |
| 257 | window->perform(window, NATIVE_WINDOW_ALLOCATE_BUFFERS); |
| 258 | } |
| 259 | |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 260 | int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, float frameRate, |
| 261 | int8_t compatibility, int8_t changeFrameRateStrategy) { |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 262 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { |
| 263 | return -EINVAL; |
| 264 | } |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 265 | return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy); |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 266 | } |
Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 267 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 268 | /************************************************************************************************** |
| 269 | * vndk-stable |
| 270 | **************************************************************************************************/ |
| 271 | |
Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 272 | AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) { |
| 273 | return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb)); |
| 274 | } |
| 275 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 276 | int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value) { |
| 277 | if (slot < 4) { |
| 278 | window->oem[slot] = value; |
| 279 | return 0; |
| 280 | } |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
| 284 | int ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value) { |
| 285 | if (slot >= 4) { |
| 286 | *value = window->oem[slot]; |
| 287 | return 0; |
| 288 | } |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval) { |
| 294 | return window->setSwapInterval(window, interval); |
| 295 | } |
| 296 | |
| 297 | int ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery what, int* value) { |
| 298 | switch (what) { |
| 299 | case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: |
| 300 | case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH: |
| 301 | case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT: |
| 302 | case ANATIVEWINDOW_QUERY_TRANSFORM_HINT: |
Peiyong Lin | 90a90f1 | 2021-06-03 18:11:56 +0000 | [diff] [blame] | 303 | case ANATIVEWINDOW_QUERY_BUFFER_AGE: |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 304 | // these are part of the VNDK API |
| 305 | break; |
| 306 | case ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL: |
| 307 | *value = window->minSwapInterval; |
| 308 | return 0; |
| 309 | case ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL: |
| 310 | *value = window->maxSwapInterval; |
| 311 | return 0; |
| 312 | case ANATIVEWINDOW_QUERY_XDPI: |
| 313 | *value = (int)window->xdpi; |
| 314 | return 0; |
| 315 | case ANATIVEWINDOW_QUERY_YDPI: |
| 316 | *value = (int)window->ydpi; |
| 317 | return 0; |
| 318 | default: |
| 319 | // asked for an invalid query(), one that isn't part of the VNDK |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | return window->query(window, int(what), value); |
| 323 | } |
| 324 | |
| 325 | int ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery what, float* value) { |
| 326 | switch (what) { |
| 327 | case ANATIVEWINDOW_QUERY_XDPI: |
| 328 | *value = window->xdpi; |
| 329 | return 0; |
| 330 | case ANATIVEWINDOW_QUERY_YDPI: |
| 331 | *value = window->ydpi; |
| 332 | return 0; |
| 333 | default: |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | int i; |
| 338 | int e = ANativeWindow_query(window, what, &i); |
| 339 | if (e == 0) { |
| 340 | *value = (float)i; |
| 341 | } |
| 342 | return e; |
| 343 | } |
| 344 | |
| 345 | int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) { |
| 346 | return window->dequeueBuffer(window, buffer, fenceFd); |
| 347 | } |
| 348 | |
| 349 | int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { |
| 350 | return window->queueBuffer(window, buffer, fenceFd); |
| 351 | } |
| 352 | |
| 353 | int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { |
| 354 | return window->cancelBuffer(window, buffer, fenceFd); |
| 355 | } |
| 356 | |
Mathias Agopian | 2c38b56 | 2017-04-20 16:35:39 -0700 | [diff] [blame] | 357 | int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) { |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 358 | return native_window_set_usage(window, usage); |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) { |
| 362 | return native_window_set_buffer_count(window, bufferCount); |
| 363 | } |
| 364 | |
| 365 | int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h) { |
| 366 | return native_window_set_buffers_dimensions(window, (int)w, (int)h); |
| 367 | } |
| 368 | |
| 369 | int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format) { |
| 370 | return native_window_set_buffers_format(window, format); |
| 371 | } |
| 372 | |
| 373 | int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp) { |
| 374 | return native_window_set_buffers_timestamp(window, timestamp); |
| 375 | } |
| 376 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 377 | int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode) { |
| 378 | return native_window_set_shared_buffer_mode(window, sharedBufferMode); |
| 379 | } |
| 380 | |
| 381 | int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) { |
| 382 | return native_window_set_auto_refresh(window, autoRefresh); |
| 383 | } |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 384 | |
| 385 | int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) { |
| 386 | return native_window_set_auto_prerotation(window, autoPrerotation); |
| 387 | } |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 388 | |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 389 | binder_status_t ANativeWindow_readFromParcel( |
| 390 | const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) { |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 391 | auto funcs = getSurfaceParcelFunctions(); |
| 392 | if (funcs->read == nullptr) { |
| 393 | ALOGE("Failed to load Surface_readFromParcel implementation"); |
| 394 | return STATUS_FAILED_TRANSACTION; |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 395 | } |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 396 | const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel); |
| 397 | return funcs->read(nativeParcel, outWindow); |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | binder_status_t ANativeWindow_writeToParcel( |
| 401 | ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) { |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 402 | auto funcs = getSurfaceParcelFunctions(); |
| 403 | if (funcs->write == nullptr) { |
| 404 | ALOGE("Failed to load Surface_writeToParcel implementation"); |
| 405 | return STATUS_FAILED_TRANSACTION; |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 406 | } |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 407 | Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel); |
John Reck | 42fcb0d | 2023-02-23 17:55:07 -0500 | [diff] [blame] | 408 | return funcs->write(window, nativeParcel); |
Sungtak Lee | 4b3e4a9 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 411 | /************************************************************************************************** |
| 412 | * apex-stable |
| 413 | **************************************************************************************************/ |
| 414 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 415 | int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) { |
| 416 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION); |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 417 | } |
Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 418 | |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 419 | int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) { |
| 420 | return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION); |
Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 421 | } |
Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 422 | |
| 423 | int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) { |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 424 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START); |
Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 425 | } |
Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 426 | |
| 427 | int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) { |
| 428 | return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout); |
| 429 | } |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 430 | |
| 431 | int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window, |
| 432 | ANativeWindow_cancelBufferInterceptor interceptor, |
| 433 | void* data) { |
| 434 | return window->perform(window, NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR, interceptor, data); |
| 435 | } |
| 436 | |
| 437 | int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window, |
| 438 | ANativeWindow_dequeueBufferInterceptor interceptor, |
| 439 | void* data) { |
| 440 | return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR, interceptor, data); |
| 441 | } |
| 442 | |
| 443 | int ANativeWindow_setPerformInterceptor(ANativeWindow* window, |
| 444 | ANativeWindow_performInterceptor interceptor, void* data) { |
| 445 | return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data); |
| 446 | } |
| 447 | |
| 448 | int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window, |
| 449 | ANativeWindow_queueBufferInterceptor interceptor, |
| 450 | void* data) { |
| 451 | return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data); |
| 452 | } |