diff options
author | Ping-Hao Wu <pinghao@google.com> | 2017-03-03 20:55:39 -0800 |
---|---|---|
committer | Emilian Peev <epeev@google.com> | 2017-04-26 10:01:06 +0100 |
commit | cfd093cb74496b657a40463de530a28dcb3ac926 (patch) | |
tree | 2f5c151ac2b4a0f0c2fcfc90ea0da2ecd60304ee | |
parent | 041daeb6e26566c6fed5b3080e0801faacccb643 (diff) | |
download | android_device_generic_goldfish-cfd093cb74496b657a40463de530a28dcb3ac926.tar.gz android_device_generic_goldfish-cfd093cb74496b657a40463de530a28dcb3ac926.tar.bz2 android_device_generic_goldfish-cfd093cb74496b657a40463de530a28dcb3ac926.zip |
Replace GraphicBufferMapper with gralloc module.
BUG: 35036220
Test: Local
Change-Id: I117c1874f721141506b35aeea17a28dbe4131938
-rw-r--r-- | camera/Android.mk | 5 | ||||
-rwxr-xr-x | camera/EmulatedCamera.cpp | 1 | ||||
-rw-r--r-- | camera/EmulatedFakeCamera2.cpp | 24 | ||||
-rw-r--r-- | camera/EmulatedFakeCamera3.cpp | 25 | ||||
-rw-r--r-- | camera/GrallocModule.h | 41 | ||||
-rwxr-xr-x | camera/PreviewWindow.cpp | 13 | ||||
-rw-r--r-- | camera/fake-pipeline2/JpegCompressor.cpp | 1 |
7 files changed, 74 insertions, 36 deletions
diff --git a/camera/Android.mk b/camera/Android.mk index bd33131..b8c468b 100644 --- a/camera/Android.mk +++ b/camera/Android.mk @@ -32,8 +32,9 @@ emulator_camera_shared_libraries := \ libcamera_client \ libui \ libdl \ - libjpeg \ - libcamera_metadata + libjpeg \ + libcamera_metadata \ + libhardware emulator_camera_static_libraries := \ libyuv_static diff --git a/camera/EmulatedCamera.cpp b/camera/EmulatedCamera.cpp index bdab833..df79210 100755 --- a/camera/EmulatedCamera.cpp +++ b/camera/EmulatedCamera.cpp @@ -26,7 +26,6 @@ #define LOG_NDEBUG 0 #define LOG_TAG "EmulatedCamera_Camera" #include <cutils/log.h> -#include <ui/Rect.h> #include "EmulatedCamera.h" //#include "EmulatedFakeCameraDevice.h" #include "Converters.h" diff --git a/camera/EmulatedFakeCamera2.cpp b/camera/EmulatedFakeCamera2.cpp index 7df6f52..47e8fc7 100644 --- a/camera/EmulatedFakeCamera2.cpp +++ b/camera/EmulatedFakeCamera2.cpp @@ -27,9 +27,8 @@ #include "EmulatedFakeCamera2.h" #include "EmulatedCameraFactory.h" -#include <ui/Rect.h> -#include <ui/GraphicBufferMapper.h> #include "gralloc_cb.h" +#include "GrallocModule.h" #define ERROR_CAMERA_NOT_PRESENT (-EPIPE) @@ -1058,11 +1057,11 @@ bool EmulatedFakeCamera2::ConfigureThread::getBuffers() { } /* Lock the buffer from the perspective of the graphics mapper */ - const Rect rect(s.width, s.height); - - res = GraphicBufferMapper::get().lock(*(b.buffer), + res = GrallocModule::getInstance().lock(*(b.buffer), GRALLOC_USAGE_HW_CAMERA_WRITE, - rect, (void**)&(b.img) ); + 0, 0, s.width, s.height, + (void**)&(b.img)); + if (res != NO_ERROR) { ALOGE("%s: grbuffer_mapper.lock failure: %s (%d)", @@ -1086,11 +1085,10 @@ bool EmulatedFakeCamera2::ConfigureThread::getBuffers() { } /* Lock the buffer from the perspective of the graphics mapper */ - const Rect rect(s.width, s.height); - - res = GraphicBufferMapper::get().lock(*(b.buffer), + res = GrallocModule::getInstance().lock(*(b.buffer), GRALLOC_USAGE_HW_CAMERA_READ, - rect, (void**)&(b.img) ); + 0, 0, s.width, s.height, + (void**)&(b.img) ); if (res != NO_ERROR) { ALOGE("%s: grbuffer_mapper.lock failure: %s (%d)", __FUNCTION__, strerror(-res), res); @@ -1366,7 +1364,7 @@ bool EmulatedFakeCamera2::ReadoutThread::threadLoop() { } else { ALOGV("Readout: Sending image buffer %zu (%p) to output stream %d", i, (void*)*(b.buffer), b.streamId); - GraphicBufferMapper::get().unlock(*(b.buffer)); + GrallocModule::getInstance().unlock(*(b.buffer)); const Stream &s = mParent->getStreamInfo(b.streamId); res = s.ops->enqueue_buffer(s.ops, captureTime, b.buffer); if (res != OK) { @@ -1410,7 +1408,7 @@ void EmulatedFakeCamera2::ReadoutThread::onJpegDone( ALOGV("%s: Compression complete, pushing to stream %d", __FUNCTION__, jpegBuffer.streamId); - GraphicBufferMapper::get().unlock(*(jpegBuffer.buffer)); + GrallocModule::getInstance().unlock(*(jpegBuffer.buffer)); const Stream &s = mParent->getStreamInfo(jpegBuffer.streamId); res = s.ops->enqueue_buffer(s.ops, mJpegTimestamp, jpegBuffer.buffer); } @@ -1418,7 +1416,7 @@ void EmulatedFakeCamera2::ReadoutThread::onJpegDone( void EmulatedFakeCamera2::ReadoutThread::onJpegInputDone( const StreamBuffer &inputBuffer) { status_t res; - GraphicBufferMapper::get().unlock(*(inputBuffer.buffer)); + GrallocModule::getInstance().unlock(*(inputBuffer.buffer)); const ReprocessStream &s = mParent->getReprocessStreamInfo(-inputBuffer.streamId); res = s.ops->release_buffer(s.ops, inputBuffer.buffer); diff --git a/camera/EmulatedFakeCamera3.cpp b/camera/EmulatedFakeCamera3.cpp index 0e305f9..fc046f9 100644 --- a/camera/EmulatedFakeCamera3.cpp +++ b/camera/EmulatedFakeCamera3.cpp @@ -30,9 +30,8 @@ #include "EmulatedFakeCamera3.h" #include "EmulatedCameraFactory.h" #include <ui/Fence.h> -#include <ui/Rect.h> -#include <ui/GraphicBufferMapper.h> #include "gralloc_cb.h" +#include "GrallocModule.h" #include "fake-pipeline2/Sensor.h" #include "fake-pipeline2/JpegCompressor.h" @@ -97,7 +96,6 @@ EmulatedFakeCamera3::EmulatedFakeCamera3(int cameraId, bool facingBack, for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++) { mDefaultTemplates[i] = NULL; } - } EmulatedFakeCamera3::~EmulatedFakeCamera3() { @@ -891,13 +889,13 @@ status_t EmulatedFakeCamera3::processCaptureRequest( } if (res == OK) { // Lock buffer for writing - const Rect rect(destBuf.width, destBuf.height); if (srcBuf.stream->format == HAL_PIXEL_FORMAT_YCbCr_420_888) { if (destBuf.format == HAL_PIXEL_FORMAT_YCrCb_420_SP) { android_ycbcr ycbcr = android_ycbcr(); - res = GraphicBufferMapper::get().lockYCbCr( + res = GrallocModule::getInstance().lock_ycbcr( *(destBuf.buffer), - GRALLOC_USAGE_HW_CAMERA_WRITE, rect, + GRALLOC_USAGE_HW_CAMERA_WRITE, + 0, 0, destBuf.width, destBuf.height, &ycbcr); // This is only valid because we know that emulator's // YCbCr_420_888 is really contiguous NV21 under the hood @@ -908,9 +906,12 @@ status_t EmulatedFakeCamera3::processCaptureRequest( res = INVALID_OPERATION; } } else { - res = GraphicBufferMapper::get().lock(*(destBuf.buffer), - GRALLOC_USAGE_HW_CAMERA_WRITE, rect, - (void**)&(destBuf.img)); + res = GrallocModule::getInstance().lock( + *(destBuf.buffer), + GRALLOC_USAGE_HW_CAMERA_WRITE, + 0, 0, destBuf.width, destBuf.height, + (void**)&(destBuf.img)); + } if (res != OK) { ALOGE("%s: Request %d: Buffer %zu: Unable to lock buffer", @@ -922,7 +923,7 @@ status_t EmulatedFakeCamera3::processCaptureRequest( // Either waiting or locking failed. Unlock locked buffers and bail // out. for (size_t j = 0; j < i; j++) { - GraphicBufferMapper::get().unlock( + GrallocModule::getInstance().unlock( *(request->output_buffers[i].buffer)); } delete sensorBuffers; @@ -2387,7 +2388,7 @@ bool EmulatedFakeCamera3::ReadoutThread::threadLoop() { __FUNCTION__, strerror(-res), res); // fallthrough for cleanup } - GraphicBufferMapper::get().unlock(*(buf->buffer)); + GrallocModule::getInstance().unlock(*(buf->buffer)); buf->status = goodBuffer ? CAMERA3_BUFFER_STATUS_OK : CAMERA3_BUFFER_STATUS_ERROR; @@ -2489,7 +2490,7 @@ void EmulatedFakeCamera3::ReadoutThread::onJpegDone( const StreamBuffer &jpegBuffer, bool success) { Mutex::Autolock jl(mJpegLock); - GraphicBufferMapper::get().unlock(*(jpegBuffer.buffer)); + GrallocModule::getInstance().unlock(*(jpegBuffer.buffer)); mJpegHalBuffer.status = success ? CAMERA3_BUFFER_STATUS_OK : CAMERA3_BUFFER_STATUS_ERROR; diff --git a/camera/GrallocModule.h b/camera/GrallocModule.h new file mode 100644 index 0000000..693be49 --- /dev/null +++ b/camera/GrallocModule.h @@ -0,0 +1,41 @@ + +#ifndef EMU_CAMERA_GRALLOC_MODULE_ +#define EMU_CAMERA_GRALLOC_MODULE_ + +#include <hardware/gralloc.h> + +class GrallocModule +{ +public: + static GrallocModule &getInstance() { + static GrallocModule instance; + return instance; + } + + int lock(buffer_handle_t handle, + int usage, int l, int t, int w, int h, void **vaddr) { + return mModule->lock(mModule, handle, usage, l, t, w, h, vaddr); + } + + int lock_ycbcr(buffer_handle_t handle, + int usage, int l, int t, int w, int h, + struct android_ycbcr *ycbcr) { + return mModule->lock_ycbcr(mModule, handle, usage, l, t, w, h, ycbcr); + } + + int unlock(buffer_handle_t handle) { + return mModule->unlock(mModule, handle); + } + +private: + GrallocModule() { + const hw_module_t *module = NULL; + if (!hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) { + ALOGE("%s: Failed to get gralloc module", __FUNCTION__); + } + mModule = reinterpret_cast<const gralloc_module_t*>(module); + } + const gralloc_module_t *mModule; +}; + +#endif diff --git a/camera/PreviewWindow.cpp b/camera/PreviewWindow.cpp index 68d3d5d..607ad7d 100755 --- a/camera/PreviewWindow.cpp +++ b/camera/PreviewWindow.cpp @@ -22,10 +22,9 @@ #define LOG_NDEBUG 0 #define LOG_TAG "EmulatedCamera_Preview" #include <cutils/log.h> -#include <ui/Rect.h> -#include <ui/GraphicBufferMapper.h> #include "EmulatedCameraDevice.h" #include "PreviewWindow.h" +#include "GrallocModule.h" namespace android { @@ -150,11 +149,11 @@ void PreviewWindow::onNextFrameAvailable(nsecs_t timestamp, /* Now let the graphics framework to lock the buffer, and provide * us with the framebuffer data address. */ void* img = NULL; - const Rect rect(mPreviewFrameWidth, mPreviewFrameHeight); - GraphicBufferMapper& grbuffer_mapper(GraphicBufferMapper::get()); - res = grbuffer_mapper.lock(*buffer, GRALLOC_USAGE_SW_WRITE_OFTEN, rect, &img); + res = GrallocModule::getInstance().lock( + *buffer, GRALLOC_USAGE_SW_WRITE_OFTEN, + 0, 0, mPreviewFrameWidth, mPreviewFrameHeight, &img); if (res != NO_ERROR) { - ALOGE("%s: grbuffer_mapper.lock failure: %d -> %s", + ALOGE("%s: gralloc.lock failure: %d -> %s", __FUNCTION__, res, strerror(res)); mPreviewWindow->cancel_buffer(mPreviewWindow, buffer); return; @@ -171,7 +170,7 @@ void PreviewWindow::onNextFrameAvailable(nsecs_t timestamp, ALOGE("%s: Unable to obtain preview frame: %d", __FUNCTION__, res); mPreviewWindow->cancel_buffer(mPreviewWindow, buffer); } - grbuffer_mapper.unlock(*buffer); + GrallocModule::getInstance().unlock(*buffer); } /*************************************************************************** diff --git a/camera/fake-pipeline2/JpegCompressor.cpp b/camera/fake-pipeline2/JpegCompressor.cpp index d0dce26..8dae6f7 100644 --- a/camera/fake-pipeline2/JpegCompressor.cpp +++ b/camera/fake-pipeline2/JpegCompressor.cpp @@ -18,7 +18,6 @@ #define LOG_TAG "EmulatedCamera2_JpegCompressor" #include <utils/Log.h> -#include <ui/GraphicBufferMapper.h> #include "JpegCompressor.h" #include "../EmulatedFakeCamera2.h" |