Restore the ability to track native Surface changes
Bug #8230990
ViewRootImpl needs to know when the native Surface objects changes
to recreate the EGL surface. A recent refactoring in Surface broke
the behavior of getGenerationId(). This simply restores the old
behavior (every change increments the generation ID by 1.)
Change-Id: Ife1df1ffb2ee7a373b8ebf2431192702ba10f344
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 03a9b09..9955bc1 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -74,17 +74,13 @@
int mNativeObject; // package scope only for SurfaceControl access
private int mGenerationId; // incremented each time mNativeSurface changes
+ @SuppressWarnings("UnusedDeclaration")
private final Canvas mCanvas = new CompatibleCanvas();
- // The Translator for density compatibility mode. This is used for scaling
- // the canvas to perform the appropriate density transformation.
- private Translator mCompatibilityTranslator;
-
// A matrix to scale the matrix set by application. This is set to null for
// non compatibility mode.
private Matrix mCompatibleMatrix;
-
/**
* Rotation constant: 0 degree rotation (natural orientation)
*/
@@ -105,8 +101,6 @@
*/
public static final int ROTATION_270 = 3;
-
-
/**
* Create an empty surface, which will later be filled in by readFromParcel().
* @hide
@@ -169,6 +163,7 @@
if (mNativeObject != 0) {
nativeRelease(mNativeObject);
mNativeObject = 0;
+ mGenerationId++;
}
mCloseGuard.close();
}
@@ -183,6 +178,7 @@
if (mNativeObject != 0) {
nativeDestroy(mNativeObject);
mNativeObject = 0;
+ mGenerationId++;
}
mCloseGuard.close();
}
@@ -291,6 +287,7 @@
"SurfaceControl native object is null. Are you using a released SurfaceControl?");
}
mNativeObject = nativeCopyFrom(mNativeObject, other.mNativeObject);
+ mGenerationId++;
}
/**
@@ -312,7 +309,10 @@
}
// transfer the reference from other to us
mNativeObject = other.mNativeObject;
+ mGenerationId++;
+
other.mNativeObject = 0;
+ other.mGenerationId++;
}
}
@@ -327,6 +327,7 @@
}
mName = source.readString();
mNativeObject = nativeReadFromParcel(mNativeObject, source);
+ mGenerationId++;
}
@Override
@@ -405,24 +406,6 @@
private Matrix mOrigMatrix = null;
@Override
- public int getWidth() {
- int w = super.getWidth();
- if (mCompatibilityTranslator != null) {
- w = (int)(w * mCompatibilityTranslator.applicationInvertedScale + .5f);
- }
- return w;
- }
-
- @Override
- public int getHeight() {
- int h = super.getHeight();
- if (mCompatibilityTranslator != null) {
- h = (int)(h * mCompatibilityTranslator.applicationInvertedScale + .5f);
- }
- return h;
- }
-
- @Override
public void setMatrix(Matrix matrix) {
if (mCompatibleMatrix == null || mOrigMatrix == null || mOrigMatrix.equals(matrix)) {
// don't scale the matrix if it's not compatibility mode, or
@@ -435,6 +418,7 @@
}
}
+ @SuppressWarnings("deprecation")
@Override
public void getMatrix(Matrix m) {
super.getMatrix(m);
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 02e76e5..1ffb1b8 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -53,7 +53,6 @@
static struct {
jclass clazz;
jfieldID mNativeObject;
- jfieldID mGenerationId;
jfieldID mCanvas;
jmethodID ctor;
} gSurfaceClassInfo;
@@ -384,8 +383,6 @@
gSurfaceClassInfo.clazz = jclass(env->NewGlobalRef(clazz));
gSurfaceClassInfo.mNativeObject =
env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "I");
- gSurfaceClassInfo.mGenerationId =
- env->GetFieldID(gSurfaceClassInfo.clazz, "mGenerationId", "I");
gSurfaceClassInfo.mCanvas =
env->GetFieldID(gSurfaceClassInfo.clazz, "mCanvas", "Landroid/graphics/Canvas;");
gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(I)V");