Merge "Fix a bug, where one thread is using JNIEnv associated with another thread." into gingerbread
This commit is contained in:
@@ -518,35 +518,48 @@ bool GraphicsJNI::setJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
JavaPixelAllocator::JavaPixelAllocator(JNIEnv* env, bool reportSizeToVM)
|
JavaPixelAllocator::JavaPixelAllocator(JNIEnv* env, bool reportSizeToVM)
|
||||||
: fEnv(env), fReportSizeToVM(reportSizeToVM) {}
|
: fReportSizeToVM(reportSizeToVM) {
|
||||||
|
if (env->GetJavaVM(&fVM) != JNI_OK) {
|
||||||
|
SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
|
||||||
|
sk_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
|
bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
|
||||||
return GraphicsJNI::setJavaPixelRef(fEnv, bitmap, ctable, fReportSizeToVM);
|
JNIEnv* env = vm2env(fVM);
|
||||||
|
return GraphicsJNI::setJavaPixelRef(env, bitmap, ctable, fReportSizeToVM);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
JavaMemoryUsageReporter::JavaMemoryUsageReporter(JNIEnv* env)
|
JavaMemoryUsageReporter::JavaMemoryUsageReporter(JNIEnv* env)
|
||||||
: fEnv(env), fTotalSize(0) {}
|
: fTotalSize(0) {
|
||||||
|
if (env->GetJavaVM(&fVM) != JNI_OK) {
|
||||||
|
SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
|
||||||
|
sk_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JavaMemoryUsageReporter::~JavaMemoryUsageReporter() {
|
JavaMemoryUsageReporter::~JavaMemoryUsageReporter() {
|
||||||
|
JNIEnv* env = vm2env(fVM);
|
||||||
jlong jtotalSize = fTotalSize;
|
jlong jtotalSize = fTotalSize;
|
||||||
fEnv->CallVoidMethod(gVMRuntime_singleton,
|
env->CallVoidMethod(gVMRuntime_singleton,
|
||||||
gVMRuntime_trackExternalFreeMethodID,
|
gVMRuntime_trackExternalFreeMethodID,
|
||||||
jtotalSize);
|
jtotalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaMemoryUsageReporter::reportMemory(size_t memorySize) {
|
bool JavaMemoryUsageReporter::reportMemory(size_t memorySize) {
|
||||||
jlong jsize = memorySize; // the VM wants longs for the size
|
jlong jsize = memorySize; // the VM wants longs for the size
|
||||||
bool r = fEnv->CallBooleanMethod(gVMRuntime_singleton,
|
JNIEnv* env = vm2env(fVM);
|
||||||
|
bool r = env->CallBooleanMethod(gVMRuntime_singleton,
|
||||||
gVMRuntime_trackExternalAllocationMethodID,
|
gVMRuntime_trackExternalAllocationMethodID,
|
||||||
jsize);
|
jsize);
|
||||||
if (GraphicsJNI::hasException(fEnv)) {
|
if (GraphicsJNI::hasException(env)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!r) {
|
if (!r) {
|
||||||
LOGE("VM won't let us allocate %zd bytes\n", memorySize);
|
LOGE("VM won't let us allocate %zd bytes\n", memorySize);
|
||||||
doThrowOOME(fEnv, "bitmap size exceeds VM budget");
|
doThrowOOME(env, "bitmap size exceeds VM budget");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fTotalSize += memorySize;
|
fTotalSize += memorySize;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
|
virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JNIEnv* fEnv;
|
JavaVM* fVM;
|
||||||
bool fReportSizeToVM;
|
bool fReportSizeToVM;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
virtual bool reportMemory(size_t memorySize);
|
virtual bool reportMemory(size_t memorySize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JNIEnv* fEnv;
|
JavaVM* fVM;
|
||||||
size_t fTotalSize;
|
size_t fTotalSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user