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

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

Merge "Add full support for Canvas.setDrawFilter()"

parents e575005f 5ff9df65
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.ColorFilter;
import android.graphics.DrawFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.Picture;
import android.graphics.PorterDuff;
@@ -546,6 +547,7 @@ class GLES20Canvas extends HardwareCanvas {
    
    private static native void nSetMatrix(int renderer, int matrix);

    @SuppressWarnings("deprecation")
    @Override
    public void getMatrix(Matrix matrix) {
        nGetMatrix(mRenderer, matrix.native_instance);
@@ -658,7 +660,16 @@ class GLES20Canvas extends HardwareCanvas {
    @Override
    public void setDrawFilter(DrawFilter filter) {
        mFilter = filter;
        if (filter == null) {
            nResetPaintFilter(mRenderer);
        } else if (filter instanceof PaintFlagsDrawFilter) {
            PaintFlagsDrawFilter flagsFilter = (PaintFlagsDrawFilter) filter;
            nSetupPaintFilter(mRenderer, flagsFilter.clearBits, flagsFilter.setBits);
        }
    }

    private static native void nResetPaintFilter(int renderer);
    private static native void nSetupPaintFilter(int renderer, int clearBits, int setBits);

    @Override
    public DrawFilter getDrawFilter() {
@@ -968,6 +979,7 @@ class GLES20Canvas extends HardwareCanvas {
    private static native void nDrawPoints(int renderer, float[] points,
            int offset, int count, int paint);

    @SuppressWarnings("deprecation")
    @Override
    public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) {
        if (index < 0 || index + count > text.length || count * 2 > pos.length) {
@@ -985,6 +997,7 @@ class GLES20Canvas extends HardwareCanvas {
    private static native void nDrawPosText(int renderer, char[] text, int index, int count,
            float[] pos, int paint);

    @SuppressWarnings("deprecation")
    @Override
    public void drawPosText(String text, float[] pos, Paint paint) {
        if (text.length() * 2 > pos.length) {
+17 −0
Original line number Diff line number Diff line
@@ -482,6 +482,20 @@ static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz,
    renderer->setupShadow(radius, dx, dy, color);
}

// ----------------------------------------------------------------------------
// Draw filters
// ----------------------------------------------------------------------------

static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz,
        OpenGLRenderer* renderer, jint clearBits, jint setBits) {
    renderer->setupPaintFilter(clearBits, setBits);
}

static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz,
        OpenGLRenderer* renderer) {
    renderer->resetPaintFilter();
}

// ----------------------------------------------------------------------------
// Text
// ----------------------------------------------------------------------------
@@ -870,6 +884,9 @@ static JNINativeMethod gMethods[] = {
    { "nSetupColorFilter",  "(II)V",           (void*) android_view_GLES20Canvas_setupColorFilter },
    { "nSetupShadow",       "(IFFFI)V",        (void*) android_view_GLES20Canvas_setupShadow },

    { "nSetupPaintFilter",  "(III)V",          (void*) android_view_GLES20Canvas_setupPaintFilter },
    { "nResetPaintFilter",  "(I)V",            (void*) android_view_GLES20Canvas_resetPaintFilter },

    { "nDrawText",          "(I[CIIFFII)V",    (void*) android_view_GLES20Canvas_drawTextArray },
    { "nDrawText",          "(ILjava/lang/String;IIFFII)V",
            (void*) android_view_GLES20Canvas_drawText },
+0 −3
Original line number Diff line number Diff line
@@ -325,9 +325,6 @@ changed.</li>

        <li>{@link android.graphics.Canvas#drawBitmapMesh drawBitmapMesh()}: colors array is
        ignored</li>

        <li>{@link android.graphics.Canvas#setDrawFilter setDrawFilter()}: can be set, but is
        ignored</li>
      </ul>
    </li>

+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package android.graphics;

public class PaintFlagsDrawFilter extends DrawFilter {
    /** @hide **/
    public final int clearBits;
    /** @hide **/
    public final int setBits;

    /**
     * Subclass of DrawFilter that affects every paint by first clearing
@@ -27,6 +31,8 @@ public class PaintFlagsDrawFilter extends DrawFilter {
     * @param setBits These bits will be set in the paint's flags
     */
    public PaintFlagsDrawFilter(int clearBits, int setBits) {
        this.clearBits = clearBits;
        this.setBits = setBits;
        // our native constructor can return 0, if the specified bits
        // are effectively a no-op
        mNativeInt = nativeConstructor(clearBits, setBits);
+69 −34
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ const char* DisplayList::OP_NAMES[] = {
    "SetupColorFilter",
    "ResetShadow",
    "SetupShadow",
    "ResetPaintFilter",
    "SetupPaintFilter",
    "DrawGLFunction"
};

@@ -249,7 +251,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                int flags = getInt();
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
                    OP_NAMES[op], f1, f2, f3, f4, paint, flags);
@@ -322,7 +324,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                Layer* layer = (Layer*) getInt();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    layer, x, y, paint);
            }
@@ -331,7 +333,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                SkBitmap* bitmap = getBitmap();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    bitmap, x, y, paint);
            }
@@ -339,7 +341,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
            case DrawBitmapMatrix: {
                SkBitmap* bitmap = getBitmap();
                SkMatrix* matrix = getMatrix();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
                    bitmap, matrix, paint);
            }
@@ -354,7 +356,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f6 = getFloat();
                float f7 = getFloat();
                float f8 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
            }
@@ -368,7 +370,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float* vertices = getFloats(verticesCount);
                bool hasColors = getInt();
                int* colors = hasColors ? getInts(colorsCount) : NULL;
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
            }
            break;
@@ -387,7 +389,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float top = getFloat();
                float right = getFloat();
                float bottom = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
                        left, top, right, bottom);
            }
@@ -403,7 +405,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    f1, f2, f3, f4, paint);
            }
