summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2013-05-03 02:11:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-05-03 02:11:03 +0000
commit17cf4e4d4a576009efbfce93bd64b687601b71c7 (patch)
treec4dd4332068a6ffdc3524059afb3e5e4562b24b9 /core/jni
parent856a5a860e11a85f8fbb1ad07f6ef444abeafbaf (diff)
parentfc0ebd7d379ff63c00ebf78ca252fab5070213da (diff)
downloadframeworks_base-17cf4e4d4a576009efbfce93bd64b687601b71c7.zip
frameworks_base-17cf4e4d4a576009efbfce93bd64b687601b71c7.tar.gz
frameworks_base-17cf4e4d4a576009efbfce93bd64b687601b71c7.tar.bz2
Merge "Really make Surface thread-safe." into jb-mr2-dev
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_view_Surface.cpp54
1 files changed, 19 insertions, 35 deletions
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index a41a389..9a19ce5 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -55,8 +55,7 @@ static const char* const OutOfResourcesException =
static struct {
jclass clazz;
jfieldID mNativeObject;
- jfieldID mNativeObjectLock;
- jfieldID mCanvas;
+ jfieldID mLock;
jmethodID ctor;
} gSurfaceClassInfo;
@@ -93,7 +92,7 @@ sp<ANativeWindow> android_view_Surface_getNativeWindow(JNIEnv* env, jobject surf
sp<Surface> android_view_Surface_getSurface(JNIEnv* env, jobject surfaceObj) {
sp<Surface> sur;
jobject lock = env->GetObjectField(surfaceObj,
- gSurfaceClassInfo.mNativeObjectLock);
+ gSurfaceClassInfo.mLock);
if (env->MonitorEnter(lock) == JNI_OK) {
sur = reinterpret_cast<Surface *>(
env->GetIntField(surfaceObj, gSurfaceClassInfo.mNativeObject));
@@ -200,12 +199,13 @@ static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCa
SkSafeUnref(previousCanvas);
}
-static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObject, jobject dirtyRectObj) {
+static void nativeLockCanvas(JNIEnv* env, jclass clazz,
+ jint nativeObject, jobject canvasObj, jobject dirtyRectObj) {
sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));
if (!isSurfaceValid(surface)) {
doThrowIAE(env);
- return NULL;
+ return;
}
// get dirty region
@@ -232,11 +232,10 @@ static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObje
OutOfResourcesException :
"java/lang/IllegalArgumentException";
jniThrowException(env, exception, NULL);
- return NULL;
+ return;
}
// Associate a SkCanvas object to this surface
- jobject canvasObj = env->GetObjectField(surfaceObj, gSurfaceClassInfo.mCanvas);
env->SetIntField(canvasObj, gCanvasClassInfo.mSurfaceFormat, outBuffer.format);
SkBitmap bitmap;
@@ -277,17 +276,10 @@ static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObje
env->SetIntField(dirtyRectObj, gRectClassInfo.right, bounds.right);
env->SetIntField(dirtyRectObj, gRectClassInfo.bottom, bounds.bottom);
}
-
- return canvasObj;
}
-static void nativeUnlockCanvasAndPost(JNIEnv* env, jobject surfaceObj, jint nativeObject, jobject canvasObj) {
- jobject ownCanvasObj = env->GetObjectField(surfaceObj, gSurfaceClassInfo.mCanvas);
- if (!env->IsSameObject(ownCanvasObj, canvasObj)) {
- doThrowIAE(env);
- return;
- }
-
+static void nativeUnlockCanvasAndPost(JNIEnv* env, jclass clazz,
+ jint nativeObject, jobject canvasObj) {
sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));
if (!isSurfaceValid(surface)) {
return;
@@ -306,8 +298,8 @@ static void nativeUnlockCanvasAndPost(JNIEnv* env, jobject surfaceObj, jint nati
// ----------------------------------------------------------------------------
-static jint nativeCopyFrom(JNIEnv* env, jclass clazz,
- jint nativeObject, jint surfaceControlNativeObj) {
+static jint nativeCreateFromSurfaceControl(JNIEnv* env, jclass clazz,
+ jint surfaceControlNativeObj) {
/*
* This is used by the WindowManagerService just after constructing
* a Surface and is necessary for returning the Surface reference to
@@ -315,17 +307,11 @@ static jint nativeCopyFrom(JNIEnv* env, jclass clazz,
*/
sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
- sp<Surface> other(ctrl->getSurface());
- if (other != NULL) {
- other->incStrong(&sRefBaseOwner);
- }
-
- sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
- if (sur != NULL) {
- sur->decStrong(&sRefBaseOwner);
+ sp<Surface> surface(ctrl->getSurface());
+ if (surface != NULL) {
+ surface->incStrong(&sRefBaseOwner);
}
-
- return int(other.get());
+ return reinterpret_cast<jint>(surface.get());
}
static jint nativeReadFromParcel(JNIEnv* env, jclass clazz,
@@ -386,12 +372,12 @@ static JNINativeMethod gSurfaceMethods[] = {
(void*)nativeIsValid },
{"nativeIsConsumerRunningBehind", "(I)Z",
(void*)nativeIsConsumerRunningBehind },
- {"nativeLockCanvas", "(ILandroid/graphics/Rect;)Landroid/graphics/Canvas;",
+ {"nativeLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)V",
(void*)nativeLockCanvas },
{"nativeUnlockCanvasAndPost", "(ILandroid/graphics/Canvas;)V",
(void*)nativeUnlockCanvasAndPost },
- {"nativeCopyFrom", "(II)I",
- (void*)nativeCopyFrom },
+ {"nativeCreateFromSurfaceControl", "(I)I",
+ (void*)nativeCreateFromSurfaceControl },
{"nativeReadFromParcel", "(ILandroid/os/Parcel;)I",
(void*)nativeReadFromParcel },
{"nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
@@ -407,10 +393,8 @@ int register_android_view_Surface(JNIEnv* env)
gSurfaceClassInfo.clazz = jclass(env->NewGlobalRef(clazz));
gSurfaceClassInfo.mNativeObject =
env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "I");
- gSurfaceClassInfo.mNativeObjectLock =
- env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObjectLock", "Ljava/lang/Object;");
- gSurfaceClassInfo.mCanvas =
- env->GetFieldID(gSurfaceClassInfo.clazz, "mCanvas", "Landroid/graphics/Canvas;");
+ gSurfaceClassInfo.mLock =
+ env->GetFieldID(gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;");
gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(I)V");
clazz = env->FindClass("android/graphics/Canvas");