Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 058fc640 authored by Chris Craik's avatar Chris Craik
Browse files

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
parent 753d849b
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ public class ThreadedRenderer extends HardwareRenderer {
    private final float mLightY;
    private final float mLightZ;
    private final float mLightRadius;
    private final float mAmbientShadowAlpha;
    private final float mSpotShadowAlpha;
    private final int mAmbientShadowAlpha;
    private final int mSpotShadowAlpha;

    private long mNativeProxy;
    private boolean mInitialized = false;
@@ -104,8 +104,10 @@ public class ThreadedRenderer extends HardwareRenderer {
        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);
        mAmbientShadowAlpha = Math.round(
                255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0));
        mSpotShadowAlpha = Math.round(
                255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0));
        a.recycle();

        long rootNodePtr = nCreateRootRenderNode();
@@ -208,7 +210,9 @@ public class ThreadedRenderer extends HardwareRenderer {
            mSurfaceHeight = height;
        }
        mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight);
        nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, lightX, mLightY, mLightZ, mLightRadius);
        nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight,
                lightX, mLightY, mLightZ, mLightRadius,
                mAmbientShadowAlpha, mSpotShadowAlpha);
    }

    @Override
@@ -453,7 +457,8 @@ public class ThreadedRenderer extends HardwareRenderer {
    private static native void nUpdateSurface(long nativeProxy, Surface window);
    private static native void nPauseSurface(long nativeProxy, Surface window);
    private static native void nSetup(long nativeProxy, int width, int height,
            float lightX, float lightY, float lightZ, float lightRadius);
            float lightX, float lightY, float lightZ, float lightRadius,
            int ambientShadowAlpha, int spotShadowAlpha);
    private static native void nSetOpaque(long nativeProxy, boolean opaque);
    private static native int nSyncAndDrawFrame(long nativeProxy,
            long frameTimeNanos, long recordDuration, float density);
+5 −3
Original line number Diff line number Diff line
@@ -219,9 +219,11 @@ static void android_view_ThreadedRenderer_pauseSurface(JNIEnv* env, jobject claz

static void android_view_ThreadedRenderer_setup(JNIEnv* env, jobject clazz, jlong proxyPtr,
        jint width, jint height,
        jfloat lightX, jfloat lightY, jfloat lightZ, jfloat lightRadius) {
        jfloat lightX, jfloat lightY, jfloat lightZ, jfloat lightRadius,
        jint ambientShadowAlpha, jint spotShadowAlpha) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    proxy->setup(width, height, Vector3(lightX, lightY, lightZ), lightRadius);
    proxy->setup(width, height, Vector3(lightX, lightY, lightZ), lightRadius,
            ambientShadowAlpha, spotShadowAlpha);
}

static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz,
@@ -358,7 +360,7 @@ static JNINativeMethod gMethods[] = {
    { "nInitialize", "(JLandroid/view/Surface;)Z", (void*) android_view_ThreadedRenderer_initialize },
    { "nUpdateSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_updateSurface },
    { "nPauseSurface", "(JLandroid/view/Surface;)V", (void*) android_view_ThreadedRenderer_pauseSurface },
    { "nSetup", "(JIIFFFF)V", (void*) android_view_ThreadedRenderer_setup },
    { "nSetup", "(JIIFFFFII)V", (void*) android_view_ThreadedRenderer_setup },
    { "nSetOpaque", "(JZ)V", (void*) android_view_ThreadedRenderer_setOpaque },
    { "nSyncAndDrawFrame", "(JJJF)I", (void*) android_view_ThreadedRenderer_syncAndDrawFrame },
    { "nDestroyCanvasAndSurface", "(J)V", (void*) android_view_ThreadedRenderer_destroyCanvasAndSurface },
+21 −11
Original line number Diff line number Diff line
@@ -132,19 +132,21 @@ static inline T min(T a, T b) {
///////////////////////////////////////////////////////////////////////////////

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::initProperties() {
    }
}

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 @@ status_t OpenGLRenderer::drawShadow(float casterAlpha,
    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);
    }

+8 −0
Original line number Diff line number Diff line
@@ -124,6 +124,8 @@ public:
    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 @@ private:

    bool mSkipOutlineClip;

    // Lighting + shadows
    Vector3 mLightCenter;
    float mLightRadius;
    uint8_t mAmbientShadowAlpha;
    uint8_t mSpotShadowAlpha;

    friend class Layer;
    friend class TextSetupFunctor;
    friend class DrawBitmapOp;
+0 −8
Original line number Diff line number Diff line
@@ -79,14 +79,6 @@ public:
     */
    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
Loading