Merge "Allow starting an RT animation via Canvas"
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.view;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.util.Pools.SynchronizedPool;
|
||||
|
||||
/**
|
||||
@@ -32,19 +33,25 @@ class GLES20RecordingCanvas extends GLES20Canvas {
|
||||
private static final SynchronizedPool<GLES20RecordingCanvas> sPool =
|
||||
new SynchronizedPool<GLES20RecordingCanvas>(POOL_LIMIT);
|
||||
|
||||
RenderNode mNode;
|
||||
|
||||
private GLES20RecordingCanvas() {
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
static GLES20RecordingCanvas obtain() {
|
||||
static GLES20RecordingCanvas obtain(@NonNull RenderNode node) {
|
||||
if (node == null) throw new IllegalArgumentException("node cannot be null");
|
||||
|
||||
GLES20RecordingCanvas canvas = sPool.acquire();
|
||||
if (canvas == null) {
|
||||
canvas = new GLES20RecordingCanvas();
|
||||
}
|
||||
canvas.mNode = node;
|
||||
return canvas;
|
||||
}
|
||||
|
||||
void recycle() {
|
||||
mNode = null;
|
||||
sPool.release(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ public class RenderNode {
|
||||
* @see #isValid()
|
||||
*/
|
||||
public HardwareCanvas start(int width, int height) {
|
||||
HardwareCanvas canvas = GLES20RecordingCanvas.obtain();
|
||||
HardwareCanvas canvas = GLES20RecordingCanvas.obtain(this);
|
||||
canvas.setViewport(width, height);
|
||||
// The dirty rect should always be null for a display list
|
||||
canvas.onPreDraw(null);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.view;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.CanvasProperty;
|
||||
import android.graphics.Paint;
|
||||
import android.util.SparseIntArray;
|
||||
@@ -100,6 +101,15 @@ public final class RenderNodeAnimator {
|
||||
target.invalidateViewProperty(true, false);
|
||||
}
|
||||
|
||||
public void start(Canvas canvas) {
|
||||
if (!(canvas instanceof GLES20RecordingCanvas)) {
|
||||
throw new IllegalArgumentException("Not a GLES20RecordingCanvas");
|
||||
}
|
||||
GLES20RecordingCanvas recordingCanvas = (GLES20RecordingCanvas) canvas;
|
||||
mTarget = recordingCanvas.mNode;
|
||||
mTarget.addAnimator(this);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
mTarget.removeAnimator(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user