Canvas.java revision b8201195dfb2bae05faaf91b9b3d065e2f199929
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.graphics; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1980756e38882720860db52f1fcc21fa1505a02abfTor Norbyeimport android.annotation.ColorInt; 20ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabreseimport android.annotation.IntDef; 21ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabreseimport android.annotation.NonNull; 22ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabreseimport android.annotation.Nullable; 23b3ec733bb830f2d4425825d93f9ed95f284e9145Tor Norbyeimport android.annotation.Size; 24b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenbergerimport android.os.Build; 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craikimport dalvik.annotation.optimization.CriticalNative; 275cb74bca88268a8b9025be2cce81e1b4f967d19dJohn Reckimport dalvik.annotation.optimization.FastNative; 285cb74bca88268a8b9025be2cce81e1b4f967d19dJohn Reck 295cb74bca88268a8b9025be2cce81e1b4f967d19dJohn Reckimport libcore.util.NativeAllocationRegistry; 305cb74bca88268a8b9025be2cce81e1b4f967d19dJohn Reck 31ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabreseimport java.lang.annotation.Retention; 32ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabreseimport java.lang.annotation.RetentionPolicy; 33ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese 34091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craikimport javax.microedition.khronos.opengles.GL; 35091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The Canvas class holds the "draw" calls. To draw something, you need 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4 basic components: A Bitmap to hold the pixels, a Canvas to host 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, 409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Path, text, Bitmap), and a paint (to describe the colors and styles for the 419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * drawing). 4261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 4361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 4461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 4561fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use Canvas, read the 4661fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/graphics/2d-graphics.html"> 4761fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * Canvas and Drawables</a> developer guide.</p></div> 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 49caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reckpublic class Canvas extends BaseCanvas { 503891f3ad598561d5a82c07795e1fee7f1d3612d1Chris Craik /** @hide */ 513891f3ad598561d5a82c07795e1fee7f1d3612d1Chris Craik public static boolean sCompatibilityRestore = false; 52ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov 53ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov /** @hide */ 545c3d927e17e98e8fd4a9f3c86f7f4def0bcfa816Florin Malita public long getNativeCanvasWrapper() { 555c3d927e17e98e8fd4a9f3c86f7f4def0bcfa816Florin Malita return mNativeCanvasWrapper; 56c677675e9c465dc1de21ecf2e0421835c7eb55b4Florin Malita } 57ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov 58a753f4c6cb8558795e673df1896532cd148781e2Chris Craik /** @hide */ 59a753f4c6cb8558795e673df1896532cd148781e2Chris Craik public boolean isRecordingFor(Object o) { return false; } 60a753f4c6cb8558795e673df1896532cd148781e2Chris Craik 61e0aa84b7dc087e999e20055dcc04cb6a48d5bd62Romain Guy // may be null 62e0aa84b7dc087e999e20055dcc04cb6a48d5bd62Romain Guy private Bitmap mBitmap; 63ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // optional field set by the caller 65ce0537b80087a6225273040a987414b1dd081aa0Romain Guy private DrawFilter mDrawFilter; 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 67f61970fc79e9c5cf340fa942597628242361864aRomain Guy // Maximum bitmap size as defined in Skia's native code 68f61970fc79e9c5cf340fa942597628242361864aRomain Guy // (see SkCanvas.cpp, SkDraw.cpp) 69f61970fc79e9c5cf340fa942597628242361864aRomain Guy private static final int MAXMIMUM_BITMAP_SIZE = 32766; 70f61970fc79e9c5cf340fa942597628242361864aRomain Guy 71775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler // The approximate size of the native allocation associated with 72775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler // a Canvas object. 73775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler private static final long NATIVE_ALLOCATION_SIZE = 525; 74e4ac2d6b5723c95e648c489b187ddde449452c13Patrick Dubroy 75f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe // Use a Holder to allow static initialization of Canvas in the boot image. 76f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe private static class NoImagePreloadHolder { 77f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( 78caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck Canvas.class.getClassLoader(), nGetNativeFinalizer(), NATIVE_ALLOCATION_SIZE); 79f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe } 80ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov 81775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler // This field is used to finalize the native Canvas properly 82775873a66a946fae2b0535abb51df9817bd1b20cRichard Uhler private Runnable mFinalizer; 83e4ac2d6b5723c95e648c489b187ddde449452c13Patrick Dubroy 84f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt /** 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to 8696e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * draw into. The initial target density is {@link Bitmap#DENSITY_NONE}; 8796e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * this will typically be replaced when a target bitmap is set for the 8896e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * canvas. 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Canvas() { 91003123004f7b23b3dc472d5c40b8c1a16df37a54Romain Guy if (!isHardwareAccelerated()) { 92003123004f7b23b3dc472d5c40b8c1a16df37a54Romain Guy // 0 means no native bitmap 93caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck mNativeCanvasWrapper = nInitRaster(null); 94f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation( 95f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe this, mNativeCanvasWrapper); 96003123004f7b23b3dc472d5c40b8c1a16df37a54Romain Guy } else { 97003123004f7b23b3dc472d5c40b8c1a16df37a54Romain Guy mFinalizer = null; 98003123004f7b23b3dc472d5c40b8c1a16df37a54Romain Guy } 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Construct a canvas with the specified bitmap to draw into. The bitmap 1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * must be mutable. 104051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 10596e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * <p>The initial target density of the canvas is the same as the given 10696e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * bitmap's density. 1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 110ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public Canvas(@NonNull Bitmap bitmap) { 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (!bitmap.isMutable()) { 112f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy throw new IllegalStateException("Immutable bitmap passed to Canvas constructor"); 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1141abf5d62429e5a9329520b2f7c2b5a5e7a8e72ecChris Craik throwIfCannotDraw(bitmap); 115caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck mNativeCanvasWrapper = nInitRaster(bitmap); 116f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation( 117f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe this, mNativeCanvasWrapper); 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mBitmap = bitmap; 11996e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn mDensity = bitmap.mDensity; 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 121ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov 122ff4adde5737be08d3e2d03fbe588c591d27d4a74Svetoslav Ganov /** @hide */ 12336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat public Canvas(long nativeCanvas) { 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (nativeCanvas == 0) { 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new IllegalStateException(); 1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1278872b38ef403cc2c44aca07d392f5e9426fd7f54Derek Sollenberger mNativeCanvasWrapper = nativeCanvas; 128f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation( 129f6765f3965ce669458e0bb5d2e226d4233a1acb3Andreas Gampe this, mNativeCanvasWrapper); 13096e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn mDensity = Bitmap.getDefaultDensity(); 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 132163935113919a184122b8b3bd672ef08c8df65dcRomain Guy 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 134091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik * Returns null. 135c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik * 136091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik * @deprecated This method is not supported and should not be invoked. 137c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik * 138091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik * @hide 139091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik */ 140091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik @Deprecated 141091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik protected GL getGL() { 142091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik return null; 143091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik } 144091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik 145091ddb1374e3bcdac129c1df5ef2555cf5c2183eChris Craik /** 1462d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy * Indicates whether this Canvas uses hardware acceleration. 147051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 1482d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy * Note that this method does not define what type of hardware acceleration 1492d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy * may or may not be used. 150051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 1512d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy * @return True if drawing operations are hardware accelerated, 1522d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy * false otherwise. 1532d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy */ 1542d6145993e19d2bb664766dbaf3c1e9ad3d12cdcRomain Guy public boolean isHardwareAccelerated() { 155163935113919a184122b8b3bd672ef08c8df65dcRomain Guy return false; 156caf0df1b7f99736aed1a0b923ef278fc4fd0fccaMike Reed } 157163935113919a184122b8b3bd672ef08c8df65dcRomain Guy 1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 159051910b9f998030dacb8a0722588cc715813fde1Raph Levien * Specify a bitmap for the canvas to draw into. All canvas state such as 1603bd9a6dc6b30ed0ce40ca9087ca0f4b1ca789100Derek Sollenberger * layers, filters, and the save/restore stack are reset with the exception 1613bd9a6dc6b30ed0ce40ca9087ca0f4b1ca789100Derek Sollenberger * of the current matrix and clip stack. Additionally, as a side-effect 1623bd9a6dc6b30ed0ce40ca9087ca0f4b1ca789100Derek Sollenberger * the canvas' target density is updated to match that of the bitmap. 1639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 16596e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * @see #setDensity(int) 16696e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * @see #getDensity() 1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 168ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void setBitmap(@Nullable Bitmap bitmap) { 169163935113919a184122b8b3bd672ef08c8df65dcRomain Guy if (isHardwareAccelerated()) { 17096890564bdbd2f2a41dfc323fc8b3938fb335639Chris Craik throw new RuntimeException("Can't set a bitmap device on a HW accelerated canvas"); 1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 173fc615a0f643408956fc0dc1b997871e2b27cee7eDerek Sollenberger if (bitmap == null) { 174caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSetBitmap(mNativeCanvasWrapper, null); 175fc615a0f643408956fc0dc1b997871e2b27cee7eDerek Sollenberger mDensity = Bitmap.DENSITY_NONE; 176fc615a0f643408956fc0dc1b997871e2b27cee7eDerek Sollenberger } else { 1770965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy if (!bitmap.isMutable()) { 1780965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy throw new IllegalStateException(); 1790965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy } 1801abf5d62429e5a9329520b2f7c2b5a5e7a8e72ecChris Craik throwIfCannotDraw(bitmap); 181fc615a0f643408956fc0dc1b997871e2b27cee7eDerek Sollenberger 182caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSetBitmap(mNativeCanvasWrapper, bitmap); 1830965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy mDensity = bitmap.mDensity; 1840965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy } 1850965a3244b4c3009d08db2e084cdcb681ef66d26Romain Guy 1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mBitmap = bitmap; 1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 188c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 189cce47eb580d666ead1f6095d1e3b65233592bbaaChris Craik /** @hide */ 1906578a989566e585eee053095dc80e2552e125db2Derek Sollenberger public void setHighContrastText(boolean highContrastText) { 191caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSetHighContrastText(mNativeCanvasWrapper, highContrastText); 1926578a989566e585eee053095dc80e2552e125db2Derek Sollenberger } 193cce47eb580d666ead1f6095d1e3b65233592bbaaChris Craik 1948afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik /** @hide */ 1958afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik public void insertReorderBarrier() {} 1968afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik 1978afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik /** @hide */ 1988afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik public void insertInorderBarrier() {} 1998afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik 200797b95b26bbb7557678af78b9a2a61830158920fChris Craik /** 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return true if the device that the current layer draws into is opaque 2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (i.e. does not support per-pixel alpha). 2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the device that the current layer draws into is opaque 2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 20695d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public boolean isOpaque() { 207caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nIsOpaque(mNativeCanvasWrapper); 20895d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the width of the current drawing layer 2129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the width of the current drawing layer 2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21595d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public int getWidth() { 216caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nGetWidth(mNativeCanvasWrapper); 21795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the height of the current drawing layer 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the height of the current drawing layer 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22495d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public int getHeight() { 225caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nGetHeight(mNativeCanvasWrapper); 22695d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22996e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * <p>Returns the target density of the canvas. The default density is 23096e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * derived from the density of its backing bitmap, or 23196e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * {@link Bitmap#DENSITY_NONE} if there is not one.</p> 2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 23396e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * @return Returns the current target density of the canvas, which is used 23496e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * to determine the scaling factor when drawing a bitmap into it. 2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 23611ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn * @see #setDensity(int) 237051910b9f998030dacb8a0722588cc715813fde1Raph Levien * @see Bitmap#getDensity() 2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23911ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn public int getDensity() { 24011ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn return mDensity; 2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24496e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * <p>Specifies the density for this Canvas' backing bitmap. This modifies 24596e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * the target density of the canvas itself, as well as the density of its 24696e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * backing bitmap via {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}. 2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24896e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * @param density The new target density of the canvas, which is used 24996e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * to determine the scaling factor when drawing a bitmap into it. Use 25096e240f25a97c10bba863df328ed73a82c34ff61Dianne Hackborn * {@link Bitmap#DENSITY_NONE} to disable bitmap scaling. 2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 25211ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn * @see #getDensity() 253051910b9f998030dacb8a0722588cc715813fde1Raph Levien * @see Bitmap#setDensity(int) 2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 25511ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn public void setDensity(int density) { 2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mBitmap != null) { 25711ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn mBitmap.setDensity(density); 2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25911ea33471e1a14a8594f0b2cd012d86340dd3bd8Dianne Hackborn mDensity = density; 2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2620d221012ff5fd314711c00ed30e9b807b9c454c1Dianne Hackborn /** @hide */ 2630d221012ff5fd314711c00ed30e9b807b9c454c1Dianne Hackborn public void setScreenDensity(int density) { 2640d221012ff5fd314711c00ed30e9b807b9c454c1Dianne Hackborn mScreenDensity = density; 2650d221012ff5fd314711c00ed30e9b807b9c454c1Dianne Hackborn } 266f61970fc79e9c5cf340fa942597628242361864aRomain Guy 267f61970fc79e9c5cf340fa942597628242361864aRomain Guy /** 268f61970fc79e9c5cf340fa942597628242361864aRomain Guy * Returns the maximum allowed width for bitmaps drawn with this canvas. 269f61970fc79e9c5cf340fa942597628242361864aRomain Guy * Attempting to draw with a bitmap wider than this value will result 270f61970fc79e9c5cf340fa942597628242361864aRomain Guy * in an error. 271051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 272051910b9f998030dacb8a0722588cc715813fde1Raph Levien * @see #getMaximumBitmapHeight() 273f61970fc79e9c5cf340fa942597628242361864aRomain Guy */ 274f61970fc79e9c5cf340fa942597628242361864aRomain Guy public int getMaximumBitmapWidth() { 275f61970fc79e9c5cf340fa942597628242361864aRomain Guy return MAXMIMUM_BITMAP_SIZE; 276f61970fc79e9c5cf340fa942597628242361864aRomain Guy } 277051910b9f998030dacb8a0722588cc715813fde1Raph Levien 278f61970fc79e9c5cf340fa942597628242361864aRomain Guy /** 279f61970fc79e9c5cf340fa942597628242361864aRomain Guy * Returns the maximum allowed height for bitmaps drawn with this canvas. 280f61970fc79e9c5cf340fa942597628242361864aRomain Guy * Attempting to draw with a bitmap taller than this value will result 281f61970fc79e9c5cf340fa942597628242361864aRomain Guy * in an error. 282051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 283051910b9f998030dacb8a0722588cc715813fde1Raph Levien * @see #getMaximumBitmapWidth() 284f61970fc79e9c5cf340fa942597628242361864aRomain Guy */ 285f61970fc79e9c5cf340fa942597628242361864aRomain Guy public int getMaximumBitmapHeight() { 286f61970fc79e9c5cf340fa942597628242361864aRomain Guy return MAXMIMUM_BITMAP_SIZE; 287f61970fc79e9c5cf340fa942597628242361864aRomain Guy } 288f61970fc79e9c5cf340fa942597628242361864aRomain Guy 2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // the SAVE_FLAG constants must match their native equivalents 2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 291ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese /** @hide */ 292ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @IntDef(flag = true, 293ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese value = { 294ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese ALL_SAVE_FLAG 295ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese }) 296ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @Retention(RetentionPolicy.SOURCE) 297ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public @interface Saveflags {} 298ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese 299f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 300f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Restore the current matrix when restore() is called. 301b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 302b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use the flagless version of {@link #save()}, {@link #saveLayer(RectF, Paint)} or 303b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link #saveLayerAlpha(RectF, int)}. For saveLayer() calls the matrix 304b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * was always restored for {@link #isHardwareAccelerated() Hardware accelerated} 305b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * canvases and as of API level {@value Build.VERSION_CODES#O} that is the default 306b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * behavior for all canvas types. 307f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MATRIX_SAVE_FLAG = 0x01; 309f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik 310f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 311f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Restore the current clip when restore() is called. 312b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 313b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use the flagless version of {@link #save()}, {@link #saveLayer(RectF, Paint)} or 314b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link #saveLayerAlpha(RectF, int)}. For saveLayer() calls the clip 315b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * was always restored for {@link #isHardwareAccelerated() Hardware accelerated} 316b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * canvases and as of API level {@value Build.VERSION_CODES#O} that is the default 317b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * behavior for all canvas types. 318f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CLIP_SAVE_FLAG = 0x02; 320f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik 321f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 322f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * The layer requires a per-pixel alpha channel. 323b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 324b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated This flag is ignored. Use the flagless version of {@link #saveLayer(RectF, Paint)} 325b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link #saveLayerAlpha(RectF, int)}. 326f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int HAS_ALPHA_LAYER_SAVE_FLAG = 0x04; 328f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik 329f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 330f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * The layer requires full 8-bit precision for each color channel. 331b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 332b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated This flag is ignored. Use the flagless version of {@link #saveLayer(RectF, Paint)} 333b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link #saveLayerAlpha(RectF, int)}. 334f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int FULL_COLOR_LAYER_SAVE_FLAG = 0x08; 336f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik 337f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 338f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Clip drawing to the bounds of the offscreen layer, omit at your own peril. 339f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p class="note"><strong>Note:</strong> it is strongly recommended to not 340f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * omit this flag for any call to <code>saveLayer()</code> and 341f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <code>saveLayerAlpha()</code> variants. Not passing this flag generally 342f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * triggers extremely poor performance with hardware accelerated rendering. 343b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 344b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated This flag results in poor performance and the same effect can be achieved with 345b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * a single layer or multiple draw commands with different clips. 346b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 347f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 3489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CLIP_TO_LAYER_SAVE_FLAG = 0x10; 349f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik 350f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik /** 351f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Restore everything when restore() is called (standard save flags). 352f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p class="note"><strong>Note:</strong> for performance reasons, it is 353f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * strongly recommended to pass this - the complete set of flags - to any 354f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * call to <code>saveLayer()</code> and <code>saveLayerAlpha()</code> 355f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * variants. 356b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 357b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * <p class="note"><strong>Note:</strong> all methods that accept this flag 358b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * have flagless versions that are equivalent to passing this flag. 359f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik */ 360051910b9f998030dacb8a0722588cc715813fde1Raph Levien public static final int ALL_SAVE_FLAG = 0x1F; 361051910b9f998030dacb8a0722588cc715813fde1Raph Levien 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 363f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Saves the current matrix and clip onto a private stack. 364f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 365f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Subsequent calls to translate,scale,rotate,skew,concat or clipRect, 366f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * clipPath will all operate as usual, but when the balancing call to 367f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * restore() is made, those calls will be forgotten, and the settings that 368f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * existed before the save() will be reinstated. 3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return The value to pass to restoreToCount() to balance this save() 3719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 37295d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public int save() { 373caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nSave(mNativeCanvasWrapper, MATRIX_SAVE_FLAG | CLIP_SAVE_FLAG); 37495d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 375051910b9f998030dacb8a0722588cc715813fde1Raph Levien 3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Based on saveFlags, can save the current matrix and clip onto a private 378f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * stack. 379f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p class="note"><strong>Note:</strong> if possible, use the 380f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * parameter-less save(). It is simpler and faster than individually 381f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * disabling the saving of matrix or clip with this method. 382f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 383f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Subsequent calls to translate,scale,rotate,skew,concat or clipRect, 384f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * clipPath will all operate as usual, but when the balancing call to 385f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * restore() is made, those calls will be forgotten, and the settings that 386f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * existed before the save() will be reinstated. 3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 388b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use {@link #save()} instead. 3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param saveFlags flag bits that specify which parts of the Canvas state 3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to save/restore 3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return The value to pass to restoreToCount() to balance this save() 3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 393ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public int save(@Saveflags int saveFlags) { 394caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nSave(mNativeCanvasWrapper, saveFlags); 39595d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 398f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * This behaves the same as save(), but in addition it allocates and 399f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * redirects drawing to an offscreen bitmap. 400f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p class="note"><strong>Note:</strong> this method is very expensive, 401f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * incurring more than double rendering cost for contained content. Avoid 402f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * using this method, especially if the bounds provided are large, or if 403f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * the {@link #CLIP_TO_LAYER_SAVE_FLAG} is omitted from the 404f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@code saveFlags} parameter. It is recommended to use a 405f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@link android.view.View#LAYER_TYPE_HARDWARE hardware layer} on a View 406f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * to apply an xfermode, color filter, or alpha, as it will perform much 407f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * better than this method. 408f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 409f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * All drawing calls are directed to a newly allocated offscreen bitmap. 410f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Only when the balancing call to restore() is made, is that offscreen 411f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * buffer drawn back to the current target of the Canvas (either the 412f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * screen, it's target Bitmap, or the previous layer). 413f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 414f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Attributes of the Paint - {@link Paint#getAlpha() alpha}, 415f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@link Paint#getXfermode() Xfermode}, and 416f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@link Paint#getColorFilter() ColorFilter} are applied when the 417f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * offscreen bitmap is drawn back when restore() is called. 4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 419b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use {@link #saveLayer(RectF, Paint)} instead. 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bounds May be null. The maximum size the offscreen bitmap 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * needs to be (in local coordinates) 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param paint This is copied, and is applied to the offscreen when 4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * restore() is called. 424f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * @param saveFlags see _SAVE_FLAG constants, generally {@link #ALL_SAVE_FLAG} is recommended 425f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * for performance reasons. 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return value to pass to restoreToCount() to balance this save() 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 428ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public int saveLayer(@Nullable RectF bounds, @Nullable Paint paint, @Saveflags int saveFlags) { 4299bc13a353fa8fac323839268789ef661b219530cChris Craik if (bounds == null) { 4309bc13a353fa8fac323839268789ef661b219530cChris Craik bounds = new RectF(getClipBounds()); 4319bc13a353fa8fac323839268789ef661b219530cChris Craik } 4329bc13a353fa8fac323839268789ef661b219530cChris Craik return saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, paint, saveFlags); 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 434c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 435c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik /** 436b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * This behaves the same as save(), but in addition it allocates and 437b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * redirects drawing to an offscreen rendering target. 438b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * <p class="note"><strong>Note:</strong> this method is very expensive, 439b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * incurring more than double rendering cost for contained content. Avoid 440b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * using this method when possible and instead use a 441b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link android.view.View#LAYER_TYPE_HARDWARE hardware layer} on a View 442b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * to apply an xfermode, color filter, or alpha, as it will perform much 443b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * better than this method. 444b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * <p> 445b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * All drawing calls are directed to a newly allocated offscreen rendering target. 446b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * Only when the balancing call to restore() is made, is that offscreen 447b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * buffer drawn back to the current target of the Canvas (which can potentially be a previous 448b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * layer if these calls are nested). 449b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * <p> 450b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * Attributes of the Paint - {@link Paint#getAlpha() alpha}, 451b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link Paint#getXfermode() Xfermode}, and 452b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * {@link Paint#getColorFilter() ColorFilter} are applied when the 453b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * offscreen rendering target is drawn back when restore() is called. 454b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 455b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @param bounds May be null. The maximum size the offscreen render target 456b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * needs to be (in local coordinates) 457b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @param paint This is copied, and is applied to the offscreen when 458b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * restore() is called. 459b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @return value to pass to restoreToCount() to balance this save() 460c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik */ 461ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public int saveLayer(@Nullable RectF bounds, @Nullable Paint paint) { 462c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik return saveLayer(bounds, paint, ALL_SAVE_FLAG); 463c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik } 464c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Helper version of saveLayer() that takes 4 values rather than a RectF. 467b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 468b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use {@link #saveLayer(float, float, float, float, Paint)} instead. 4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 470ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint, 471ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @Saveflags int saveFlags) { 472caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nSaveLayer(mNativeCanvasWrapper, left, top, right, bottom, 473dfba4d3d11bbf47dff45f94d61d4d97510b3034aDerek Sollenberger paint != null ? paint.getNativeInstance() : 0, 474f296dca95f09be9832b5dcc79717986525d2b6cbRomain Guy saveFlags); 4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 478b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * Convenience for {@link #saveLayer(RectF, Paint)} that takes the four float coordinates of the 479b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * bounds rectangle. 480c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik */ 481ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint) { 482c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik return saveLayer(left, top, right, bottom, paint, ALL_SAVE_FLAG); 483c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik } 484c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 485c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik /** 486f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * This behaves the same as save(), but in addition it allocates and 487f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * redirects drawing to an offscreen bitmap. 488f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p class="note"><strong>Note:</strong> this method is very expensive, 489f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * incurring more than double rendering cost for contained content. Avoid 490f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * using this method, especially if the bounds provided are large, or if 491f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * the {@link #CLIP_TO_LAYER_SAVE_FLAG} is omitted from the 492f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@code saveFlags} parameter. It is recommended to use a 493f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * {@link android.view.View#LAYER_TYPE_HARDWARE hardware layer} on a View 494f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * to apply an xfermode, color filter, or alpha, as it will perform much 495f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * better than this method. 496f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 497f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * All drawing calls are directed to a newly allocated offscreen bitmap. 498f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * Only when the balancing call to restore() is made, is that offscreen 499f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * buffer drawn back to the current target of the Canvas (either the 500f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * screen, it's target Bitmap, or the previous layer). 501f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * <p> 502f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * The {@code alpha} parameter is applied when the offscreen bitmap is 503f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * drawn back when restore() is called. 5049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 505b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use {@link #saveLayerAlpha(RectF, int)} instead. 5069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bounds The maximum size the offscreen bitmap needs to be 5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (in local coordinates) 5080d3d1f825f399c62f2ba236b53bef17581e03a16Sungsoo Lim * @param alpha The alpha to apply to the offscreen when it is 5099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project drawn during restore() 510f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * @param saveFlags see _SAVE_FLAG constants, generally {@link #ALL_SAVE_FLAG} is recommended 511f37a364a530c5c055cf4634f0b0463454a252b0fChris Craik * for performance reasons. 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return value to pass to restoreToCount() to balance this call 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5149bc13a353fa8fac323839268789ef661b219530cChris Craik public int saveLayerAlpha(@Nullable RectF bounds, int alpha, @Saveflags int saveFlags) { 5159bc13a353fa8fac323839268789ef661b219530cChris Craik if (bounds == null) { 5169bc13a353fa8fac323839268789ef661b219530cChris Craik bounds = new RectF(getClipBounds()); 5179bc13a353fa8fac323839268789ef661b219530cChris Craik } 5189bc13a353fa8fac323839268789ef661b219530cChris Craik return saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, alpha, saveFlags); 5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 520c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 521c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik /** 522b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * Convenience for {@link #saveLayer(RectF, Paint)} but instead of taking a entire Paint object 523b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * it takes only the {@code alpha} parameter. 524b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 525b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @param bounds The maximum size the offscreen bitmap needs to be 526b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * (in local coordinates) 527b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @param alpha The alpha to apply to the offscreen when it is 528b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger drawn during restore() 529c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik */ 5309bc13a353fa8fac323839268789ef661b219530cChris Craik public int saveLayerAlpha(@Nullable RectF bounds, int alpha) { 531c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik return saveLayerAlpha(bounds, alpha, ALL_SAVE_FLAG); 532c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik } 533c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Helper for saveLayerAlpha() that takes 4 values instead of a RectF. 536b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * 537b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * @deprecated Use {@link #saveLayerAlpha(float, float, float, float, int)} instead. 5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 539f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, 540ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @Saveflags int saveFlags) { 5419bc13a353fa8fac323839268789ef661b219530cChris Craik alpha = Math.min(255, Math.max(0, alpha)); 542caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nSaveLayerAlpha(mNativeCanvasWrapper, left, top, right, bottom, 5439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project alpha, saveFlags); 5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 547b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * Convenience for {@link #saveLayerAlpha(RectF, int)} that takes the four float coordinates of 548b8201195dfb2bae05faaf91b9b3d065e2f199929Derek Sollenberger * the bounds rectangle. 549c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik */ 550c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) { 551c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik return saveLayerAlpha(left, top, right, bottom, alpha, ALL_SAVE_FLAG); 552c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik } 553c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik 554c306ad61a791bae34ed83b339f27cb67a1d91b53Chris Craik /** 5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This call balances a previous call to save(), and is used to remove all 5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * modifications to the matrix/clip state since the last save call. It is 5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * an error to call restore() more times than save() was called. 5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 55995d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void restore() { 560bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik if (!nRestore(mNativeCanvasWrapper) 561bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik && (!sCompatibilityRestore || !isHardwareAccelerated())) { 562bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik throw new IllegalStateException("Underflow in restore - more restores than saves"); 563bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik } 56495d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the number of matrix/clip states on the Canvas' private stack. 5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This will equal # save() calls - # restore() calls. 5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 57095d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public int getSaveCount() { 571caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nGetSaveCount(mNativeCanvasWrapper); 57295d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Efficient way to pop any calls to save() that happened after the save 5769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * count reached saveCount. It is an error for saveCount to be less than 1. 5779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Example: 5799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * int count = canvas.save(); 5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ... // more calls potentially to save() 5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * canvas.restoreToCount(count); 5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * // now the canvas is back in the same state it was before the initial 5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * // call to save(). 5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param saveCount The save level to restore to. 5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 58795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void restoreToCount(int saveCount) { 588bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik if (saveCount < 1) { 589bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik if (!sCompatibilityRestore || !isHardwareAccelerated()) { 590bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik // do nothing and throw without restoring 591bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik throw new IllegalArgumentException( 592bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik "Underflow in restoreToCount - more restores than saves"); 593bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik } 594bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik // compat behavior - restore as far as possible 595bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik saveCount = 1; 596bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik } 597bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik nRestoreToCount(mNativeCanvasWrapper, saveCount); 59895d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified translation 6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The distance to translate in X 6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The distance to translate in Y 6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 60695d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void translate(float dx, float dy) { 60741f864ec45c4fc5c490936fd145c4b087c076646John Reck if (dx == 0.0f && dy == 0.0f) return; 608caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nTranslate(mNativeCanvasWrapper, dx, dy); 60995d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified scale. 6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sx The amount to scale in X 6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sy The amount to scale in Y 6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 61795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void scale(float sx, float sy) { 61841f864ec45c4fc5c490936fd145c4b087c076646John Reck if (sx == 1.0f && sy == 1.0f) return; 619caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nScale(mNativeCanvasWrapper, sx, sy); 62095d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified scale. 6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sx The amount to scale in X 6269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sy The amount to scale in Y 627cc3ec6cdb2b892eb29513e72d8b205acbe997b25Gilles Debunne * @param px The x-coord for the pivot point (unchanged by the scale) 628cc3ec6cdb2b892eb29513e72d8b205acbe997b25Gilles Debunne * @param py The y-coord for the pivot point (unchanged by the scale) 6299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void scale(float sx, float sy, float px, float py) { 63141f864ec45c4fc5c490936fd145c4b087c076646John Reck if (sx == 1.0f && sy == 1.0f) return; 6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project translate(px, py); 6339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project scale(sx, sy); 6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project translate(-px, -py); 6359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified rotation. 6399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param degrees The amount to rotate, in degrees 6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 64295d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void rotate(float degrees) { 64341f864ec45c4fc5c490936fd145c4b087c076646John Reck if (degrees == 0.0f) return; 644caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nRotate(mNativeCanvasWrapper, degrees); 64595d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 6469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified rotation. 6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param degrees The amount to rotate, in degrees 6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param px The x-coord for the pivot point (unchanged by the rotation) 6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param py The y-coord for the pivot point (unchanged by the rotation) 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void rotate(float degrees, float px, float py) { 65541f864ec45c4fc5c490936fd145c4b087c076646John Reck if (degrees == 0.0f) return; 6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project translate(px, py); 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project rotate(degrees); 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project translate(-px, -py); 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Preconcat the current matrix with the specified skew. 6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sx The amount to skew in X 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sy The amount to skew in Y 6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 66795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public void skew(float sx, float sy) { 66841f864ec45c4fc5c490936fd145c4b087c076646John Reck if (sx == 0.0f && sy == 0.0f) return; 669caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSkew(mNativeCanvasWrapper, sx, sy); 67095d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6734e7b772b733593fbe25c733e95b8dcea293234b6Romain Guy * Preconcat the current matrix with the specified matrix. If the specified 6744e7b772b733593fbe25c733e95b8dcea293234b6Romain Guy * matrix is null, this method does nothing. 6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param matrix The matrix to preconcatenate with the current matrix 6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 678ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void concat(@Nullable Matrix matrix) { 679caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck if (matrix != null) nConcat(mNativeCanvasWrapper, matrix.native_instance); 6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 681051910b9f998030dacb8a0722588cc715813fde1Raph Levien 6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Completely replace the current matrix with the specified matrix. If the 6849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * matrix parameter is null, then the current matrix is reset to identity. 685051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 686f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy * <strong>Note:</strong> it is recommended to use {@link #concat(Matrix)}, 687f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy * {@link #scale(float, float)}, {@link #translate(float, float)} and 688f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy * {@link #rotate(float)} instead of this method. 6899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param matrix The matrix to replace the current matrix with. If it is 6919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * null, set the current matrix to identity. 692051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 693051910b9f998030dacb8a0722588cc715813fde1Raph Levien * @see #concat(Matrix) 6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 695ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void setMatrix(@Nullable Matrix matrix) { 696caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSetMatrix(mNativeCanvasWrapper, 6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project matrix == null ? 0 : matrix.native_instance); 6989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 699051910b9f998030dacb8a0722588cc715813fde1Raph Levien 7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return, in ctm, the current transformation matrix. This does not alter 7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the matrix in the canvas, but just returns a copy of it. 703eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * 704eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * @deprecated {@link #isHardwareAccelerated() Hardware accelerated} canvases may have any 705eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * matrix when passed to a View or Drawable, as it is implementation defined where in the 706eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * hierarchy such canvases are created. It is recommended in such cases to either draw contents 707eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * irrespective of the current matrix, or to track relevant transform state outside of the 708eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * canvas. 7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 710f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy @Deprecated 711ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void getMatrix(@NonNull Matrix ctm) { 712bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik nGetMatrix(mNativeCanvasWrapper, ctm.native_instance); 7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 71441030da16856c8869e1e51d4a0405432fa96614eRomain Guy 71541030da16856c8869e1e51d4a0405432fa96614eRomain Guy /** 7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return a new matrix with a copy of the canvas' current transformation 7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * matrix. 718eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * 719eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * @deprecated {@link #isHardwareAccelerated() Hardware accelerated} canvases may have any 720eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * matrix when passed to a View or Drawable, as it is implementation defined where in the 721eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * hierarchy such canvases are created. It is recommended in such cases to either draw contents 722eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * irrespective of the current matrix, or to track relevant transform state outside of the 723eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * canvas. 7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 72565447287cb4112cf74483c87be70bcd00b622e2dRomain Guy @Deprecated 726ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public final @NonNull Matrix getMatrix() { 7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Matrix m = new Matrix(); 728f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy //noinspection deprecation 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project getMatrix(m); 7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return m; 7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 732051910b9f998030dacb8a0722588cc715813fde1Raph Levien 7339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Modify the current clip with the specified rectangle. 7359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The rect to intersect with the current clip 7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param op How the clip is modified 7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 7399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 740ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRect(@NonNull RectF rect, @NonNull Region.Op op) { 741caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 742f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy op.nativeInt); 7439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Modify the current clip with the specified rectangle, which is 7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 7489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The rectangle to intersect with the current clip. 7509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param op How the clip is modified 7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 753ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRect(@NonNull Rect rect, @NonNull Region.Op op) { 754caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 755f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy op.nativeInt); 7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified rectangle, which is 7609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 7619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The rectangle to intersect with the current clip. 7639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 765ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRect(@NonNull RectF rect) { 766caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 76795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita Region.Op.INTERSECT.nativeInt); 76895d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 76995d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita 7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified rectangle, which is 7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 7739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The rectangle to intersect with the current clip. 7759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 7769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 777ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRect(@NonNull Rect rect) { 778caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 77995d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita Region.Op.INTERSECT.nativeInt); 78095d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 781051910b9f998030dacb8a0722588cc715813fde1Raph Levien 7829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Modify the current clip with the specified rectangle, which is 7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param left The left side of the rectangle to intersect with the 7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 7889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param top The top of the rectangle to intersect with the current 7899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clip 7909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param right The right side of the rectangle to intersect with the 7919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bottom The bottom of the rectangle to intersect with the current 7939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clip 7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param op How the clip is modified 7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 797ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRect(float left, float top, float right, float bottom, 798ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull Region.Op op) { 799caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, left, top, right, bottom, op.nativeInt); 8009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified rectangle, which is 8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param left The left side of the rectangle to intersect with the 8079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 8089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param top The top of the rectangle to intersect with the current clip 8099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param right The right side of the rectangle to intersect with the 8109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 8119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bottom The bottom of the rectangle to intersect with the current 8129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clip 8139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 8149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 81595d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public boolean clipRect(float left, float top, float right, float bottom) { 816caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, left, top, right, bottom, 81795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita Region.Op.INTERSECT.nativeInt); 81895d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 819f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy 8209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified rectangle, which is 8229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * expressed in local coordinates. 8239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param left The left side of the rectangle to intersect with the 8259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 8269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param top The top of the rectangle to intersect with the current clip 8279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param right The right side of the rectangle to intersect with the 8289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 8299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bottom The bottom of the rectangle to intersect with the current 8309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clip 8319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting clip is non-empty 8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 83395d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita public boolean clipRect(int left, int top, int right, int bottom) { 834caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipRect(mNativeCanvasWrapper, left, top, right, bottom, 83595d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita Region.Op.INTERSECT.nativeInt); 83695d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 837f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy 8389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Modify the current clip with the specified path. 8409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The path to operate on the current clip 8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param op How the clip is modified 8439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting is non-empty 8449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 845ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipPath(@NonNull Path path, @NonNull Region.Op op) { 846caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nClipPath(mNativeCanvasWrapper, path.readOnlyNI(), op.nativeInt); 8479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 848051910b9f998030dacb8a0722588cc715813fde1Raph Levien 8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified path. 8519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The path to intersect with the current clip 8539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting is non-empty 8549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 855ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipPath(@NonNull Path path) { 8569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return clipPath(path, Region.Op.INTERSECT); 8579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 858051910b9f998030dacb8a0722588cc715813fde1Raph Levien 8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Modify the current clip with the specified region. Note that unlike 8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clipRect() and clipPath() which transform their arguments by the 8629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current matrix, clipRegion() assumes its argument is already in the 8639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * coordinate system of the current layer's bitmap, and so not 8649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * transformation is performed. 8659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param region The region to operate on the current clip, based on op 8679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param op How the clip is modified 8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting is non-empty 8690d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * 870b29b16e5423fe7deab8ebf3da512c6d2192f19b5Derek Sollenberger * @removed 8710d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * @deprecated Unlike all other clip calls this API does not respect the 8720d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * current matrix. Use {@link #clipRect(Rect)} as an alternative. 8739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 874eda57925cafdf1dab451e70052dea27846f368b4Chris Craik @Deprecated 875ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRegion(@NonNull Region region, @NonNull Region.Op op) { 876b29b16e5423fe7deab8ebf3da512c6d2192f19b5Derek Sollenberger return false; 8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Intersect the current clip with the specified region. Note that unlike 8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clipRect() and clipPath() which transform their arguments by the 8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current matrix, clipRegion() assumes its argument is already in the 8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * coordinate system of the current layer's bitmap, and so not 8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * transformation is performed. 8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param region The region to operate on the current clip, based on op 8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the resulting is non-empty 8880d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * 889b29b16e5423fe7deab8ebf3da512c6d2192f19b5Derek Sollenberger * @removed 8900d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * @deprecated Unlike all other clip calls this API does not respect the 8910d181540e0c96da454f45e65987f690b27b929d9Derek Sollenberger * current matrix. Use {@link #clipRect(Rect)} as an alternative. 8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 893eda57925cafdf1dab451e70052dea27846f368b4Chris Craik @Deprecated 894ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean clipRegion(@NonNull Region region) { 895b29b16e5423fe7deab8ebf3da512c6d2192f19b5Derek Sollenberger return false; 8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 897051910b9f998030dacb8a0722588cc715813fde1Raph Levien 898ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public @Nullable DrawFilter getDrawFilter() { 8999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mDrawFilter; 9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 901051910b9f998030dacb8a0722588cc715813fde1Raph Levien 902ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void setDrawFilter(@Nullable DrawFilter filter) { 90336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat long nativeFilter = 0; 9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (filter != null) { 9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project nativeFilter = filter.mNativeInt; 9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mDrawFilter = filter; 908caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nSetDrawFilter(mNativeCanvasWrapper, nativeFilter); 9099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9118b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase /** 9128b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * Constant values used as parameters to {@code quickReject()} calls. These values 9138b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * specify how much space around the shape should be accounted for, depending on whether 9148b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * the shaped area is antialiased or not. 9158b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * 9168b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * @see #quickReject(float, float, float, float, EdgeType) 9178b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * @see #quickReject(Path, EdgeType) 9188b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase * @see #quickReject(RectF, EdgeType) 9198b9ed44f8d559be2590b25cb4b72d2aefd3b3784Chet Haase */ 9209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public enum EdgeType { 921d320001807168f5565bab9807ef13c111096bbb3Chet Haase 922d320001807168f5565bab9807ef13c111096bbb3Chet Haase /** 923d320001807168f5565bab9807ef13c111096bbb3Chet Haase * Black-and-White: Treat edges by just rounding to nearest pixel boundary 924d320001807168f5565bab9807ef13c111096bbb3Chet Haase */ 9259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project BW(0), //!< treat edges by just rounding to nearest pixel boundary 926d320001807168f5565bab9807ef13c111096bbb3Chet Haase 927d320001807168f5565bab9807ef13c111096bbb3Chet Haase /** 928d320001807168f5565bab9807ef13c111096bbb3Chet Haase * Antialiased: Treat edges by rounding-out, since they may be antialiased 929d320001807168f5565bab9807ef13c111096bbb3Chet Haase */ 930d320001807168f5565bab9807ef13c111096bbb3Chet Haase AA(1); 931051910b9f998030dacb8a0722588cc715813fde1Raph Levien 9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project EdgeType(int nativeInt) { 9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project this.nativeInt = nativeInt; 9349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 935c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 936c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy /** 937c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy * @hide 938c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy */ 939c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy public final int nativeInt; 9409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return true if the specified rectangle, after being transformed by the 9449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current matrix, would lie completely outside of the current clip. Call 9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this to check if an area you intend to draw into is clipped out (and 9469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * therefore you can skip making the draw calls). 9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect the rect to compare with the current clip 949d320001807168f5565bab9807ef13c111096bbb3Chet Haase * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 950d320001807168f5565bab9807ef13c111096bbb3Chet Haase * since that means it may affect a larger area (more pixels) than 951d320001807168f5565bab9807ef13c111096bbb3Chet Haase * non-antialiased ({@link Canvas.EdgeType#BW}). 9529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the rect (transformed by the canvas' matrix) 9539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * does not intersect with the canvas' clip 9549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 955ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean quickReject(@NonNull RectF rect, @NonNull EdgeType type) { 956caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nQuickReject(mNativeCanvasWrapper, 95795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita rect.left, rect.top, rect.right, rect.bottom); 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return true if the specified path, after being transformed by the 9629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current matrix, would lie completely outside of the current clip. Call 9639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this to check if an area you intend to draw into is clipped out (and 9649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * therefore you can skip making the draw calls). Note: for speed it may 9659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * return false even if the path itself might not intersect the clip 9669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (i.e. the bounds of the path intersects, but the path does not). 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The path to compare with the current clip 969d320001807168f5565bab9807ef13c111096bbb3Chet Haase * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 970d320001807168f5565bab9807ef13c111096bbb3Chet Haase * since that means it may affect a larger area (more pixels) than 971d320001807168f5565bab9807ef13c111096bbb3Chet Haase * non-antialiased ({@link Canvas.EdgeType#BW}). 9729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the path (transformed by the canvas' matrix) 9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * does not intersect with the canvas' clip 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 975ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean quickReject(@NonNull Path path, @NonNull EdgeType type) { 976caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nQuickReject(mNativeCanvasWrapper, path.readOnlyNI()); 9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return true if the specified rectangle, after being transformed by the 9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current matrix, would lie completely outside of the current clip. Call 9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this to check if an area you intend to draw into is clipped out (and 9839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * therefore you can skip making the draw calls). 9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param left The left side of the rectangle to compare with the 9869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 9879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param top The top of the rectangle to compare with the current 9889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * clip 9899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param right The right side of the rectangle to compare with the 9909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 9919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bottom The bottom of the rectangle to compare with the 9929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current clip 993d320001807168f5565bab9807ef13c111096bbb3Chet Haase * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 994d320001807168f5565bab9807ef13c111096bbb3Chet Haase * since that means it may affect a larger area (more pixels) than 995d320001807168f5565bab9807ef13c111096bbb3Chet Haase * non-antialiased ({@link Canvas.EdgeType#BW}). 9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the rect (transformed by the canvas' matrix) 9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * does not intersect with the canvas' clip 9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 999ca79cf69d09efa0c327e9b1237d86a119aea5da7Derek Sollenberger public boolean quickReject(float left, float top, float right, float bottom, 1000ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull EdgeType type) { 1001caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nQuickReject(mNativeCanvasWrapper, left, top, right, bottom); 10029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1005708144e828b1a549567ce50cd8ed3cda62930501Derek Sollenberger * Return the bounds of the current clip (in local coordinates) in the 1006708144e828b1a549567ce50cd8ed3cda62930501Derek Sollenberger * bounds parameter, and return true if it is non-empty. This can be useful 1007708144e828b1a549567ce50cd8ed3cda62930501Derek Sollenberger * in a way similar to quickReject, in that it tells you that drawing 1008708144e828b1a549567ce50cd8ed3cda62930501Derek Sollenberger * outside of these bounds will be clipped out. 10099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bounds Return the clip bounds here. If it is null, ignore it but 10119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * still return true if the current clip is non-empty. 10129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the current clip is non-empty. 10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1014ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public boolean getClipBounds(@Nullable Rect bounds) { 1015caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck return nGetClipBounds(mNativeCanvasWrapper, bounds); 10169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1017051910b9f998030dacb8a0722588cc715813fde1Raph Levien 10189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1019708144e828b1a549567ce50cd8ed3cda62930501Derek Sollenberger * Retrieve the bounds of the current clip (in local coordinates). 10209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the clip bounds, or [0, 0, 0, 0] if the clip is empty. 10229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1023ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public final @NonNull Rect getClipBounds() { 10249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Rect r = new Rect(); 10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project getClipBounds(r); 10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return r; 10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1028051910b9f998030dacb8a0722588cc715813fde1Raph Levien 10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1030caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Save the canvas state, draw the picture, and restore the canvas state. 1031caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * This differs from picture.draw(canvas), which does not perform any 1032caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * save/restore. 10339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1034caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * <p> 1035caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * <strong>Note:</strong> This forces the picture to internally call 1036caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * {@link Picture#endRecording} in order to prepare for playback. 1037caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1038caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param picture The picture to be drawn 10399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1040caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPicture(@NonNull Picture picture) { 1041caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck picture.endRecording(); 1042caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck int restoreCount = save(); 1043caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck picture.draw(this); 1044caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck restoreToCount(restoreCount); 10459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1048caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draw the picture, stretched to fit into the dst rectangle. 10499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10501ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawPicture(@NonNull Picture picture, @NonNull RectF dst) { 1051caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck save(); 1052caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck translate(dst.left, dst.top); 1053caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck if (picture.getWidth() > 0 && picture.getHeight() > 0) { 10541ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); 1055caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1056caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck drawPicture(picture); 1057caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck restore(); 10589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1061caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draw the picture, stretched to fit into the dst rectangle. 10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawPicture(@NonNull Picture picture, @NonNull Rect dst) { 1064caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck save(); 1065caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck translate(dst.left, dst.top); 1066caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck if (picture.getWidth() > 0 && picture.getHeight() > 0) { 10671ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck scale((float) dst.width() / picture.getWidth(), 10681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck (float) dst.height() / picture.getHeight()); 1069caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1070caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck drawPicture(picture); 1071caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck restore(); 10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1074caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public enum VertexMode { 1075caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck TRIANGLES(0), 1076caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck TRIANGLE_STRIP(1), 1077caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck TRIANGLE_FAN(2); 1078caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1079caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck VertexMode(int nativeInt) { 1080caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck this.nativeInt = nativeInt; 1081caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1082caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1083caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 1084caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 1085caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1086caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public final int nativeInt; 10879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1090caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Releases the resources associated with this canvas. 10919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1092caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1094caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void release() { 1095caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck mNativeCanvasWrapper = 0; 1096caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck if (mFinalizer != null) { 1097caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck mFinalizer.run(); 1098caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck mFinalizer = null; 1099caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 11009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1101051910b9f998030dacb8a0722588cc715813fde1Raph Levien 11029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1103caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Free up as much memory as possible from private caches (e.g. fonts, images) 11049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1105caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 11069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1107caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public static void freeCaches() { 1108caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nFreeCaches(); 110995d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 11109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1112caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Free up text layout caches 1113caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1114caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 11159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1116caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public static void freeTextLayoutCaches() { 1117caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck nFreeTextLayoutCaches(); 11189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1120caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native void nFreeCaches(); 1121caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native void nFreeTextLayoutCaches(); 1122caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native long nInitRaster(Bitmap bitmap); 1123caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native long nGetNativeFinalizer(); 1124caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1125caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck // ---------------- @FastNative ------------------- 1126caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1127caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @FastNative 1128bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nSetBitmap(long canvasHandle, Bitmap bitmap); 1129bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik 1130caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @FastNative 1131bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native boolean nGetClipBounds(long nativeCanvas, Rect bounds); 1132bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik 1133bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik // ---------------- @CriticalNative ------------------- 1134bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik 1135bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1136caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native boolean nIsOpaque(long canvasHandle); 1137bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1138caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native void nSetHighContrastText(long renderer, boolean highContrastText); 1139bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1140caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native int nGetWidth(long canvasHandle); 1141bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1142caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native int nGetHeight(long canvasHandle); 1143caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1144bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1145caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native int nSave(long canvasHandle, int saveFlags); 1146bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1147bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native int nSaveLayer(long nativeCanvas, float l, float t, float r, float b, 1148bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik long nativePaint, int layerFlags); 1149bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1150bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native int nSaveLayerAlpha(long nativeCanvas, float l, float t, float r, float b, 1151bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik int alpha, int layerFlags); 1152bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1153bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native boolean nRestore(long canvasHandle); 1154bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1155bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nRestoreToCount(long canvasHandle, int saveCount); 1156bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1157caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native int nGetSaveCount(long canvasHandle); 1158caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1159bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1160bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nTranslate(long canvasHandle, float dx, float dy); 1161bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1162bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nScale(long canvasHandle, float sx, float sy); 1163bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1164caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native void nRotate(long canvasHandle, float degrees); 1165bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1166bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nSkew(long canvasHandle, float sx, float sy); 1167bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1168bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nConcat(long nativeCanvas, long nativeMatrix); 1169bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1170bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nSetMatrix(long nativeCanvas, long nativeMatrix); 1171bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1172caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck private static native boolean nClipRect(long nativeCanvas, 1173bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik float left, float top, float right, float bottom, int regionOp); 1174bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1175bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native boolean nClipPath(long nativeCanvas, long nativePath, int regionOp); 1176bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1177bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nSetDrawFilter(long nativeCanvas, long nativeFilter); 1178bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1179bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native void nGetMatrix(long nativeCanvas, long nativeMatrix); 1180bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1181bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native boolean nQuickReject(long nativeCanvas, long nativePath); 1182bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik @CriticalNative 1183bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik private static native boolean nQuickReject(long nativeCanvas, float left, float top, 1184bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik float right, float bottom); 1185bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik 1186bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik 1187bfa0b29883d56edfc2ec217962290d3c94f9fc2aChris Craik // ---------------- Draw Methods ------------------- 1188caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 11899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11901ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 11911ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified arc, which will be scaled to fit inside the specified oval. 11921ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 11931ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 11941ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * If the start angle is negative or >= 360, the start angle is treated as start angle modulo 11951ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * 360. 11961ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 11971ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 11981ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs 11991ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * slightly from SkPath::arcTo, which treats the sweep angle modulo 360. If the sweep angle is 12001ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * negative, the sweep angle is treated as sweep angle modulo 360 12011ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 12021ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12031ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 12041ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * degrees (3 o'clock on a watch.) 12051ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 1206caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 12071ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param oval The bounds of oval used to define the shape and size of the arc 1208caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param startAngle Starting angle (in degrees) where the arc begins 1209caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param sweepAngle Sweep angle (in degrees) measured clockwise 12101ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param useCenter If true, include the center of the oval in the arc, and close it if it is 12111ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * being stroked. This will draw a wedge 12121ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the arc 12139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12141ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawArc(@NonNull RectF oval, float startAngle, float sweepAngle, boolean useCenter, 12151ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck @NonNull Paint paint) { 12161ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawArc(oval, startAngle, sweepAngle, useCenter, paint); 121795d49149cc7fff87a18449fa661454c1b5ddbd30Florin Malita } 12189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12201ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12211ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified arc, which will be scaled to fit inside the specified oval. 12221ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 12231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12241ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * If the start angle is negative or >= 360, the start angle is treated as start angle modulo 12251ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * 360. 12261ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 12271ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12281ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * If the sweep angle is >= 360, then the oval is drawn completely. Note that this differs 12291ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * slightly from SkPath::arcTo, which treats the sweep angle modulo 360. If the sweep angle is 12301ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * negative, the sweep angle is treated as sweep angle modulo 360 12311ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 12321ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12331ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 12341ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * degrees (3 o'clock on a watch.) 12351ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 1236caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1237caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param startAngle Starting angle (in degrees) where the arc begins 1238caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param sweepAngle Sweep angle (in degrees) measured clockwise 12391ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param useCenter If true, include the center of the oval in the arc, and close it if it is 12401ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * being stroked. This will draw a wedge 12411ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the arc 12429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12431ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawArc(float left, float top, float right, float bottom, float startAngle, 12441ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck float sweepAngle, boolean useCenter, @NonNull Paint paint) { 12451ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint); 12469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12491ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB 12501ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * color, using srcover porterduff mode. 12519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1252caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param a alpha component (0..255) of the color to draw onto the canvas 1253caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param r red component (0..255) of the color to draw onto the canvas 1254caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param g green component (0..255) of the color to draw onto the canvas 1255caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param b blue component (0..255) of the color to draw onto the canvas 12569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1257caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawARGB(int a, int r, int g, int b) { 1258caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawARGB(a, r, g, b); 12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12621ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, 12631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * transformed by the current matrix. 12641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12651ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Note: if the paint contains a maskfilter that generates a mask which extends beyond the 12661ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it 12671ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be 12681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the edge color replicated. 12691ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12701ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * If the bitmap and canvas have different densities, this function will take care of 12711ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * automatically scaling the bitmap to draw at the same density as the canvas. 1272051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 12739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bitmap The bitmap to be drawn 12741ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param left The position of the left side of the bitmap being drawn 12751ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param top The position of the top side of the bitmap being drawn 12761ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the bitmap (may be null) 12779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1278ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) { 1279caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawBitmap(bitmap, left, top, paint); 12809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12831ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified bitmap, scaling/translating automatically to fill the destination 12841ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * rectangle. If the source rectangle is not null, it specifies the subset of the bitmap to 12851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * draw. 12861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12871ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Note: if the paint contains a maskfilter that generates a mask which extends beyond the 12881ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it 12891ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be 12901ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the edge color replicated. 12911ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 12921ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * This function <em>ignores the density associated with the bitmap</em>. This is because the 12931ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * source and destination rectangle coordinate spaces are in their respective densities, so must 12941ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * already have the appropriate scaling factor applied. 1295051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 12961ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param bitmap The bitmap to be drawn 12971ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param src May be null. The subset of the bitmap to be drawn 12981ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param dst The rectangle that the bitmap will be scaled/translated to fit into 12991ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint May be null. The paint used to draw the bitmap 13009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13011ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull RectF dst, 13021ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck @Nullable Paint paint) { 13031ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawBitmap(bitmap, src, dst, paint); 1304caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 13059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13071ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified bitmap, scaling/translating automatically to fill the destination 13081ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * rectangle. If the source rectangle is not null, it specifies the subset of the bitmap to 13091ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * draw. 13101ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 13111ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Note: if the paint contains a maskfilter that generates a mask which extends beyond the 13121ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it 13131ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be 13141ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the edge color replicated. 13151ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 13161ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * This function <em>ignores the density associated with the bitmap</em>. This is because the 13171ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * source and destination rectangle coordinate spaces are in their respective densities, so must 13181ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * already have the appropriate scaling factor applied. 1319051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 13209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bitmap The bitmap to be drawn 13211ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param src May be null. The subset of the bitmap to be drawn 13221ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param dst The rectangle that the bitmap will be scaled/translated to fit into 13231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint May be null. The paint used to draw the bitmap 13249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1325ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, 1326ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @Nullable Paint paint) { 1327caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawBitmap(bitmap, src, dst, paint); 1328caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1329caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1330caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 13311ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Treat the specified array of colors as a bitmap, and draw it. This gives the same result as 13321ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * first creating a bitmap from the array, and then drawing it, but this method avoids 13331ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * explicitly creating a bitmap object which can be more efficient if the colors are changing 13341ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * often. 13359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 13369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param colors Array of colors representing the pixels of the bitmap 13379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param offset Offset into the array of colors for the first pixel 13381ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param stride The number of colors in the array between rows (must be >= width or <= -width). 13399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x The X coordinate for where to draw the bitmap 13409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y The Y coordinate for where to draw the bitmap 13419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width The width of the bitmap 13429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height The height of the bitmap 13431ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param hasAlpha True if the alpha channel of the colors contains valid values. If false, the 13441ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * alpha byte is ignored (assumed to be 0xFF for every pixel). 13451ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint May be null. The paint used to draw the bitmap 1346cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 13471ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * requires an internal copy of color buffer contents every time this method is 13481ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * called. Using a Bitmap avoids this copy, and allows the application to more 13491ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * explicitly control the lifetime and copies of pixel data. 13509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1351cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik @Deprecated 1352ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawBitmap(@NonNull int[] colors, int offset, int stride, float x, float y, 1353ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese int width, int height, boolean hasAlpha, @Nullable Paint paint) { 1354caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawBitmap(colors, offset, stride, x, y, width, height, hasAlpha, paint); 13559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1356cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik 1357cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik /** 1358cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik * Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y 1359cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik * 1360cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 13611ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * requires an internal copy of color buffer contents every time this method is 13621ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * called. Using a Bitmap avoids this copy, and allows the application to more 13631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * explicitly control the lifetime and copies of pixel data. 13649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1365cd23df6a08cf7a9bdee11e703f40bca5904d779dChris Craik @Deprecated 1366ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawBitmap(@NonNull int[] colors, int offset, int stride, int x, int y, 1367ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese int width, int height, boolean hasAlpha, @Nullable Paint paint) { 1368caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawBitmap(colors, offset, stride, x, y, width, height, hasAlpha, paint); 13699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1370051910b9f998030dacb8a0722588cc715813fde1Raph Levien 13719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13721ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the bitmap using the specified matrix. 13731ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * 13741ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param bitmap The bitmap to draw 13751ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param matrix The matrix used to transform the bitmap when it is drawn 13761ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint May be null. The paint used to draw the bitmap 13771ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck */ 13781ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) { 13791ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawBitmap(bitmap, matrix, paint); 13801ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck } 13811ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck 13821ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck /** 13831ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the bitmap through the mesh, where mesh vertices are evenly distributed across the 13841ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * bitmap. There are meshWidth+1 vertices across, and meshHeight+1 vertices down. The verts 13851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * array is accessed in row-major order, so that the first meshWidth+1 vertices are distributed 13861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * across the top of the bitmap from left to right. A more general version of this method is 13871ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * drawVertices(). 13889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 13899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bitmap The bitmap to draw using the mesh 13901ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param meshWidth The number of columns in the mesh. Nothing is drawn if this is 0 13911ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param meshHeight The number of rows in the mesh. Nothing is drawn if this is 0 13921ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param verts Array of x,y pairs, specifying where the mesh should be drawn. There must be at 13931ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * least (meshWidth+1) * (meshHeight+1) * 2 + vertOffset values in the array 13949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param vertOffset Number of verts elements to skip before drawing 13951ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param colors May be null. Specifies a color at each vertex, which is interpolated across the 13961ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * cell, and whose values are multiplied by the corresponding bitmap colors. If not 13971ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * null, there must be at least (meshWidth+1) * (meshHeight+1) + colorOffset values 13981ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * in the array. 13999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param colorOffset Number of color elements to skip before drawing 14001ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint May be null. The paint used to draw the bitmap 14019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1402ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawBitmapMesh(@NonNull Bitmap bitmap, int meshWidth, int meshHeight, 1403ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull float[] verts, int vertOffset, @Nullable int[] colors, int colorOffset, 1404ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @Nullable Paint paint) { 1405caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawBitmapMesh(bitmap, meshWidth, meshHeight, verts, vertOffset, colors, colorOffset, 1406caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck paint); 14079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1408051910b9f998030dacb8a0722588cc715813fde1Raph Levien 14099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14101ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified circle using the specified paint. If radius is <= 0, then nothing will be 14111ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * drawn. The circle will be filled or framed based on the Style in the paint. 14129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 14131ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param cx The x-coordinate of the center of the cirle to be drawn 14141ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param cy The y-coordinate of the center of the cirle to be drawn 1415caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param radius The radius of the cirle to be drawn 14161ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the circle 14179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1418caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint) { 1419caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawCircle(cx, cy, radius, paint); 14209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 142136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat 14229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Fill the entire canvas' bitmap (restricted to the current clip) with the specified color, 14241ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * using srcover porterduff mode. 14259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1426caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param color the color to draw onto the canvas 14279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1428caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawColor(@ColorInt int color) { 1429caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawColor(color); 14309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 14319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 14329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14331ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and 14341ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * porter-duff xfermode. 14359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1436caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param color the color to draw with 14371ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param mode the porter-duff mode to apply to the color 14389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1439caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawColor(@ColorInt int color, @NonNull PorterDuff.Mode mode) { 1440caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawColor(color, mode); 1441f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt } 14429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 14439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14441ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw a line segment with the specified start and stop x,y coordinates, using the specified 14451ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * paint. 14461ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 14471ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Note that since a line is always "framed", the Style is ignored in the paint. 14481ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 14491ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 14501ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Degenerate lines (length is 0) will not be drawn. 14511ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * </p> 1452caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1453caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param startX The x-coordinate of the start point of the line 1454caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param startY The y-coordinate of the start point of the line 14551ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the line 14569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1457caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawLine(float startX, float startY, float stopX, float stopY, 1458ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull Paint paint) { 1459caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawLine(startX, startY, stopX, stopY, paint); 14609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 14619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 14629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw a series of lines. Each line is taken from 4 consecutive values in the pts array. Thus 14641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * to draw 1 line, the array must contain at least 4 values. This is logically the same as 14651ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * drawing the array as follows: drawLine(pts[0], pts[1], pts[2], pts[3]) followed by 1466caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * drawLine(pts[4], pts[5], pts[6], pts[7]) and so on. 14679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 14681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 14691ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param offset Number of values in the array to skip before drawing. 14701ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param count The number of values in the array to process, after skipping "offset" of them. 14711ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Since each line uses 4 values, the number of "lines" that are drawn is really 14721ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * (count >> 2). 14731ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the points 14749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 14751ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawLines(@Size(multiple = 4) @NonNull float[] pts, int offset, int count, 1476ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull Paint paint) { 1477caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawLines(pts, offset, count, paint); 1478caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1479caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 14801ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawLines(@Size(multiple = 4) @NonNull float[] pts, @NonNull Paint paint) { 1481caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawLines(pts, paint); 1482f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt } 1483f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt 1484f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt /** 14851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified oval using the specified paint. The oval will be filled or framed based on 14861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the Style in the paint. 1487caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1488caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param oval The rectangle bounds of the oval to be drawn 1489caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1490caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawOval(@NonNull RectF oval, @NonNull Paint paint) { 1491caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawOval(oval, paint); 1492f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt } 1493f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt 1494f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt /** 14951ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified oval using the specified paint. The oval will be filled or framed based on 14961ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the Style in the paint. 14971ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck */ 14981ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawOval(float left, float top, float right, float bottom, @NonNull Paint paint) { 14991ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawOval(left, top, right, bottom, paint); 15001ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck } 15011ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck 15021ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck /** 15031ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Fill the entire canvas' bitmap (restricted to the current clip) with the specified paint. 15041ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * This is equivalent (but faster) to drawing an infinitely large rectangle with the specified 15051ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * paint. 1506c6abf5bff6bbfafa1f133644f02a5d50d5269b7fRaph Levien * 1507caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used to draw onto the canvas 1508caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1509caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPaint(@NonNull Paint paint) { 1510caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPaint(paint); 1511caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1512caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1513caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 1514caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1515c6abf5bff6bbfafa1f133644f02a5d50d5269b7fRaph Levien * 1516caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param patch The ninepatch object to render 1517caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param dst The destination rectangle. 1518caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint to draw the bitmap with. may be null 1519caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 1520caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1521caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst, @Nullable Paint paint) { 1522caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPatch(patch, dst, paint); 1523caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1524caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1525caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 1526caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1527c6abf5bff6bbfafa1f133644f02a5d50d5269b7fRaph Levien * 1528caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param patch The ninepatch object to render 1529caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param dst The destination rectangle. 1530caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint to draw the bitmap with. may be null 1531caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @hide 1532caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1533caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPatch(@NonNull NinePatch patch, @NonNull RectF dst, @Nullable Paint paint) { 1534caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPatch(patch, dst, paint); 1535caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1536caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1537caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 15381ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified path using the specified paint. The path will be filled or framed based on 15391ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the Style in the paint. 1540c6abf5bff6bbfafa1f133644f02a5d50d5269b7fRaph Levien * 15411ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param path The path to be drawn 1542caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used to draw the path 1543f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt */ 1544caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPath(@NonNull Path path, @NonNull Paint paint) { 1545caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPath(path, paint); 1546caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1547f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt 1548caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 1549caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Helper for drawPoints() for drawing a single point. 1550caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1551caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawPoint(float x, float y, @NonNull Paint paint) { 1552caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPoint(x, y, paint); 1553caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1554f47d7405bbcb25d7cdf89ebb059f41520fe9ab87Doug Felt 1555caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 15561ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw a series of points. Each point is centered at the coordinate specified by pts[], and its 15571ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * diameter is specified by the paint's stroke width (as transformed by the canvas' CTM), with 15581ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * special treatment for a stroke width of 0, which always draws exactly 1 pixel (or at most 4 15591ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * if antialiasing is enabled). The shape of the point is controlled by the paint's Cap type. 15601ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * The shape is a square, unless the cap type is Round, in which case the shape is a circle. 1561caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 15621ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 15631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param offset Number of values to skip before starting to draw. 15641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param count The number of values to process, after skipping offset of them. Since one point 15651ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * uses two values, the number of "points" that are drawn is really (count >> 1). 15661ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the points 1567caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 15681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawPoints(@Size(multiple = 2) float[] pts, int offset, int count, 1569caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @NonNull Paint paint) { 1570caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPoints(pts, offset, count, paint); 1571caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1572caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1573caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 1574caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Helper for drawPoints() that assumes you want to draw the entire array 1575caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 15761ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawPoints(@Size(multiple = 2) @NonNull float[] pts, @NonNull Paint paint) { 1577caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPoints(pts, paint); 15789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 15799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 15809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 15811ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text in the array, with each character's origin specified by the pos array. 1582eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * 15831ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 15841ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param index The index of the first character to draw 15851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param count The number of characters to draw, starting from index. 15861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param pos Array of [x,y] positions, used to position each character 15871ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used for the text (e.g. color, size, style) 15881ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @deprecated This method does not support glyph composition and decomposition and should 15891ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * therefore not be used to render complex scripts. It also doesn't handle 15901ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * supplementary characters (eg emoji). 15919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1592f9d9c065ed75f1196316a9a31f92309f602cef76Romain Guy @Deprecated 1593b3ec733bb830f2d4425825d93f9ed95f284e9145Tor Norbye public void drawPosText(@NonNull char[] text, int index, int count, 15941ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck @NonNull @Size(multiple = 2) float[] pos, 1595ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese @NonNull Paint paint) { 1596caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPosText(text, index, count, pos, paint); 1597caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1598caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1599caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16001ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text in the array, with each character's origin specified by the pos array. 1601caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16021ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 16031ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param pos Array of [x,y] positions, used to position each character 1604caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used for the text (e.g. color, size, style) 16051ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @deprecated This method does not support glyph composition and decomposition and should 16061ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * therefore not be used to render complex scripts. It also doesn't handle 16071ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * supplementary characters (eg emoji). 1608caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1609caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @Deprecated 16101ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawPosText(@NonNull String text, @NonNull @Size(multiple = 2) float[] pos, 1611caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @NonNull Paint paint) { 1612caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawPosText(text, pos, paint); 1613caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1614caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1615caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16161ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified Rect using the specified paint. The rectangle will be filled or framed 16171ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Style in the paint. 1618caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16191ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param rect The rect to be drawn 16201ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the rect 1621caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 16221ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawRect(@NonNull RectF rect, @NonNull Paint paint) { 16231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawRect(rect, paint); 1624caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1625caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1626caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16271ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified Rect using the specified Paint. The rectangle will be filled or framed 16281ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Style in the paint. 1629caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16301ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param r The rectangle to be drawn. 16311ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used to draw the rectangle 1632caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1633caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawRect(@NonNull Rect r, @NonNull Paint paint) { 1634caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawRect(r, paint); 1635caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1636caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1637caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16381ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified Rect using the specified paint. The rectangle will be filled or framed 16391ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Style in the paint. 1640caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16411ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param left The left side of the rectangle to be drawn 16421ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param top The top side of the rectangle to be drawn 16431ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param right The right side of the rectangle to be drawn 16441ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param bottom The bottom side of the rectangle to be drawn 1645caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used to draw the rect 1646caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 16471ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) { 16481ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawRect(left, top, right, bottom, paint); 1649caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1650caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1651caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16521ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Fill the entire canvas' bitmap (restricted to the current clip) with the specified RGB color, 16531ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * using srcover porterduff mode. 1654caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1655caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param r red component (0..255) of the color to draw onto the canvas 1656caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param g green component (0..255) of the color to draw onto the canvas 1657caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param b blue component (0..255) of the color to draw onto the canvas 1658caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1659caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawRGB(int r, int g, int b) { 1660caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawRGB(r, g, b); 1661caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1662caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1663caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified round-rect using the specified paint. The roundrect will be filled or 16651ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * framed based on the Style in the paint. 1666caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16671ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param rect The rectangular bounds of the roundRect to be drawn 16681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param rx The x-radius of the oval used to round the corners 16691ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param ry The y-radius of the oval used to round the corners 1670caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used to draw the roundRect 1671caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 16721ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint) { 16731ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawRoundRect(rect, rx, ry, paint); 1674caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1675caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1676caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16771ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified round-rect using the specified paint. The roundrect will be filled or 16781ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * framed based on the Style in the paint. 1679caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16801ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param rx The x-radius of the oval used to round the corners 16811ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param ry The y-radius of the oval used to round the corners 1682caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used to draw the roundRect 1683caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 16841ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, 16851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck @NonNull Paint paint) { 16861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawRoundRect(left, top, right, bottom, rx, ry, paint); 1687caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1688caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1689caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 16901ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted 16911ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Align setting in the paint. 1692caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 16931ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 16941ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param x The x-coordinate of the origin of the text being drawn 16951ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param y The y-coordinate of the baseline of the text being drawn 1696caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used for the text (e.g. color, size, style) 1697caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 1698caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawText(@NonNull char[] text, int index, int count, float x, float y, 1699caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @NonNull Paint paint) { 1700caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawText(text, index, count, x, y, paint); 1701caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1702caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1703caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 17041ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted 17051ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Align setting in the paint. 1706caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 17071ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 17081ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param x The x-coordinate of the origin of the text being drawn 17091ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param y The y-coordinate of the baseline of the text being drawn 1710caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used for the text (e.g. color, size, style) 1711caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 17121ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint) { 17131ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawText(text, x, y, paint); 17149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17171ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted 17181ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * based on the Align setting in the paint. 1719051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 17201ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 17211ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param start The index of the first character in text to draw 17221ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param end (end - 1) is the index of the last character in text to draw 17231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param x The x-coordinate of the origin of the text being drawn 17241ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param y The y-coordinate of the baseline of the text being drawn 17259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param paint The paint used for the text (e.g. color, size, style) 1726caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck */ 17271ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawText(@NonNull String text, int start, int end, float x, float y, 17281ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck @NonNull Paint paint) { 17291ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck super.drawText(text, start, end, x, y, paint); 1730caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1731caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck 1732caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck /** 17331ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the specified range of text, specified by start/end, with its origin at (x,y), in the 17341ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * specified Paint. The origin is interpreted based on the Align setting in the Paint. 1735eda57925cafdf1dab451e70052dea27846f368b4Chris Craik * 17361ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 1737caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param start The index of the first character in text to draw 17381ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param end (end - 1) is the index of the last character in text to draw 17391ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param x The x-coordinate of origin for where to draw the text 17401ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param y The y-coordinate of origin for where to draw the text 1741caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint The paint used for the text (e.g. color, size, style) 17429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 17431ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck public void drawText(@NonNull CharSequence text, int start, int end, float x, float y, 1744b3ec733bb830f2d4425825d93f9ed95f284e9145Tor Norbye @NonNull Paint paint) { 1745caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawText(text, start, end, x, y, paint); 17469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17491ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text, with origin at (x,y), using the specified paint, along the specified path. The 17501ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * paint's Align setting determins where along the path to start the text. 17519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 17521ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 17531ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param path The path the text should follow for its baseline 17541ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param hOffset The distance along the path to add to the text's starting position 17551ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param vOffset The distance above(-) or below(+) the path to position the text 17561ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used for the text (e.g. color, size, style) 17579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1758ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawTextOnPath(@NonNull char[] text, int index, int count, @NonNull Path path, 1759ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese float hOffset, float vOffset, @NonNull Paint paint) { 1760caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawTextOnPath(text, index, count, path, hOffset, vOffset, paint); 17619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the text, with origin at (x,y), using the specified paint, along the specified path. The 17651ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * paint's Align setting determins where along the path to start the text. 17669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 17671ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param text The text to be drawn 17681ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param path The path the text should follow for its baseline 17691ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param hOffset The distance along the path to add to the text's starting position 17701ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param vOffset The distance above(-) or below(+) the path to position the text 17711ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param paint The paint used for the text (e.g. color, size, style) 17729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1773ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese public void drawTextOnPath(@NonNull String text, @NonNull Path path, float hOffset, 1774ff7215aa0cb28a4815126b056f34b2bd29e5c651Antonio Calabrese float vOffset, @NonNull Paint paint) { 1775caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawTextOnPath(text, path, hOffset, vOffset, paint); 17769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1779caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draw a run of text, all in a single direction, with optional context for complex text 1780caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * shaping. 17811ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 17821ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * See {@link #drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint)} for 17831ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * more details. This method uses a character array rather than CharSequence to represent the 17841ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * string. Also, to be consistent with the pattern established in {@link #drawText}, in this 17851ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * method {@code count} and {@code contextCount} are used rather than offsets of the end 17861ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * position; {@code count = end - start, contextCount = contextEnd - 1787caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * contextStart}. 1788051910b9f998030dacb8a0722588cc715813fde1Raph Levien * 1789caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param text the text to render 1790caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param index the start of the text to render 1791caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param count the count of chars to render 17921ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param contextIndex the start of the context for shaping. Must be no greater than index. 17931ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param contextCount the number of characters in the context for shaping. contexIndex + 17941ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * contextCount must be no less than index + count. 1795caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param x the x position at which to draw the text 1796caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param y the y position at which to draw the text 1797caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param isRtl whether the run is in RTL direction 1798caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint the paint 17999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1800caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawTextRun(@NonNull char[] text, int index, int count, int contextIndex, 1801caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck int contextCount, float x, float y, boolean isRtl, @NonNull Paint paint) { 1802caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawTextRun(text, index, count, contextIndex, contextCount, x, y, isRtl, paint); 18039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1804da8532c6f48b4c10b5e2ccb9e08690341efa1616Romain Guy 1805da8532c6f48b4c10b5e2ccb9e08690341efa1616Romain Guy /** 1806caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Draw a run of text, all in a single direction, with optional context for complex text 1807caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * shaping. 18081ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 18091ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * The run of text includes the characters from {@code start} to {@code end} in the text. In 1810caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * addition, the range {@code contextStart} to {@code contextEnd} is used as context for the 1811caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * purpose of complex text shaping, such as Arabic text potentially shaped differently based on 1812caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * the text next to it. 18131ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 18141ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * All text outside the range {@code contextStart..contextEnd} is ignored. The text between 1815caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * {@code start} and {@code end} will be laid out and drawn. 18161ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 18171ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is 1818caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * suitable only for runs of a single direction. Alignment of the text is as determined by the 1819caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * Paint's TextAlign value. Further, {@code 0 <= contextStart <= start <= end <= contextEnd 1820caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * <= text.length} must hold on entry. 18211ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * <p> 18221ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Also see {@link android.graphics.Paint#getRunAdvance} for a corresponding method to measure 18231ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * the text; the advance width of the text drawn matches the value obtained from that method. 1824caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * 1825caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param text the text to render 18261ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param start the start of the text to render. Data before this position can be used for 18271ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * shaping context. 18281ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param end the end of the text to render. Data at or after this position can be used for 18291ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * shaping context. 1830caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param contextStart the index of the start of the shaping context 1831caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param contextEnd the index of the end of the shaping context 1832caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param x the x position at which to draw the text 1833caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param y the y position at which to draw the text 1834caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param isRtl whether the run is in RTL direction 1835caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint the paint 1836caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @see #drawTextRun(char[], int, int, int, int, float, float, boolean, Paint) 1837caf0df1b7f99736aed1a0b923ef278fc4fd0fccaMike Reed */ 1838caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart, 1839caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) { 1840caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawTextRun(text, start, end, contextStart, contextEnd, x, y, isRtl, paint); 1841caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 1842caf0df1b7f99736aed1a0b923ef278fc4fd0fccaMike Reed 184330ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio /** 18441ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * Draw the array of vertices, interpreted as triangles (based on mode). The verts array is 18451ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * required, and specifies the x,y pairs for each vertex. If texs is non-null, then it is used 18461ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * to specify the coordinate in shader coordinates to use at each vertex (the paint must have a 18471ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * shader in this case). If there is no texs array, but there is a color array, then each color 18481ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * is interpolated across its corresponding triangle in a gradient. If both texs and colors 18491ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * arrays are present, then they behave as before, but the resulting color at each pixels is the 18501ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * result of multiplying the colors from the shader and the color-gradient together. The indices 18511ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * array is optional, but if it is present, then it is used to specify the index of each 18521ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * triangle, rather than just walking through the arrays in order. 185330ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio * 1854caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param mode How to interpret the array of vertices 18551ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param vertexCount The number of values in the vertices array (and corresponding texs and 18561ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * colors arrays if non-null). Each logical vertex is two values (x, y), vertexCount 18571ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * must be a multiple of 2. 1858caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param verts Array of vertices for the mesh 1859caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param vertOffset Number of values in the verts to skip before drawing. 18601ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param texs May be null. If not null, specifies the coordinates to sample into the current 18611ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * shader (e.g. bitmap tile or gradient) 1862caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param texOffset Number of values in texs to skip before drawing. 18631ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param colors May be null. If not null, specifies a color for each vertex, to be interpolated 18641ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * across the triangle. 1865caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param colorOffset Number of values in colors to skip before drawing. 18661ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * @param indices If not null, array of indices to reference into the vertex (texs, colors) 18671ece145e018a7e66d3f422e647d3f6cb1887dca5John Reck * array. 1868caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param indexCount number of entries in the indices array (if not null). 1869caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck * @param paint Specifies the shader to use if the texs array is non-null. 187030ca5cd11a23f06f2f8eeaa587685450826f800fFabrice Di Meglio */ 1871caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck public void drawVertices(@NonNull VertexMode mode, int vertexCount, @NonNull float[] verts, 1872caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck int vertOffset, @Nullable float[] texs, int texOffset, @Nullable int[] colors, 1873caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck int colorOffset, @Nullable short[] indices, int indexOffset, int indexCount, 1874caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck @NonNull Paint paint) { 1875caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck super.drawVertices(mode, vertexCount, verts, vertOffset, texs, texOffset, 1876caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck colors, colorOffset, indices, indexOffset, indexCount, paint); 1877caa08ff5e9ee004634a95776fc72bb769f1286deJohn Reck } 18789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1879