@@ -415,7 +417,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f4 = getFloat();
                float f5 = getFloat();
                float f6 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
            }
@@ -424,7 +426,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f1 = getFloat();
                float f2 = getFloat();
                float f3 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
            }
@@ -434,7 +436,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
            }
@@ -447,28 +449,28 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float f5 = getFloat();
                float f6 = getFloat();
                int i1 = getInt();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
            }
            break;
            case DrawPath: {
                SkPath* path = getPath();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
            }
            break;
            case DrawLines: {
                int count = 0;
                float* points = getFloats(count);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
            }
            break;
            case DrawPoints: {
                int count = 0;
                float* points = getFloats(count);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
            }
            break;
@@ -477,7 +479,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                int count = getInt();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                float length = getFloat();
                ALOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
                    text.text(), text.length(), count, x, y, paint, length);
@@ -488,7 +490,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                int count = getInt();
                int positionsCount = 0;
                float* positions = getFloats(positionsCount);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
                    text.text(), text.length(), count, paint);
            }
@@ -523,6 +525,16 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                    radius, dx, dy, color);
            }
            break;
            case ResetPaintFilter: {
                ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
            }
            break;
            case SetupPaintFilter: {
                int clearBits = getInt();
                int setBits = getInt();
                ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
            }
            break;
            default:
                ALOGD("Display List error: op not handled: %s%s",
                    (char*) indent, OP_NAMES[op]);
@@ -588,7 +600,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                int flags = getInt();
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
                    OP_NAMES[op], f1, f2, f3, f4, paint, flags);
@@ -671,7 +683,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                Layer* layer = (Layer*) getInt();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    layer, x, y, paint);
                renderer.drawLayer(layer, x, y, paint);
@@ -681,7 +693,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                SkBitmap* bitmap = getBitmap();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    bitmap, x, y, paint);
                renderer.drawBitmap(bitmap, x, y, paint);
@@ -690,7 +702,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
            case DrawBitmapMatrix: {
                SkBitmap* bitmap = getBitmap();
                SkMatrix* matrix = getMatrix();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
                    bitmap, matrix, paint);
                renderer.drawBitmap(bitmap, matrix, paint);
@@ -706,7 +718,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f6 = getFloat();
                float f7 = getFloat();
                float f8 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
                renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
@@ -722,7 +734,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float* vertices = getFloats(verticesCount);
                bool hasColors = getInt();
                int* colors = hasColors ? getInts(colorsCount) : NULL;
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);

                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint);
@@ -746,7 +758,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float top = getFloat();
                float right = getFloat();
                float bottom = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);

                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
@@ -765,7 +777,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
                    f1, f2, f3, f4, paint);
                renderer.drawRect(f1, f2, f3, f4, paint);
@@ -778,7 +790,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f4 = getFloat();
                float f5 = getFloat();
                float f6 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
                renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
@@ -788,7 +800,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f1 = getFloat();
                float f2 = getFloat();
                float f3 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
                renderer.drawCircle(f1, f2, f3, paint);
@@ -799,7 +811,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f2 = getFloat();
                float f3 = getFloat();
                float f4 = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
                renderer.drawOval(f1, f2, f3, f4, paint);
@@ -813,7 +825,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                float f5 = getFloat();
                float f6 = getFloat();
                int i1 = getInt();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
                renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
@@ -821,7 +833,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
            break;
            case DrawPath: {
                SkPath* path = getPath();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
                renderer.drawPath(path, paint);
            }
@@ -829,7 +841,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
            case DrawLines: {
                int count = 0;
                float* points = getFloats(count);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                renderer.drawLines(points, count, paint);
            }
@@ -837,7 +849,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
            case DrawPoints: {
                int count = 0;
                float* points = getFloats(count);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                renderer.drawPoints(points, count, paint);
            }
@@ -847,7 +859,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                int count = getInt();
                float x = getFloat();
                float y = getFloat();
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                float length = getFloat();
                DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
                        OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
@@ -859,7 +871,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                int count = getInt();
                int positionsCount = 0;
                float* positions = getFloats(positionsCount);
                SkPaint* paint = getPaint();
                SkPaint* paint = getPaint(renderer);
                DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
                        OP_NAMES[op], text.text(), text.length(), count, paint);
                renderer.drawPosText(text.text(), text.length(), count, positions, paint);
@@ -902,6 +914,19 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
                renderer.setupShadow(radius, dx, dy, color);
            }
            break;
            case ResetPaintFilter: {
                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                renderer.resetPaintFilter();
            }
            break;
            case SetupPaintFilter: {
                int clearBits = getInt();
                int setBits = getInt();
                DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
                        clearBits, setBits);
                renderer.setupPaintFilter(clearBits, setBits);
            }
            break;
            default:
                DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
                    (char*) indent, OP_NAMES[op]);
@@ -1277,5 +1302,15 @@ void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int colo
    addInt(color);
}

void DisplayListRenderer::resetPaintFilter() {
    addOp(DisplayList::ResetPaintFilter);
}

void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
    addOp(DisplayList::SetupPaintFilter);
    addInt(clearBits);
    addInt(setBits);
}

}; // namespace uirenderer
}; // namespace android
Loading