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

Commit c95c8d6b authored by Romain Guy's avatar Romain Guy
Browse files

Add support for non AA lines.

Change-Id: Id5200e94815404d62760437d0d2dbb0a9276c700
parent 31529ff7
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -80,8 +80,12 @@ public:
        glDeleteTextures(1, &mTexture);
    }

    inline float getLength(float x1, float y1, float x2, float y2) {
        return sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    }

    void update(float x1, float y1, float x2, float y2, float lineWidth, float& tx, float& ty) {
        const float length = sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
        const float length = getLength(x1, y1, x2, y2);
        const float half = lineWidth * 0.5f;

        mPatch->updateVertices(gLineTextureWidth, gLineTextureHeight,
@@ -89,7 +93,7 @@ public:
                mXDivs, mYDivs, mXDivsCount, mYDivsCount);

        tx = -gLineAABias;
        ty = -half - gLineAABias;
        ty = lineWidth == 1.0f ? -gLineAABias : -half - gLineAABias;
    }

    inline GLvoid* getVertices() const {
+32 −10
Original line number Diff line number Diff line
@@ -612,16 +612,29 @@ void OpenGLRenderer::drawLines(float* points, int count, const SkPaint* paint) {
    const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
    const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;

    const bool isAA = paint->isAntiAlias();
    if (isAA) {
        GLuint textureUnit = 0;
        setupTextureAlpha8(mLine.getTexture(), 0, 0, textureUnit, 0.0f, 0.0f, r, g, b, a,
                mode, false, true, mLine.getVertices(), mLine.getTexCoords());
    } else {
        setupColorRect(0.0f, 0.0f, 1.0f, 1.0f, r, g, b, a, mode, false);
    }

    const float strokeWidth = paint->getStrokeWidth();
    const GLsizei elementsCount = isAA ? mLine.getElementsCount() : gMeshCount;
    const GLenum drawMode = isAA ? GL_TRIANGLES : GL_TRIANGLE_STRIP;

    for (int i = 0; i < count; i += 4) {
        float tx = 0.0f;
        float ty = 0.0f;

        if (isAA) {
            mLine.update(points[i], points[i + 1], points[i + 2], points[i + 3],
                paint->getStrokeWidth(), tx, ty);
                    strokeWidth, tx, ty);
        } else {
            ty = -strokeWidth * 0.5f;
        }

        const float dx = points[i + 2] - points[i];
        const float dy = points[i + 3] - points[i + 1];
@@ -633,13 +646,17 @@ void OpenGLRenderer::drawLines(float* points, int count, const SkPaint* paint) {
            mModelView.rotate(angle * RAD_TO_DEG, 0.0f, 0.0f, 1.0f);
        }
        mModelView.translate(tx, ty, 0.0f);
        if (!isAA) {
            float length = mLine.getLength(points[i], points[i + 1], points[i + 2], points[i + 3]);
            mModelView.scale(length, strokeWidth, 1.0f);
        }
        mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);

        if (mShader) {
            mShader->updateTransforms(mCaches.currentProgram, mModelView, *mSnapshot);
        }

        glDrawArrays(GL_TRIANGLES, 0, mLine.getElementsCount());
        glDrawArrays(drawMode, 0, elementsCount);
    }

    glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
@@ -978,6 +995,14 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot
    const GLfloat g = a * ((color >>  8) & 0xFF) / 255.0f;
    const GLfloat b = a * ((color      ) & 0xFF) / 255.0f;

    setupColorRect(left, top, right, bottom, r, g, b, a, mode, ignoreTransform);

    // Draw the mesh
    glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
}

void OpenGLRenderer::setupColorRect(float left, float top, float right, float bottom,
        float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform) {
    GLuint textureUnit = 0;

    // Describe the required shaders
@@ -990,7 +1015,7 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot
    }

    // Setup the blending mode
    chooseBlending(alpha < 255 || (mShader && mShader->blend()), mode, description);
    chooseBlending(a < 1.0f || (mShader && mShader->blend()), mode, description);

    // Build and use the appropriate shader
    useProgram(mCaches.programCache.get(description));
@@ -1017,9 +1042,6 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot
    if (mColorFilter) {
        mColorFilter->setupProgram(mCaches.currentProgram);
    }

    // Draw the mesh
    glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
}

void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
+6 −0
Original line number Diff line number Diff line
@@ -188,6 +188,12 @@ private:
    void drawColorRect(float left, float top, float right, float bottom,
            int color, SkXfermode::Mode mode, bool ignoreTransform = false);

    /**
     * Setups shaders to draw a colored rect.
     */
    void setupColorRect(float left, float top, float right, float bottom,
            float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform);

    /**
     * Draws a textured rectangle with the specified texture. The specified coordinates
     * are transformed by the current snapshot's transform matrix.