Implement native compress API
Bug: 135133301
Test: Ifbcb41388a48afc64bb22623bb7e981b288b2457
Refactor the bulk of Bitmap_compress into hwui/Bitmap::compress, so that
it can be shared by the new API. Update its enum to match the proper
style. Also make the enum a class so it does not need to have a special
return value for a bad parameter, which is now handled by the caller.
Add ABitmap_compress, which implements the new API by calling
hwui/Bitmap::compress.
Change-Id: Ia8ba4c17b517a05b664c6e317e235836473fd7f6
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index 26c7f8d..ea8a521 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -15,6 +15,7 @@
*/
#include <android/bitmap.h>
+#include <android/data_space.h>
#include <android/graphics/bitmap.h>
#include <android/data_space.h>
@@ -74,3 +75,20 @@
ABitmap_releaseRef(bitmap.get());
return ANDROID_BITMAP_RESULT_SUCCESS;
}
+
+int AndroidBitmap_compress(const AndroidBitmapInfo* info,
+ int32_t dataSpace,
+ const void* pixels,
+ int32_t format, int32_t quality,
+ void* userContext,
+ AndroidBitmap_compress_write_fn fn) {
+ if (NULL == info || NULL == pixels || NULL == fn) {
+ return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
+ }
+ if (quality < 0 || quality > 100) {
+ return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
+ }
+
+ return ABitmap_compress(info, (ADataSpace) dataSpace, pixels,
+ (AndroidBitmapCompressFormat) format, quality, userContext, fn);
+}