Ensure munmap matches mmap am: aa394dd42c am: 068403a842 am: d073e28853 am: c9cf811b50

am: b74a6f60d1

Change-Id: I76f992080c2a7be15bf2518f2d914cb82f3aa30f
This commit is contained in:
John Reck
2016-09-13 20:47:01 +00:00
committed by android-build-merger
4 changed files with 11 additions and 10 deletions

View File

@@ -151,12 +151,12 @@ Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
mPixelRef->unref(); mPixelRef->unref();
} }
Bitmap::Bitmap(void* address, int fd, Bitmap::Bitmap(void* address, int fd, size_t mappedSize,
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
: mPixelStorageType(PixelStorageType::Ashmem) { : mPixelStorageType(PixelStorageType::Ashmem) {
mPixelStorage.ashmem.address = address; mPixelStorage.ashmem.address = address;
mPixelStorage.ashmem.fd = fd; mPixelStorage.ashmem.fd = fd;
mPixelStorage.ashmem.size = ashmem_get_size_region(fd); mPixelStorage.ashmem.size = mappedSize;
mPixelRef.reset(new WrappedPixelRef(this, address, info, rowBytes, ctable)); mPixelRef.reset(new WrappedPixelRef(this, address, info, rowBytes, ctable));
// Note: this will trigger a call to onStrongRefDestroyed(), but // Note: this will trigger a call to onStrongRefDestroyed(), but
// we want the pixel ref to have a ref count of 0 at this point // we want the pixel ref to have a ref count of 0 at this point
@@ -1027,7 +1027,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
// Map the pixels in place and take ownership of the ashmem region. // Map the pixels in place and take ownership of the ashmem region.
nativeBitmap = GraphicsJNI::mapAshmemPixelRef(env, bitmap.get(), nativeBitmap = GraphicsJNI::mapAshmemPixelRef(env, bitmap.get(),
ctable, dupFd, const_cast<void*>(blob.data()), !isMutable); ctable, dupFd, const_cast<void*>(blob.data()), size, !isMutable);
SkSafeUnref(ctable); SkSafeUnref(ctable);
if (!nativeBitmap) { if (!nativeBitmap) {
close(dupFd); close(dupFd);

View File

@@ -51,8 +51,8 @@ public:
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
Bitmap(void* address, void* context, FreeFunc freeFunc, Bitmap(void* address, void* context, FreeFunc freeFunc,
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
Bitmap(void* address, int fd, const SkImageInfo& info, size_t rowBytes, Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info,
SkColorTable* ctable); size_t rowBytes, SkColorTable* ctable);
const SkImageInfo& info() const; const SkImageInfo& info() const;

View File

@@ -613,7 +613,7 @@ android::Bitmap* GraphicsJNI::allocateAshmemPixelRef(JNIEnv* env, SkBitmap* bitm
return nullptr; return nullptr;
} }
android::Bitmap* wrapper = new android::Bitmap(addr, fd, info, rowBytes, ctable); android::Bitmap* wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, ctable);
wrapper->getSkBitmap(bitmap); wrapper->getSkBitmap(bitmap);
// since we're already allocated, we lockPixels right away // since we're already allocated, we lockPixels right away
// HeapAllocator behaves this way too // HeapAllocator behaves this way too
@@ -623,7 +623,7 @@ android::Bitmap* GraphicsJNI::allocateAshmemPixelRef(JNIEnv* env, SkBitmap* bitm
} }
android::Bitmap* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, android::Bitmap* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
SkColorTable* ctable, int fd, void* addr, bool readOnly) { SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly) {
const SkImageInfo& info = bitmap->info(); const SkImageInfo& info = bitmap->info();
if (info.colorType() == kUnknown_SkColorType) { if (info.colorType() == kUnknown_SkColorType) {
doThrowIAE(env, "unknown bitmap configuration"); doThrowIAE(env, "unknown bitmap configuration");
@@ -633,7 +633,8 @@ android::Bitmap* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
if (!addr) { if (!addr) {
// Map existing ashmem region if not already mapped. // Map existing ashmem region if not already mapped.
int flags = readOnly ? (PROT_READ) : (PROT_READ | PROT_WRITE); int flags = readOnly ? (PROT_READ) : (PROT_READ | PROT_WRITE);
addr = mmap(NULL, ashmem_get_size_region(fd), flags, MAP_SHARED, fd, 0); size = ashmem_get_size_region(fd);
addr = mmap(NULL, size, flags, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) { if (addr == MAP_FAILED) {
return nullptr; return nullptr;
} }
@@ -643,7 +644,7 @@ android::Bitmap* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
// attempting to compute our own. // attempting to compute our own.
const size_t rowBytes = bitmap->rowBytes(); const size_t rowBytes = bitmap->rowBytes();
android::Bitmap* wrapper = new android::Bitmap(addr, fd, info, rowBytes, ctable); android::Bitmap* wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, ctable);
wrapper->getSkBitmap(bitmap); wrapper->getSkBitmap(bitmap);
if (readOnly) { if (readOnly) {
bitmap->pixelRef()->setImmutable(); bitmap->pixelRef()->setImmutable();

View File

@@ -101,7 +101,7 @@ public:
SkColorTable* ctable); SkColorTable* ctable);
static android::Bitmap* mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, static android::Bitmap* mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
SkColorTable* ctable, int fd, void* addr, bool readOnly); SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly);
/** /**
* Given a bitmap we natively allocate a memory block to store the contents * Given a bitmap we natively allocate a memory block to store the contents