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

Commit 30036092 authored by Chris Craik's avatar Chris Craik
Browse files

Glop path texture support

Change-Id: I505eb05991ca4c9b2e01e49988b8f962fad51462
parent 5b14d989
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ class RoundRectClipState;
 * are enabled/disabled dynamically based on mesh content.
 */
enum VertexAttribFlags {
    // NOTE: position attribute always enabled
    kNone_Attrib = 0,
    kTextureCoord_Attrib = 1 << 0,
    kColor_Attrib = 1 << 1,
@@ -61,9 +60,6 @@ enum VertexAttribFlags {
 */
// TODO: PREVENT_COPY_AND_ASSIGN(...) or similar
struct Glop {
    Rect bounds;
    const RoundRectClipState* roundRectClipState;

    /*
     * Stores mesh - vertex and index data.
     *
@@ -85,8 +81,10 @@ struct Glop {

    struct Fill {
        Program* program;

        Texture* texture;
        GLenum textureFilter;
        GLenum textureClamp;

        bool colorEnabled;
        FloatColor color;
@@ -113,11 +111,24 @@ struct Glop {
        bool fudgingOffset;
    } transform;

    const RoundRectClipState* roundRectClipState;

    /**
     * Blending to be used by this draw - both GL_NONE if blending is disabled.
     *
     * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib
     */
    struct Blend {
        GLenum src;
        GLenum dst;
    } blend;

    /**
     * Bounds of the drawing command in layer space. Only mapped into layer
     * space once GlopBuilder::build() is called.
     */
    Rect bounds;

    /**
     * Additional render state to enumerate:
     * - scissor + (bits for whether each of LTRB needed?)
+24 −2
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture, bool isAlphaMask

    mOutGlop->fill.texture = &texture;
    mOutGlop->fill.textureFilter = PaintUtils::getFilter(paint);
    mOutGlop->fill.textureClamp = GL_CLAMP_TO_EDGE;

    if (paint) {
        int color = paint->getColor();
@@ -289,7 +290,8 @@ GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) {
    REQUIRE_STAGES(kMeshStage);

    mOutGlop->fill.texture = nullptr;
    mOutGlop->fill.textureFilter = GL_NEAREST;
    mOutGlop->fill.textureFilter = GL_INVALID_ENUM;
    mOutGlop->fill.textureClamp = GL_INVALID_ENUM;

    setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()),
            paint.getShader(), paint.getColorFilter());
@@ -297,6 +299,27 @@ GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) {
    return *this;
}

GlopBuilder& GlopBuilder::setFillPathTexturePaint(Texture& texture,
        const SkPaint& paint, float alphaScale) {
    TRIGGER_STAGE(kFillStage);
    REQUIRE_STAGES(kMeshStage);

    mOutGlop->fill.texture = &texture;

    //specify invalid, since these are always static for path textures
    mOutGlop->fill.textureFilter = GL_INVALID_ENUM;
    mOutGlop->fill.textureClamp = GL_INVALID_ENUM;

    setFill(paint.getColor(), alphaScale, PaintUtils::getXfermode(paint.getXfermode()),
            paint.getShader(), paint.getColorFilter());

    mDescription.modulate = mOutGlop->fill.color.a < 1.0f
            || mOutGlop->fill.color.r > 0.0f
            || mOutGlop->fill.color.g > 0.0f
            || mOutGlop->fill.color.b > 0.0f;
    return *this;
}

////////////////////////////////////////////////////////////////////////////////
// Transform
////////////////////////////////////////////////////////////////////////////////
@@ -311,7 +334,6 @@ GlopBuilder& GlopBuilder::setTransformClip(const Matrix4& ortho,
    return *this;
}


////////////////////////////////////////////////////////////////////////////////
// ModelView
////////////////////////////////////////////////////////////////////////////////
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ public:
    GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale);
    GlopBuilder& setFillTexturePaint(Texture& texture, bool isAlphaMaskTexture,
            const SkPaint* paint, float alphaScale);
    GlopBuilder& setFillPathTexturePaint(Texture& texture,
            const SkPaint& paint, float alphaScale);

    GlopBuilder& setTransformClip(const Matrix4& ortho, const Matrix4& transform, bool fudgingOffset);

+22 −8
Original line number Diff line number Diff line
@@ -2505,7 +2505,7 @@ void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
    mDirty = true;
}

void OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture,
void OpenGLRenderer::drawShape(float left, float top, PathTexture* texture,
        const SkPaint* paint) {
    if (!texture) return;
    const AutoTexture autoCleanup(texture);
@@ -2528,7 +2528,7 @@ void OpenGLRenderer::drawRoundRect(float left, float top, float right, float bot

    if (p->getPathEffect() != nullptr) {
        mCaches.textureState().activateTexture(0);
        const PathTexture* texture = mCaches.pathCache.getRoundRect(
        PathTexture* texture = mCaches.pathCache.getRoundRect(
                right - left, bottom - top, rx, ry, p);
        drawShape(left, top, texture, p);
    } else {
@@ -2546,7 +2546,7 @@ void OpenGLRenderer::drawCircle(float x, float y, float radius, const SkPaint* p
    }
    if (p->getPathEffect() != nullptr) {
        mCaches.textureState().activateTexture(0);
        const PathTexture* texture = mCaches.pathCache.getCircle(radius, p);
        PathTexture* texture = mCaches.pathCache.getCircle(radius, p);
        drawShape(x - radius, y - radius, texture, p);
    } else {
        SkPath path;
@@ -2569,7 +2569,7 @@ void OpenGLRenderer::drawOval(float left, float top, float right, float bottom,

    if (p->getPathEffect() != nullptr) {
        mCaches.textureState().activateTexture(0);
        const PathTexture* texture = mCaches.pathCache.getOval(right - left, bottom - top, p);
        PathTexture* texture = mCaches.pathCache.getOval(right - left, bottom - top, p);
        drawShape(left, top, texture, p);
    } else {
        SkPath path;
@@ -2593,7 +2593,7 @@ void OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
    // TODO: support fills (accounting for concavity if useCenter && sweepAngle > 180)
    if (p->getStyle() != SkPaint::kStroke_Style || p->getPathEffect() != nullptr || useCenter) {
        mCaches.textureState().activateTexture(0);
        const PathTexture* texture = mCaches.pathCache.getArc(right - left, bottom - top,
        PathTexture* texture = mCaches.pathCache.getArc(right - left, bottom - top,
                startAngle, sweepAngle, useCenter, p);
        drawShape(left, top, texture, p);
        return;
@@ -2630,7 +2630,7 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom,
        if (p->getPathEffect() != nullptr || p->getStrokeJoin() != SkPaint::kMiter_Join ||
                p->getStrokeMiter() != SkPaintDefaults_MiterLimit) {
            mCaches.textureState().activateTexture(0);
            const PathTexture* texture =
            PathTexture* texture =
                    mCaches.pathCache.getRect(right - left, bottom - top, p);
            drawShape(left, top, texture, p);
        } else {
@@ -2974,7 +2974,7 @@ void OpenGLRenderer::drawPath(const SkPath* path, const SkPaint* paint) {

    mCaches.textureState().activateTexture(0);

    const PathTexture* texture = mCaches.pathCache.get(path, paint);
    PathTexture* texture = mCaches.pathCache.get(path, paint);
    if (!texture) return;
    const AutoTexture autoCleanup(texture);

@@ -3107,12 +3107,26 @@ Texture* OpenGLRenderer::getTexture(const SkBitmap* bitmap) {
    return texture;
}

void OpenGLRenderer::drawPathTexture(const PathTexture* texture,
void OpenGLRenderer::drawPathTexture(PathTexture* texture,
        float x, float y, const SkPaint* paint) {
    if (quickRejectSetupScissor(x, y, x + texture->width, y + texture->height)) {
        return;
    }

    if (USE_GLOPS && !paint->getShader()) {
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
        aBuilder.setMeshTexturedUnitQuad(nullptr, true)
                .setFillPathTexturePaint(*texture, *paint, currentSnapshot()->alpha)
                .setTransformClip(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false)
                .setModelViewMapUnitToRect(Rect(x, y, x + texture->width, y + texture->height))
                .setRoundRectClipState(currentSnapshot()->roundRectClipState)
                .build();
        renderGlop(glop);
        return;
    }


    int alpha;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);
+2 −2
Original line number Diff line number Diff line
@@ -690,7 +690,7 @@ private:
     * @param texture The texture reprsenting the shape
     * @param paint The paint to draw the shape with
     */
    void drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
    void drawShape(float left, float top, PathTexture* texture, const SkPaint* paint);

    /**
     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
@@ -819,7 +819,7 @@ private:
     * @param y The y coordinate where the texture will be drawn
     * @param paint The paint to draw the texture with
     */
     void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint);
     void drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint);

    /**
     * Resets the texture coordinates stored in mMeshVertices. Setting the values
Loading