Create colored shadows demo
Test: HwAccelerationTest demo
Bug: 68211332
Change-Id: Ia53a6ac2854570d0495b355bbebee1dcec2f47ba
diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java
index ea6e63c..5070151 100644
--- a/core/java/android/view/RenderNode.java
+++ b/core/java/android/view/RenderNode.java
@@ -353,6 +353,11 @@
return nHasShadow(mNativeRenderNode);
}
+ /** setShadowColor */
+ public boolean setShadowColor(int color) {
+ return nSetShadowColor(mNativeRenderNode, color);
+ }
+
/**
* Enables or disables clipping to the outline.
*
@@ -910,6 +915,8 @@
@CriticalNative
private static native boolean nHasShadow(long renderNode);
@CriticalNative
+ private static native boolean nSetShadowColor(long renderNode, int color);
+ @CriticalNative
private static native boolean nSetClipToOutline(long renderNode, boolean clipToOutline);
@CriticalNative
private static native boolean nSetRevealClip(long renderNode,
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index e12c0b0..be09fe8 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -15182,6 +15182,15 @@
return mRenderNode.hasShadow();
}
+ /**
+ * @hide
+ */
+ public void setShadowColor(@ColorInt int color) {
+ if (mRenderNode.setShadowColor(color)) {
+ invalidateViewProperty(true, true);
+ }
+ }
+
/** @hide */
public void setRevealClip(boolean shouldClip, float x, float y, float radius) {
diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp
index 6e8c931..37ff8c8 100644
--- a/core/jni/android_view_RenderNode.cpp
+++ b/core/jni/android_view_RenderNode.cpp
@@ -174,6 +174,10 @@
return renderNode->stagingProperties().hasShadow();
}
+static jboolean android_view_RenderNode_setShadowColor(jlong renderNodePtr, jint shadowColor) {
+ return SET_AND_DIRTY(setShadowColor, static_cast<SkColor>(shadowColor), RenderNode::GENERIC);
+}
+
static jboolean android_view_RenderNode_setClipToOutline(jlong renderNodePtr,
jboolean clipToOutline) {
RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
@@ -571,6 +575,7 @@
{ "nSetOutlineEmpty", "(J)Z", (void*) android_view_RenderNode_setOutlineEmpty },
{ "nSetOutlineNone", "(J)Z", (void*) android_view_RenderNode_setOutlineNone },
{ "nHasShadow", "(J)Z", (void*) android_view_RenderNode_hasShadow },
+ { "nSetShadowColor", "(JI)Z", (void*) android_view_RenderNode_setShadowColor },
{ "nSetClipToOutline", "(JZ)Z", (void*) android_view_RenderNode_setClipToOutline },
{ "nSetRevealClip", "(JZFFF)Z", (void*) android_view_RenderNode_setRevealClip },
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 837c4ef..3d2c252 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -26,6 +26,7 @@
#include <SkBlendMode.h>
#include <SkCamera.h>
+#include <SkColor.h>
#include <SkMatrix.h>
#include <SkRegion.h>
@@ -506,6 +507,14 @@
getOutline().getAlpha() != 0.0f;
}
+ SkColor getShadowColor() const {
+ return mPrimitiveFields.mShadowColor;
+ }
+
+ bool setShadowColor(SkColor shadowColor) {
+ return RP_SET(mPrimitiveFields.mShadowColor, shadowColor);
+ }
+
bool fitsOnLayer() const {
const DeviceInfo* deviceInfo = DeviceInfo::get();
return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() &&
@@ -529,6 +538,7 @@
int mLeft = 0, mTop = 0, mRight = 0, mBottom = 0;
int mWidth = 0, mHeight = 0;
int mClippingFlags = CLIP_TO_BOUNDS;
+ SkColor mShadowColor = SK_ColorBLACK;
float mAlpha = 1;
float mTranslationX = 0, mTranslationY = 0, mTranslationZ = 0;
float mElevation = 0;
diff --git a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp
index 67e0602..7b59ccf 100644
--- a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp
+++ b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp
@@ -189,7 +189,7 @@
}
SkShadowUtils::DrawShadow(
canvas, *casterPath, zParams, skiaLightPos, SkiaPipeline::getLightRadius(),
- ambientAlpha, spotAlpha, SK_ColorBLACK,
+ ambientAlpha, spotAlpha, casterProperties.getShadowColor(),
casterAlpha < 1.0f ? SkShadowFlags::kTransparentOccluder_ShadowFlag : 0);
}
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 9caf9d0..ebf5f68 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -282,6 +282,15 @@
<category android:name="com.android.test.hwui.TEST" />
</intent-filter>
</activity>
+
+ <activity
+ android:name="ColoredShadowsActivity"
+ android:label="View/ColoredShadows">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
<activity
android:name="OpaqueActivity"
diff --git a/tests/HwAccelerationTest/res/layout/colored_shadows_activity.xml b/tests/HwAccelerationTest/res/layout/colored_shadows_activity.xml
new file mode 100644
index 0000000..1863325
--- /dev/null
+++ b/tests/HwAccelerationTest/res/layout/colored_shadows_activity.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2017, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/colored_grid">
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+ <include layout="@layout/colored_shadows_row" />
+</LinearLayout>
diff --git a/tests/HwAccelerationTest/res/layout/colored_shadows_row.xml b/tests/HwAccelerationTest/res/layout/colored_shadows_row.xml
new file mode 100644
index 0000000..61b0759
--- /dev/null
+++ b/tests/HwAccelerationTest/res/layout/colored_shadows_row.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2017, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="25dp"
+ android:paddingBottom="25dp"
+ android:clipToPadding="false" >
+ <View android:id="@+id/grey"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:elevation="16dp"
+ android:background="#3C4043"
+ android:layout_marginLeft="20dp" />
+ <View android:id="@+id/blue"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:elevation="16dp"
+ android:background="#185ABC"
+ android:layout_marginLeft="20dp"/>
+ <View android:id="@+id/red"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:elevation="16dp"
+ android:background="#B31412"
+ android:layout_marginLeft="20dp"/>
+ <View android:id="@+id/yellow"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:elevation="16dp"
+ android:background="#EA8600"
+ android:layout_marginLeft="20dp"/>
+ <View android:id="@+id/green"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:elevation="16dp"
+ android:background="#137333"
+ android:layout_marginLeft="20dp"/>
+</LinearLayout>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ColoredShadowsActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ColoredShadowsActivity.java
new file mode 100644
index 0000000..135c93c
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ColoredShadowsActivity.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.test.hwui;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class ColoredShadowsActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.colored_shadows_activity);
+ ViewGroup grid = findViewById(R.id.colored_grid);
+ for (int i = 0; i < grid.getChildCount(); i++) {
+ setShadowColors((ViewGroup) grid.getChildAt(i), i);
+ }
+ }
+
+ private void setShadowColors(ViewGroup row, int rowIndex) {
+ for (int i = 0; i < row.getChildCount(); i++) {
+ View view = row.getChildAt(i);
+ view.setShadowColor(shadowColorFor(view));
+ view.setElevation(6.0f * (rowIndex + 1));
+ }
+ }
+
+ private int shadowColorFor(View view) {
+ switch (view.getId()) {
+ case R.id.grey: return 0xFF3C4043;
+ case R.id.blue: return 0xFF185ABC;
+ case R.id.red: return 0xFFB31412;
+ case R.id.yellow: return 0xFFEA8600;
+ case R.id.green: return 0xFF137333;
+ default: return 0xFF000000;
+ }
+ }
+
+}