Loading core/java/android/view/HardwareRenderer.java +12 −28 Original line number Diff line number Diff line Loading @@ -247,25 +247,9 @@ public abstract class HardwareRenderer { */ abstract void detachSurfaceTexture(long hardwareLayer); /** * Setup the hardware renderer for drawing. This is called whenever the size * of the target surface changes or when the surface is first created. * * @param width Width of the drawing surface. * @param height Height of the drawing surface. * @param surfaceInsets Insets between the drawing surface and actual * surface bounds. * @param lightX X position of the shadow casting light * @param lightY Y position of the shadow casting light * @param lightZ Z position of the shadow casting light * @param lightRadius radius of the shadow casting light */ abstract void setup(int width, int height, Rect surfaceInsets, float lightX, float lightY, float lightZ, float lightRadius); /** * Gets the current width of the surface. This is the width that the surface * was last set to in a call to {@link #setup(int, int, Rect, float, float, float, float)}. * was last set to in a call to {@link #setup(int, int, Rect)}. * * @return the current width of the surface */ Loading @@ -273,7 +257,7 @@ public abstract class HardwareRenderer { /** * Gets the current height of the surface. This is the height that the surface * was last set to in a call to {@link #setup(int, int, Rect, float, float, float, float)}. * was last set to in a call to {@link #setup(int, int, Rect)}. * * @return the current width of the surface */ Loading Loading @@ -371,19 +355,18 @@ public abstract class HardwareRenderer { * @param width The width of the drawing surface. * @param height The height of the drawing surface. * @param surface The surface to hardware accelerate * @param metrics The display metrics used to draw the output. * @param surfaceInsets The drawing surface insets to apply * * @return true if the surface was initialized, false otherwise. Returning * false might mean that the surface was already initialized. */ boolean initializeIfNeeded(int width, int height, Surface surface, Rect surfaceInsets, DisplayMetrics metrics) boolean initializeIfNeeded(int width, int height, Surface surface, Rect surfaceInsets) throws OutOfResourcesException { if (isRequested()) { // We lost the gl context, so recreate it. if (!isEnabled()) { if (initialize(surface)) { setup(width, height, surfaceInsets, metrics); setup(width, height, surfaceInsets); return true; } } Loading @@ -391,13 +374,14 @@ public abstract class HardwareRenderer { return false; } void setup(int width, int height, Rect surfaceInsets, DisplayMetrics metrics) { float lightX = width / 2.0f; float lightY = -400 * metrics.density; float lightZ = 800 * metrics.density; float lightRadius = 800 * metrics.density; setup(width, height, surfaceInsets, lightX, lightY, lightZ, lightRadius); } /** * Sets up the renderer for drawing. * * @param width The width of the drawing surface. * @param height The height of the drawing surface. * @param surfaceInsets The drawing surface insets to apply */ abstract void setup(int width, int height, Rect surfaceInsets); /** * Optional, sets the name of the renderer. Useful for debugging purposes. Loading core/java/android/view/ThreadedRenderer.java +22 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.view; import com.android.internal.R; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.Drawable; Loading Loading @@ -78,6 +81,13 @@ public class ThreadedRenderer extends HardwareRenderer { // applied as translation when updating the root render node. private int mInsetTop, mInsetLeft; // Light and shadow properties specified by the theme. private final float mLightY; private final float mLightZ; private final float mLightRadius; private final float mAmbientShadowAlpha; private final float mSpotShadowAlpha; private long mNativeProxy; private boolean mInitialized = false; private RenderNode mRootNode; Loading @@ -85,6 +95,15 @@ public class ThreadedRenderer extends HardwareRenderer { private boolean mProfilingEnabled; ThreadedRenderer(Context context, boolean translucent) { final TypedArray a = context.obtainStyledAttributes( null, R.styleable.Lighting, R.attr.lightingStyle, 0); mLightY = a.getDimension(R.styleable.Lighting_lightY, 0); mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0); mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0); mAmbientShadowAlpha = a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0); mSpotShadowAlpha = a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0); a.recycle(); long rootNodePtr = nCreateRootRenderNode(); mRootNode = RenderNode.adopt(rootNodePtr); mRootNode.setClipToBounds(false); Loading Loading @@ -164,8 +183,8 @@ public class ThreadedRenderer extends HardwareRenderer { } @Override void setup(int width, int height, Rect surfaceInsets, float lightX, float lightY, float lightZ, float lightRadius) { void setup(int width, int height, Rect surfaceInsets) { final float lightX = width / 2.0f; mWidth = width; mHeight = height; if (surfaceInsets != null) { Loading @@ -180,7 +199,7 @@ public class ThreadedRenderer extends HardwareRenderer { mSurfaceHeight = height; } mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight); nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, lightX, lightY, lightZ, lightRadius); nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, lightX, mLightY, mLightZ, mLightRadius); } @Override Loading core/java/android/view/ViewRootImpl.java +3 −6 Original line number Diff line number Diff line Loading @@ -1714,8 +1714,7 @@ public final class ViewRootImpl implements ViewParent, mWidth != mAttachInfo.mHardwareRenderer.getWidth() || mHeight != mAttachInfo.mHardwareRenderer.getHeight()) { final Rect shadowInsets = params != null ? params.shadowInsets : null; mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight, shadowInsets, mAttachInfo.mRootView.getResources().getDisplayMetrics()); mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight, shadowInsets); if (!hwInitialized) { mAttachInfo.mHardwareRenderer.invalidate(mSurface); mFullRedrawNeeded = true; Loading Loading @@ -2459,8 +2458,7 @@ public final class ViewRootImpl implements ViewParent, try { attachInfo.mHardwareRenderer.initializeIfNeeded( mWidth, mHeight, mSurface, surfaceInsets, attachInfo.mRootView.getResources().getDisplayMetrics()); mWidth, mHeight, mSurface, surfaceInsets); } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); return; Loading Loading @@ -3159,8 +3157,7 @@ public final class ViewRootImpl implements ViewParent, final WindowManager.LayoutParams lp = mWindowAttributes; final Rect surfaceInsets = lp != null ? lp.shadowInsets : null; mAttachInfo.mHardwareRenderer.initializeIfNeeded( mWidth, mHeight, mSurface, surfaceInsets, mAttachInfo.mRootView.getResources().getDisplayMetrics()); mWidth, mHeight, mSurface, surfaceInsets); } catch (OutOfResourcesException e) { Log.e(TAG, "OutOfResourcesException locking surface", e); try { Loading core/res/res/values/attrs.xml +17 −0 Original line number Diff line number Diff line Loading @@ -985,6 +985,14 @@ <!-- The color applied to framework buttons in their normal state. --> <attr name="colorButtonNormal" format="color" /> <!-- ================== --> <!-- Hardware rendering --> <!-- ================== --> <eat-comment /> <!-- Reference to the Lighting style. --> <attr name="lightingStyle" format="reference" /> </declare-styleable> <!-- **************************************************************** --> Loading Loading @@ -7141,4 +7149,13 @@ <attr name="layout_ignoreOffset" format="boolean" /> <attr name="layout_gravity" /> </declare-styleable> <!-- @hide --> <declare-styleable name="Lighting"> <attr name="lightY" format="dimension" /> <attr name="lightZ" format="dimension" /> <attr name="lightRadius" format="dimension" /> <attr name="ambientShadowAlpha" format="float" /> <attr name="spotShadowAlpha" format="float" /> </declare-styleable> </resources> core/res/res/values/styles.xml +8 −0 Original line number Diff line number Diff line Loading @@ -1362,4 +1362,12 @@ please see styles_device_defaults.xml. <item name="padding">16dp</item> </style> <style name="Lighting"> <item name="lightY">-200dp</item> <item name="lightZ">800dp</item> <item name="lightRadius">800dp</item> <item name="ambientShadowAlpha">0.125</item> <item name="spotShadowAlpha">0.25</item> </style> </resources> Loading
core/java/android/view/HardwareRenderer.java +12 −28 Original line number Diff line number Diff line Loading @@ -247,25 +247,9 @@ public abstract class HardwareRenderer { */ abstract void detachSurfaceTexture(long hardwareLayer); /** * Setup the hardware renderer for drawing. This is called whenever the size * of the target surface changes or when the surface is first created. * * @param width Width of the drawing surface. * @param height Height of the drawing surface. * @param surfaceInsets Insets between the drawing surface and actual * surface bounds. * @param lightX X position of the shadow casting light * @param lightY Y position of the shadow casting light * @param lightZ Z position of the shadow casting light * @param lightRadius radius of the shadow casting light */ abstract void setup(int width, int height, Rect surfaceInsets, float lightX, float lightY, float lightZ, float lightRadius); /** * Gets the current width of the surface. This is the width that the surface * was last set to in a call to {@link #setup(int, int, Rect, float, float, float, float)}. * was last set to in a call to {@link #setup(int, int, Rect)}. * * @return the current width of the surface */ Loading @@ -273,7 +257,7 @@ public abstract class HardwareRenderer { /** * Gets the current height of the surface. This is the height that the surface * was last set to in a call to {@link #setup(int, int, Rect, float, float, float, float)}. * was last set to in a call to {@link #setup(int, int, Rect)}. * * @return the current width of the surface */ Loading Loading @@ -371,19 +355,18 @@ public abstract class HardwareRenderer { * @param width The width of the drawing surface. * @param height The height of the drawing surface. * @param surface The surface to hardware accelerate * @param metrics The display metrics used to draw the output. * @param surfaceInsets The drawing surface insets to apply * * @return true if the surface was initialized, false otherwise. Returning * false might mean that the surface was already initialized. */ boolean initializeIfNeeded(int width, int height, Surface surface, Rect surfaceInsets, DisplayMetrics metrics) boolean initializeIfNeeded(int width, int height, Surface surface, Rect surfaceInsets) throws OutOfResourcesException { if (isRequested()) { // We lost the gl context, so recreate it. if (!isEnabled()) { if (initialize(surface)) { setup(width, height, surfaceInsets, metrics); setup(width, height, surfaceInsets); return true; } } Loading @@ -391,13 +374,14 @@ public abstract class HardwareRenderer { return false; } void setup(int width, int height, Rect surfaceInsets, DisplayMetrics metrics) { float lightX = width / 2.0f; float lightY = -400 * metrics.density; float lightZ = 800 * metrics.density; float lightRadius = 800 * metrics.density; setup(width, height, surfaceInsets, lightX, lightY, lightZ, lightRadius); } /** * Sets up the renderer for drawing. * * @param width The width of the drawing surface. * @param height The height of the drawing surface. * @param surfaceInsets The drawing surface insets to apply */ abstract void setup(int width, int height, Rect surfaceInsets); /** * Optional, sets the name of the renderer. Useful for debugging purposes. Loading
core/java/android/view/ThreadedRenderer.java +22 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,11 @@ package android.view; import com.android.internal.R; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.Drawable; Loading Loading @@ -78,6 +81,13 @@ public class ThreadedRenderer extends HardwareRenderer { // applied as translation when updating the root render node. private int mInsetTop, mInsetLeft; // Light and shadow properties specified by the theme. private final float mLightY; private final float mLightZ; private final float mLightRadius; private final float mAmbientShadowAlpha; private final float mSpotShadowAlpha; private long mNativeProxy; private boolean mInitialized = false; private RenderNode mRootNode; Loading @@ -85,6 +95,15 @@ public class ThreadedRenderer extends HardwareRenderer { private boolean mProfilingEnabled; ThreadedRenderer(Context context, boolean translucent) { final TypedArray a = context.obtainStyledAttributes( null, R.styleable.Lighting, R.attr.lightingStyle, 0); mLightY = a.getDimension(R.styleable.Lighting_lightY, 0); mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0); mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0); mAmbientShadowAlpha = a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0); mSpotShadowAlpha = a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0); a.recycle(); long rootNodePtr = nCreateRootRenderNode(); mRootNode = RenderNode.adopt(rootNodePtr); mRootNode.setClipToBounds(false); Loading Loading @@ -164,8 +183,8 @@ public class ThreadedRenderer extends HardwareRenderer { } @Override void setup(int width, int height, Rect surfaceInsets, float lightX, float lightY, float lightZ, float lightRadius) { void setup(int width, int height, Rect surfaceInsets) { final float lightX = width / 2.0f; mWidth = width; mHeight = height; if (surfaceInsets != null) { Loading @@ -180,7 +199,7 @@ public class ThreadedRenderer extends HardwareRenderer { mSurfaceHeight = height; } mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight); nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, lightX, lightY, lightZ, lightRadius); nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, lightX, mLightY, mLightZ, mLightRadius); } @Override Loading
core/java/android/view/ViewRootImpl.java +3 −6 Original line number Diff line number Diff line Loading @@ -1714,8 +1714,7 @@ public final class ViewRootImpl implements ViewParent, mWidth != mAttachInfo.mHardwareRenderer.getWidth() || mHeight != mAttachInfo.mHardwareRenderer.getHeight()) { final Rect shadowInsets = params != null ? params.shadowInsets : null; mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight, shadowInsets, mAttachInfo.mRootView.getResources().getDisplayMetrics()); mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight, shadowInsets); if (!hwInitialized) { mAttachInfo.mHardwareRenderer.invalidate(mSurface); mFullRedrawNeeded = true; Loading Loading @@ -2459,8 +2458,7 @@ public final class ViewRootImpl implements ViewParent, try { attachInfo.mHardwareRenderer.initializeIfNeeded( mWidth, mHeight, mSurface, surfaceInsets, attachInfo.mRootView.getResources().getDisplayMetrics()); mWidth, mHeight, mSurface, surfaceInsets); } catch (OutOfResourcesException e) { handleOutOfResourcesException(e); return; Loading Loading @@ -3159,8 +3157,7 @@ public final class ViewRootImpl implements ViewParent, final WindowManager.LayoutParams lp = mWindowAttributes; final Rect surfaceInsets = lp != null ? lp.shadowInsets : null; mAttachInfo.mHardwareRenderer.initializeIfNeeded( mWidth, mHeight, mSurface, surfaceInsets, mAttachInfo.mRootView.getResources().getDisplayMetrics()); mWidth, mHeight, mSurface, surfaceInsets); } catch (OutOfResourcesException e) { Log.e(TAG, "OutOfResourcesException locking surface", e); try { Loading
core/res/res/values/attrs.xml +17 −0 Original line number Diff line number Diff line Loading @@ -985,6 +985,14 @@ <!-- The color applied to framework buttons in their normal state. --> <attr name="colorButtonNormal" format="color" /> <!-- ================== --> <!-- Hardware rendering --> <!-- ================== --> <eat-comment /> <!-- Reference to the Lighting style. --> <attr name="lightingStyle" format="reference" /> </declare-styleable> <!-- **************************************************************** --> Loading Loading @@ -7141,4 +7149,13 @@ <attr name="layout_ignoreOffset" format="boolean" /> <attr name="layout_gravity" /> </declare-styleable> <!-- @hide --> <declare-styleable name="Lighting"> <attr name="lightY" format="dimension" /> <attr name="lightZ" format="dimension" /> <attr name="lightRadius" format="dimension" /> <attr name="ambientShadowAlpha" format="float" /> <attr name="spotShadowAlpha" format="float" /> </declare-styleable> </resources>
core/res/res/values/styles.xml +8 −0 Original line number Diff line number Diff line Loading @@ -1362,4 +1362,12 @@ please see styles_device_defaults.xml. <item name="padding">16dp</item> </style> <style name="Lighting"> <item name="lightY">-200dp</item> <item name="lightZ">800dp</item> <item name="lightRadius">800dp</item> <item name="ambientShadowAlpha">0.125</item> <item name="spotShadowAlpha">0.25</item> </style> </resources>