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

Commit ecad24b4 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "GlopBuilder, and test app refactor"

parents e8d05b5b 03188874
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@ LOCAL_SRC_FILES := \
    CanvasState.cpp \
    ClipArea.cpp \
    DamageAccumulator.cpp \
    DisplayList.cpp \
    DeferredDisplayList.cpp \
    DeferredLayerUpdater.cpp \
    DisplayList.cpp \
    DisplayListRenderer.cpp \
    Dither.cpp \
    DrawProfiler.cpp \
@@ -44,6 +44,7 @@ LOCAL_SRC_FILES := \
    FboCache.cpp \
    FontRenderer.cpp \
    GammaFontRenderer.cpp \
    GlopBuilder.cpp \
    GradientCache.cpp \
    Image.cpp \
    Interpolator.cpp \
@@ -70,9 +71,9 @@ LOCAL_SRC_FILES := \
    Snapshot.cpp \
    SpotShadow.cpp \
    TessellationCache.cpp \
    TextDropShadowCache.cpp \
    Texture.cpp \
    TextureCache.cpp \
    TextDropShadowCache.cpp
    TextureCache.cpp

intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)

+8 −9
Original line number Diff line number Diff line
@@ -23,10 +23,13 @@

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <SkXfermode.h>

namespace android {
namespace uirenderer {

class Program;

/*
 * Enumerates optional vertex attributes
 *
@@ -53,18 +56,16 @@ struct Glop {
    Rect bounds;

    struct Mesh {
        VertexAttribFlags vertexFlags = static_cast<VertexAttribFlags>(0);
        VertexAttribFlags vertexFlags;
        GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
        GLuint vertexBufferObject = 0;
        GLuint indexBufferObject = 0;
        GLuint vertexBufferObject;
        GLuint indexBufferObject;
        int vertexCount;
        GLsizei stride;
    } mesh;

    struct Fill {
        Program* program;
        GLuint shaderId;
        GLuint textureId;

        struct Color {
            float a, r, g, b;
@@ -89,10 +90,8 @@ struct Glop {
    } transform;

    struct Blend {
        static const SkXfermode::Mode kDisable =
                static_cast<SkXfermode::Mode>(SkXfermode::kLastMode + 1);
        SkXfermode::Mode mode;
        bool swapSrcDst;
        GLenum src;
        GLenum dst;
    } blend;

    /**
+133 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "GlopBuilder.h"

#include "Caches.h"
#include "Glop.h"
#include "Matrix.h"
#include "Texture.h"
#include "renderstate/MeshState.h"
#include "renderstate/RenderState.h"
#include "utils/PaintUtils.h"

#include <GLES2/gl2.h>
#include <SkPaint.h>

namespace android {
namespace uirenderer {

GlopBuilder::GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop)
        : mRenderState(renderState)
        , mCaches(caches)
        , mOutGlop(outGlop){
}

GlopBuilder& GlopBuilder::setMeshUnitQuad() {
    mOutGlop->mesh.vertexFlags = static_cast<VertexAttribFlags>(0);
    mOutGlop->mesh.primitiveMode = GL_TRIANGLE_STRIP;
    mOutGlop->mesh.vertexBufferObject = mRenderState.meshState().getUnitQuadVBO();
    mOutGlop->mesh.indexBufferObject = 0;
    mOutGlop->mesh.vertexCount = 4;
    mOutGlop->mesh.stride = kTextureVertexStride;
    return *this;
}

GlopBuilder& GlopBuilder::setTransformAndRect(ModelViewMode mode,
        const Matrix4& ortho, const Matrix4& transform,
        float left, float top, float right, float bottom, bool offset) {
    mOutGlop->transform.ortho.load(ortho);

    mOutGlop->transform.modelView.loadTranslate(left, top, 0.0f);
    if (mode == kModelViewMode_TranslateAndScale) {
        mOutGlop->transform.modelView.scale(right - left, bottom - top, 1.0f);
    }

    mOutGlop->transform.canvas.load(transform);

    mOutGlop->transform.offset = offset;

    mOutGlop->bounds.set(left, top, right, bottom);
    mOutGlop->transform.canvas.mapRect(mOutGlop->bounds);
    return *this;
}

GlopBuilder& GlopBuilder::setPaint(const SkPaint* paint, float alphaScale) {
    // TODO: support null paint
    const SkShader* shader = paint->getShader();
    const SkColorFilter* colorFilter = paint->getColorFilter();

    SkXfermode::Mode mode = PaintUtils::getXfermode(paint->getXfermode());
    if (mode != SkXfermode::kClear_Mode) {
        int color = paint->getColor();
        float alpha = (SkColorGetA(color) / 255.0f) * alphaScale;
        if (shader) {
            // shader discards color channels
            color |= 0x00FFFFFF;
        }
        mOutGlop->fill.color = {
                alpha,
                alpha * SkColorGetR(color),
                alpha * SkColorGetG(color),
                alpha * SkColorGetB(color)
        };
    } else {
        mOutGlop->fill.color = { 1, 0, 0, 0 };
    }
    const bool SWAP_SRC_DST = false;
    const bool HAS_FRAMEBUFFER_FETCH = false; //mExtensions.hasFramebufferFetch();

    mOutGlop->blend = {GL_ZERO, GL_ZERO};
    if (mOutGlop->fill.color.a < 1.0f
            || (shader && !shader->isOpaque())
            || PaintUtils::isBlendedColorFilter(colorFilter)
            || mode != SkXfermode::kSrcOver_Mode) {
        if (CC_LIKELY(mode <= SkXfermode::kScreen_Mode)) {
            Blend::getFactors(mode, SWAP_SRC_DST,
                    &mOutGlop->blend.src, &mOutGlop->blend.dst);
        } else {
            // These blend modes are not supported by OpenGL directly and have
            // to be implemented using shaders. Since the shader will perform
            // the blending, don't enable GL blending off here
            // If the blend mode cannot be implemented using shaders, fall
            // back to the default SrcOver blend mode instead
            if (CC_UNLIKELY(HAS_FRAMEBUFFER_FETCH)) {
                mDescription.framebufferMode = mode;
                mDescription.swapSrcDst = SWAP_SRC_DST;
                // blending in shader, don't enable
            } else {
                // unsupported
                Blend::getFactors(SkXfermode::kSrcOver_Mode, SWAP_SRC_DST,
                        &mOutGlop->blend.src, &mOutGlop->blend.dst);
            }
        }
    }

    return *this;
}

GlopBuilder& GlopBuilder::setTexture(Texture* texture) {
    LOG_ALWAYS_FATAL("not yet supported");
    return *this;
}

void GlopBuilder::build() {
    mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
    mOutGlop->fill.program = mCaches.programCache.get(mDescription);
}

} /* namespace uirenderer */
} /* namespace android */
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef RENDERSTATE_GLOPBUILDER_H
#define RENDERSTATE_GLOPBUILDER_H

#include "OpenGLRenderer.h"
#include "Program.h"
#include "utils/Macros.h"

class SkPaint;

namespace android {
namespace uirenderer {

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

class GlopBuilder {
    PREVENT_COPY_AND_ASSIGN(GlopBuilder);
public:
    GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop);
    GlopBuilder& setMeshUnitQuad();
    GlopBuilder& setTransformAndRect(ModelViewMode mode,
            const Matrix4& ortho, const Matrix4& transform,
            float left, float top, float right, float bottom, bool offset);
    GlopBuilder& setPaint(const SkPaint* paint, float alphaScale);
    GlopBuilder& setTexture(Texture* texture);
    void build();
private:
    ProgramDescription mDescription;
    RenderState& mRenderState;
    Caches& mCaches;
    Glop* mOutGlop;
};

} /* namespace uirenderer */
} /* namespace android */

