summaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2021-07-09 05:33:36 +0000
committerScott Lobdell <slobdell@google.com>2021-07-09 05:33:36 +0000
commit8507fe74dccb3114f7942bb3ca2087dab2c890e6 (patch)
tree5d15051c03662b66bb54d04f158eb1b0ca623c44 /graphics
parent70ec282c1bd5e68015ed9412a730f5254ee6585c (diff)
parent9dd561f2a032908f6c916be577f6a7136c9b03ef (diff)
Merge SP1A.210624.001
Change-Id: I96a39cdca22771b76e89caebd53ed52416005092
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/HardwareRenderer.java26
-rw-r--r--graphics/java/android/graphics/drawable/RippleAnimationSession.java20
-rw-r--r--graphics/java/android/graphics/drawable/RippleDrawable.java78
3 files changed, 80 insertions, 44 deletions
diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java
index 6aa74cb415f9..e141d5178570 100644
--- a/graphics/java/android/graphics/HardwareRenderer.java
+++ b/graphics/java/android/graphics/HardwareRenderer.java
@@ -762,6 +762,16 @@ public class HardwareRenderer {
nSetASurfaceTransactionCallback(mNativeProxy, callback);
}
+ private PrepareSurfaceControlForWebviewCallback mAPrepareSurfaceControlForWebviewCallback;
+
+ /** @hide */
+ public void setPrepareSurfaceControlForWebviewCallback(
+ PrepareSurfaceControlForWebviewCallback callback) {
+ // ensure callback is kept alive on the java side since weak ref is used in native code
+ mAPrepareSurfaceControlForWebviewCallback = callback;
+ nSetPrepareSurfaceControlForWebviewCallback(mNativeProxy, callback);
+ }
+
/** @hide */
public void setFrameCallback(FrameDrawingCallback callback) {
nSetFrameCallback(mNativeProxy, callback);
@@ -876,6 +886,19 @@ public class HardwareRenderer {
session.close();
}
+ /**
+ * Interface used to receive callbacks when Webview requests a surface control.
+ *
+ * @hide
+ */
+ public interface PrepareSurfaceControlForWebviewCallback {
+ /**
+ * Invoked when Webview calls to get a surface control.
+ *
+ */
+ void prepare();
+ }
+
/**
* Interface used to receive callbacks when a transaction needs to be merged.
*
@@ -1374,6 +1397,9 @@ public class HardwareRenderer {
private static native void nSetASurfaceTransactionCallback(long nativeProxy,
ASurfaceTransactionCallback callback);
+ private static native void nSetPrepareSurfaceControlForWebviewCallback(long nativeProxy,
+ PrepareSurfaceControlForWebviewCallback callback);
+
private static native void nSetFrameCallback(long nativeProxy, FrameDrawingCallback callback);
private static native void nSetFrameCompleteCallback(long nativeProxy,
diff --git a/graphics/java/android/graphics/drawable/RippleAnimationSession.java b/graphics/java/android/graphics/drawable/RippleAnimationSession.java
index 55fb83c81961..74fb618f8fd7 100644
--- a/graphics/java/android/graphics/drawable/RippleAnimationSession.java
+++ b/graphics/java/android/graphics/drawable/RippleAnimationSession.java
@@ -60,6 +60,10 @@ public final class RippleAnimationSession {
mForceSoftware = forceSoftware;
}
+ boolean isForceSoftware() {
+ return mForceSoftware;
+ }
+
@NonNull RippleAnimationSession enter(Canvas canvas) {
mStartTime = AnimationUtils.currentAnimationTimeMillis();
if (isHwAccelerated(canvas)) {
@@ -130,7 +134,6 @@ public final class RippleAnimationSession {
return this;
}
-
private void exitHardware(RecordingCanvas canvas) {
AnimationProperties<CanvasProperty<Float>, CanvasProperty<Paint>>
props = getCanvasProperties();
@@ -199,6 +202,15 @@ public final class RippleAnimationSession {
startAnimation(expand, loop);
}
+ void setRadius(float radius) {
+ mProperties.setRadius(radius);
+ mProperties.getShader().setRadius(radius);
+ if (mCanvasProperties != null) {
+ mCanvasProperties.setRadius(CanvasProperty.createFloat(radius));
+ mCanvasProperties.getShader().setRadius(radius);
+ }
+ }
+
@NonNull AnimationProperties<Float, Paint> getProperties() {
return mProperties;
}
@@ -249,7 +261,7 @@ public final class RippleAnimationSession {
static class AnimationProperties<FloatType, PaintType> {
private final FloatType mProgress;
- private final FloatType mMaxRadius;
+ private FloatType mMaxRadius;
private final FloatType mNoisePhase;
private final PaintType mPaint;
private final RippleShader mShader;
@@ -273,6 +285,10 @@ public final class RippleAnimationSession {
return mProgress;
}
+ void setRadius(FloatType radius) {
+ mMaxRadius = radius;
+ }
+
void setOrigin(FloatType x, FloatType y) {
mX = x;
mY = y;
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index 1651a8cdcad5..8aba87ba3c8f 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -734,7 +734,7 @@ public class RippleDrawable extends LayerDrawable {
}
/**
- * Notifies all the animating ripples that the hotspot bounds have changed.
+ * Notifies all the animating ripples that the hotspot bounds have changed and modify sessions.
*/
private void onHotspotBoundsChanged() {
final int count = mExitingRipplesCount;
@@ -750,6 +750,20 @@ public class RippleDrawable extends LayerDrawable {
if (mBackground != null) {
mBackground.onHotspotBoundsChanged();
}
+ float newRadius = Math.round(computeRadius());
+ for (int i = 0; i < mRunningAnimations.size(); i++) {
+ RippleAnimationSession s = mRunningAnimations.get(i);
+ s.setRadius(newRadius);
+ s.getProperties().getShader()
+ .setResolution(mHotspotBounds.width(), mHotspotBounds.height());
+ float cx = mHotspotBounds.centerX(), cy = mHotspotBounds.centerY();
+ s.getProperties().getShader().setOrigin(cx, cy);
+ s.getProperties().setOrigin(cx, cy);
+ if (!s.isForceSoftware()) {
+ s.getCanvasProperties()
+ .setOrigin(CanvasProperty.createFloat(cx), CanvasProperty.createFloat(cy));
+ }
+ }
}
/**
@@ -840,31 +854,16 @@ public class RippleDrawable extends LayerDrawable {
}
private void drawPatterned(@NonNull Canvas canvas) {
- final Rect bounds = getDirtyBounds();
+ final Rect bounds = mHotspotBounds;
final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
boolean useCanvasProps = shouldUseCanvasProps(canvas);
- boolean changedHotspotBounds = !bounds.equals(mHotspotBounds);
if (isBounded()) {
- canvas.clipRect(bounds);
+ canvas.clipRect(getDirtyBounds());
}
final float x, y, cx, cy, w, h;
- if (changedHotspotBounds) {
- x = mHotspotBounds.exactCenterX();
- y = mHotspotBounds.exactCenterY();
- cx = x;
- cy = y;
- h = mHotspotBounds.height();
- w = mHotspotBounds.width();
- useCanvasProps = false;
- } else {
- x = mPendingX;
- y = mPendingY;
- cx = bounds.centerX();
- cy = bounds.centerY();
- h = bounds.height();
- w = bounds.width();
- }
boolean addRipple = mAddRipple;
+ cx = bounds.centerX();
+ cy = bounds.centerY();
boolean shouldExit = mExitingAnimation;
mExitingAnimation = false;
mAddRipple = false;
@@ -875,6 +874,16 @@ public class RippleDrawable extends LayerDrawable {
drawContent(canvas);
drawPatternedBackground(canvas, cx, cy);
if (addRipple && mRunningAnimations.size() <= MAX_RIPPLES) {
+ if (mHasPending) {
+ x = mPendingX;
+ y = mPendingY;
+ mHasPending = false;
+ } else {
+ x = bounds.exactCenterX();
+ y = bounds.exactCenterY();
+ }
+ h = bounds.height();
+ w = bounds.width();
RippleAnimationSession.AnimationProperties<Float, Paint> properties =
createAnimationProperties(x, y, cx, cy, w, h);
mRunningAnimations.add(new RippleAnimationSession(properties, !useCanvasProps)
@@ -898,33 +907,13 @@ public class RippleDrawable extends LayerDrawable {
CanvasProperty<Paint>>
p = s.getCanvasProperties();
RecordingCanvas can = (RecordingCanvas) canvas;
- CanvasProperty<Float> xProp, yProp;
- if (changedHotspotBounds) {
- xProp = CanvasProperty.createFloat(x);
- yProp = CanvasProperty.createFloat(y);
- p.getShader().setTouch(x, y);
- p.getShader().setOrigin(x, y);
- } else {
- xProp = p.getX();
- yProp = p.getY();
- }
- can.drawRipple(xProp, yProp, p.getMaxRadius(), p.getPaint(),
+ can.drawRipple(p.getX(), p.getY(), p.getMaxRadius(), p.getPaint(),
p.getProgress(), p.getNoisePhase(), p.getColor(), p.getShader());
} else {
RippleAnimationSession.AnimationProperties<Float, Paint> p =
s.getProperties();
- float xProp, yProp;
- if (changedHotspotBounds) {
- xProp = x;
- yProp = y;
- p.getShader().setTouch(x, y);
- p.getShader().setOrigin(x, y);
- } else {
- xProp = p.getX();
- yProp = p.getY();
- }
float radius = p.getMaxRadius();
- canvas.drawCircle(xProp, yProp, radius, p.getPaint());
+ canvas.drawCircle(p.getX(), p.getY(), radius, p.getPaint());
}
}
canvas.restoreToCount(saveCount);
@@ -1111,6 +1100,11 @@ public class RippleDrawable extends LayerDrawable {
if (mState.mRippleStyle == STYLE_SOLID) {
mMaskCanvas.translate(left, top);
}
+ if (mState.mRippleStyle == STYLE_PATTERNED) {
+ for (int i = 0; i < mRunningAnimations.size(); i++) {
+ mRunningAnimations.get(i).getProperties().getShader().setShader(mMaskShader);
+ }
+ }
}
private int getMaskType() {