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