Loading core/java/android/view/ViewRoot.java +3 −4 Original line number Diff line number Diff line Loading @@ -960,11 +960,10 @@ public final class ViewRoot extends Handler implements ViewParent, mTmpLocation[1] + host.mBottom - host.mTop); host.gatherTransparentRegion(mTransparentRegion); if (mAppScale != 1.0f) { mTransparentRegion.scale(mAppScale); } // TODO: scale the region, like: // Region uses native methods. We probabl should have ScalableRegion class. // Region does not have equals method ? if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { mPreviousTransparentRegion.set(mTransparentRegion); // reconfigure window manager Loading core/jni/android/graphics/Region.cpp +40 −1 Original line number Diff line number Diff line Loading @@ -102,6 +102,36 @@ static void Region_translate(JNIEnv* env, jobject region, int x, int y, jobject rgn->translate(x, y); } // Scale the rectangle by given scale and set the reuslt to the dst. static void scale_rect(SkIRect* dst, const SkIRect& src, float scale) { dst->fLeft = (int)::roundf(src.fLeft * scale); dst->fTop = (int)::roundf(src.fTop * scale); dst->fRight = (int)::roundf(src.fRight * scale); dst->fBottom = (int)::roundf(src.fBottom * scale); } // Scale the region by given scale and set the reuslt to the dst. // dest and src can be the same region instance. static void scale_rgn(SkRegion* dst, const SkRegion& src, float scale) { SkRegion tmp; SkRegion::Iterator iter(src); for (; !iter.done(); iter.next()) { SkIRect r; scale_rect(&r, iter.rect(), scale); tmp.op(r, SkRegion::kUnion_Op); } dst->swap(tmp); } static void Region_scale(JNIEnv* env, jobject region, jfloat scale, jobject dst) { SkRegion* rgn = GetSkRegion(env, region); if (dst) scale_rgn(GetSkRegion(env, dst), *rgn, scale); else scale_rgn(rgn, *rgn, scale); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "Parcel.h" Loading Loading @@ -139,6 +169,13 @@ static jboolean Region_writeToParcel(JNIEnv* env, jobject clazz, const SkRegion* //////////////////////////////////////////////////////////////////////////////////////////////////////////// static jboolean Region_equals(JNIEnv* env, jobject clazz, const SkRegion *r1, const SkRegion* r2) { return (jboolean) (*r1 == *r2); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// struct RgnIterPair { SkRegion fRgn; // a copy of the caller's region SkRegion::Iterator fIter; // an iterator acting upon the copy (fRgn) Loading Loading @@ -206,10 +243,12 @@ static JNINativeMethod gRegionMethods[] = { { "quickContains", "(IIII)Z", (void*)Region_quickContains }, { "quickReject", "(IIII)Z", (void*)Region_quickRejectIIII }, { "quickReject", "(Landroid/graphics/Region;)Z", (void*)Region_quickRejectRgn }, { "scale", "(FLandroid/graphics/Region;)V", (void*)Region_scale }, { "translate", "(IILandroid/graphics/Region;)V", (void*)Region_translate }, // parceling methods { "nativeCreateFromParcel", "(Landroid/os/Parcel;)I", (void*)Region_createFromParcel }, { "nativeWriteToParcel", "(ILandroid/os/Parcel;)Z", (void*)Region_writeToParcel } { "nativeWriteToParcel", "(ILandroid/os/Parcel;)Z", (void*)Region_writeToParcel }, { "nativeEquals", "(II)Z", (void*)Region_equals }, }; int register_android_graphics_Region(JNIEnv* env); Loading graphics/java/android/graphics/Region.java +32 −1 Original line number Diff line number Diff line Loading @@ -211,6 +211,26 @@ public class Region implements Parcelable { */ public native void translate(int dx, int dy, Region dst); /** * Scale the region by the given scale amount. This re-constructs new region by * scaling the rects that this region consists of. New rectis are computed by scaling * coordinates by float, then rounded by roundf() function to integers. This may results * in less internal rects if 0 < scale < 1. Zero and Negative scale result in * an empty region. If this region is empty, do nothing. * * @hide */ public void scale(float scale) { scale(scale, null); } /** * Set the dst region to the result of scaling this region by the given scale amount. * If this region is empty, then dst will be set to empty. * @hide */ public native void scale(float scale, Region dst); public final boolean union(Rect r) { return op(r, Op.UNION); } Loading Loading @@ -295,6 +315,15 @@ public class Region implements Parcelable { } } @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Region)) { return false; } Region peer = (Region) obj; return nativeEquals(mNativeRegion, peer.mNativeRegion); } protected void finalize() throws Throwable { nativeDestructor(mNativeRegion); } Loading Loading @@ -340,5 +369,7 @@ public class Region implements Parcelable { private static native boolean nativeWriteToParcel(int native_region, Parcel p); private static native boolean nativeEquals(int native_r1, int native_r2); private final int mNativeRegion; } Loading
core/java/android/view/ViewRoot.java +3 −4 Original line number Diff line number Diff line Loading @@ -960,11 +960,10 @@ public final class ViewRoot extends Handler implements ViewParent, mTmpLocation[1] + host.mBottom - host.mTop); host.gatherTransparentRegion(mTransparentRegion); if (mAppScale != 1.0f) { mTransparentRegion.scale(mAppScale); } // TODO: scale the region, like: // Region uses native methods. We probabl should have ScalableRegion class. // Region does not have equals method ? if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { mPreviousTransparentRegion.set(mTransparentRegion); // reconfigure window manager Loading
core/jni/android/graphics/Region.cpp +40 −1 Original line number Diff line number Diff line Loading @@ -102,6 +102,36 @@ static void Region_translate(JNIEnv* env, jobject region, int x, int y, jobject rgn->translate(x, y); } // Scale the rectangle by given scale and set the reuslt to the dst. static void scale_rect(SkIRect* dst, const SkIRect& src, float scale) { dst->fLeft = (int)::roundf(src.fLeft * scale); dst->fTop = (int)::roundf(src.fTop * scale); dst->fRight = (int)::roundf(src.fRight * scale); dst->fBottom = (int)::roundf(src.fBottom * scale); } // Scale the region by given scale and set the reuslt to the dst. // dest and src can be the same region instance. static void scale_rgn(SkRegion* dst, const SkRegion& src, float scale) { SkRegion tmp; SkRegion::Iterator iter(src); for (; !iter.done(); iter.next()) { SkIRect r; scale_rect(&r, iter.rect(), scale); tmp.op(r, SkRegion::kUnion_Op); } dst->swap(tmp); } static void Region_scale(JNIEnv* env, jobject region, jfloat scale, jobject dst) { SkRegion* rgn = GetSkRegion(env, region); if (dst) scale_rgn(GetSkRegion(env, dst), *rgn, scale); else scale_rgn(rgn, *rgn, scale); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "Parcel.h" Loading Loading @@ -139,6 +169,13 @@ static jboolean Region_writeToParcel(JNIEnv* env, jobject clazz, const SkRegion* //////////////////////////////////////////////////////////////////////////////////////////////////////////// static jboolean Region_equals(JNIEnv* env, jobject clazz, const SkRegion *r1, const SkRegion* r2) { return (jboolean) (*r1 == *r2); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// struct RgnIterPair { SkRegion fRgn; // a copy of the caller's region SkRegion::Iterator fIter; // an iterator acting upon the copy (fRgn) Loading Loading @@ -206,10 +243,12 @@ static JNINativeMethod gRegionMethods[] = { { "quickContains", "(IIII)Z", (void*)Region_quickContains }, { "quickReject", "(IIII)Z", (void*)Region_quickRejectIIII }, { "quickReject", "(Landroid/graphics/Region;)Z", (void*)Region_quickRejectRgn }, { "scale", "(FLandroid/graphics/Region;)V", (void*)Region_scale }, { "translate", "(IILandroid/graphics/Region;)V", (void*)Region_translate }, // parceling methods { "nativeCreateFromParcel", "(Landroid/os/Parcel;)I", (void*)Region_createFromParcel }, { "nativeWriteToParcel", "(ILandroid/os/Parcel;)Z", (void*)Region_writeToParcel } { "nativeWriteToParcel", "(ILandroid/os/Parcel;)Z", (void*)Region_writeToParcel }, { "nativeEquals", "(II)Z", (void*)Region_equals }, }; int register_android_graphics_Region(JNIEnv* env); Loading
graphics/java/android/graphics/Region.java +32 −1 Original line number Diff line number Diff line Loading @@ -211,6 +211,26 @@ public class Region implements Parcelable { */ public native void translate(int dx, int dy, Region dst); /** * Scale the region by the given scale amount. This re-constructs new region by * scaling the rects that this region consists of. New rectis are computed by scaling * coordinates by float, then rounded by roundf() function to integers. This may results * in less internal rects if 0 < scale < 1. Zero and Negative scale result in * an empty region. If this region is empty, do nothing. * * @hide */ public void scale(float scale) { scale(scale, null); } /** * Set the dst region to the result of scaling this region by the given scale amount. * If this region is empty, then dst will be set to empty. * @hide */ public native void scale(float scale, Region dst); public final boolean union(Rect r) { return op(r, Op.UNION); } Loading Loading @@ -295,6 +315,15 @@ public class Region implements Parcelable { } } @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof Region)) { return false; } Region peer = (Region) obj; return nativeEquals(mNativeRegion, peer.mNativeRegion); } protected void finalize() throws Throwable { nativeDestructor(mNativeRegion); } Loading Loading @@ -340,5 +369,7 @@ public class Region implements Parcelable { private static native boolean nativeWriteToParcel(int native_region, Parcel p); private static native boolean nativeEquals(int native_r1, int native_r2); private final int mNativeRegion; }