Skip to content

Commit 48e723a

Browse files
committed
[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
1 parent e338115 commit 48e723a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

include/ui/GraphicBuffer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <utils/Flattenable.h>
2727
#include <pixelflinger/pixelflinger.h>
2828

29+
#include <hardware/hardware.h>
30+
2931
struct android_native_buffer_t;
3032

3133
namespace android {
@@ -63,6 +65,13 @@ class GraphicBuffer
6365
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
6466
};
6567

68+
enum {
69+
TRANSFORM_IDENTITY = 0,
70+
TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
71+
TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
72+
TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270
73+
};
74+
6675
GraphicBuffer();
6776

6877
// creates w * h buffer
@@ -79,6 +88,7 @@ class GraphicBuffer
7988
uint32_t getHeight() const { return height; }
8089
uint32_t getStride() const { return stride; }
8190
uint32_t getUsage() const { return usage; }
91+
uint32_t getTransform() const { return transform; }
8292
PixelFormat getPixelFormat() const { return format; }
8393
Rect getBounds() const { return Rect(width, height); }
8494

include/ui/android_native_buffer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ typedef struct android_native_buffer_t
5151
int stride;
5252
int format;
5353
int usage;
54-
55-
void* reserved[2];
54+
55+
/* transformation as defined in hardware.h */
56+
uint8_t transform;
57+
58+
uint8_t reserved_bytes[3];
59+
void* reserved[1];
5660

5761
buffer_handle_t handle;
5862

libs/ui/GraphicBuffer.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ GraphicBuffer::GraphicBuffer()
4545
stride =
4646
format =
4747
usage = 0;
48+
transform = 0;
4849
handle = NULL;
4950
}
5051

@@ -57,7 +58,8 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
5758
height =
5859
stride =
5960
format =
60-
usage = 0;
61+
usage =
62+
transform = 0;
6163
handle = NULL;
6264
mInitCheck = initSize(w, h, reqFormat, reqUsage);
6365
}
@@ -74,6 +76,7 @@ GraphicBuffer::GraphicBuffer(uint32_t w, uint32_t h,
7476
stride = inStride;
7577
format = inFormat;
7678
usage = inUsage;
79+
transform = 0;
7780
handle = inHandle;
7881
}
7982

@@ -182,8 +185,10 @@ status_t GraphicBuffer::lock(GGLSurface* sur, uint32_t usage)
182185
return res;
183186
}
184187

188+
const int kFlattenFdsOffset = 9;
189+
185190
size_t GraphicBuffer::getFlattenedSize() const {
186-
return (8 + (handle ? handle->numInts : 0))*sizeof(int);
191+
return (kFlattenFdsOffset + (handle ? handle->numInts : 0))*sizeof(int);
187192
}
188193

189194
size_t GraphicBuffer::getFdCount() const {
@@ -208,13 +213,14 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size,
208213
buf[5] = usage;
209214
buf[6] = 0;
210215
buf[7] = 0;
216+
buf[8] = transform;
211217

212218
if (handle) {
213219
buf[6] = handle->numFds;
214220
buf[7] = handle->numInts;
215221
native_handle_t const* const h = handle;
216222
memcpy(fds, h->data, h->numFds*sizeof(int));
217-
memcpy(&buf[8], h->data + h->numFds, h->numInts*sizeof(int));
223+
memcpy(&buf[kFlattenFdsOffset], h->data + h->numFds, h->numInts*sizeof(int));
218224
}
219225

220226
return NO_ERROR;
@@ -223,15 +229,15 @@ status_t GraphicBuffer::flatten(void* buffer, size_t size,
223229
status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
224230
int fds[], size_t count)
225231
{
226-
if (size < 8*sizeof(int)) return NO_MEMORY;
232+
if (size < kFlattenFdsOffset*sizeof(int)) return NO_MEMORY;
227233

228234
int const* buf = static_cast<int const*>(buffer);
229235
if (buf[0] != 'GBFR') return BAD_TYPE;
230236

231237
const size_t numFds = buf[6];
232238
const size_t numInts = buf[7];
233239

234-
const size_t sizeNeeded = (8 + numInts) * sizeof(int);
240+
const size_t sizeNeeded = (kFlattenFdsOffset + numInts) * sizeof(int);
235241
if (size < sizeNeeded) return NO_MEMORY;
236242

237243
size_t fdCountNeeded = 0;
@@ -248,9 +254,10 @@ status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
248254
stride = buf[3];
249255
format = buf[4];
250256
usage = buf[5];
257+
transform = buf[8];
251258
native_handle* h = native_handle_create(numFds, numInts);
252259
memcpy(h->data, fds, numFds*sizeof(int));
253-
memcpy(h->data + numFds, &buf[8], numInts*sizeof(int));
260+
memcpy(h->data + numFds, &buf[kFlattenFdsOffset], numInts*sizeof(int));
254261
handle = h;
255262
} else {
256263
width = height = stride = format = usage = 0;

0 commit comments

Comments
 (0)