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

Commit 2ea75880 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Prepare OpenGLRenderer to use glyphs from TextLayoutCache

- add OpenGLRenderer.drawGlyph()
- refactor glypth logging code

Change-Id: I797e6f1304d3f3f8f6ed31e7f9965d336233d2a4
parent f470ced7
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -764,13 +764,6 @@ public:
        env->ReleaseStringChars(text, textArray);
    }

    static void logGlyphs(sp<TextLayoutCacheValue> value) {
        LOGD("drawTextWithGlyphs -- got glyphs - count=%d", value->getGlyphsCount());
        for (size_t i = 0; i < value->getGlyphsCount(); i++) {
            LOGD("                          glyphs[%d]=%d", i, value->getGlyphs()[i]);
        }
    }

    static void drawTextWithGlyphs(SkCanvas* canvas, const jchar* textArray,
            int start, int end,
            jfloat x, jfloat y, int flags, SkPaint* paint) {
@@ -779,7 +772,7 @@ public:
        sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
                paint, textArray, start, count, count, flags);
        if (value == NULL) {
            LOGE("drawTextWithGlyphs -- cannot get Cache value");
            LOGE("Cannot get TextLayoutCache value");
            return ;
        }
#if DEBUG_GLYPHS
@@ -796,7 +789,7 @@ public:
        sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
                paint, textArray, start, count, contextCount, flags);
        if (value == NULL) {
            LOGE("drawTextWithGlyphs -- cannot get Cache value");
            LOGE("Cannot get TextLayoutCache value");
            return ;
        }
#if DEBUG_GLYPHS
+8 −0
Original line number Diff line number Diff line
@@ -64,6 +64,14 @@ enum {
    kDirection_Mask = 0x1
};

static void logGlyphs(sp<TextLayoutCacheValue> value) {
    if (value == NULL) return;
    LOGD("Got glyphs - count=%d", value->getGlyphsCount());
    for (size_t i = 0; i < value->getGlyphsCount(); i++) {
        LOGD("      glyphs[%d]=%d", i, value->getGlyphs()[i]);
    }
}

class TextLayout {
public:

+30 −0
Original line number Diff line number Diff line
@@ -419,6 +419,20 @@ static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz,

static void renderText(OpenGLRenderer* renderer, const jchar* text, int count,
        jfloat x, jfloat y, int flags, SkPaint* paint) {
#if 0 // TODO: replace "0" by "RTL_USE_HARFBUZZ" when renderer->drawGlyphs() is implemented
    sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
            paint, text, 0, count, count, flags);
    if (value == NULL) {
        LOGE("Cannot get TextLayoutCache value");
        return ;
    }
#if DEBUG_GLYPHS
    logGlyphs(value);
#endif
    const jchar* glyphArray = value->getGlyphs();
    int glyphCount = value->getGlyphsCount();
    renderer->drawGlyphs((const char*) glyphArray, 0, glyphCount << 1, x, y, paint);
#else
    const jchar *workText;
    jchar* buffer = NULL;
    int32_t workBytes;
@@ -426,11 +440,26 @@ static void renderText(OpenGLRenderer* renderer, const jchar* text, int count,
        renderer->drawText((const char*) workText, workBytes, count, x, y, paint);
        free(buffer);
    }
#endif
}

static void renderTextRun(OpenGLRenderer* renderer, const jchar* text,
        jint start, jint count, jint contextCount, jfloat x, jfloat y,
        int flags, SkPaint* paint) {
#if 0 // TODO: replace "0" by "RTL_USE_HARFBUZZ" when renderer->drawGlyphs() is implemented
    sp<TextLayoutCacheValue> value = gTextLayoutCache.getValue(
            paint, text, start, count, contextCount, flags);
    if (value == NULL) {
        LOGE("Cannot get TextLayoutCache value");
        return ;
    }
#if DEBUG_GLYPHS
    logGlyphs(value);
#endif
    const jchar* glyphArray = value->getGlyphs();
    int glyphCount = value->getGlyphsCount();
    renderer->drawGlyphs((const char*) glyphArray, 0, glyphCount << 1, x, y, paint);
#else
    uint8_t rtl = flags & 0x1;
    if (rtl) {
        SkAutoSTMalloc<80, jchar> buffer(contextCount);
@@ -443,6 +472,7 @@ static void renderTextRun(OpenGLRenderer* renderer, const jchar* text,
    } else {
        renderer->drawText((const char*) (text + start), count << 1, count, x, y, paint);
    }
#endif
}

static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz,
+5 −0
Original line number Diff line number Diff line
@@ -1982,6 +1982,11 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
    drawTextDecorations(text, bytesCount, length, oldX, oldY, paint);
}

void OpenGLRenderer::drawGlyphs(const char* glyphs, int index, int count, float x, float y,
        SkPaint* paint) {
    // TODO
}

void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
    if (mSnapshot->isIgnored()) return;

+2 −0
Original line number Diff line number Diff line
@@ -123,6 +123,8 @@ public:
    virtual void drawPoints(float* points, int count, SkPaint* paint);
    virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
            SkPaint* paint);
    virtual void drawGlyphs(const char* glyphs, int index, int count, float x, float y,
            SkPaint* paint);

    virtual void resetShader();
    virtual void setupShader(SkiaShader* shader);