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

Commit 623ee2a5 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Fix tons of bugs and add new text rendering support."

parents f5e9018b 61c8c9c5
Loading
Loading
Loading
Loading
+80 −21
Original line number Diff line number Diff line
@@ -610,10 +610,14 @@ class GLES20Canvas extends Canvas {
        if ((index | count | (index + count) | (text.length - index - count)) < 0) {
            throw new IndexOutOfBoundsException();
        }

        boolean hasModifier = setupModifiers(paint);
        try {
            nDrawText(mRenderer, text, index, count, x, y, paint.mBidiFlags, paint.mNativePaint);
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }
    
    private native void nDrawText(int renderer, char[] text, int index, int count, float x, float y,
            int bidiFlags, int paint);
@@ -621,6 +625,7 @@ class GLES20Canvas extends Canvas {
    @Override
    public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
        boolean hasModifier = setupModifiers(paint);
        try {
            if (text instanceof String || text instanceof SpannedString ||
                    text instanceof SpannableString) {
                nDrawText(mRenderer, text.toString(), start, end, x, y, paint.mBidiFlags,
@@ -634,18 +639,24 @@ class GLES20Canvas extends Canvas {
                nDrawText(mRenderer, buf, 0, end - start, x, y, paint.mBidiFlags, paint.mNativePaint);
                TemporaryBuffer.recycle(buf);
            }
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }

    @Override
    public void drawText(String text, int start, int end, float x, float y, Paint paint) {
        if ((start | end | (end - start) | (text.length() - end)) < 0) {
            throw new IndexOutOfBoundsException();
        }

        boolean hasModifier = setupModifiers(paint);
        try {
            nDrawText(mRenderer, text, start, end, x, y, paint.mBidiFlags, paint.mNativePaint);
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }

    private native void nDrawText(int renderer, String text, int start, int end, float x, float y,
            int bidiFlags, int paint);
@@ -653,9 +664,13 @@ class GLES20Canvas extends Canvas {
    @Override
    public void drawText(String text, float x, float y, Paint paint) {
        boolean hasModifier = setupModifiers(paint);
        nDrawText(mRenderer, text, 0, text.length(), x, y, paint.mBidiFlags, paint.mNativePaint);
        try {
            nDrawText(mRenderer, text, 0, text.length(), x, y, paint.mBidiFlags,
                    paint.mNativePaint);
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }

    @Override
    public void drawTextOnPath(char[] text, int index, int count, Path path, float hOffset,
@@ -671,15 +686,59 @@ class GLES20Canvas extends Canvas {
    @Override
    public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount,
            float x, float y, int dir, Paint paint) {
        throw new UnsupportedOperationException();
        if ((index | count | text.length - index - count) < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) {
            throw new IllegalArgumentException("Unknown direction: " + dir);
        }

        boolean hasModifier = setupModifiers(paint);
        try {
            nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, dir,
                    paint.mNativePaint);
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }

    private native void nDrawTextRun(int renderer, char[] text, int index, int count,
            int contextIndex, int contextCount, float x, float y, int dir, int nativePaint);

    @Override
    public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
            float x, float y, int dir, Paint paint) {
        throw new UnsupportedOperationException();
        if ((start | end | end - start | text.length() - end) < 0) {
            throw new IndexOutOfBoundsException();
        }

        boolean hasModifier = setupModifiers(paint);
        try {
            int flags = dir == 0 ? 0 : 1;
            if (text instanceof String || text instanceof SpannedString ||
                    text instanceof SpannableString) {
                nDrawTextRun(mRenderer, text.toString(), start, end, contextStart,
                        contextEnd, x, y, flags, paint.mNativePaint);
            } else if (text instanceof GraphicsOperations) {
                ((GraphicsOperations) text).drawTextRun(this, start, end,
                        contextStart, contextEnd, x, y, flags, paint);
            } else {
                int contextLen = contextEnd - contextStart;
                int len = end - start;
                char[] buf = TemporaryBuffer.obtain(contextLen);
                TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
                nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen,
                        x, y, flags, paint.mNativePaint);
                TemporaryBuffer.recycle(buf);
            }
        } finally {
            if (hasModifier) nResetModifiers(mRenderer);
        }
    }

    private native void nDrawTextRun(int renderer, String text, int start, int end,
            int contextStart, int contextEnd, float x, float y, int flags, int nativePaint);

    @Override
    public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
            float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices,
+12 −1
Original line number Diff line number Diff line
@@ -34,11 +34,22 @@ import javax.microedition.khronos.opengles.GL;
 * 
 * @hide
 */
abstract class HardwareRenderer {
public abstract class HardwareRenderer {
    private boolean mEnabled;
    private boolean mRequested = true;
    private static final String LOG_TAG = "HardwareRenderer";

    /**
     * Indicates whether hardware acceleration is available under any form for
     * the view hierarchy.
     * 
     * @return True if the view hierarchy can potentially be hardware accelerated,
     *         false otherwise
     */
    public static boolean isAvailable() {
        return GLES20Canvas.isAvailable();
    }

    /**
     * Destroys the hardware rendering context.
     */
+5 −3
Original line number Diff line number Diff line
@@ -149,7 +149,9 @@ static SkiaShader* LinearGradient_postCreate1(JNIEnv* env, jobject o, SkShader*
    storedBounds[2] = x1; storedBounds[3] = y1;
    jfloat* storedPositions = new jfloat[count];
    uint32_t* storedColors = new uint32_t[count];
    memcpy(storedColors, colorValues, count);
    for (size_t i = 0; i < count; i++) {
        storedColors[i] = static_cast<uint32_t>(colorValues[i]);
    }

    if (posArray) {
        AutoJavaFloatArray autoPos(env, posArray, count);
@@ -185,8 +187,8 @@ static SkiaShader* LinearGradient_postCreate2(JNIEnv* env, jobject o, SkShader*
    storedPositions[1] = 1.0f;

    uint32_t* storedColors = new uint32_t[2];
    storedColors[0] = color0;
    storedColors[1] = color1;
    storedColors[0] = static_cast<uint32_t>(color0);
    storedColors[1] = static_cast<uint32_t>(color1);

    SkiaShader* skiaShader = new SkiaLinearGradientShader(storedBounds, storedColors,
            storedPositions, 2, shader, static_cast<SkShader::TileMode>(tileMode), NULL,
+13 −5
Original line number Diff line number Diff line
@@ -221,6 +221,18 @@ void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len,
    }
}

bool TextLayout::prepareRtlTextRun(const jchar* context, jsize start, jsize& count,
        jsize contextCount, jchar* shaped) {
    UErrorCode status = U_ZERO_ERROR;
    count = shapeRtlText(context, start, count, contextCount, shaped, status);
    if (U_SUCCESS(status)) {
        return true;
    } else {
        LOG(LOG_WARN, "LAYOUT", "drawTextRun error %d\n", status);
    }
    return false;
}

void TextLayout::drawTextRun(SkPaint* paint, const jchar* chars,
                             jint start, jint count, jint contextCount,
                             int dirFlags, jfloat x, jfloat y, SkCanvas* canvas) {
@@ -231,12 +243,8 @@ void TextLayout::drawTextRun(SkPaint* paint, const jchar* chars,
     uint8_t rtl = dirFlags & 0x1;
     if (rtl) {
         SkAutoSTMalloc<80, jchar> buffer(contextCount);
         UErrorCode status = U_ZERO_ERROR;
         count = shapeRtlText(chars, start, count, contextCount, buffer.get(), status);
         if (U_SUCCESS(status)) {
         if (prepareRtlTextRun(chars, start, count, contextCount, buffer.get())) {
             canvas->drawText(buffer.get(), count << 1, x_, y_, *paint);
         } else {
             LOG(LOG_WARN, "LAYOUT", "drawTextRun error %d\n", status);
         }
     } else {
         canvas->drawText(chars + start, count << 1, x_, y_, *paint);
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ public:
                               
   static bool prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags,
        const jchar** outText, int32_t* outBytes, jchar** outBuffer);
    static bool prepareRtlTextRun(const jchar* context, jsize start, jsize& count,
        jsize contextCount, jchar* shaped);
        

private:
    static bool needsLayout(const jchar* text, jint len, jint bidiFlags);
Loading