From 30eb1b1803b590cf08cbf425dbdda4d330044f77 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 2 Nov 2010 20:57:14 -0700 Subject: [PATCH] [3171580] Add transform field to native buffers. (DO NOT MERGE) This field indicate how the content of the buffer needs to be transformed. Change-Id: Ide3e980a90599e931406135693231276626adbbb --- include/ui/GraphicBuffer.h | 10 ++++++++++ include/ui/android_native_buffer.h | 8 ++++++-- libs/ui/GraphicBuffer.cpp | 19 +++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h index 6edc3caab..0be26a79a 100644 --- a/include/ui/GraphicBuffer.h +++ b/include/ui/GraphicBuffer.h @@ -26,6 +26,8 @@ #include #include +#include + struct android_native_buffer_t; namespace android { @@ -63,6 +65,13 @@ public: USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK }; + enum { + TRANSFORM_IDENTITY = 0, + TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, + TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, + TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270 + }; + GraphicBuffer(); // creates w * h buffer @@ -79,6 +88,7 @@ public: uint32_t getHeight() const { return height; } uint32_t getStride() const { return stride; } uint32_t getUsage() const { return usage; } + uint32_t getTransform() const { return transform; } PixelFormat getPixelFormat() const { return format; } Rect getBounds() const { return Rect(width, height); } diff --git a/include/ui/android_native_buffer.h b/include/ui/android_native_buffer.h index 402843e20..a472824bc 100644 --- a/include/ui/android_native_buffer.h +++ b/include/ui/android_native_buffer.h @@ -51,8 +51,12 @@ typedef struct android_native_buffer_t int stride; int format; int usage; - - void* reserved[2]; + + /* transformation as defined in hardware.h */ + uint8_t transform; + + uint8_t reserved_bytes[3]; + void* reserved[1]; buffer_handle_t handle; diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index 828a988be..367195439 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -45,6 +45,7 @@ GraphicBuffer::GraphicBuffer() stride = format = usage = 0; + transform = 0; handle = NULL; } @@ -57,7 +58,8 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h, height = stride = format = - usage = 0; + usage = + transform = 0; handle = NULL; mInitCheck = initSize(w, h, reqFormat, reqUsage); } @@ -74,6 +76,7 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h, stride = inStride; format = inFormat; usage = inUsage; + transform = 0; handle = inHandle; } @@ -182,8 +185,10 @@ status_t GraphicBuffer::lock(GGLSurface* sur, uint32_t usage) return res; } +const int kFlattenFdsOffset = 9; + size_t GraphicBuffer::getFlattenedSize() const { - return (8 + (handle ? handle->numInts : 0))*sizeof(int); + return (kFlattenFdsOffset + (handle ? handle->numInts : 0))*sizeof(int); } size_t GraphicBuffer::getFdCount() const { @@ -208,13 +213,14 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size, buf[5] = usage; buf[6] = 0; buf[7] = 0; + buf[8] = transform; if (handle) { buf[6] = handle->numFds; buf[7] = handle->numInts; native_handle_t const* const h = handle; memcpy(fds, h->data, h->numFds*sizeof(int)); - memcpy(&buf[8], h->data + h->numFds, h->numInts*sizeof(int)); + memcpy(&buf[kFlattenFdsOffset], h->data + h->numFds, h->numInts*sizeof(int)); } return NO_ERROR; @@ -223,7 +229,7 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size, status_t GraphicBuffer::unflatten(void const* buffer, size_t size, int fds[], size_t count) { - if (size < 8*sizeof(int)) return NO_MEMORY; + if (size < kFlattenFdsOffset*sizeof(int)) return NO_MEMORY; int const* buf = static_cast(buffer); if (buf[0] != 'GBFR') return BAD_TYPE; @@ -231,7 +237,7 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size, const size_t numFds = buf[6]; const size_t numInts = buf[7]; - const size_t sizeNeeded = (8 + numInts) * sizeof(int); + const size_t sizeNeeded = (kFlattenFdsOffset + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; size_t fdCountNeeded = 0; @@ -248,9 +254,10 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size, stride = buf[3]; format = buf[4]; usage = buf[5]; + transform = buf[8]; native_handle* h = native_handle_create(numFds, numInts); memcpy(h->data, fds, numFds*sizeof(int)); - memcpy(h->data + numFds, &buf[8], numInts*sizeof(int)); + memcpy(h->data + numFds, &buf[kFlattenFdsOffset], numInts*sizeof(int)); handle = h; } else { width = height = stride = format = usage = 0;