[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
diff --git a/include/ui/GraphicBuffer.h b/include/ui/GraphicBuffer.h
index 6edc3ca..0be26a7 100644
--- a/include/ui/GraphicBuffer.h
+++ b/include/ui/GraphicBuffer.h
@@ -26,6 +26,8 @@
#include <utils/Flattenable.h>
#include <pixelflinger/pixelflinger.h>
+#include <hardware/hardware.h>
+
struct android_native_buffer_t;
namespace android {
@@ -63,6 +65,13 @@
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 @@
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 402843e..a472824 100644
--- a/include/ui/android_native_buffer.h
+++ b/include/ui/android_native_buffer.h
@@ -51,8 +51,12 @@
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 828a988..3671954 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -45,6 +45,7 @@
stride =
format =
usage = 0;
+ transform = 0;
handle = NULL;
}
@@ -57,7 +58,8 @@
height =
stride =
format =
- usage = 0;
+ usage =
+ transform = 0;
handle = NULL;
mInitCheck = initSize(w, h, reqFormat, reqUsage);
}
@@ -74,6 +76,7 @@
stride = inStride;
format = inFormat;
usage = inUsage;
+ transform = 0;
handle = inHandle;
}
@@ -182,8 +185,10 @@
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 @@
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::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<int const*>(buffer);
if (buf[0] != 'GBFR') return BAD_TYPE;
@@ -231,7 +237,7 @@
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 @@
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;