summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-03-17 19:28:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-03-17 19:28:30 +0000
commite0583b2c93a8c0781700d8630487e9c7cfbd213f (patch)
tree2e6150db47a34c3ce2b619ae4a43468a79aba816
parent1a1ec625570e79f0f172472776f16a81a03eaa42 (diff)
parent618236fe886b84f99cd7c48ece96b16f82a9d2b2 (diff)
downloadframeworks_base-e0583b2c93a8c0781700d8630487e9c7cfbd213f.zip
frameworks_base-e0583b2c93a8c0781700d8630487e9c7cfbd213f.tar.gz
frameworks_base-e0583b2c93a8c0781700d8630487e9c7cfbd213f.tar.bz2
Merge "Revert "Remove castsShadow and globalCamera APIs""
-rw-r--r--api/current.txt7
-rw-r--r--core/java/android/view/RenderNode.java19
-rw-r--r--core/java/android/view/View.java112
-rw-r--r--core/res/res/values/attrs.xml4
-rw-r--r--core/res/res/values/public.xml1
-rw-r--r--libs/hwui/DisplayList.cpp2
-rw-r--r--libs/hwui/RenderProperties.cpp2
-rw-r--r--libs/hwui/RenderProperties.h10
8 files changed, 152 insertions, 5 deletions
diff --git a/api/current.txt b/api/current.txt
index a6b7d2c..23229d4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -346,6 +346,7 @@ package android {
field public static final int canRetrieveWindowContent = 16843653; // 0x1010385
field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230
field public static final deprecated int capitalize = 16843113; // 0x1010169
+ field public static final int castsShadow = 16843775; // 0x10103ff
field public static final int category = 16843752; // 0x10103e8
field public static final int centerBright = 16842956; // 0x10100cc
field public static final int centerColor = 16843275; // 0x101020b
@@ -825,7 +826,7 @@ package android {
field public static final int persistent = 16842765; // 0x101000d
field public static final int persistentDrawingCache = 16842990; // 0x10100ee
field public static final deprecated int phoneNumber = 16843111; // 0x1010167
- field public static final int pinned = 16843776; // 0x1010400
+ field public static final int pinned = 16843777; // 0x1010401
field public static final int pivotX = 16843189; // 0x10101b5
field public static final int pivotY = 16843190; // 0x10101b6
field public static final int popupAnimationStyle = 16843465; // 0x10102c9
@@ -889,7 +890,7 @@ package android {
field public static final int required = 16843406; // 0x101028e
field public static final int requiredAccountType = 16843734; // 0x10103d6
field public static final int requiredForAllUsers = 16843728; // 0x10103d0
- field public static final int requiredForProfile = 16843775; // 0x10103ff
+ field public static final int requiredForProfile = 16843776; // 0x1010400
field public static final int requiresFadingEdge = 16843685; // 0x10103a5
field public static final int requiresSmallestWidthDp = 16843620; // 0x1010364
field public static final int resizeMode = 16843619; // 0x1010363
@@ -29015,6 +29016,7 @@ package android.view {
method protected float getBottomFadingEdgeStrength();
method protected int getBottomPaddingOffset();
method public float getCameraDistance();
+ method public final boolean getCastsShadow();
method public android.graphics.Rect getClipBounds();
method public final boolean getClipToOutline();
method public java.lang.CharSequence getContentDescription();
@@ -29284,6 +29286,7 @@ package android.view {
method public void setBackgroundResource(int);
method public final void setBottom(int);
method public void setCameraDistance(float);
+ method public void setCastsShadow(boolean);
method public void setClickable(boolean);
method public void setClipBounds(android.graphics.Rect);
method public void setClipToOutline(boolean);
diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java
index 1978682..430bf5e 100644
--- a/core/java/android/view/RenderNode.java
+++ b/core/java/android/view/RenderNode.java
@@ -365,6 +365,25 @@ public class RenderNode {
}
/**
+ * Set whether the DisplayList should cast a shadow.
+ *
+ * The shape of the shadow casting area is defined by the outline of the display list, if set
+ * and non-empty, otherwise it will be the bounds rect.
+ */
+ public void setCastsShadow(boolean castsShadow) {
+ nSetCastsShadow(mNativeDisplayList, castsShadow);
+ }
+
+ /**
+ * Sets whether the DisplayList should be drawn with perspective applied from the global camera.
+ *
+ * If set to true, camera distance will be ignored. Defaults to false.
+ */
+ public void setUsesGlobalCamera(boolean usesGlobalCamera) {
+ nSetUsesGlobalCamera(mNativeDisplayList, usesGlobalCamera);
+ }
+
+ /**
* Set the static matrix on the display list. The specified matrix is combined with other
* transforms (such as {@link #setScaleX(float)}, {@link #setRotation(float)}, etc.)
*
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ecd73af..eff78d3 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -2386,6 +2386,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
static final int PFLAG3_FITTING_SYSTEM_WINDOWS = 0x80;
+ /**
+ * Flag indicating that an view will cast a shadow onto the Z=0 plane if elevated.
+ */
+ static final int PFLAG3_CASTS_SHADOW = 0x100;
+
+ /**
+ * Flag indicating that view will be transformed by the global camera if rotated in 3d, or given
+ * a non-0 Z translation.
+ */
+ static final int PFLAG3_USES_GLOBAL_CAMERA = 0x200;
+
/* End of masks for mPrivateFlags3 */
static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED;
@@ -4028,6 +4039,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
case R.styleable.View_layerType:
setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null);
break;
+ case R.styleable.View_castsShadow:
+ if (a.getBoolean(attr, false)) {
+ mPrivateFlags3 |= PFLAG3_CASTS_SHADOW;
+ }
+ break;
case R.styleable.View_textDirection:
// Clear any text direction flag already set
mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK;
@@ -10836,6 +10852,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @param outline The new outline of the view. Must be non-null, and convex.
*
+ * @see #setCastsShadow(boolean)
* @see #getOutline(Path)
* @see #getClipToOutline()
* @see #setClipToOutline(boolean)
@@ -10899,6 +10916,95 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * Returns whether the View will cast shadows when its
+ * {@link #setTranslationZ(float) z translation} is greater than 0, or it is
+ * rotated in 3D.
+ *
+ * @see #setTranslationZ(float)
+ * @see #setRotationX(float)
+ * @see #setRotationY(float)
+ * @see #setCastsShadow(boolean)
+ * @attr ref android.R.styleable#View_castsShadow
+ */
+ public final boolean getCastsShadow() {
+ return ((mPrivateFlags3 & PFLAG3_CASTS_SHADOW) != 0);
+ }
+
+ /**
+ * Set to true to enable this View to cast shadows.
+ * <p>
+ * If enabled, and the View has a z translation greater than 0, or is
+ * rotated in 3D, the shadow will be cast onto its parent at the z = 0
+ * plane.
+ * <p>
+ * The shape of the shadow being cast is defined by the
+ * {@link #setOutline(Path) outline} of the view, or the rectangular bounds
+ * of the view if the outline is not set or is empty.
+ *
+ * @see #setTranslationZ(float)
+ * @see #getCastsShadow()
+ * @attr ref android.R.styleable#View_castsShadow
+ */
+ public void setCastsShadow(boolean castsShadow) {
+ // TODO : Add a fast invalidation here.
+ if (getCastsShadow() != castsShadow) {
+ if (castsShadow) {
+ mPrivateFlags3 |= PFLAG3_CASTS_SHADOW;
+ } else {
+ mPrivateFlags3 &= ~PFLAG3_CASTS_SHADOW;
+ }
+ if (mDisplayList != null) {
+ mDisplayList.setCastsShadow(castsShadow);
+ }
+ }
+ }
+
+ /**
+ * Returns whether the View will be transformed by the global camera.
+ *
+ * @see #setUsesGlobalCamera(boolean)
+ *
+ * @hide
+ */
+ public final boolean getUsesGlobalCamera() {
+ return ((mPrivateFlags3 & PFLAG3_USES_GLOBAL_CAMERA) != 0);
+ }
+
+ /**
+ * Sets whether the View should be transformed by the global camera.
+ * <p>
+ * If the view has a Z translation or 3D rotation, perspective from the
+ * global camera will be applied. This enables an app to transform multiple
+ * views in 3D with coherent perspective projection among them all.
+ * <p>
+ * Setting this to true will cause {@link #setCameraDistance() camera distance}
+ * to be ignored, as the global camera's position will dictate perspective
+ * transform.
+ * <p>
+ * This should not be used in conjunction with {@link android.graphics.Camera}.
+ *
+ * @see #getUsesGlobalCamera()
+ * @see #setTranslationZ(float)
+ * @see #setRotationX(float)
+ * @see #setRotationY(float)
+ *
+ * @hide
+ */
+ public void setUsesGlobalCamera(boolean usesGlobalCamera) {
+ // TODO : Add a fast invalidation here.
+ if (getUsesGlobalCamera() != usesGlobalCamera) {
+ if (usesGlobalCamera) {
+ mPrivateFlags3 |= PFLAG3_USES_GLOBAL_CAMERA;
+ } else {
+ mPrivateFlags3 &= ~PFLAG3_USES_GLOBAL_CAMERA;
+ }
+ if (mDisplayList != null) {
+ mDisplayList.setUsesGlobalCamera(usesGlobalCamera);
+ }
+ }
+ }
+
+ /**
* Hit rectangle in parent's coordinates
*
* @param outRect The hit rectangle of the view.
@@ -11461,7 +11567,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
// Damage the entire IsolatedZVolume recieving this view's shadow.
- if (getTranslationZ() != 0) {
+ if (getCastsShadow() && getTranslationZ() != 0) {
damageIsolatedZVolume();
}
}
@@ -11541,7 +11647,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
} else {
damageInParent();
}
- if (invalidateParent && getTranslationZ() != 0) {
+ if (invalidateParent && getCastsShadow() && getTranslationZ() != 0) {
damageIsolatedZVolume();
}
}
@@ -14579,6 +14685,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
displayList.setOutline(mOutline);
displayList.setClipToOutline(getClipToOutline());
+ displayList.setCastsShadow(getCastsShadow());
+ displayList.setUsesGlobalCamera(getUsesGlobalCamera());
float alpha = 1;
if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags &
ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 8482fdb..2043960 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2132,6 +2132,10 @@
<!-- scale of the view in the y direction. -->
<attr name="scaleY" format="float" />
+ <!-- Defines whether the View casts a shadow when it has a 3D rotation or Z
+ translation.-->
+ <attr name="castsShadow" format="boolean" />
+
<!-- Determines which side the vertical scroll bar should be placed on. -->
<attr name="verticalScrollbarPosition">
<!-- Place the scroll bar wherever the system default determines. -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 404b852..25c8baa 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2111,6 +2111,7 @@
<public type="attr" name="controlY2" />
<public type="attr" name="sharedElementName" />
<public type="attr" name="transitionGroup" />
+ <public type="attr" name="castsShadow" />
<public type="attr" name="requiredForProfile"/>
<public type="attr" name="pinned" />
diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp
index f4de8ec..346fbce 100644
--- a/libs/hwui/DisplayList.cpp
+++ b/libs/hwui/DisplayList.cpp
@@ -432,7 +432,7 @@ void RenderNode::iterate3dChildren(const Vector<ZDrawDisplayListOpPair>& zTransl
// OR if its caster's Z value is similar to the previous potential caster
if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) {
- if (caster->properties().mAlpha > 0.0f) {
+ if (caster->properties().mCastsShadow && caster->properties().mAlpha > 0.0f) {
mat4 shadowMatrixXY(casterOp->mTransformFromParent);
caster->applyViewPropertyTransforms(shadowMatrixXY);
diff --git a/libs/hwui/RenderProperties.cpp b/libs/hwui/RenderProperties.cpp
index 233aace..714fd1b 100644
--- a/libs/hwui/RenderProperties.cpp
+++ b/libs/hwui/RenderProperties.cpp
@@ -27,6 +27,8 @@ RenderProperties::RenderProperties()
, mProjectBackwards(false)
, mProjectionReceiver(false)
, mClipToOutline(false)
+ , mCastsShadow(false)
+ , mUsesGlobalCamera(false) // TODO: respect value when rendering
, mAlpha(1)
, mHasOverlappingRendering(true)
, mTranslationX(0), mTranslationY(0), mTranslationZ(0)
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 6e3b8ae..a5ce4a6 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -52,6 +52,14 @@ public:
mClipToBounds = clipToBounds;
}
+ void setCastsShadow(bool castsShadow) {
+ mCastsShadow = castsShadow;
+ }
+
+ void setUsesGlobalCamera(bool usesGlobalCamera) {
+ mUsesGlobalCamera = usesGlobalCamera;
+ }
+
void setProjectBackwards(bool shouldProject) {
mProjectBackwards = shouldProject;
}
@@ -401,6 +409,8 @@ private:
bool mProjectionReceiver;
SkPath mOutline;
bool mClipToOutline;
+ bool mCastsShadow;
+ bool mUsesGlobalCamera; // TODO: respect value when rendering
float mAlpha;
bool mHasOverlappingRendering;
float mTranslationX, mTranslationY, mTranslationZ;