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

Commit 079ba2c8 authored by Romain Guy's avatar Romain Guy
Browse files

Improve clip support (add intersect, union and replace.)

This change also modifies the way the clip is stored. The clip is now
always stored in screen-space coordinates.

Change-Id: I96375784d82dfe975bc6477a159e6866e7052487
parent ebd6f94d
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -149,43 +149,44 @@ class GLES20Canvas extends Canvas {

    @Override
    public boolean clipRect(float left, float top, float right, float bottom) {
        return nClipRect(mRenderer, left, top, right, bottom);
        return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
    }
    
    private native boolean nClipRect(int renderer, float left, float top, float right, float bottom);
    private native boolean nClipRect(int renderer, float left, float top,
            float right, float bottom, int op);

    @Override
    public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) {
        throw new UnsupportedOperationException();
        return nClipRect(mRenderer, left, top, right, bottom, op.nativeInt);
    }

    @Override
    public boolean clipRect(int left, int top, int right, int bottom) {
        return nClipRect(mRenderer, left, top, right, bottom);        
        return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);        
    }
    
    private native boolean nClipRect(int renderer, int left, int top, int right, int bottom);
    private native boolean nClipRect(int renderer, int left, int top, int right, int bottom, int op);

    @Override
    public boolean clipRect(Rect rect) {
        return clipRect(rect.left, rect.top, rect.right, rect.bottom);        
        return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
                Region.Op.INTERSECT.nativeInt);        
    }

    @Override
    public boolean clipRect(Rect rect, Region.Op op) {
        // TODO: Implement
        throw new UnsupportedOperationException();
        return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt);
    }

    @Override
    public boolean clipRect(RectF rect) {
        return clipRect(rect.left, rect.top, rect.right, rect.bottom);
        return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
                Region.Op.INTERSECT.nativeInt);
    }

    @Override
    public boolean clipRect(RectF rect, Region.Op op) {
        // TODO: Implement
        throw new UnsupportedOperationException();
        return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom, op.nativeInt);
    }

    @Override
@@ -347,7 +348,6 @@ class GLES20Canvas extends Canvas {

    @Override
    public void setDrawFilter(DrawFilter filter) {
        // Don't crash, but ignore the draw filter
        // TODO: Implement PaintDrawFilter
        mFilter = filter;
    }
+9 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <SkCanvas.h>
#include <SkMatrix.h>
#include <SkPaint.h>
#include <SkRegion.h>
#include <SkXfermode.h>

#include <OpenGLRenderer.h>
@@ -120,13 +121,15 @@ static bool android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject canvas,
}

static bool android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject canvas,
        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom) {
    return renderer->clipRect(left, top, right, bottom);
        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
        SkRegion::Op op) {
    return renderer->clipRect(left, top, right, bottom, op);
}

static bool android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject canvas,
        OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom) {
    return renderer->clipRect(float(left), float(top), float(right), float(bottom));
        OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom,
        SkRegion::Op op) {
    return renderer->clipRect(float(left), float(top), float(right), float(bottom), op);
}

static bool android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject canvas,
@@ -257,8 +260,8 @@ static JNINativeMethod gMethods[] = {
    {   "nSaveLayerAlpha",    "(IFFFFII)I",      (void*) android_view_GLES20Canvas_saveLayerAlpha },

    {   "nQuickReject",       "(IFFFFI)Z",       (void*) android_view_GLES20Canvas_quickReject },
    {   "nClipRect",          "(IFFFF)Z",        (void*) android_view_GLES20Canvas_clipRectF },
    {   "nClipRect",          "(IIIII)Z",        (void*) android_view_GLES20Canvas_clipRect },
    {   "nClipRect",          "(IFFFFI)Z",       (void*) android_view_GLES20Canvas_clipRectF },
    {   "nClipRect",          "(IIIIII)Z",       (void*) android_view_GLES20Canvas_clipRect },

    {   "nTranslate",         "(IFF)V",          (void*) android_view_GLES20Canvas_translate },
    {   "nRotate",            "(IF)V",           (void*) android_view_GLES20Canvas_rotate },
+5 −1
Original line number Diff line number Diff line
@@ -33,7 +33,11 @@ public class Region implements Parcelable {
        Op(int nativeInt) {
            this.nativeInt = nativeInt;
        }
        final int nativeInt;

        /**
         * @hide
         */
        public final int nativeInt;
    }

    /** Create an empty region
+19 −0
Original line number Diff line number Diff line
@@ -93,6 +93,25 @@ void Matrix4::copyTo(SkMatrix& v) const {
    v.set(SkMatrix::kMPersp2, data[15]);
}

void Matrix4::loadInverse(const Matrix4& v) {
    double scale = 1.0 /
            (v.data[0]  * ((double) v.data[5]  * v.data[15] - (double) v.data[13] * v.data[7]) +
             v.data[4]  * ((double) v.data[13] * v.data[3]  - (double) v.data[1]  * v.data[15]) +
             v.data[12] * ((double) v.data[1]  * v.data[7]  - (double) v.data[5]  * v.data[3]));

    data[0]  = (v.data[5] * v.data[15] - v.data[13] * v.data[7])  * scale;
    data[4]  = (v.data[12] * v.data[7] - v.data[4]  * v.data[15]) * scale;
    data[12] = (v.data[4] * v.data[13] - v.data[12] * v.data[5])  * scale;

    data[1]  = (v.data[13] * v.data[3] - v.data[1]  * v.data[15]) * scale;
    data[5]  = (v.data[0] * v.data[15] - v.data[12] * v.data[3])  * scale;
    data[13] = (v.data[12] * v.data[1] - v.data[0]  * v.data[13]) * scale;

    data[3]  = (v.data[1] * v.data[7] - v.data[5] * v.data[3]) * scale;
    data[7]  = (v.data[4] * v.data[3] - v.data[0] * v.data[7]) * scale;
    data[15] = (v.data[0] * v.data[5] - v.data[4] * v.data[1]) * scale;
}

void Matrix4::copyTo(float* v) const {
    memcpy(v, data, sizeof(data));
}
+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ public:
    void load(const Matrix4& v);
    void load(const SkMatrix& v);

    void loadInverse(const Matrix4& v);

    void loadTranslate(float x, float y, float z);
    void loadScale(float sx, float sy, float sz);
    void loadRotate(float angle, float x, float y, float z);
Loading