summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2011-08-16 13:55:02 -0700
committerRomain Guy <romainguy@google.com>2011-08-16 13:55:02 -0700
commit302a9df1d50373c82923bb84ff665dfce584fb22 (patch)
tree01a6e183b3c0f49676730a679397a31692942f8d /core
parent95a78c38373bb99258d83a6ab2c92825d979f200 (diff)
downloadframeworks_base-302a9df1d50373c82923bb84ff665dfce584fb22.zip
frameworks_base-302a9df1d50373c82923bb84ff665dfce584fb22.tar.gz
frameworks_base-302a9df1d50373c82923bb84ff665dfce584fb22.tar.bz2
Add an API to set the transform on a TextureView's surface texture.
Bug #5156689 Change-Id: I635a625885c9b832a60d44ece0de7613ceb84109
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/GLES20Canvas.java1
-rw-r--r--core/java/android/view/GLES20RenderLayer.java8
-rw-r--r--core/java/android/view/GLES20TextureLayer.java6
-rw-r--r--core/java/android/view/HardwareLayer.java8
-rw-r--r--core/java/android/view/TextureView.java53
-rw-r--r--core/jni/android_view_GLES20Canvas.cpp7
6 files changed, 83 insertions, 0 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index e586370..cfbb47c 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -151,6 +151,7 @@ class GLES20Canvas extends HardwareCanvas {
static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo);
static native void nUpdateTextureLayer(int layerId, int width, int height, boolean opaque,
SurfaceTexture surface);
+ static native void nSetTextureLayerTransform(int layerId, int matrix);
static native void nDestroyLayer(int layerId);
static native void nDestroyLayerDeferred(int layerId);
static native boolean nCopyLayer(int layerId, int bitmap);
diff --git a/core/java/android/view/GLES20RenderLayer.java b/core/java/android/view/GLES20RenderLayer.java
index 41f16e2..23a7166 100644
--- a/core/java/android/view/GLES20RenderLayer.java
+++ b/core/java/android/view/GLES20RenderLayer.java
@@ -17,6 +17,7 @@
package android.view;
import android.graphics.Canvas;
+import android.graphics.Matrix;
/**
* An OpenGL ES 2.0 implementation of {@link HardwareLayer}. This
@@ -87,4 +88,11 @@ class GLES20RenderLayer extends GLES20Layer {
}
return getCanvas();
}
+
+ /**
+ * Ignored
+ */
+ @Override
+ void setTransform(Matrix matrix) {
+ }
}
diff --git a/core/java/android/view/GLES20TextureLayer.java b/core/java/android/view/GLES20TextureLayer.java
index 391d9f4..6c41023 100644
--- a/core/java/android/view/GLES20TextureLayer.java
+++ b/core/java/android/view/GLES20TextureLayer.java
@@ -17,6 +17,7 @@
package android.view;
import android.graphics.Canvas;
+import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
/**
@@ -75,4 +76,9 @@ class GLES20TextureLayer extends GLES20Layer {
super.update(width, height, isOpaque);
GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface);
}
+
+ @Override
+ void setTransform(Matrix matrix) {
+ GLES20Canvas.nSetTextureLayerTransform(mLayer, matrix.native_instance);
+ }
}
diff --git a/core/java/android/view/HardwareLayer.java b/core/java/android/view/HardwareLayer.java
index dfb39ae..28389ab 100644
--- a/core/java/android/view/HardwareLayer.java
+++ b/core/java/android/view/HardwareLayer.java
@@ -18,6 +18,7 @@ package android.view;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Matrix;
/**
* A hardware layer can be used to render graphics operations into a hardware
@@ -150,4 +151,11 @@ abstract class HardwareLayer {
mHeight = height;
mOpaque = isOpaque;
}
+
+ /**
+ * Sets an optional transform on this layer.
+ *
+ * @param matrix The transform to apply to the layer.
+ */
+ abstract void setTransform(Matrix matrix);
}
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 53a6bcb..b72222e 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -19,6 +19,7 @@ package android.view;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
@@ -104,6 +105,9 @@ public class TextureView extends View {
private boolean mOpaque = true;
+ private final Matrix mMatrix = new Matrix();
+ private boolean mMatrixChanged;
+
private final Object[] mLock = new Object[0];
private boolean mUpdateLayer;
@@ -312,6 +316,11 @@ public class TextureView extends View {
applyUpdate();
+ if (mMatrixChanged) {
+ mLayer.setTransform(mMatrix);
+ mMatrixChanged = false;
+ }
+
return mLayer;
}
@@ -358,6 +367,50 @@ public class TextureView extends View {
}
/**
+ * <p>Sets the transform to associate with this texture view.
+ * The specified transform applies to the underlying surface
+ * texture and does not affect the size or position of the view
+ * itself, only of its content.</p>
+ *
+ * <p>Some transforms might prevent the content from drawing
+ * all the pixels contained within this view's bounds. In such
+ * situations, make sure this texture view is not marked opaque.</p>
+ *
+ * @param transform The transform to apply to the content of
+ * this view.
+ *
+ * @see #getTransform(android.graphics.Matrix)
+ * @see #isOpaque()
+ * @see #setOpaque(boolean)
+ */
+ public void setTransform(Matrix transform) {
+ mMatrix.set(transform);
+ mMatrixChanged = true;
+ invalidate();
+ }
+
+ /**
+ * Returns the transform associated with this texture view.
+ *
+ * @param transform The {@link Matrix} in which to copy the current
+ * transform. Can be null.
+ *
+ * @return The specified matrix if not null or a new {@link Matrix}
+ * instance otherwise.
+ *
+ * @see #setTransform(android.graphics.Matrix)
+ */
+ public Matrix getTransform(Matrix transform) {
+ if (transform == null) {
+ transform = new Matrix();
+ }
+
+ transform.set(mMatrix);
+
+ return transform;
+ }
+
+ /**
* <p>Returns a {@link android.graphics.Bitmap} representation of the content
* of the associated surface texture. If the surface texture is not available,
* this method returns null.</p>
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index 039c5ba..80c79fd 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -683,6 +683,12 @@ static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject cl
LayerRenderer::updateTextureLayer(layer, width, height, isOpaque, renderTarget, transform);
}
+static void android_view_GLES20Canvas_setTextureLayerTransform(JNIEnv* env, jobject clazz,
+ Layer* layer, SkMatrix* matrix) {
+
+ layer->getTransform().load(*matrix);
+}
+
static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, Layer* layer) {
LayerRenderer::destroyLayer(layer);
}
@@ -827,6 +833,7 @@ static JNINativeMethod gMethods[] = {
{ "nCreateTextureLayer", "(Z[I)I", (void*) android_view_GLES20Canvas_createTextureLayer },
{ "nUpdateTextureLayer", "(IIIZLandroid/graphics/SurfaceTexture;)V",
(void*) android_view_GLES20Canvas_updateTextureLayer },
+ { "nSetTextureLayerTransform", "(II)V", (void*) android_view_GLES20Canvas_setTextureLayerTransform },
{ "nDestroyLayer", "(I)V", (void*) android_view_GLES20Canvas_destroyLayer },
{ "nDestroyLayerDeferred", "(I)V", (void*) android_view_GLES20Canvas_destroyLayerDeferred },
{ "nDrawLayer", "(IIFFI)V", (void*) android_view_GLES20Canvas_drawLayer },