Connect shadow style attributes to renderer
bug:15859361
Moves lighting info out of StatefulBaseRenderer, since it's not useful
at record time, and only used by OGLR.
Change-Id: I7ab065d02d9304afad1dc4c48597a7a621366f8e
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 5a96132..4f81066 100755
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -132,19 +132,21 @@
///////////////////////////////////////////////////////////////////////////////
OpenGLRenderer::OpenGLRenderer(RenderState& renderState)
- : mCaches(Caches::getInstance())
+ : mFrameStarted(false)
+ , mCaches(Caches::getInstance())
, mExtensions(Extensions::getInstance())
- , mRenderState(renderState) {
+ , mRenderState(renderState)
+ , mScissorOptimizationDisabled(false)
+ , mCountOverdraw(false)
+ , mLightCenter(FLT_MIN, FLT_MIN, FLT_MIN)
+ , mLightRadius(FLT_MIN)
+ , mAmbientShadowAlpha(0)
+ , mSpotShadowAlpha(0) {
// *set* draw modifiers to be 0
memset(&mDrawModifiers, 0, sizeof(mDrawModifiers));
mDrawModifiers.mOverrideLayerAlpha = 1.0f;
memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));
-
- mFrameStarted = false;
- mCountOverdraw = false;
-
- mScissorOptimizationDisabled = false;
}
OpenGLRenderer::~OpenGLRenderer() {
@@ -163,6 +165,14 @@
}
}
+void OpenGLRenderer::initLight(const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
+ mLightCenter = lightCenter;
+ mLightRadius = lightRadius;
+ mAmbientShadowAlpha = ambientShadowAlpha;
+ mSpotShadowAlpha = spotShadowAlpha;
+}
+
///////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////
@@ -3172,13 +3182,13 @@
SkPaint paint;
paint.setAntiAlias(true); // want to use AlphaVertex
- if (ambientShadowVertexBuffer && mCaches.propertyAmbientShadowStrength > 0) {
- paint.setARGB(casterAlpha * mCaches.propertyAmbientShadowStrength, 0, 0, 0);
+ if (ambientShadowVertexBuffer && mAmbientShadowAlpha > 0) {
+ paint.setARGB(casterAlpha * mAmbientShadowAlpha, 0, 0, 0);
drawVertexBuffer(*ambientShadowVertexBuffer, &paint);
}
- if (spotShadowVertexBuffer && mCaches.propertySpotShadowStrength > 0) {
- paint.setARGB(casterAlpha * mCaches.propertySpotShadowStrength, 0, 0, 0);
+ if (spotShadowVertexBuffer && mSpotShadowAlpha > 0) {
+ paint.setARGB(casterAlpha * mSpotShadowAlpha, 0, 0, 0);
drawVertexBuffer(*spotShadowVertexBuffer, &paint);
}
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 4e7844b..f698b45 100755
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -124,6 +124,8 @@
virtual ~OpenGLRenderer();
void initProperties();
+ void initLight(const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
virtual void onViewportInitialized();
virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
@@ -1010,6 +1012,12 @@
bool mSkipOutlineClip;
+ // Lighting + shadows
+ Vector3 mLightCenter;
+ float mLightRadius;
+ uint8_t mAmbientShadowAlpha;
+ uint8_t mSpotShadowAlpha;
+
friend class Layer;
friend class TextSetupFunctor;
friend class DrawBitmapOp;
diff --git a/libs/hwui/Renderer.h b/libs/hwui/Renderer.h
index ccd3ba5..40a21e4 100644
--- a/libs/hwui/Renderer.h
+++ b/libs/hwui/Renderer.h
@@ -80,14 +80,6 @@
virtual void setViewport(int width, int height) = 0;
/**
- * Sets the position and size of the spot shadow casting light.
- *
- * @param lightCenter The light's Y position, relative to the render target's top left
- * @param lightRadius The light's radius
- */
- virtual void initializeLight(const Vector3& lightCenter, float lightRadius) = 0;
-
- /**
* Prepares the renderer to draw a frame. This method must be invoked
* at the beginning of each frame. When this method is invoked, the
* entire drawing surface is assumed to be redrawn.
diff --git a/libs/hwui/StatefulBaseRenderer.cpp b/libs/hwui/StatefulBaseRenderer.cpp
index 95c0ee5..140c6e8 100644
--- a/libs/hwui/StatefulBaseRenderer.cpp
+++ b/libs/hwui/StatefulBaseRenderer.cpp
@@ -23,10 +23,13 @@
namespace android {
namespace uirenderer {
-StatefulBaseRenderer::StatefulBaseRenderer() :
- mDirtyClip(false), mWidth(-1), mHeight(-1),
- mSaveCount(1), mFirstSnapshot(new Snapshot), mSnapshot(mFirstSnapshot),
- mLightCenter(FLT_MIN, FLT_MIN, FLT_MIN), mLightRadius(FLT_MIN) {
+StatefulBaseRenderer::StatefulBaseRenderer()
+ : mDirtyClip(false)
+ , mWidth(-1)
+ , mHeight(-1)
+ , mSaveCount(1)
+ , mFirstSnapshot(new Snapshot)
+ , mSnapshot(mFirstSnapshot) {
}
void StatefulBaseRenderer::initializeSaveStack(float clipLeft, float clipTop,
@@ -45,11 +48,6 @@
onViewportInitialized();
}
-void StatefulBaseRenderer::initializeLight(const Vector3& lightCenter, float lightRadius) {
- mLightCenter = lightCenter;
- mLightRadius = lightRadius;
-}
-
///////////////////////////////////////////////////////////////////////////////
// Save (layer)
///////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/StatefulBaseRenderer.h b/libs/hwui/StatefulBaseRenderer.h
index e8e024f..25cc832 100644
--- a/libs/hwui/StatefulBaseRenderer.h
+++ b/libs/hwui/StatefulBaseRenderer.h
@@ -52,7 +52,6 @@
* the render target.
*/
virtual void setViewport(int width, int height);
- virtual void initializeLight(const Vector3& lightCenter, float lightRadius);
void initializeSaveStack(float clipLeft, float clipTop, float clipRight, float clipBottom);
// getters
@@ -161,10 +160,6 @@
// Current state
// TODO: should become private, once hooks needed by OpenGLRenderer are added
sp<Snapshot> mSnapshot;
-
- Vector3 mLightCenter;
- float mLightRadius;
-
}; // class StatefulBaseRenderer
}; // namespace uirenderer
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 2147810..756f660 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -110,10 +110,11 @@
// and such to prevent from trying to render into this surface
}
-void CanvasContext::setup(int width, int height, const Vector3& lightCenter, float lightRadius) {
+void CanvasContext::setup(int width, int height, const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
if (!mCanvas) return;
mCanvas->setViewport(width, height);
- mCanvas->initializeLight(lightCenter, lightRadius);
+ mCanvas->initLight(lightCenter, lightRadius, ambientShadowAlpha, spotShadowAlpha);
}
void CanvasContext::setOpaque(bool opaque) {
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 1bab1b1..2a01027 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -53,7 +53,8 @@
bool initialize(ANativeWindow* window);
void updateSurface(ANativeWindow* window);
void pauseSurface(ANativeWindow* window);
- void setup(int width, int height, const Vector3& lightCenter, float lightRadius);
+ void setup(int width, int height, const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
void setOpaque(bool opaque);
void makeCurrent();
void processLayerUpdate(DeferredLayerUpdater* layerUpdater);
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index 91f5801..1e91eb5 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -39,6 +39,8 @@
#define CREATE_BRIDGE3(name, a1, a2, a3) CREATE_BRIDGE(name, a1,a2,a3,,,,,)
#define CREATE_BRIDGE4(name, a1, a2, a3, a4) CREATE_BRIDGE(name, a1,a2,a3,a4,,,,)
#define CREATE_BRIDGE5(name, a1, a2, a3, a4, a5) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,,,)
+#define CREATE_BRIDGE6(name, a1, a2, a3, a4, a5, a6) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,,)
+#define CREATE_BRIDGE7(name, a1, a2, a3, a4, a5, a6, a7) CREATE_BRIDGE(name, a1,a2,a3,a4,a5,a6,a7,)
#define CREATE_BRIDGE(name, a1, a2, a3, a4, a5, a6, a7, a8) \
typedef struct { \
a1; a2; a3; a4; a5; a6; a7; a8; \
@@ -152,19 +154,24 @@
postAndWait(task);
}
-CREATE_BRIDGE5(setup, CanvasContext* context, int width, int height,
- Vector3 lightCenter, int lightRadius) {
- args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius);
+CREATE_BRIDGE7(setup, CanvasContext* context, int width, int height,
+ Vector3 lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
+ args->context->setup(args->width, args->height, args->lightCenter, args->lightRadius,
+ args->ambientShadowAlpha, args->spotShadowAlpha);
return NULL;
}
-void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius) {
+void RenderProxy::setup(int width, int height, const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha) {
SETUP_TASK(setup);
args->context = mContext;
args->width = width;
args->height = height;
args->lightCenter = lightCenter;
args->lightRadius = lightRadius;
+ args->ambientShadowAlpha = ambientShadowAlpha;
+ args->spotShadowAlpha = spotShadowAlpha;
post(task);
}
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index 0027403..28d0173 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -67,7 +67,8 @@
ANDROID_API bool initialize(const sp<ANativeWindow>& window);
ANDROID_API void updateSurface(const sp<ANativeWindow>& window);
ANDROID_API void pauseSurface(const sp<ANativeWindow>& window);
- ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius);
+ ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius,
+ uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
ANDROID_API void setOpaque(bool opaque);
ANDROID_API int syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos,
float density);