From 23ea2f3155db32732e6ea9d24d7f69a065a15b3f Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Mon, 20 Apr 2020 14:32:11 -0700 Subject: Update emulated camera to use gralloc lock w/ region Gralloc buffers should be locked using proper regions. Prior to this change, the emulated camera would try to lock 2D Y16 buffers using a [total-byte-size,1] rectangle. Cuttlefish's existing gralloc implementation does not perform any validation on the supplied region. Cuttlefish is updating its gralloc implementation to gralloc 4.0 on Minigbm which will start performing more validation including validation the lock access region. Bug: b/146515640 Test: cts -m CtsCameraTestCases Change-Id: I35bc2c83d3ebbb59283122e1df6b87436427f974 --- .../hwl/EmulatedRequestProcessor.cpp | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/devices/EmulatedCamera/hwl/EmulatedRequestProcessor.cpp b/devices/EmulatedCamera/hwl/EmulatedRequestProcessor.cpp index 7acae76..e78d3c3 100644 --- a/devices/EmulatedCamera/hwl/EmulatedRequestProcessor.cpp +++ b/devices/EmulatedCamera/hwl/EmulatedRequestProcessor.cpp @@ -232,21 +232,25 @@ status_t EmulatedRequestProcessor::LockSensorBuffer( } else { uint32_t buffer_size = 0, stride = 0; auto ret = GetBufferSizeAndStride(stream, &buffer_size, &stride); - if (ret == OK) { + if (ret != OK) { + ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, + stream.override_format); + return BAD_VALUE; + } + if (stream.override_format == HAL_PIXEL_FORMAT_BLOB) { sensor_buffer->plane.img.img = static_cast(importer.lock(buffer, usage, buffer_size)); - if (sensor_buffer->plane.img.img != nullptr) { - sensor_buffer->plane.img.stride = stride; - sensor_buffer->plane.img.buffer_size = buffer_size; - } else { - ALOGE("%s: Failed to lock output buffer!", __FUNCTION__); - return BAD_VALUE; - } } else { - ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, - stream.override_format); + IMapper::Rect region{0, 0, width, height}; + sensor_buffer->plane.img.img = + static_cast(importer.lock(buffer, usage, region)); + } + if (sensor_buffer->plane.img.img == nullptr) { + ALOGE("%s: Failed to lock output buffer!", __FUNCTION__); return BAD_VALUE; } + sensor_buffer->plane.img.stride = stride; + sensor_buffer->plane.img.buffer_size = buffer_size; } return OK; -- cgit v1.2.3