Commit a1d10e49 authored by jaekyun's avatar jaekyun Committed by Commit bot

Check whether Java bitmap memory size is same to one of SkBitmap

This is to understand why Issue 476559 is happening.

BUG=476559

Review URL: https://codereview.chromium.org/1136053003

Cr-Commit-Position: refs/heads/master@{#329288}
parent 4b6e14e8
...@@ -44,7 +44,7 @@ public class BitmapHelper { ...@@ -44,7 +44,7 @@ public class BitmapHelper {
} }
} }
/** /**
* Provides a matching Bitmap.Config for the enum config value passed. * Provides a matching Bitmap.Config for the enum config value passed.
* *
* @param bitmapFormatValue The Bitmap Configuration enum value. * @param bitmapFormatValue The Bitmap Configuration enum value.
...@@ -64,4 +64,8 @@ public class BitmapHelper { ...@@ -64,4 +64,8 @@ public class BitmapHelper {
} }
} }
@CalledByNative
private static int getByteCount(Bitmap bitmap) {
return bitmap.getByteCount();
}
} }
...@@ -29,6 +29,7 @@ JavaBitmap::JavaBitmap(jobject bitmap) ...@@ -29,6 +29,7 @@ JavaBitmap::JavaBitmap(jobject bitmap)
size_ = gfx::Size(info.width, info.height); size_ = gfx::Size(info.width, info.height);
format_ = info.format; format_ = info.format;
stride_ = info.stride; stride_ = info.stride;
byte_count_ = Java_BitmapHelper_getByteCount(AttachCurrentThread(), bitmap_);
} }
JavaBitmap::~JavaBitmap() { JavaBitmap::~JavaBitmap() {
...@@ -108,6 +109,7 @@ SkBitmap CreateSkBitmapFromJavaBitmap(const JavaBitmap& jbitmap) { ...@@ -108,6 +109,7 @@ SkBitmap CreateSkBitmapFromJavaBitmap(const JavaBitmap& jbitmap) {
CHECK(false) << "Invalid Java bitmap format: " << jbitmap.format(); CHECK(false) << "Invalid Java bitmap format: " << jbitmap.format();
break; break;
} }
CHECK_EQ(jbitmap.byte_count(), static_cast<int>(skbitmap.getSize()));
const void* src_pixels = jbitmap.pixels(); const void* src_pixels = jbitmap.pixels();
void* dst_pixels = skbitmap.getPixels(); void* dst_pixels = skbitmap.getPixels();
memcpy(dst_pixels, src_pixels, skbitmap.getSize()); memcpy(dst_pixels, src_pixels, skbitmap.getSize());
......
...@@ -37,6 +37,7 @@ class GFX_EXPORT JavaBitmap { ...@@ -37,6 +37,7 @@ class GFX_EXPORT JavaBitmap {
// Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888 // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888
inline int format() const { return format_; } inline int format() const { return format_; }
inline uint32_t stride() const { return stride_; } inline uint32_t stride() const { return stride_; }
inline int byte_count() const { return byte_count_; }
// Registers methods with JNI and returns true if succeeded. // Registers methods with JNI and returns true if succeeded.
static bool RegisterJavaBitmap(JNIEnv* env); static bool RegisterJavaBitmap(JNIEnv* env);
...@@ -47,6 +48,7 @@ class GFX_EXPORT JavaBitmap { ...@@ -47,6 +48,7 @@ class GFX_EXPORT JavaBitmap {
gfx::Size size_; gfx::Size size_;
int format_; int format_;
uint32_t stride_; uint32_t stride_;
int byte_count_;
DISALLOW_COPY_AND_ASSIGN(JavaBitmap); DISALLOW_COPY_AND_ASSIGN(JavaBitmap);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment