| 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 | 19055a2 | 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 | 19055a2 | 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 | 19055a2 | 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 | 19055a2 | 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 | f83160f | 2021-12-07 11:41:05 -0800 | [diff] [blame] | 191 | static_assert(static_cast<int>(DEPTH) == static_cast<int>(HAL_DATASPACE_DEPTH)); | 
|  | 192 | static_assert(static_cast<int>(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 |  | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 208 | int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate, int8_t compatibility) { | 
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 209 | return ANativeWindow_setFrameRateWithChangeStrategy(window, frameRate, compatibility, | 
|  | 210 | ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS); | 
| Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
| Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 213 | void ANativeWindow_tryAllocateBuffers(ANativeWindow* window) { | 
|  | 214 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { | 
|  | 215 | return; | 
|  | 216 | } | 
|  | 217 | window->perform(window, NATIVE_WINDOW_ALLOCATE_BUFFERS); | 
|  | 218 | } | 
|  | 219 |  | 
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 220 | int32_t ANativeWindow_setFrameRateWithChangeStrategy(ANativeWindow* window, float frameRate, | 
|  | 221 | int8_t compatibility, int8_t changeFrameRateStrategy) { | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 222 | if (!window || !query(window, NATIVE_WINDOW_IS_VALID)) { | 
|  | 223 | return -EINVAL; | 
|  | 224 | } | 
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 225 | return native_window_set_frame_rate(window, frameRate, compatibility, changeFrameRateStrategy); | 
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 226 | } | 
| Alec Mouri | d9d8572 | 2020-02-13 13:57:19 -0800 | [diff] [blame] | 227 |  | 
| Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 228 | /************************************************************************************************** | 
|  | 229 | * vndk-stable | 
|  | 230 | **************************************************************************************************/ | 
|  | 231 |  | 
| Mathias Agopian | 453effd | 2017-04-03 15:34:13 -0700 | [diff] [blame] | 232 | AHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb) { | 
|  | 233 | return AHardwareBuffer_from_GraphicBuffer(static_cast<GraphicBuffer*>(anwb)); | 
|  | 234 | } | 
|  | 235 |  | 
| Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 236 | int ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value) { | 
|  | 237 | if (slot < 4) { | 
|  | 238 | window->oem[slot] = value; | 
|  | 239 | return 0; | 
|  | 240 | } | 
|  | 241 | return -EINVAL; | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | int ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value) { | 
|  | 245 | if (slot >= 4) { | 
|  | 246 | *value = window->oem[slot]; | 
|  | 247 | return 0; | 
|  | 248 | } | 
|  | 249 | return -EINVAL; | 
|  | 250 | } | 
|  | 251 |  | 
|  | 252 |  | 
|  | 253 | int ANativeWindow_setSwapInterval(ANativeWindow* window, int interval) { | 
|  | 254 | return window->setSwapInterval(window, interval); | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | int ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery what, int* value) { | 
|  | 258 | switch (what) { | 
|  | 259 | case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: | 
|  | 260 | case ANATIVEWINDOW_QUERY_DEFAULT_WIDTH: | 
|  | 261 | case ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT: | 
|  | 262 | case ANATIVEWINDOW_QUERY_TRANSFORM_HINT: | 
| Peiyong Lin | 90a90f1 | 2021-06-03 18:11:56 +0000 | [diff] [blame] | 263 | case ANATIVEWINDOW_QUERY_BUFFER_AGE: | 
| Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 264 | // these are part of the VNDK API | 
|  | 265 | break; | 
|  | 266 | case ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL: | 
|  | 267 | *value = window->minSwapInterval; | 
|  | 268 | return 0; | 
|  | 269 | case ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL: | 
|  | 270 | *value = window->maxSwapInterval; | 
|  | 271 | return 0; | 
|  | 272 | case ANATIVEWINDOW_QUERY_XDPI: | 
|  | 273 | *value = (int)window->xdpi; | 
|  | 274 | return 0; | 
|  | 275 | case ANATIVEWINDOW_QUERY_YDPI: | 
|  | 276 | *value = (int)window->ydpi; | 
|  | 277 | return 0; | 
|  | 278 | default: | 
|  | 279 | // asked for an invalid query(), one that isn't part of the VNDK | 
|  | 280 | return -EINVAL; | 
|  | 281 | } | 
|  | 282 | return window->query(window, int(what), value); | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | int ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery what, float* value) { | 
|  | 286 | switch (what) { | 
|  | 287 | case ANATIVEWINDOW_QUERY_XDPI: | 
|  | 288 | *value = window->xdpi; | 
|  | 289 | return 0; | 
|  | 290 | case ANATIVEWINDOW_QUERY_YDPI: | 
|  | 291 | *value = window->ydpi; | 
|  | 292 | return 0; | 
|  | 293 | default: | 
|  | 294 | break; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | int i; | 
|  | 298 | int e = ANativeWindow_query(window, what, &i); | 
|  | 299 | if (e == 0) { | 
|  | 300 | *value = (float)i; | 
|  | 301 | } | 
|  | 302 | return e; | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) { | 
|  | 306 | return window->dequeueBuffer(window, buffer, fenceFd); | 
|  | 307 | } | 
|  | 308 |  | 
|  | 309 | int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 310 | return window->queueBuffer(window, buffer, fenceFd); | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) { | 
|  | 314 | return window->cancelBuffer(window, buffer, fenceFd); | 
|  | 315 | } | 
|  | 316 |  | 
| Mathias Agopian | 2c38b56 | 2017-04-20 16:35:39 -0700 | [diff] [blame] | 317 | int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage) { | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 318 | return native_window_set_usage(window, usage); | 
| Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 319 | } | 
|  | 320 |  | 
|  | 321 | int ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount) { | 
|  | 322 | return native_window_set_buffer_count(window, bufferCount); | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | int ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h) { | 
|  | 326 | return native_window_set_buffers_dimensions(window, (int)w, (int)h); | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | int ANativeWindow_setBuffersFormat(ANativeWindow* window, int format) { | 
|  | 330 | return native_window_set_buffers_format(window, format); | 
|  | 331 | } | 
|  | 332 |  | 
|  | 333 | int ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp) { | 
|  | 334 | return native_window_set_buffers_timestamp(window, timestamp); | 
|  | 335 | } | 
|  | 336 |  | 
| Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 337 | int ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode) { | 
|  | 338 | return native_window_set_shared_buffer_mode(window, sharedBufferMode); | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | int ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh) { | 
|  | 342 | return native_window_set_auto_refresh(window, autoRefresh); | 
|  | 343 | } | 
| Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 344 |  | 
|  | 345 | int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation) { | 
|  | 346 | return native_window_set_auto_prerotation(window, autoPrerotation); | 
|  | 347 | } | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 348 |  | 
| Sungtak Lee | 19055a2 | 2022-11-01 23:39:37 +0000 | [diff] [blame] | 349 | binder_status_t ANativeWindow_readFromParcel( | 
|  | 350 | const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) { | 
|  | 351 | const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel); | 
|  | 352 |  | 
|  | 353 | // Use a android::view::Surface to unparcel the window | 
|  | 354 | std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>(); | 
|  | 355 | status_t ret = shimSurface->readFromParcel(nativeParcel); | 
|  | 356 | if (ret != OK) { | 
|  | 357 | ALOGE("%s: Error: Failed to create android::view::Surface from AParcel", __FUNCTION__); | 
|  | 358 | return STATUS_BAD_VALUE; | 
|  | 359 | } | 
|  | 360 | sp<Surface> surface = sp<Surface>::make( | 
|  | 361 | shimSurface->graphicBufferProducer, false, shimSurface->surfaceControlHandle); | 
|  | 362 | ANativeWindow* anw = surface.get(); | 
|  | 363 | ANativeWindow_acquire(anw); | 
|  | 364 | *outWindow = anw; | 
|  | 365 | return STATUS_OK; | 
|  | 366 | } | 
|  | 367 |  | 
|  | 368 | binder_status_t ANativeWindow_writeToParcel( | 
|  | 369 | ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) { | 
|  | 370 | int value; | 
|  | 371 | int err = (*window->query)(window, NATIVE_WINDOW_CONCRETE_TYPE, &value); | 
|  | 372 | if (err != OK || value != NATIVE_WINDOW_SURFACE) { | 
|  | 373 | ALOGE("Error: ANativeWindow is not backed by Surface"); | 
|  | 374 | return STATUS_BAD_VALUE; | 
|  | 375 | } | 
|  | 376 | // Use a android::view::Surface to parcelize the window | 
|  | 377 | std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>(); | 
|  | 378 | shimSurface->graphicBufferProducer = IGraphicBufferProducer_from_ANativeWindow(window); | 
|  | 379 | shimSurface->surfaceControlHandle = SurfaceControlHandle_from_ANativeWindow(window); | 
|  | 380 |  | 
|  | 381 | Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel); | 
|  | 382 | return shimSurface->writeToParcel(nativeParcel); | 
|  | 383 | } | 
|  | 384 |  | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 385 | /************************************************************************************************** | 
|  | 386 | * apex-stable | 
|  | 387 | **************************************************************************************************/ | 
|  | 388 |  | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 389 | int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window) { | 
|  | 390 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION); | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 391 | } | 
| Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 392 |  | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 393 | int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window) { | 
|  | 394 | return query64(window, NATIVE_WINDOW_GET_LAST_QUEUE_DURATION); | 
| Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 395 | } | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 396 |  | 
|  | 397 | int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window) { | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 398 | return query64(window, NATIVE_WINDOW_GET_LAST_DEQUEUE_START); | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 399 | } | 
| Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 400 |  | 
|  | 401 | int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout) { | 
|  | 402 | return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, timeout); | 
|  | 403 | } | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 404 |  | 
|  | 405 | int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window, | 
|  | 406 | ANativeWindow_cancelBufferInterceptor interceptor, | 
|  | 407 | void* data) { | 
|  | 408 | return window->perform(window, NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR, interceptor, data); | 
|  | 409 | } | 
|  | 410 |  | 
|  | 411 | int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window, | 
|  | 412 | ANativeWindow_dequeueBufferInterceptor interceptor, | 
|  | 413 | void* data) { | 
|  | 414 | return window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR, interceptor, data); | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | int ANativeWindow_setPerformInterceptor(ANativeWindow* window, | 
|  | 418 | ANativeWindow_performInterceptor interceptor, void* data) { | 
|  | 419 | return window->perform(window, NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR, interceptor, data); | 
|  | 420 | } | 
|  | 421 |  | 
|  | 422 | int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window, | 
|  | 423 | ANativeWindow_queueBufferInterceptor interceptor, | 
|  | 424 | void* data) { | 
|  | 425 | return window->perform(window, NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR, interceptor, data); | 
|  | 426 | } |