libgralloc: Store unaligned buffer resolution in private handle.
Add unaligned_width and unaligned_height in private_handle_t to store
the buffer resolution without alignment that client asked to allocate.
Change-Id: I28d757af4178f581e6a83dc06198106c85fc7262
CRs-Fixed: 1040942
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 0ef0a9a..8d43f98 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -180,6 +180,18 @@
}
+void AdrenoMemInfo::getUnalignedWidthAndHeight(const private_handle_t *hnd, int& unaligned_w,
+ int& unaligned_h) {
+ MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
+ if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
+ unaligned_w = metadata->bufferDim.sliceWidth;
+ unaligned_h = metadata->bufferDim.sliceHeight;
+ } else {
+ unaligned_w = hnd->unaligned_width;
+ unaligned_h = hnd->unaligned_height;
+ }
+}
+
bool isUncompressedRgbFormat(int format)
{
bool is_rgb_format = false;
@@ -709,7 +721,6 @@
return size;
}
-
void getBufferAttributes(int width, int height, int format, int usage,
int& alignedw, int &alignedh, int& tiled, unsigned int& size)
{
@@ -892,7 +903,7 @@
private_handle_t* hnd = new private_handle_t(data.fd, data.size,
data.allocType, 0, format,
- alignedw, alignedh);
+ alignedw, alignedh, -1, 0, 0, w, h);
hnd->base = (uint64_t) data.base;
hnd->offset = data.offset;
hnd->gpuaddr = 0;
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 5b22e6d..8bae926 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -53,6 +53,16 @@
{
int err = 0;
int flags = 0;
+ int alignedw = 0;
+ int alignedh = 0;
+
+ AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
+ height,
+ format,
+ usage,
+ alignedw,
+ alignedh);
+
size = roundUpToPageSize(size);
alloc_data data;
data.offset = 0;
@@ -153,8 +163,8 @@
flags |= data.allocType;
uint64_t eBaseAddr = (uint64_t)(eData.base) + eData.offset;
private_handle_t *hnd = new private_handle_t(data.fd, size, flags,
- bufferType, format, width, height, eData.fd, eData.offset,
- eBaseAddr);
+ bufferType, format, alignedw, alignedh,
+ eData.fd, eData.offset, eBaseAddr, width, height);
hnd->offset = data.offset;
hnd->base = (uint64_t)(data.base) + data.offset;
@@ -327,7 +337,7 @@
err = gralloc_alloc_framebuffer(usage, pHandle);
} else {
err = gralloc_alloc_buffer(size, usage, pHandle, bufferType,
- grallocFormat, alignedw, alignedh);
+ grallocFormat, w, h);
}
if (err < 0) {
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index 578240a..3324840 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -140,6 +140,15 @@
int tileEnabled, int& alignedw, int &alignedh);
/*
+ * Function to compute unaligned width and unaligned height based on
+ * private handle
+ *
+ * @return unaligned width, unaligned height
+ */
+ void getUnalignedWidthAndHeight(const private_handle_t *hnd, int& unaligned_w,
+ int& unaligned_h);
+
+ /*
* Function to return whether GPU support MacroTile feature
*
* @return >0 : supported
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 613c066..336ac60 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -233,9 +233,11 @@
// The gpu address mapped into the mmu.
uint64_t gpuaddr __attribute__((aligned(8)));
int format;
- int width;
- int height;
+ int width; // holds aligned width of the actual buffer allocated
+ int height; // holds aligned height of the actual buffer allocated
uint64_t base_metadata __attribute__((aligned(8)));
+ int unaligned_width; // holds width client asked to allocate
+ int unaligned_height; // holds height client asked to allocate
#ifdef __cplusplus
static const int sNumFds = 2;
@@ -246,18 +248,40 @@
static const int sMagic = 'gmsm';
private_handle_t(int fd, unsigned int size, int flags, int bufferType,
- int format, int width, int height, int eFd = -1,
- unsigned int eOffset = 0, uint64_t eBase = 0) :
- fd(fd), fd_metadata(eFd), magic(sMagic),
+ int format, int width, int height) :
+ fd(fd), fd_metadata(-1), magic(sMagic),
flags(flags), size(size), offset(0), bufferType(bufferType),
- base(0), offset_metadata(eOffset), gpuaddr(0),
+ base(0), offset_metadata(0), gpuaddr(0),
format(format), width(width), height(height),
- base_metadata(eBase)
+ base_metadata(0), unaligned_width(width),
+ unaligned_height(height)
{
version = (int) sizeof(native_handle);
numInts = sNumInts();
numFds = sNumFds;
}
+
+ private_handle_t(int fd, unsigned int size, int flags, int bufferType,
+ int format, int width, int height,
+ int eFd, unsigned int eOffset, uint64_t eBase) :
+ private_handle_t(fd, size, flags, bufferType, format, width, height)
+ {
+ fd_metadata = eFd;
+ offset_metadata = eOffset;
+ base_metadata = eBase;
+ }
+
+ private_handle_t(int fd, unsigned int size, int flags, int bufferType,
+ int format, int width, int height,
+ int eFd, unsigned int eOffset, uint64_t eBase,
+ int unaligned_w, int unaligned_h) :
+ private_handle_t(fd, size, flags, bufferType, format, width, height,
+ eFd, eOffset, eBase)
+ {
+ unaligned_width = unaligned_w;
+ unaligned_height = unaligned_h;
+ }
+
~private_handle_t() {
magic = 0;
}
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 142586b..d8880ef 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -309,6 +309,7 @@
int width = va_arg(args, int);
int height = va_arg(args, int);
int format = va_arg(args, int);
+ int alignedw = 0, alignedh = 0;
native_handle_t** handle = va_arg(args, native_handle_t**);
private_handle_t* hnd = (private_handle_t*)native_handle_create(
@@ -321,8 +322,12 @@
hnd->offset = offset;
hnd->base = uint64_t(base) + offset;
hnd->gpuaddr = 0;
- hnd->width = width;
- hnd->height = height;
+ AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
+ height, format, 0, alignedw, alignedh);
+ hnd->width = alignedw;
+ hnd->height = alignedh;
+ hnd->unaligned_width = width;
+ hnd->unaligned_height = height;
hnd->format = format;
*handle = (native_handle_t *)hnd;
res = 0;