diff options
author | John Reck <jreck@google.com> | 2017-11-13 16:47:35 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2017-11-13 16:53:48 -0800 |
commit | 3c0369bf0263b1b172932fdbc6a53efb01c965fc (patch) | |
tree | c95bab7d9c6bc49104b7ca30a2344ae4faeab2e7 | |
parent | ae5eb83a32a2005bd2c872bdf7b0621190ddb062 (diff) |
Create colored shadows demo
Test: HwAccelerationTest demo
Bug: 68211332
Change-Id: Ia53a6ac2854570d0495b355bbebee1dcec2f47ba
-rw-r--r-- | core/java/android/view/RenderNode.java | 7 | ||||
-rw-r--r-- | core/java/android/view/View.java | 9 | ||||
-rw-r--r-- | core/jni/android_view_RenderNode.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/RenderProperties.h | 10 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp | 2 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | tests/HwAccelerationTest/res/layout/colored_shadows_activity.xml | 32 | ||||
-rw-r--r-- | tests/HwAccelerationTest/res/layout/colored_shadows_row.xml | 57 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/ColoredShadowsActivity.java | 55 |
9 files changed, 185 insertions, 1 deletions
diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java index ea6e63c3b9de..5070151815f5 100644 --- a/core/java/android/view/RenderNode.java +++ b/core/java/android/view/RenderNode.java @@ -353,6 +353,11 @@ public class RenderNode { return nHasShadow(mNativeRenderNode); } + /** setShadowColor */ + public boolean setShadowColor(int color) { + return nSetShadowColor(mNativeRenderNode, color); + } + /** * Enables or disables clipping to the outline. * @@ -910,6 +915,8 @@ public class RenderNode { @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 e12c0b0d93b8..be09fe869518 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -15182,6 +15182,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, 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 6e8c93132562..37ff8c8cefd2 100644 --- a/core/jni/android_view_RenderNode.cpp +++ b/core/jni/android_view_RenderNode.cpp @@ -174,6 +174,10 @@ static jboolean android_view_RenderNode_hasShadow(jlong renderNodePtr) { 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 @@ static const JNINativeMethod gMethods[] = { { "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 837c4effea9f..3d2c2520624b 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 @@ public: 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 @@ private: 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 67e06022b17c..7b59ccf3eec7 100644 --- a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp +++ b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp @@ -189,7 +189,7 @@ void EndReorderBarrierDrawable::drawShadow(SkCanvas* canvas, RenderNodeDrawable* } 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 9caf9d0f6e26..ebf5f6854c6f 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 000000000000..18633250cfcb --- /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 000000000000..61b075974926 --- /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 000000000000..135c93c97af2 --- /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; + } + } + +} |