diff --git a/libqcomui/Android.mk b/libqcomui/Android.mk index 270de84..2b786d9 100644 --- a/libqcomui/Android.mk +++ b/libqcomui/Android.mk @@ -7,9 +7,10 @@ LOCAL_SRC_FILES := \ LOCAL_SHARED_LIBRARIES := \ libutils \ libcutils \ - libmemalloc + libmemalloc \ + libui -LOCAL_C_INCLUDES := $(TOP)/hardware/qcom/display/libgralloc +LOCAL_C_INCLUDES := $(TOP)/hardware/qcom/display/libgralloc \ LOCAL_CFLAGS := -DLOG_TAG=\"libQcomUI\" LOCAL_MODULE := libQcomUI LOCAL_MODULE_TAGS := optional diff --git a/libqcomui/qcom_ui.cpp b/libqcomui/qcom_ui.cpp index 9f843dd..df82cae 100644 --- a/libqcomui/qcom_ui.cpp +++ b/libqcomui/qcom_ui.cpp @@ -108,6 +108,9 @@ int getNumberOfArgsForOperation(int operation) { case NATIVE_WINDOW_SET_BUFFERS_SIZE: num_args = 1; break; + case NATIVE_WINDOW_UPDATE_BUFFERS_GEOMETRY: + num_args = 3; + break; default: LOGE("%s: invalid operation(0x%x)", __FUNCTION__, operation); break; }; @@ -169,6 +172,81 @@ int checkBuffer(native_handle_t *buffer_handle, int size, int usage) return 0; } - +/* + * Checks if memory needs to be reallocated for this buffer. + * + * @param: Geometry of the current buffer. + * @param: Required Geometry. + * @param: Geometry of the updated buffer. + * + * @return True if a memory reallocation is required. + */ +bool needNewBuffer(const qBufGeometry currentGeometry, + const qBufGeometry requiredGeometry, + const qBufGeometry updatedGeometry) +{ + // If the current buffer info matches the updated info, + // we do not require any memory allocation. + if (updatedGeometry.width && updatedGeometry.height && + updatedGeometry.format) { + return false; + } + if (currentGeometry.width != requiredGeometry.width || + currentGeometry.height != requiredGeometry.height || + currentGeometry.format != requiredGeometry.format) { + // Current and required geometry do not match. Allocation + // required. + return true; + } + return false; +} + +/* + * Update the geometry of this buffer without reallocation. + * + * @param: buffer whose geometry needs to be updated. + * @param: Updated width + * @param: Updated height + * @param: Updated format + */ +int updateBufferGeometry(sp buffer, const qBufGeometry updatedGeometry) +{ + if (buffer == 0) { + LOGE("%s: graphic buffer is NULL", __FUNCTION__); + return -EINVAL; + } + + if (!updatedGeometry.width || !updatedGeometry.height || + !updatedGeometry.format) { + // No update required. Return. + return 0; + } + if (buffer->width == updatedGeometry.width && + buffer->height == updatedGeometry.height && + buffer->format == updatedGeometry.format) { + // The buffer has already been updated. Return. + return 0; + } + + // Validate the handle + if (private_handle_t::validate(buffer->handle)) { + LOGE("%s: handle is invalid", __FUNCTION__); + return -EINVAL; + } + buffer->width = updatedGeometry.width; + buffer->height = updatedGeometry.height; + buffer->format = updatedGeometry.format; + private_handle_t *hnd = (private_handle_t*)(buffer->handle); + if (hnd) { + hnd->width = updatedGeometry.width; + hnd->height = updatedGeometry.height; + hnd->format = updatedGeometry.format; + } else { + LOGE("%s: hnd is NULL", __FUNCTION__); + return -EINVAL; + } + + return 0; +} diff --git a/libqcomui/qcom_ui.h b/libqcomui/qcom_ui.h index b55ff4a..0b78f47 100644 --- a/libqcomui/qcom_ui.h +++ b/libqcomui/qcom_ui.h @@ -31,12 +31,31 @@ #define INCLUDE_LIBQCOM_UI #include +#include + +using android::sp; +using android::GraphicBuffer; /* * Qcom specific Native Window perform operations */ enum { - NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000, + NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000, + NATIVE_WINDOW_UPDATE_BUFFERS_GEOMETRY = 0x20000000, +}; + +/* + * Structure to hold the buffer geometry + */ +struct qBufGeometry { + int width; + int height; + int format; + void set(int w, int h, int f) { + width = w; + height = h; + format = f; + } }; /* @@ -69,4 +88,25 @@ bool isGPUSupportedFormat(int format); * @return -EINVAL if the operation is invalid. */ int getNumberOfArgsForOperation(int operation); + +/* + * Checks if memory needs to be reallocated for this buffer. + * + * @param: Geometry of the current buffer. + * @param: Required Geometry. + * @param: Geometry of the updated buffer. + * + * @return True if a memory reallocation is required. + */ +bool needNewBuffer(const qBufGeometry currentGeometry, + const qBufGeometry requiredGeometry, + const qBufGeometry updatedGeometry); + +/* + * Update the geometry of this buffer without reallocation. + * + * @param: buffer whose geometry needs to be updated. + * @param: Updated buffer geometry + */ +int updateBufferGeometry(sp buffer, const qBufGeometry bufGeometry); #endif // INCLUDE_LIBQCOM_UI