Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 17 | #include "EvsDisplay.h" |
| 18 | |
| 19 | #include <ui/GraphicBufferAllocator.h> |
| 20 | #include <ui/GraphicBufferMapper.h> |
| 21 | |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 22 | using ::android::frameworks::automotive::display::V1_0::HwDisplayConfig; |
| 23 | using ::android::frameworks::automotive::display::V1_0::HwDisplayState; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 24 | using ::android::frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService; |
| 25 | using ::android::hardware::automotive::evs::V1_0::DisplayDesc; |
| 26 | using ::android::hardware::automotive::evs::V1_0::DisplayState; |
| 27 | using ::android::hardware::automotive::evs::V1_0::EvsResult; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 28 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 29 | namespace { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 30 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 31 | // Arbitrary magic number for self-recognition |
| 32 | constexpr uint32_t kDefaultDisplayBufferId = 0x3870; |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | namespace android::hardware::automotive::evs::V1_1::implementation { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 37 | |
| 38 | EvsDisplay::EvsDisplay() { |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 39 | EvsDisplay(nullptr, 0); |
| 40 | } |
| 41 | |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 42 | EvsDisplay::EvsDisplay(sp<IAutomotiveDisplayProxyService> pDisplayProxy, uint64_t displayId) |
| 43 | : mDisplayProxy(pDisplayProxy), |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 44 | mDisplayId(displayId), |
| 45 | mGlWrapper(std::make_unique<GlWrapper>()) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 46 | ALOGD("EvsDisplay instantiated"); |
| 47 | |
| 48 | // Set up our self description |
| 49 | // NOTE: These are arbitrary values chosen for testing |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 50 | mInfo.displayId = "Mock Display"; |
| 51 | mInfo.vendorFlags = 3870; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 52 | |
| 53 | // Assemble the buffer description we'll use for our render target |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 54 | mBuffer.width = 640; |
| 55 | mBuffer.height = 360; |
| 56 | mBuffer.format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 57 | mBuffer.usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER; |
| 58 | mBuffer.bufferId = kDefaultDisplayBufferId; |
| 59 | mBuffer.pixelSize = 4; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 62 | EvsDisplay::~EvsDisplay() { |
| 63 | ALOGD("EvsDisplay being destroyed"); |
| 64 | forceShutdown(); |
| 65 | } |
| 66 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 67 | /** |
| 68 | * This gets called if another caller "steals" ownership of the display |
| 69 | */ |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 70 | void EvsDisplay::forceShutdown() { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 71 | ALOGD("EvsDisplay forceShutdown"); |
| 72 | std::lock_guard<std::mutex> lock(mAccessLock); |
| 73 | |
| 74 | // If the buffer isn't being held by a remote client, release it now as an |
| 75 | // optimization to release the resources more quickly than the destructor might |
| 76 | // get called. |
| 77 | if (mBuffer.memHandle) { |
| 78 | // Report if we're going away while a buffer is outstanding |
| 79 | if (mFrameBusy) { |
| 80 | ALOGE("EvsDisplay going down while client is holding a buffer"); |
| 81 | } |
| 82 | |
| 83 | // Drop the graphics buffer we've been using |
| 84 | GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
| 85 | alloc.free(mBuffer.memHandle); |
| 86 | mBuffer.memHandle = nullptr; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 87 | |
| 88 | if (mGlWrapper) { |
| 89 | mGlWrapper->hideWindow(mDisplayProxy, mDisplayId); |
| 90 | mGlWrapper->shutdown(); |
| 91 | } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // Put this object into an unrecoverable error state since somebody else |
| 95 | // is going to own the display now. |
| 96 | mRequestedState = DisplayState::DEAD; |
| 97 | } |
| 98 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Returns basic information about the EVS display provided by the system. |
| 101 | * See the description of the DisplayDesc structure for details. |
| 102 | */ |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 103 | Return<void> EvsDisplay::getDisplayInfo(getDisplayInfo_cb _hidl_cb) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 104 | ALOGD("getDisplayInfo"); |
| 105 | |
| 106 | // Send back our self description |
| 107 | _hidl_cb(mInfo); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 108 | return {}; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Clients may set the display state to express their desired state. |
| 113 | * The HAL implementation must gracefully accept a request for any state |
| 114 | * while in any other state, although the response may be to ignore the request. |
| 115 | * The display is defined to start in the NOT_VISIBLE state upon initialization. |
| 116 | * The client is then expected to request the VISIBLE_ON_NEXT_FRAME state, and |
| 117 | * then begin providing video. When the display is no longer required, the client |
| 118 | * is expected to request the NOT_VISIBLE state after passing the last video frame. |
| 119 | */ |
| 120 | Return<EvsResult> EvsDisplay::setDisplayState(DisplayState state) { |
| 121 | ALOGD("setDisplayState"); |
| 122 | std::lock_guard<std::mutex> lock(mAccessLock); |
| 123 | |
| 124 | if (mRequestedState == DisplayState::DEAD) { |
| 125 | // This object no longer owns the display -- it's been superceeded! |
| 126 | return EvsResult::OWNERSHIP_LOST; |
| 127 | } |
| 128 | |
| 129 | // Ensure we recognize the requested state so we don't go off the rails |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 130 | if (state >= DisplayState::NUM_STATES) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 131 | return EvsResult::INVALID_ARG; |
| 132 | } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 133 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 134 | if (!mGlWrapper) { |
| 135 | switch (state) { |
| 136 | case DisplayState::NOT_VISIBLE: |
| 137 | mGlWrapper->hideWindow(mDisplayProxy, mDisplayId); |
| 138 | break; |
| 139 | case DisplayState::VISIBLE: |
| 140 | mGlWrapper->showWindow(mDisplayProxy, mDisplayId); |
| 141 | break; |
| 142 | default: |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Record the requested state |
| 148 | mRequestedState = state; |
| 149 | |
| 150 | return EvsResult::OK; |
| 151 | } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * The HAL implementation should report the actual current state, which might |
| 155 | * transiently differ from the most recently requested state. Note, however, that |
| 156 | * the logic responsible for changing display states should generally live above |
| 157 | * the device layer, making it undesirable for the HAL implementation to |
| 158 | * spontaneously change display states. |
| 159 | */ |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 160 | Return<DisplayState> EvsDisplay::getDisplayState() { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 161 | ALOGD("getDisplayState"); |
| 162 | std::lock_guard<std::mutex> lock(mAccessLock); |
| 163 | |
| 164 | return mRequestedState; |
| 165 | } |
| 166 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 167 | /** |
| 168 | * This call returns a handle to a frame buffer associated with the display. |
| 169 | * This buffer may be locked and written to by software and/or GL. This buffer |
| 170 | * must be returned via a call to returnTargetBufferForDisplay() even if the |
| 171 | * display is no longer visible. |
| 172 | */ |
| 173 | // TODO: We need to know if/when our client dies so we can get the buffer back! (blocked b/31632518) |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 174 | Return<void> EvsDisplay::getTargetBuffer(getTargetBuffer_cb _hidl_cb) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 175 | ALOGD("getTargetBuffer"); |
| 176 | std::lock_guard<std::mutex> lock(mAccessLock); |
| 177 | |
| 178 | if (mRequestedState == DisplayState::DEAD) { |
| 179 | ALOGE("Rejecting buffer request from object that lost ownership of the display."); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 180 | _hidl_cb({}); |
| 181 | return {}; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // If we don't already have a buffer, allocate one now |
| 185 | if (!mBuffer.memHandle) { |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 186 | // Initialize our display window |
| 187 | // NOTE: This will cause the display to become "VISIBLE" before a frame is actually |
| 188 | // returned, which is contrary to the spec and will likely result in a black frame being |
| 189 | // (briefly) shown. |
| 190 | if (mGlWrapper->initialize(mDisplayProxy, mDisplayId)) { |
| 191 | // Assemble the buffer description we'll use for our render target |
| 192 | mBuffer.width = mGlWrapper->getWidth(); |
| 193 | mBuffer.height = mGlWrapper->getHeight(); |
| 194 | mBuffer.format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 195 | mBuffer.usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER; |
| 196 | mBuffer.bufferId = kDefaultDisplayBufferId; |
| 197 | mBuffer.pixelSize = 4; |
| 198 | } else { |
| 199 | // If we failed to initialize a EGL, then we're not going to display |
| 200 | // any. |
| 201 | mGlWrapper = nullptr; |
| 202 | } |
| 203 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 204 | // Allocate the buffer that will hold our displayable image |
| 205 | buffer_handle_t handle = nullptr; |
| 206 | GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 207 | status_t result = alloc.allocate(mBuffer.width, mBuffer.height, mBuffer.format, 1, |
| 208 | mBuffer.usage, &handle, &mBuffer.stride, 0, "EvsDisplay"); |
| 209 | if (result != NO_ERROR || !handle) { |
| 210 | ALOGE("Error %d allocating %d x %d graphics buffer", result, mBuffer.width, |
| 211 | mBuffer.height); |
| 212 | if (mGlWrapper) { |
| 213 | mGlWrapper->shutdown(); |
| 214 | } |
| 215 | _hidl_cb({}); |
| 216 | return {}; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | mBuffer.memHandle = handle; |
| 220 | mFrameBusy = false; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 221 | ALOGD("Allocated new buffer %p with stride %u", mBuffer.memHandle.getNativeHandle(), |
| 222 | mBuffer.stride); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | // Do we have a frame available? |
| 226 | if (mFrameBusy) { |
| 227 | // This means either we have a 2nd client trying to compete for buffers |
| 228 | // (an unsupported mode of operation) or else the client hasn't returned |
| 229 | // a previously issued buffer yet (they're behaving badly). |
| 230 | // NOTE: We have to make the callback even if we have nothing to provide |
| 231 | ALOGE("getTargetBuffer called while no buffers available."); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 232 | _hidl_cb({}); |
| 233 | return {}; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 234 | } else { |
| 235 | // Mark our buffer as busy |
| 236 | mFrameBusy = true; |
| 237 | |
| 238 | // Send the buffer to the client |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 239 | ALOGD("Providing display buffer handle %p as id %d", mBuffer.memHandle.getNativeHandle(), |
| 240 | mBuffer.bufferId); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 241 | _hidl_cb(mBuffer); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 242 | return {}; |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 246 | /** |
| 247 | * This call tells the display that the buffer is ready for display. |
| 248 | * The buffer is no longer valid for use by the client after this call. |
| 249 | */ |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 250 | Return<EvsResult> EvsDisplay::returnTargetBufferForDisplayImpl(const uint32_t bufferId, |
| 251 | const buffer_handle_t memHandle) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 252 | ALOGD("returnTargetBufferForDisplay %p", memHandle); |
| 253 | std::lock_guard<std::mutex> lock(mAccessLock); |
| 254 | |
| 255 | // Nobody should call us with a null handle |
| 256 | if (!memHandle) { |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 257 | ALOGE("returnTargetBufferForDisplay called without a valid buffer handle.\n"); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 258 | return EvsResult::INVALID_ARG; |
| 259 | } |
| 260 | if (bufferId != mBuffer.bufferId) { |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 261 | ALOGE("Got an unrecognized frame returned.\n"); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 262 | return EvsResult::INVALID_ARG; |
| 263 | } |
| 264 | if (!mFrameBusy) { |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 265 | ALOGE("A frame was returned with no outstanding frames.\n"); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 266 | return EvsResult::BUFFER_NOT_AVAILABLE; |
| 267 | } |
| 268 | |
| 269 | mFrameBusy = false; |
| 270 | |
| 271 | // If we've been displaced by another owner of the display, then we can't do anything else |
| 272 | if (mRequestedState == DisplayState::DEAD) { |
| 273 | return EvsResult::OWNERSHIP_LOST; |
| 274 | } |
| 275 | |
| 276 | // If we were waiting for a new frame, this is it! |
| 277 | if (mRequestedState == DisplayState::VISIBLE_ON_NEXT_FRAME) { |
| 278 | mRequestedState = DisplayState::VISIBLE; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 279 | if (mGlWrapper) { |
| 280 | mGlWrapper->showWindow(mDisplayProxy, mDisplayId); |
| 281 | } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // Validate we're in an expected state |
| 285 | if (mRequestedState != DisplayState::VISIBLE) { |
| 286 | // We shouldn't get frames back when we're not visible. |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 287 | ALOGE("Got an unexpected frame returned while not visible - ignoring.\n"); |
| 288 | } else if (mGlWrapper) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 289 | // This is where the buffer would be made visible. |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 290 | if (!mGlWrapper->updateImageTexture(mBuffer)) { |
| 291 | return EvsResult::UNDERLYING_SERVICE_ERROR; |
| 292 | } |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 293 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 294 | // Put the image on the screen |
| 295 | mGlWrapper->renderImageToScreen(); |
| 296 | } else { |
| 297 | // TODO: Move below validation logic to somewhere else |
| 298 | #if 0 |
| 299 | // For now we simply validate it has the data we expect in it by reading it back |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 300 | // Lock our display buffer for reading |
| 301 | uint32_t* pixels = nullptr; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 302 | GraphicBufferMapper& mapper = GraphicBufferMapper::get(); |
| 303 | mapper.lock(mBuffer.memHandle, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_NEVER, |
| 304 | android::Rect(mBuffer.width, mBuffer.height), (void**)&pixels); |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 305 | |
| 306 | // If we failed to lock the pixel buffer, we're about to crash, but log it first |
| 307 | if (!pixels) { |
| 308 | ALOGE("Display failed to gain access to image buffer for reading"); |
| 309 | } |
| 310 | |
| 311 | // Check the test pixels |
| 312 | bool frameLooksGood = true; |
| 313 | for (unsigned row = 0; row < mBuffer.height; row++) { |
| 314 | for (unsigned col = 0; col < mBuffer.width; col++) { |
| 315 | // Index into the row to check the pixel at this column. |
| 316 | // We expect 0xFF in the LSB channel, a vertical gradient in the |
| 317 | // second channel, a horitzontal gradient in the third channel, and |
| 318 | // 0xFF in the MSB. |
| 319 | // The exception is the very first 32 bits which is used for the |
| 320 | // time varying frame signature to avoid getting fooled by a static image. |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 321 | uint32_t expectedPixel = 0xFF0000FF | // MSB and LSB |
| 322 | ((row & 0xFF) << 8) | // vertical gradient |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 323 | ((col & 0xFF) << 16); // horizontal gradient |
| 324 | if ((row | col) == 0) { |
| 325 | // we'll check the "uniqueness" of the frame signature below |
| 326 | continue; |
| 327 | } |
| 328 | // Walk across this row (we'll step rows below) |
| 329 | uint32_t receivedPixel = pixels[col]; |
| 330 | if (receivedPixel != expectedPixel) { |
| 331 | ALOGE("Pixel check mismatch in frame buffer"); |
| 332 | frameLooksGood = false; |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (!frameLooksGood) { |
| 338 | break; |
| 339 | } |
| 340 | |
| 341 | // Point to the next row (NOTE: gralloc reports stride in units of pixels) |
| 342 | pixels = pixels + mBuffer.stride; |
| 343 | } |
| 344 | |
| 345 | // Ensure we don't see the same buffer twice without it being rewritten |
| 346 | static uint32_t prevSignature = ~0; |
| 347 | uint32_t signature = pixels[0] & 0xFF; |
| 348 | if (prevSignature == signature) { |
| 349 | frameLooksGood = false; |
| 350 | ALOGE("Duplicate, likely stale frame buffer detected"); |
| 351 | } |
| 352 | |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 353 | // Release our output buffer |
| 354 | mapper.unlock(mBuffer.memHandle); |
| 355 | |
| 356 | if (!frameLooksGood) { |
| 357 | return EvsResult::UNDERLYING_SERVICE_ERROR; |
| 358 | } |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 359 | #endif |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | return EvsResult::OK; |
| 363 | } |
| 364 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 365 | Return<EvsResult> EvsDisplay::returnTargetBufferForDisplay(const V1_0::BufferDesc& buffer) { |
Changyeon Jo | 2400b69 | 2019-07-18 21:32:48 -0700 | [diff] [blame] | 366 | return returnTargetBufferForDisplayImpl(buffer.bufferId, buffer.memHandle); |
| 367 | } |
| 368 | |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 369 | Return<void> EvsDisplay::getDisplayInfo_1_1(getDisplayInfo_1_1_cb _info_cb) { |
| 370 | if (mDisplayProxy != nullptr) { |
| 371 | return mDisplayProxy->getDisplayInfo(mDisplayId, _info_cb); |
| 372 | } else { |
| 373 | HwDisplayConfig nullConfig; |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 374 | HwDisplayState nullState; |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 375 | _info_cb(nullConfig, nullState); |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 376 | return {}; |
Changyeon Jo | 043a7a0 | 2020-01-02 17:55:55 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 380 | } // namespace android::hardware::automotive::evs::V1_1::implementation |