#endif // RENDERSTATE_GLOPBUILDER_H
+7 −4
Original line number Diff line number Diff line
@@ -19,10 +19,13 @@
#include "DeferredDisplayList.h"
#include "DisplayListRenderer.h"
#include "GammaFontRenderer.h"
#include "Glop.h"
#include "GlopBuilder.h"
#include "Patch.h"
#include "PathTessellator.h"
#include "Properties.h"
#include "RenderNode.h"
#include "renderstate/MeshState.h"
#include "renderstate/RenderState.h"
#include "ShadowTessellator.h"
#include "SkiaShader.h"
@@ -100,7 +103,7 @@ OpenGLRenderer::OpenGLRenderer(RenderState& renderState)
    memset(&mDrawModifiers, 0, sizeof(mDrawModifiers));
    mDrawModifiers.mOverrideLayerAlpha = 1.0f;

    memcpy(mMeshVertices, kMeshVertices, sizeof(kMeshVertices));
    memcpy(mMeshVertices, kUnitQuadVertices, sizeof(kUnitQuadVertices));
}

OpenGLRenderer::~OpenGLRenderer() {
@@ -1703,9 +1706,9 @@ void OpenGLRenderer::setupDrawBlending(const SkPaint* paint, bool blend, bool sw
    // When the blending mode is kClear_Mode, we need to use a modulate color
    // argb=1,0,0,0
    accountForClear(mode);
    blend |= (mColorSet && mColorA < 1.0f) ||
            (getShader(paint) && !getShader(paint)->isOpaque()) ||
            PaintUtils::isBlendedColorFilter(getColorFilter(paint));
    blend |= (mColorSet && mColorA < 1.0f)
            || (getShader(paint) && !getShader(paint)->isOpaque())
            || PaintUtils::isBlendedColorFilter(getColorFilter(paint));
    chooseBlending(blend, mode, mDescription, swapSrcDst);
}

Loading