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

Commit 922d3a7f authored by Chris Craik's avatar Chris Craik
Browse files

Glop SkiaShader support

Change-Id: I894a0b62701bd02367ab970813e4c332147351a2
parent 91d415d8
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -18,10 +18,19 @@

#include "utils/Macros.h"

#include <stdint.h>

namespace android {
namespace uirenderer {

struct FloatColor {
    void set(uint32_t color) {
        a = ((color >> 24) & 0xff) / 255.0f;
        r = a * ((color >> 16) & 0xff) / 255.0f;
        g = a * ((color >>  8) & 0xff) / 255.0f;
        b = a * ((color      ) & 0xff) / 255.0f;
    }

    float r;
    float g;
    float b;
+5 −5
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@

#include "FloatColor.h"
#include "Matrix.h"
#include "Program.h"
#include "Rect.h"
#include "SkiaShader.h"
#include "utils/Macros.h"

#include <GLES2/gl2.h>
@@ -31,6 +33,7 @@ namespace uirenderer {

class Program;
class RoundRectClipState;
class Texture;

/*
 * Enumerates optional vertex attributes
@@ -89,11 +92,6 @@ struct Glop {
        bool colorEnabled;
        FloatColor color;

        /* TODO
        union shader {
            //...
        }; TODO
        */
        ProgramDescription::ColorFilterMode filterMode;
        union Filter {
            struct Matrix {
@@ -102,6 +100,8 @@ struct Glop {
            } matrix;
            FloatColor color;
        } filter;

        SkiaShaderData skiaShaderData;
    } fill;

    struct Transform {
+8 −7
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ namespace uirenderer {
    LOG_ALWAYS_FATAL_IF((mStageFlags & (requiredFlags)) != (requiredFlags), \
            "not prepared for current stage")

static void setUnitQuadTextureCoords(Rect uvs, TextureVertex* quadVertex) {;
static void setUnitQuadTextureCoords(Rect uvs, TextureVertex* quadVertex) {
    TextureVertex::setUV(quadVertex++, uvs.left, uvs.top);
    TextureVertex::setUV(quadVertex++, uvs.right, uvs.top);
    TextureVertex::setUV(quadVertex++, uvs.left, uvs.bottom);
@@ -49,6 +49,7 @@ static void setUnitQuadTextureCoords(Rect uvs, TextureVertex* quadVertex) {;
GlopBuilder::GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop)
        : mRenderState(renderState)
        , mCaches(caches)
        , mShader(nullptr)
        , mOutGlop(outGlop) {
    mStageFlags = kInitialStage;
}
@@ -192,12 +193,7 @@ void GlopBuilder::setFill(int color, float alphaScale, SkXfermode::Mode mode,
            }
        }
    }

    if (shader) {
        SkiaShader::describe(&mCaches, mDescription, mCaches.extensions(), *shader);
        // TODO: store shader data
        LOG_ALWAYS_FATAL("shaders not yet supported");
    }
    mShader = shader; // shader resolved in ::build()

    if (colorFilter) {
        SkColor color;
@@ -394,6 +390,11 @@ GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundR
void GlopBuilder::build() {
    REQUIRE_STAGES(kAllStages);

    // serialize shader info into ShaderData
    GLuint textureUnit = mOutGlop->fill.texture ? 1 : 0;
    SkiaShader::store(mCaches, mShader, mOutGlop->transform.modelView,
            &textureUnit, &mDescription, &(mOutGlop->fill.skiaShaderData));

    mOutGlop->fill.program = mCaches.programCache.get(mDescription);
    mOutGlop->transform.canvas.mapRect(mOutGlop->bounds);

+3 −1
Original line number Diff line number Diff line
@@ -21,16 +21,17 @@
#include "utils/Macros.h"

class SkPaint;
class SkShader;

namespace android {
namespace uirenderer {

class Caches;
struct Glop;
class Matrix4;
class RenderState;
class Texture;
class VertexBuffer;
struct Glop;

class GlopBuilder {
    PREVENT_COPY_AND_ASSIGN(GlopBuilder);
@@ -74,6 +75,7 @@ private:
    ProgramDescription mDescription;
    RenderState& mRenderState;
    Caches& mCaches;
    const SkShader* mShader;
    Glop* mOutGlop;
};

+7 −21
Original line number Diff line number Diff line
@@ -62,20 +62,6 @@
namespace android {
namespace uirenderer {

///////////////////////////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
// Functions
///////////////////////////////////////////////////////////////////////////////

template<typename T>
static inline T min(T a, T b) {
    return a < b ? a : b;
}

///////////////////////////////////////////////////////////////////////////////
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////
@@ -1199,7 +1185,7 @@ void OpenGLRenderer::dirtyLayerUnchecked(Rect& bounds, Region* region) {
void OpenGLRenderer::issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount) {
    GLsizei elementsCount = quadsCount * 6;
    while (elementsCount > 0) {
        GLsizei drawCount = min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
        GLsizei drawCount = MathUtils::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);

        setupDrawIndexedVertices(&mesh[0].x);
        glDrawElements(GL_TRIANGLES, drawCount, GL_UNSIGNED_SHORT, nullptr);
@@ -1970,7 +1956,7 @@ void OpenGLRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t
}

void OpenGLRenderer::drawAlphaBitmap(Texture* texture, const SkPaint* paint) {
    if (USE_GLOPS && (!paint || !paint->getShader())) {
    if (USE_GLOPS) {
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
        aBuilder.setMeshTexturedUnitQuad(texture->uvMapper, true)
@@ -2358,7 +2344,7 @@ void OpenGLRenderer::drawVertexBuffer(float translateX, float translateY,
        return;
    }

    if (USE_GLOPS && !paint->getShader()) {
    if (USE_GLOPS) {
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
        bool fudgeOffset = displayFlags & kVertexBuffer_Offset;
@@ -3052,7 +3038,7 @@ void OpenGLRenderer::drawLayer(Layer* layer, float x, float y) {
            GLsizei elementsCount = layer->meshElementCount;

            while (elementsCount > 0) {
                GLsizei drawCount = min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
                GLsizei drawCount = MathUtils::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);

                setupDrawMeshIndices(&mesh[0].x, &mesh[0].u);
                DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate,
@@ -3113,7 +3099,7 @@ void OpenGLRenderer::drawPathTexture(PathTexture* texture,
        return;
    }

    if (USE_GLOPS && !paint->getShader()) {
    if (USE_GLOPS) {
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
        aBuilder.setMeshTexturedUnitQuad(nullptr, true)
@@ -3274,7 +3260,7 @@ void OpenGLRenderer::drawColorRects(const float* rects, int count, const SkPaint
        return;
    }

    if (USE_GLOPS && !paint->getShader()) {
    if (USE_GLOPS) {
        const Matrix4& transform = ignoreTransform ? Matrix4::identity() : *currentTransform();
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
@@ -3320,7 +3306,7 @@ void OpenGLRenderer::drawColorRects(const float* rects, int count, const SkPaint
void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
        const SkPaint* paint, bool ignoreTransform) {

    if (USE_GLOPS && !paint->getShader()) {
    if (USE_GLOPS) {
        const Matrix4& transform = ignoreTransform ? Matrix4::identity() : *currentTransform();
        Glop glop;
        GlopBuilder aBuilder(mRenderState, mCaches, &glop);
Loading