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

Commit 75687983 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Layers were using an extra Snapshot causing extra clipping."

parents b01a5efe 2542d199
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1657,7 +1657,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
     * Convenience value to check for float values that are close enough to zero to be considered
     * zero.
     */
    private static float NONZERO_EPSILON = .001f;
    private static final float NONZERO_EPSILON = .001f;

    /**
     * The degrees rotation around the vertical axis through the pivot point.
+23 −35
Original line number Diff line number Diff line
@@ -219,22 +219,16 @@ int OpenGLRenderer::save(int flags) {
}

void OpenGLRenderer::restore() {
    if (mSaveCount > 1 && restoreSnapshot()) {
        setScissorFromClip();
    if (mSaveCount > 1) {
        restoreSnapshot();
    }
}

void OpenGLRenderer::restoreToCount(int saveCount) {
    if (saveCount < 1) saveCount = 1;

    bool restoreClip = false;

    while (mSaveCount > saveCount) {
        restoreClip |= restoreSnapshot();
    }

    if (restoreClip) {
        setScissorFromClip();
        restoreSnapshot();
    }
}

@@ -267,12 +261,11 @@ bool OpenGLRenderer::restoreSnapshot() {
    }
    mSnapshot = previous;

    if (!skip) {
        return restoreClip;
    } else {
        bool restorePreviousClip = restoreSnapshot();
        return restoreClip || restorePreviousClip;
    if (restoreClip) {
        setScissorFromClip();
    }

    return restoreClip;
}

///////////////////////////////////////////////////////////////////////////////
@@ -339,21 +332,15 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
    snapshot->layer = layer;
    snapshot->fbo = layer->fbo;

    // Creates a new snapshot to draw into the FBO
    saveSnapshot();
    mSaveCount--;

    mSnapshot->skip = true;
    mSnapshot->transform.loadTranslate(-left, -top, 0.0f);
    mSnapshot->setClip(0.0f, 0.0f, right - left, bottom - top);
    mSnapshot->viewport.set(0.0f, 0.0f, right - left, bottom - top);
    mSnapshot->height = bottom - top;
    snapshot->transform.loadTranslate(-left, -top, 0.0f);
    snapshot->setClip(0.0f, 0.0f, right - left, bottom - top);
    snapshot->viewport.set(0.0f, 0.0f, right - left, bottom - top);
    snapshot->height = bottom - top;
    snapshot->flags |= Snapshot::kFlagDirtyOrtho;
    snapshot->orthoMatrix.load(mOrthoMatrix);

    setScissorFromClip();

    mSnapshot->flags = Snapshot::kFlagDirtyOrtho | Snapshot::kFlagClipSet;
    mSnapshot->orthoMatrix.load(mOrthoMatrix);

    // Change the ortho projection
    glViewport(0, 0, right - left, bottom - top);
    // Don't flip the FBO, it will get flipped when drawing back to the framebuffer
@@ -594,6 +581,12 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);

    uint32_t color = paint->getColor();
    const GLfloat a = alpha / 255.0f;
    const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
    const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
    const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;

    mFontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()), paint->getTextSize());
    if (mHasShadow) {
        glActiveTexture(gTextureUnits[0]);
@@ -601,19 +594,13 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
                count, mShadowRadius);
        const AutoTexture autoCleanup(shadow);

        setupShadow(shadow, x, y, mode);
        setupShadow(shadow, x, y, mode, a);

        // Draw the mesh
        glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
        glDisableVertexAttribArray(mCurrentProgram->getAttrib("texCoords"));
    }

    uint32_t color = paint->getColor();
    const GLfloat a = alpha / 255.0f;
    const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
    const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
    const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;

    GLuint textureUnit = 0;
    glActiveTexture(gTextureUnits[textureUnit]);

@@ -705,11 +692,12 @@ void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
///////////////////////////////////////////////////////////////////////////////

void OpenGLRenderer::setupShadow(const ShadowTexture* texture, float x, float y,
        SkXfermode::Mode mode) {
        SkXfermode::Mode mode, float alpha) {
    const float sx = x - texture->left + mShadowDx;
    const float sy = y - texture->top + mShadowDy;

    const GLfloat a = ((mShadowColor >> 24) & 0xFF) / 255.0f;
    const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
    const GLfloat a = shadowAlpha < 255 ? shadowAlpha / 255.0f : alpha;
    const GLfloat r = a * ((mShadowColor >> 16) & 0xFF) / 255.0f;
    const GLfloat g = a * ((mShadowColor >>  8) & 0xFF) / 255.0f;
    const GLfloat b = a * ((mShadowColor      ) & 0xFF) / 255.0f;
+4 −3
Original line number Diff line number Diff line
@@ -120,8 +120,7 @@ private:
    /**
     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
     *
     * @return True if the clip should be also reapplied by calling
     *         #setScissorFromClip().
     * @return True if the clip was modified.
     */
    bool restoreSnapshot();

@@ -232,8 +231,10 @@ private:
     * @param x The x coordinate of the shadow
     * @param y The y coordinate of the shadow
     * @param mode The blending mode
     * @param alpha The alpha value
     */
    void setupShadow(const ShadowTexture* texture, float x, float y, SkXfermode::Mode mode);
    void setupShadow(const ShadowTexture* texture, float x, float y, SkXfermode::Mode mode,
            float alpha);

    /**
     * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
+1 −8
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ namespace uirenderer {
 */
class Snapshot: public LightRefBase<Snapshot> {
public:
    Snapshot(): skip(false), flags(0), previous(NULL), layer(NULL), fbo(0) { }
    Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0) { }

    /**
     * Copies the specified snapshot. Only the transform and clip rectangle
@@ -54,7 +54,6 @@ public:
            height(s->height),
            transform(s->transform),
            clipRect(s->clipRect),
            skip(false),
            flags(0),
            previous(s),
            layer(NULL),
@@ -165,12 +164,6 @@ public:
     */
    Rect clipRect;

    /**
     * This snapshot should be skipped. Snapshots marked as skipped are
     * created by the renderer and should be hidden from the user.
     */
    bool skip;

    /**
     * Dirty flags.
     */
+2 −0
Original line number Diff line number Diff line
@@ -73,7 +73,9 @@ public class TextActivity extends Activity {
            mLargePaint.setShadowLayer(2.5f, 3.0f, 3.0f, 0xff000000);
            canvas.drawText("Hello OpenGL renderer!", 100, 400, mLargePaint);
            mLargePaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff00ff00);
            mLargePaint.setAlpha(100);
            canvas.drawText("Hello OpenGL renderer!", 100, 500, mLargePaint);
            mLargePaint.setAlpha(255);
            mLargePaint.clearShadowLayer();
            
            canvas.drawText("Hello OpenGL renderer!", 500, 40, mStrikePaint);