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

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

Merge "Move more GL state management to RenderState and its directory"

parents 2920f0f5 96a5c4c7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -7,8 +7,11 @@ LOCAL_CLANG_CFLAGS += \
LOCAL_SRC_FILES := \
    font/CacheTexture.cpp \
    font/Font.cpp \
    renderstate/MeshState.cpp \
    renderstate/PixelBufferState.cpp \
    renderstate/RenderState.cpp \
    renderstate/Scissor.cpp \
    renderstate/Stencil.cpp \
    renderthread/CanvasContext.cpp \
    renderthread/DrawFrameTask.cpp \
    renderthread/EglManager.cpp \
@@ -63,7 +66,6 @@ LOCAL_SRC_FILES := \
    SkiaShader.cpp \
    Snapshot.cpp \
    SpotShadow.cpp \
    Stencil.cpp \
    TessellationCache.cpp \
    Texture.cpp \
    TextureCache.cpp \
+16 −180
Original line number Diff line number Diff line
@@ -29,12 +29,10 @@
#include <utils/String8.h>

namespace android {

using namespace uirenderer;
ANDROID_SINGLETON_STATIC_INSTANCE(Caches);

namespace uirenderer {

Caches* Caches::sInstance = nullptr;

///////////////////////////////////////////////////////////////////////////////
// Macros
///////////////////////////////////////////////////////////////////////////////
@@ -49,8 +47,12 @@ namespace uirenderer {
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////

Caches::Caches(): Singleton<Caches>(),
        mExtensions(Extensions::getInstance()), mInitialized(false), mRenderState(nullptr) {
Caches::Caches(RenderState& renderState)
        : patchCache(renderState)
        , mRenderState(&renderState)
        , mExtensions(Extensions::getInstance())
        , mInitialized(false) {
    INIT_LOGD("Creating OpenGL renderer caches");
    init();
    initFont();
    initConstraints();
@@ -60,7 +62,8 @@ Caches::Caches(): Singleton<Caches>(),
    initTempProperties();

    mDebugLevel = readDebugLevel();
    ALOGD("Enabling debug mode %d", mDebugLevel);
    ALOGD_IF(mDebugLevel != kDebugDisabled,
            "Enabling debug mode %d", mDebugLevel);
}

bool Caches::init() {
@@ -68,25 +71,10 @@ bool Caches::init() {

    ATRACE_NAME("Caches::init");

    glGenBuffers(1, &meshBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);

    mCurrentBuffer = meshBuffer;
    mCurrentIndicesBuffer = 0;
    mCurrentPositionPointer = this;
    mCurrentPositionStride = 0;
    mCurrentTexCoordsPointer = this;
    mCurrentPixelBuffer = 0;

    mTexCoordsArrayEnabled = false;

    glActiveTexture(gTextureUnits[0]);
    mTextureUnit = 0;

    mRegionMesh = nullptr;
    mMeshIndices = 0;
    mShadowStripsIndices = 0;
    blend = false;
    lastSrcMode = GL_ZERO;
    lastDstMode = GL_ZERO;
@@ -98,11 +86,12 @@ bool Caches::init() {
    debugOverdraw = false;
    debugStencilClip = kStencilHide;

    patchCache.init(*this);
    patchCache.init();

    mInitialized = true;

    resetBoundTextures();
    mPixelBufferState.reset(new PixelBufferState());

    return true;
}
@@ -216,17 +205,8 @@ bool Caches::initProperties() {

void Caches::terminate() {
    if (!mInitialized) return;

    glDeleteBuffers(1, &meshBuffer);
    mCurrentBuffer = 0;

    glDeleteBuffers(1, &mMeshIndices);
    mMeshIndices = 0;
    mRegionMesh.release();

    glDeleteBuffers(1, &mShadowStripsIndices);
    mShadowStripsIndices = 0;

    fboCache.clear();

    programCache.clear();
@@ -236,6 +216,8 @@ void Caches::terminate() {

    clearGarbage();

    mPixelBufferState.release();

    mInitialized = false;
}

@@ -366,155 +348,9 @@ void Caches::flush(FlushMode mode) {
}

///////////////////////////////////////////////////////////////////////////////
// VBO
///////////////////////////////////////////////////////////////////////////////

bool Caches::bindMeshBuffer() {
    return bindMeshBuffer(meshBuffer);
}

bool Caches::bindMeshBuffer(const GLuint buffer) {
    if (mCurrentBuffer != buffer) {
        glBindBuffer(GL_ARRAY_BUFFER, buffer);
        mCurrentBuffer = buffer;
        return true;
    }
    return false;
}

bool Caches::unbindMeshBuffer() {
    if (mCurrentBuffer) {
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        mCurrentBuffer = 0;
        return true;
    }
    return false;
}

bool Caches::bindIndicesBufferInternal(const GLuint buffer) {
    if (mCurrentIndicesBuffer != buffer) {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
        mCurrentIndicesBuffer = buffer;
        return true;
    }
    return false;
}

bool Caches::bindQuadIndicesBuffer() {
    if (!mMeshIndices) {
        std::unique_ptr<uint16_t[]> regionIndices(new uint16_t[gMaxNumberOfQuads * 6]);
        for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
            uint16_t quad = i * 4;
            int index = i * 6;
            regionIndices[index    ] = quad;       // top-left
            regionIndices[index + 1] = quad + 1;   // top-right
            regionIndices[index + 2] = quad + 2;   // bottom-left
            regionIndices[index + 3] = quad + 2;   // bottom-left
            regionIndices[index + 4] = quad + 1;   // top-right
            regionIndices[index + 5] = quad + 3;   // bottom-right
        }

        glGenBuffers(1, &mMeshIndices);
        bool force = bindIndicesBufferInternal(mMeshIndices);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
                regionIndices.get(), GL_STATIC_DRAW);
        return force;
    }

    return bindIndicesBufferInternal(mMeshIndices);
}

bool Caches::bindShadowIndicesBuffer() {
    if (!mShadowStripsIndices) {
        std::unique_ptr<uint16_t[]> shadowIndices(new uint16_t[MAX_SHADOW_INDEX_COUNT]);
        ShadowTessellator::generateShadowIndices(shadowIndices.get());
        glGenBuffers(1, &mShadowStripsIndices);
        bool force = bindIndicesBufferInternal(mShadowStripsIndices);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_SHADOW_INDEX_COUNT * sizeof(uint16_t),
            shadowIndices.get(), GL_STATIC_DRAW);
        return force;
    }

    return bindIndicesBufferInternal(mShadowStripsIndices);
}

bool Caches::unbindIndicesBuffer() {
    if (mCurrentIndicesBuffer) {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        mCurrentIndicesBuffer = 0;
        return true;
    }
    return false;
}

///////////////////////////////////////////////////////////////////////////////
// PBO
///////////////////////////////////////////////////////////////////////////////

bool Caches::bindPixelBuffer(const GLuint buffer) {
    if (mCurrentPixelBuffer != buffer) {
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
        mCurrentPixelBuffer = buffer;
        return true;
    }
    return false;
}

bool Caches::unbindPixelBuffer() {
    if (mCurrentPixelBuffer) {
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
        mCurrentPixelBuffer = 0;
        return true;
    }
    return false;
}

///////////////////////////////////////////////////////////////////////////////
// Meshes and textures
// Textures
///////////////////////////////////////////////////////////////////////////////

void Caches::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
    if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) {
        GLuint slot = currentProgram->position;
        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
        mCurrentPositionPointer = vertices;
        mCurrentPositionStride = stride;
    }
}

void Caches::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
    if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) {
        GLuint slot = currentProgram->texCoords;
        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
        mCurrentTexCoordsPointer = vertices;
        mCurrentTexCoordsStride = stride;
    }
}

void Caches::resetVertexPointers() {
    mCurrentPositionPointer = this;
    mCurrentTexCoordsPointer = this;
}

void Caches::resetTexCoordsVertexPointer() {
    mCurrentTexCoordsPointer = this;
}

void Caches::enableTexCoordsVertexArray() {
    if (!mTexCoordsArrayEnabled) {
        glEnableVertexAttribArray(Program::kBindingTexCoords);
        mCurrentTexCoordsPointer = this;
        mTexCoordsArrayEnabled = true;
    }
}

void Caches::disableTexCoordsVertexArray() {
    if (mTexCoordsArrayEnabled) {
        glDisableVertexAttribArray(Program::kBindingTexCoords);
        mTexCoordsArrayEnabled = false;
    }
}

void Caches::activeTexture(GLuint textureUnit) {
    if (mTextureUnit != textureUnit) {
        glActiveTexture(gTextureUnits[textureUnit]);
@@ -614,7 +450,7 @@ void Caches::unregisterFunctors(uint32_t functorCount) {
TextureVertex* Caches::getRegionMesh() {
    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
    if (!mRegionMesh) {
        mRegionMesh.reset(new TextureVertex[gMaxNumberOfQuads * 4]);
        mRegionMesh.reset(new TextureVertex[kMaxNumberOfQuads * 4]);
    }

    return mRegionMesh.get();
+41 −131
Original line number Diff line number Diff line
@@ -21,7 +21,27 @@
    #define LOG_TAG "OpenGLRenderer"
#endif


#include "AssetAtlas.h"
#include "Dither.h"
#include "Extensions.h"
#include "FboCache.h"
#include "GradientCache.h"
#include "LayerCache.h"
#include "PatchCache.h"
#include "ProgramCache.h"
#include "PathCache.h"
#include "RenderBufferCache.h"
#include "renderstate/PixelBufferState.h"
#include "ResourceCache.h"
#include "TessellationCache.h"
#include "TextDropShadowCache.h"
#include "TextureCache.h"
#include "thread/TaskProcessor.h"
#include "thread/TaskManager.h"

#include <vector>
#include <memory>

#include <GLES3/gl3.h>

@@ -33,25 +53,6 @@

#include <SkPath.h>

#include "thread/TaskProcessor.h"
#include "thread/TaskManager.h"

#include "AssetAtlas.h"
#include "Extensions.h"
#include "TextureCache.h"
#include "LayerCache.h"
#include "RenderBufferCache.h"
#include "GradientCache.h"
#include "PatchCache.h"
#include "ProgramCache.h"
#include "PathCache.h"
#include "TessellationCache.h"
#include "TextDropShadowCache.h"
#include "FboCache.h"
#include "ResourceCache.h"
#include "Stencil.h"
#include "Dither.h"

namespace android {
namespace uirenderer {

@@ -64,29 +65,6 @@ class GammaFontRenderer;
// GL ES 2.0 defines that at least 16 texture units must be supported
#define REQUIRED_TEXTURE_UNITS_COUNT 3

// Maximum number of quads that pre-allocated meshes can draw
static const uint32_t gMaxNumberOfQuads = 2048;

// Generates simple and textured vertices
#define FV(x, y, u, v) { x, y, u, v }

// This array is never used directly but used as a memcpy source in the
// OpenGLRenderer constructor
static const TextureVertex gMeshVertices[] = {
        FV(0.0f, 0.0f, 0.0f, 0.0f),
        FV(1.0f, 0.0f, 1.0f, 0.0f),
        FV(0.0f, 1.0f, 0.0f, 1.0f),
        FV(1.0f, 1.0f, 1.0f, 1.0f)
};
static const GLsizei gMeshStride = sizeof(TextureVertex);
static const GLsizei gVertexStride = sizeof(Vertex);
static const GLsizei gAlphaVertexStride = sizeof(AlphaVertex);
static const GLsizei gMeshTextureOffset = 2 * sizeof(float);
static const GLsizei gVertexAlphaOffset = 2 * sizeof(float);
static const GLsizei gVertexAAWidthOffset = 2 * sizeof(float);
static const GLsizei gVertexAALengthOffset = 3 * sizeof(float);
static const GLsizei gMeshCount = 4;

// Must define as many texture units as specified by REQUIRED_TEXTURE_UNITS_COUNT
static const GLenum gTextureUnits[] = {
    GL_TEXTURE0,
@@ -94,16 +72,6 @@ static const GLenum gTextureUnits[] = {
    GL_TEXTURE2
};

///////////////////////////////////////////////////////////////////////////////
// Debug
///////////////////////////////////////////////////////////////////////////////

struct CacheLogger {
    CacheLogger() {
        INIT_LOGD("Creating OpenGL renderer caches");
    }
}; // struct CacheLogger

///////////////////////////////////////////////////////////////////////////////
// Caches
///////////////////////////////////////////////////////////////////////////////
@@ -111,12 +79,25 @@ struct CacheLogger {
class RenderNode;
class RenderState;

class ANDROID_API Caches: public Singleton<Caches> {
    Caches();
class ANDROID_API Caches {
public:
    static Caches& createInstance(RenderState& renderState) {
        LOG_ALWAYS_FATAL_IF(sInstance, "double create of Caches attempted");
        sInstance = new Caches(renderState);
        return *sInstance;
    }

    friend class Singleton<Caches>;
    static Caches& getInstance() {
        LOG_ALWAYS_FATAL_IF(!sInstance, "instance not yet created");
        return *sInstance;
    }

    CacheLogger mLogger;
    static bool hasInstance() {
        return sInstance != 0;
    }
private:
    Caches(RenderState& renderState);
    static Caches* sInstance;

public:
    enum FlushMode {
@@ -135,8 +116,6 @@ public:
     */
    bool initProperties();

    void setRenderState(RenderState* renderState) { mRenderState = renderState; }

    /**
     * Flush the cache.
     *
@@ -175,59 +154,6 @@ public:
     */
    void deleteLayerDeferred(Layer* layer);

    /**
     * Binds the VBO used to render simple textured quads.
     */
    bool bindMeshBuffer();

    /**
     * Binds the specified VBO if needed.
     */
    bool bindMeshBuffer(const GLuint buffer);

    /**
     * Unbinds the VBO used to render simple textured quads.
     */
    bool unbindMeshBuffer();

    /**
     * Binds a global indices buffer that can draw up to
     * gMaxNumberOfQuads quads.
     */
    bool bindQuadIndicesBuffer();
    bool bindShadowIndicesBuffer();
    bool unbindIndicesBuffer();

    /**
     * Binds the specified buffer as the current GL unpack pixel buffer.
     */
    bool bindPixelBuffer(const GLuint buffer);

    /**
     * Resets the current unpack pixel buffer to 0 (default value.)
     */
    bool unbindPixelBuffer();

    /**
     * Binds an attrib to the specified float vertex pointer.
     * Assumes a stride of gMeshStride and a size of 2.
     */
    void bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride = gMeshStride);

    /**
     * Binds an attrib to the specified float vertex pointer.
     * Assumes a stride of gMeshStride and a size of 2.
     */
    void bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride = gMeshStride);

    /**
     * Resets the vertex pointers.
     */
    void resetVertexPointers();
    void resetTexCoordsVertexPointer();

    void enableTexCoordsVertexArray();
    void disableTexCoordsVertexArray();

    /**
     * Activate the specified texture unit. The texture unit must
@@ -300,9 +226,6 @@ public:
    bool drawDeferDisabled;
    bool drawReorderDisabled;

    // VBO to draw with
    GLuint meshBuffer;

    // Misc
    GLint maxTextureSize;

@@ -333,7 +256,6 @@ public:
    TaskManager tasks;

    Dither dither;
    Stencil stencil;

    bool gpuPixelBuffersEnabled;

@@ -356,6 +278,8 @@ public:
    int propertyAmbientShadowStrength;
    int propertySpotShadowStrength;

    PixelBufferState& pixelBuffer() { return *mPixelBufferState; }

private:
    enum OverdrawColorSet {
        kColorSet_Default = 0,
@@ -367,8 +291,6 @@ private:
    void initConstraints();
    void initStaticProperties();

    bool bindIndicesBufferInternal(const GLuint buffer);

    static void eventMarkNull(GLsizei length, const GLchar* marker) { }
    static void startMarkNull(GLsizei length, const GLchar* marker) { }
    static void endMarkNull() { }
@@ -381,15 +303,9 @@ private:
        if (label) *label = '\0';
    }

    GLuint mCurrentBuffer;
    GLuint mCurrentIndicesBuffer;
    GLuint mCurrentPixelBuffer;
    const void* mCurrentPositionPointer;
    GLsizei mCurrentPositionStride;
    const void* mCurrentTexCoordsPointer;
    GLsizei mCurrentTexCoordsStride;
    RenderState* mRenderState;

    bool mTexCoordsArrayEnabled;
    std::unique_ptr<PixelBufferState> mPixelBufferState; // TODO: move to RenderState

    GLuint mTextureUnit;

@@ -398,10 +314,6 @@ private:
    // Used to render layers
    std::unique_ptr<TextureVertex[]> mRegionMesh;

    // Global index buffer
    GLuint mMeshIndices;
    GLuint mShadowStripsIndices;

    mutable Mutex mGarbageLock;
    Vector<Layer*> mLayerGarbage;

@@ -414,8 +326,6 @@ private:
    GLuint mBoundTextures[REQUIRED_TEXTURE_UNITS_COUNT];

    OverdrawColorSet mOverdrawDebugColorSet;

    RenderState* mRenderState;
}; // class Caches

}; // namespace uirenderer
+32 −30
Original line number Diff line number Diff line
@@ -14,7 +14,17 @@
 * limitations under the License.
 */

#define LOG_TAG "OpenGLRenderer"
#include "FontRenderer.h"

#include "Caches.h"
#include "Debug.h"
#include "Extensions.h"
#include "OpenGLRenderer.h"
#include "PixelBuffer.h"
#include "Rect.h"
#include "renderstate/RenderState.h"
#include "utils/Blur.h"
#include "utils/Timing.h"

#include <SkGlyph.h>
#include <SkUtils.h>
@@ -27,17 +37,6 @@
#include <RenderScript.h>
#endif

#include "utils/Blur.h"
#include "utils/Timing.h"

#include "Caches.h"
#include "Debug.h"
#include "Extensions.h"
#include "FontRenderer.h"
#include "OpenGLRenderer.h"
#include "PixelBuffer.h"
#include "Rect.h"

namespace android {
namespace uirenderer {

@@ -47,9 +46,7 @@ namespace uirenderer {
///////////////////////////////////////////////////////////////////////////////
// TextSetupFunctor
///////////////////////////////////////////////////////////////////////////////
status_t TextSetupFunctor::operator ()(int what, void* data) {
    Data* typedData = reinterpret_cast<Data*>(data);
    GLenum glyphFormat = typedData ? typedData->glyphFormat : GL_ALPHA;
status_t TextSetupFunctor::setup(GLenum glyphFormat) {

    renderer->setupDraw();
    renderer->setupDrawTextGamma(paint);
@@ -397,7 +394,7 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp

CacheTexture* FontRenderer::createCacheTexture(int width, int height, GLenum format,
        bool allocate) {
    CacheTexture* cacheTexture = new CacheTexture(width, height, format, gMaxNumberOfQuads);
    CacheTexture* cacheTexture = new CacheTexture(width, height, format, kMaxNumberOfQuads);

    if (allocate) {
        Caches::getInstance().activeTexture(0);
@@ -473,7 +470,7 @@ void FontRenderer::checkTextureUpdate() {
    checkTextureUpdateForCache(caches, mRGBACacheTextures, resetPixelStore, lastTextureId);

    // Unbind any PBO we might have used to update textures
    caches.unbindPixelBuffer();
    caches.pixelBuffer().unbind();

    // Reset to default unpack row length to avoid affecting texture
    // uploads in other parts of the renderer
@@ -485,26 +482,29 @@ void FontRenderer::checkTextureUpdate() {
}

void FontRenderer::issueDrawCommand(Vector<CacheTexture*>& cacheTextures) {
    Caches& caches = Caches::getInstance();
    if (!mFunctor) return;

    Caches& caches = mFunctor->renderer->getCaches();
    RenderState& renderState = mFunctor->renderer->renderState();

    bool first = true;
    bool force = false;
    bool forceRebind = false;
    for (uint32_t i = 0; i < cacheTextures.size(); i++) {
        CacheTexture* texture = cacheTextures[i];
        if (texture->canDraw()) {
            if (first) {
                if (mFunctor) {
                    TextSetupFunctor::Data functorData(texture->getFormat());
                    (*mFunctor)(0, &functorData);
                    mFunctor->setup(texture->getFormat());
                }

                checkTextureUpdate();
                caches.bindQuadIndicesBuffer();
                renderState.meshState().bindQuadIndicesBuffer();

                if (!mDrawn) {
                    // If returns true, a VBO was bound and we must
                    // rebind our vertex attrib pointers even if
                    // they have the same values as the current pointers
                    force = caches.unbindMeshBuffer();
                    forceRebind = renderState.meshState().unbindMeshBuffer();
                }

                caches.activeTexture(0);
@@ -515,14 +515,16 @@ void FontRenderer::issueDrawCommand(Vector<CacheTexture*>& cacheTextures) {
            texture->setLinearFiltering(mLinearFiltering, false);

            TextureVertex* mesh = texture->mesh();
            caches.bindPositionVertexPointer(force, &mesh[0].x);
            caches.bindTexCoordsVertexPointer(force, &mesh[0].u);
            force = false;
            MeshState& meshState = renderState.meshState();
            Program* program = caches.currentProgram;
            meshState.bindPositionVertexPointer(program, forceRebind, &mesh[0].x);
            meshState.bindTexCoordsVertexPointer(program, forceRebind, &mesh[0].u);

            glDrawElements(GL_TRIANGLES, texture->meshElementCount(),
                    GL_UNSIGNED_SHORT, texture->indices());

            texture->resetMesh();
            forceRebind = false;
        }
    }
}
@@ -647,7 +649,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(const SkPaint* paint, co
                Font::BITMAP, dataBuffer, paddedWidth, paddedHeight, nullptr, positions);

        // Unbind any PBO we might have used
        Caches::getInstance().unbindPixelBuffer();
        Caches::getInstance().pixelBuffer().unbind();

        blurImage(&dataBuffer, paddedWidth, paddedHeight, radius);
    }
@@ -661,7 +663,7 @@ FontRenderer::DropShadow FontRenderer::renderDropShadow(const SkPaint* paint, co
    return image;
}

void FontRenderer::initRender(const Rect* clip, Rect* bounds, Functor* functor) {
void FontRenderer::initRender(const Rect* clip, Rect* bounds, TextSetupFunctor* functor) {
    checkInit();

    mDrawn = false;
@@ -689,7 +691,7 @@ void FontRenderer::endPrecaching() {

bool FontRenderer::renderPosText(const SkPaint* paint, const Rect* clip, const char *text,
        uint32_t startIndex, uint32_t len, int numGlyphs, int x, int y,
        const float* positions, Rect* bounds, Functor* functor, bool forceFinish) {
        const float* positions, Rect* bounds, TextSetupFunctor* functor, bool forceFinish) {
    if (!mCurrentFont) {
        ALOGE("No font set");
        return false;
@@ -707,7 +709,7 @@ bool FontRenderer::renderPosText(const SkPaint* paint, const Rect* clip, const c

bool FontRenderer::renderTextOnPath(const SkPaint* paint, const Rect* clip, const char *text,
        uint32_t startIndex, uint32_t len, int numGlyphs, const SkPath* path,
        float hOffset, float vOffset, Rect* bounds, Functor* functor) {
        float hOffset, float vOffset, Rect* bounds, TextSetupFunctor* functor) {
    if (!mCurrentFont) {
        ALOGE("No font set");
        return false;
+20 −39
Original line number Diff line number Diff line
@@ -17,7 +17,12 @@
#ifndef ANDROID_HWUI_FONT_RENDERER_H
#define ANDROID_HWUI_FONT_RENDERER_H

#include <utils/Functor.h>
#include "font/FontUtil.h"
#include "font/CacheTexture.h"
#include "font/CachedGlyphInfo.h"
#include "font/Font.h"
#include "utils/SortedList.h"

#include <utils/LruCache.h>
#include <utils/Vector.h>
#include <utils/StrongPointer.h>
@@ -26,12 +31,6 @@

#include <GLES2/gl2.h>

#include "font/FontUtil.h"
#include "font/CacheTexture.h"
#include "font/CachedGlyphInfo.h"
#include "font/Font.h"
#include "utils/SortedList.h"

#ifdef ANDROID_ENABLE_RENDERSCRIPT
#include "RenderScript.h"
namespace RSC {
@@ -47,26 +46,20 @@ namespace uirenderer {

class OpenGLRenderer;

///////////////////////////////////////////////////////////////////////////////
// TextSetupFunctor
///////////////////////////////////////////////////////////////////////////////
class TextSetupFunctor: public Functor {
class TextSetupFunctor {
public:
    struct Data {
        Data(GLenum glyphFormat) : glyphFormat(glyphFormat) {
        }

        GLenum glyphFormat;
    };

    TextSetupFunctor(OpenGLRenderer* renderer, float x, float y, bool pureTranslate,
            int alpha, SkXfermode::Mode mode, const SkPaint* paint): Functor(),
            renderer(renderer), x(x), y(y), pureTranslate(pureTranslate),
            alpha(alpha), mode(mode), paint(paint) {
            int alpha, SkXfermode::Mode mode, const SkPaint* paint)
        : renderer(renderer)
        , x(x)
        , y(y)
        , pureTranslate(pureTranslate)
        , alpha(alpha)
        , mode(mode)
        , paint(paint) {
    }
    ~TextSetupFunctor() { }

    status_t operator ()(int what, void* data) override;
    status_t setup(GLenum glyphFormat);

    OpenGLRenderer* renderer;
    float x;
@@ -77,10 +70,6 @@ public:
    const SkPaint* paint;
};

///////////////////////////////////////////////////////////////////////////////
// FontRenderer
///////////////////////////////////////////////////////////////////////////////

class FontRenderer {
public:
    FontRenderer();
@@ -101,22 +90,14 @@ public:
    // bounds is an out parameter
    bool renderPosText(const SkPaint* paint, const Rect* clip, const char *text,
            uint32_t startIndex, uint32_t len, int numGlyphs, int x, int y, const float* positions,
            Rect* bounds, Functor* functor, bool forceFinish = true);
            Rect* bounds, TextSetupFunctor* functor, bool forceFinish = true);

    // bounds is an out parameter
    bool renderTextOnPath(const SkPaint* paint, const Rect* clip, const char *text,
            uint32_t startIndex, uint32_t len, int numGlyphs, const SkPath* path,
            float hOffset, float vOffset, Rect* bounds, Functor* functor);
            float hOffset, float vOffset, Rect* bounds, TextSetupFunctor* functor);

    struct DropShadow {
        DropShadow() { };

        DropShadow(const DropShadow& dropShadow):
            width(dropShadow.width), height(dropShadow.height),
            image(dropShadow.image), penX(dropShadow.penX),
            penY(dropShadow.penY) {
        }

        uint32_t width;
        uint32_t height;
        uint8_t* image;
@@ -152,7 +133,7 @@ private:
    void flushAllAndInvalidate();

    void checkInit();
    void initRender(const Rect* clip, Rect* bounds, Functor* functor);
    void initRender(const Rect* clip, Rect* bounds, TextSetupFunctor* functor);
    void finishRender();

    void issueDrawCommand(Vector<CacheTexture*>& cacheTextures);
@@ -193,7 +174,7 @@ private:

    bool mUploadTexture;

    Functor* mFunctor;
    TextSetupFunctor* mFunctor;
    const Rect* mClip;
    Rect* mBounds;
    bool mDrawn;
Loading