Canvas.java revision 5c3d927e17e98e8fd4a9f3c86f7f4def0bcfa816
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19import android.text.GraphicsOperations; 20import android.text.SpannableString; 21import android.text.SpannedString; 22import android.text.TextUtils; 23 24import javax.microedition.khronos.opengles.GL; 25 26/** 27 * The Canvas class holds the "draw" calls. To draw something, you need 28 * 4 basic components: A Bitmap to hold the pixels, a Canvas to host 29 * the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, 30 * Path, text, Bitmap), and a paint (to describe the colors and styles for the 31 * drawing). 32 * 33 * <div class="special reference"> 34 * <h3>Developer Guides</h3> 35 * <p>For more information about how to use Canvas, read the 36 * <a href="{@docRoot}guide/topics/graphics/2d-graphics.html"> 37 * Canvas and Drawables</a> developer guide.</p></div> 38 */ 39public class Canvas { 40 41 // assigned in constructors or setBitmap, freed in finalizer 42 private long mNativeCanvasWrapper; 43 44 /** @hide */ 45 public long getNativeCanvasWrapper() { 46 return mNativeCanvasWrapper; 47 } 48 49 // may be null 50 private Bitmap mBitmap; 51 52 // optional field set by the caller 53 private DrawFilter mDrawFilter; 54 55 /** 56 * @hide 57 */ 58 protected int mDensity = Bitmap.DENSITY_NONE; 59 60 /** 61 * Used to determine when compatibility scaling is in effect. 62 * 63 * @hide 64 */ 65 protected int mScreenDensity = Bitmap.DENSITY_NONE; 66 67 // Used by native code 68 @SuppressWarnings("UnusedDeclaration") 69 private int mSurfaceFormat; 70 71 /** 72 * Flag for drawTextRun indicating left-to-right run direction. 73 * @hide 74 */ 75 public static final int DIRECTION_LTR = 0; 76 77 /** 78 * Flag for drawTextRun indicating right-to-left run direction. 79 * @hide 80 */ 81 public static final int DIRECTION_RTL = 1; 82 83 // Maximum bitmap size as defined in Skia's native code 84 // (see SkCanvas.cpp, SkDraw.cpp) 85 private static final int MAXMIMUM_BITMAP_SIZE = 32766; 86 87 // This field is used to finalize the native Canvas properly 88 private final CanvasFinalizer mFinalizer; 89 90 private static final class CanvasFinalizer { 91 private long mNativeCanvasWrapper; 92 93 public CanvasFinalizer(long nativeCanvas) { 94 mNativeCanvasWrapper = nativeCanvas; 95 } 96 97 @Override 98 protected void finalize() throws Throwable { 99 try { 100 dispose(); 101 } finally { 102 super.finalize(); 103 } 104 } 105 106 public void dispose() { 107 if (mNativeCanvasWrapper != 0) { 108 finalizer(mNativeCanvasWrapper); 109 mNativeCanvasWrapper = 0; 110 } 111 } 112 } 113 114 /** 115 * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to 116 * draw into. The initial target density is {@link Bitmap#DENSITY_NONE}; 117 * this will typically be replaced when a target bitmap is set for the 118 * canvas. 119 */ 120 public Canvas() { 121 if (!isHardwareAccelerated()) { 122 // 0 means no native bitmap 123 mNativeCanvasWrapper = initRaster(0); 124 mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper); 125 } else { 126 mFinalizer = null; 127 } 128 } 129 130 /** 131 * Construct a canvas with the specified bitmap to draw into. The bitmap 132 * must be mutable. 133 * 134 * <p>The initial target density of the canvas is the same as the given 135 * bitmap's density. 136 * 137 * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 138 */ 139 public Canvas(Bitmap bitmap) { 140 if (!bitmap.isMutable()) { 141 throw new IllegalStateException("Immutable bitmap passed to Canvas constructor"); 142 } 143 throwIfCannotDraw(bitmap); 144 mNativeCanvasWrapper = initRaster(bitmap.ni()); 145 mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper); 146 mBitmap = bitmap; 147 mDensity = bitmap.mDensity; 148 } 149 150 /** @hide */ 151 public Canvas(long nativeCanvas) { 152 if (nativeCanvas == 0) { 153 throw new IllegalStateException(); 154 } 155 mNativeCanvasWrapper = initCanvas(nativeCanvas); 156 mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper); 157 mDensity = Bitmap.getDefaultDensity(); 158 } 159 160 /** 161 * Returns null. 162 * 163 * @deprecated This method is not supported and should not be invoked. 164 * 165 * @hide 166 */ 167 @Deprecated 168 protected GL getGL() { 169 return null; 170 } 171 172 /** 173 * Indicates whether this Canvas uses hardware acceleration. 174 * 175 * Note that this method does not define what type of hardware acceleration 176 * may or may not be used. 177 * 178 * @return True if drawing operations are hardware accelerated, 179 * false otherwise. 180 */ 181 public boolean isHardwareAccelerated() { 182 return false; 183 } 184 185 /** 186 * Specify a bitmap for the canvas to draw into. All canvas state such as 187 * layers, filters, and the save/restore stack are reset with the exception 188 * of the current matrix and clip stack. Additionally, as a side-effect 189 * the canvas' target density is updated to match that of the bitmap. 190 * 191 * @param bitmap Specifies a mutable bitmap for the canvas to draw into. 192 * @see #setDensity(int) 193 * @see #getDensity() 194 */ 195 public void setBitmap(Bitmap bitmap) { 196 if (isHardwareAccelerated()) { 197 throw new RuntimeException("Can't set a bitmap device on a GL canvas"); 198 } 199 200 if (bitmap == null) { 201 native_setBitmap(mNativeCanvasWrapper, 0, false); 202 mDensity = Bitmap.DENSITY_NONE; 203 } else { 204 if (!bitmap.isMutable()) { 205 throw new IllegalStateException(); 206 } 207 throwIfCannotDraw(bitmap); 208 209 native_setBitmap(mNativeCanvasWrapper, bitmap.ni(), true); 210 mDensity = bitmap.mDensity; 211 } 212 213 mBitmap = bitmap; 214 } 215 216 /** 217 * setBitmap() variant for native callers with a raw bitmap handle. 218 */ 219 private void setNativeBitmap(long bitmapHandle) { 220 native_setBitmap(mNativeCanvasWrapper, bitmapHandle, false); 221 } 222 223 /** 224 * Set the viewport dimensions if this canvas is GL based. If it is not, 225 * this method is ignored and no exception is thrown. 226 * 227 * @param width The width of the viewport 228 * @param height The height of the viewport 229 * 230 * @hide 231 */ 232 public void setViewport(int width, int height) {} 233 234 /** 235 * @hide 236 */ 237 public void initializeLight(float lightX, float lightY, float lightZ, float lightRadius) {} 238 239 /** 240 * Return true if the device that the current layer draws into is opaque 241 * (i.e. does not support per-pixel alpha). 242 * 243 * @return true if the device that the current layer draws into is opaque 244 */ 245 public native boolean isOpaque(); 246 247 /** 248 * Returns the width of the current drawing layer 249 * 250 * @return the width of the current drawing layer 251 */ 252 public native int getWidth(); 253 254 /** 255 * Returns the height of the current drawing layer 256 * 257 * @return the height of the current drawing layer 258 */ 259 public native int getHeight(); 260 261 /** 262 * <p>Returns the target density of the canvas. The default density is 263 * derived from the density of its backing bitmap, or 264 * {@link Bitmap#DENSITY_NONE} if there is not one.</p> 265 * 266 * @return Returns the current target density of the canvas, which is used 267 * to determine the scaling factor when drawing a bitmap into it. 268 * 269 * @see #setDensity(int) 270 * @see Bitmap#getDensity() 271 */ 272 public int getDensity() { 273 return mDensity; 274 } 275 276 /** 277 * <p>Specifies the density for this Canvas' backing bitmap. This modifies 278 * the target density of the canvas itself, as well as the density of its 279 * backing bitmap via {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}. 280 * 281 * @param density The new target density of the canvas, which is used 282 * to determine the scaling factor when drawing a bitmap into it. Use 283 * {@link Bitmap#DENSITY_NONE} to disable bitmap scaling. 284 * 285 * @see #getDensity() 286 * @see Bitmap#setDensity(int) 287 */ 288 public void setDensity(int density) { 289 if (mBitmap != null) { 290 mBitmap.setDensity(density); 291 } 292 mDensity = density; 293 } 294 295 /** @hide */ 296 public void setScreenDensity(int density) { 297 mScreenDensity = density; 298 } 299 300 /** 301 * Returns the maximum allowed width for bitmaps drawn with this canvas. 302 * Attempting to draw with a bitmap wider than this value will result 303 * in an error. 304 * 305 * @see #getMaximumBitmapHeight() 306 */ 307 public int getMaximumBitmapWidth() { 308 return MAXMIMUM_BITMAP_SIZE; 309 } 310 311 /** 312 * Returns the maximum allowed height for bitmaps drawn with this canvas. 313 * Attempting to draw with a bitmap taller than this value will result 314 * in an error. 315 * 316 * @see #getMaximumBitmapWidth() 317 */ 318 public int getMaximumBitmapHeight() { 319 return MAXMIMUM_BITMAP_SIZE; 320 } 321 322 // the SAVE_FLAG constants must match their native equivalents 323 324 /** restore the current matrix when restore() is called */ 325 public static final int MATRIX_SAVE_FLAG = 0x01; 326 /** restore the current clip when restore() is called */ 327 public static final int CLIP_SAVE_FLAG = 0x02; 328 /** the layer needs to per-pixel alpha */ 329 public static final int HAS_ALPHA_LAYER_SAVE_FLAG = 0x04; 330 /** the layer needs to 8-bits per color component */ 331 public static final int FULL_COLOR_LAYER_SAVE_FLAG = 0x08; 332 /** clip against the layer's bounds */ 333 public static final int CLIP_TO_LAYER_SAVE_FLAG = 0x10; 334 /** restore everything when restore() is called */ 335 public static final int ALL_SAVE_FLAG = 0x1F; 336 337 /** 338 * Saves the current matrix and clip onto a private stack. Subsequent 339 * calls to translate,scale,rotate,skew,concat or clipRect,clipPath 340 * will all operate as usual, but when the balancing call to restore() 341 * is made, those calls will be forgotten, and the settings that existed 342 * before the save() will be reinstated. 343 * 344 * @return The value to pass to restoreToCount() to balance this save() 345 */ 346 public native int save(); 347 348 /** 349 * Based on saveFlags, can save the current matrix and clip onto a private 350 * stack. Subsequent calls to translate,scale,rotate,skew,concat or 351 * clipRect,clipPath will all operate as usual, but when the balancing 352 * call to restore() is made, those calls will be forgotten, and the 353 * settings that existed before the save() will be reinstated. 354 * 355 * @param saveFlags flag bits that specify which parts of the Canvas state 356 * to save/restore 357 * @return The value to pass to restoreToCount() to balance this save() 358 */ 359 public native int save(int saveFlags); 360 361 /** 362 * This behaves the same as save(), but in addition it allocates an 363 * offscreen bitmap. All drawing calls are directed there, and only when 364 * the balancing call to restore() is made is that offscreen transfered to 365 * the canvas (or the previous layer). Subsequent calls to translate, 366 * scale, rotate, skew, concat or clipRect, clipPath all operate on this 367 * copy. When the balancing call to restore() is made, this copy is 368 * deleted and the previous matrix/clip state is restored. 369 * 370 * @param bounds May be null. The maximum size the offscreen bitmap 371 * needs to be (in local coordinates) 372 * @param paint This is copied, and is applied to the offscreen when 373 * restore() is called. 374 * @param saveFlags see _SAVE_FLAG constants 375 * @return value to pass to restoreToCount() to balance this save() 376 */ 377 public int saveLayer(RectF bounds, Paint paint, int saveFlags) { 378 return native_saveLayer(mNativeCanvasWrapper, bounds, 379 paint != null ? paint.mNativePaint : 0, 380 saveFlags); 381 } 382 383 /** 384 * Convenience for saveLayer(bounds, paint, {@link #ALL_SAVE_FLAG}) 385 */ 386 public int saveLayer(RectF bounds, Paint paint) { 387 return saveLayer(bounds, paint, ALL_SAVE_FLAG); 388 } 389 390 /** 391 * Helper version of saveLayer() that takes 4 values rather than a RectF. 392 */ 393 public int saveLayer(float left, float top, float right, float bottom, Paint paint, 394 int saveFlags) { 395 return native_saveLayer(mNativeCanvasWrapper, left, top, right, bottom, 396 paint != null ? paint.mNativePaint : 0, 397 saveFlags); 398 } 399 400 /** 401 * Convenience for saveLayer(left, top, right, bottom, paint, {@link #ALL_SAVE_FLAG}) 402 */ 403 public int saveLayer(float left, float top, float right, float bottom, Paint paint) { 404 return saveLayer(left, top, right, bottom, paint, ALL_SAVE_FLAG); 405 } 406 407 /** 408 * This behaves the same as save(), but in addition it allocates an 409 * offscreen bitmap. All drawing calls are directed there, and only when 410 * the balancing call to restore() is made is that offscreen transfered to 411 * the canvas (or the previous layer). Subsequent calls to translate, 412 * scale, rotate, skew, concat or clipRect, clipPath all operate on this 413 * copy. When the balancing call to restore() is made, this copy is 414 * deleted and the previous matrix/clip state is restored. 415 * 416 * @param bounds The maximum size the offscreen bitmap needs to be 417 * (in local coordinates) 418 * @param alpha The alpha to apply to the offscreen when when it is 419 drawn during restore() 420 * @param saveFlags see _SAVE_FLAG constants 421 * @return value to pass to restoreToCount() to balance this call 422 */ 423 public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) { 424 alpha = Math.min(255, Math.max(0, alpha)); 425 return native_saveLayerAlpha(mNativeCanvasWrapper, bounds, alpha, saveFlags); 426 } 427 428 /** 429 * Convenience for saveLayerAlpha(bounds, alpha, {@link #ALL_SAVE_FLAG}) 430 */ 431 public int saveLayerAlpha(RectF bounds, int alpha) { 432 return saveLayerAlpha(bounds, alpha, ALL_SAVE_FLAG); 433 } 434 435 /** 436 * Helper for saveLayerAlpha() that takes 4 values instead of a RectF. 437 */ 438 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, 439 int saveFlags) { 440 return native_saveLayerAlpha(mNativeCanvasWrapper, left, top, right, bottom, 441 alpha, saveFlags); 442 } 443 444 /** 445 * Helper for saveLayerAlpha(left, top, right, bottom, alpha, {@link #ALL_SAVE_FLAG}) 446 */ 447 public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) { 448 return saveLayerAlpha(left, top, right, bottom, alpha, ALL_SAVE_FLAG); 449 } 450 451 /** 452 * This call balances a previous call to save(), and is used to remove all 453 * modifications to the matrix/clip state since the last save call. It is 454 * an error to call restore() more times than save() was called. 455 */ 456 public native void restore(); 457 458 /** 459 * Returns the number of matrix/clip states on the Canvas' private stack. 460 * This will equal # save() calls - # restore() calls. 461 */ 462 public native int getSaveCount(); 463 464 /** 465 * Efficient way to pop any calls to save() that happened after the save 466 * count reached saveCount. It is an error for saveCount to be less than 1. 467 * 468 * Example: 469 * int count = canvas.save(); 470 * ... // more calls potentially to save() 471 * canvas.restoreToCount(count); 472 * // now the canvas is back in the same state it was before the initial 473 * // call to save(). 474 * 475 * @param saveCount The save level to restore to. 476 */ 477 public native void restoreToCount(int saveCount); 478 479 /** 480 * Preconcat the current matrix with the specified translation 481 * 482 * @param dx The distance to translate in X 483 * @param dy The distance to translate in Y 484 */ 485 public native void translate(float dx, float dy); 486 487 /** 488 * Preconcat the current matrix with the specified scale. 489 * 490 * @param sx The amount to scale in X 491 * @param sy The amount to scale in Y 492 */ 493 public native void scale(float sx, float sy); 494 495 /** 496 * Preconcat the current matrix with the specified scale. 497 * 498 * @param sx The amount to scale in X 499 * @param sy The amount to scale in Y 500 * @param px The x-coord for the pivot point (unchanged by the scale) 501 * @param py The y-coord for the pivot point (unchanged by the scale) 502 */ 503 public final void scale(float sx, float sy, float px, float py) { 504 translate(px, py); 505 scale(sx, sy); 506 translate(-px, -py); 507 } 508 509 /** 510 * Preconcat the current matrix with the specified rotation. 511 * 512 * @param degrees The amount to rotate, in degrees 513 */ 514 public native void rotate(float degrees); 515 516 /** 517 * Preconcat the current matrix with the specified rotation. 518 * 519 * @param degrees The amount to rotate, in degrees 520 * @param px The x-coord for the pivot point (unchanged by the rotation) 521 * @param py The y-coord for the pivot point (unchanged by the rotation) 522 */ 523 public final void rotate(float degrees, float px, float py) { 524 translate(px, py); 525 rotate(degrees); 526 translate(-px, -py); 527 } 528 529 /** 530 * Preconcat the current matrix with the specified skew. 531 * 532 * @param sx The amount to skew in X 533 * @param sy The amount to skew in Y 534 */ 535 public native void skew(float sx, float sy); 536 537 /** 538 * Preconcat the current matrix with the specified matrix. If the specified 539 * matrix is null, this method does nothing. 540 * 541 * @param matrix The matrix to preconcatenate with the current matrix 542 */ 543 public void concat(Matrix matrix) { 544 if (matrix != null) native_concat(mNativeCanvasWrapper, matrix.native_instance); 545 } 546 547 /** 548 * Completely replace the current matrix with the specified matrix. If the 549 * matrix parameter is null, then the current matrix is reset to identity. 550 * 551 * <strong>Note:</strong> it is recommended to use {@link #concat(Matrix)}, 552 * {@link #scale(float, float)}, {@link #translate(float, float)} and 553 * {@link #rotate(float)} instead of this method. 554 * 555 * @param matrix The matrix to replace the current matrix with. If it is 556 * null, set the current matrix to identity. 557 * 558 * @see #concat(Matrix) 559 */ 560 public void setMatrix(Matrix matrix) { 561 native_setMatrix(mNativeCanvasWrapper, 562 matrix == null ? 0 : matrix.native_instance); 563 } 564 565 /** 566 * Return, in ctm, the current transformation matrix. This does not alter 567 * the matrix in the canvas, but just returns a copy of it. 568 */ 569 @Deprecated 570 public void getMatrix(Matrix ctm) { 571 native_getCTM(mNativeCanvasWrapper, ctm.native_instance); 572 } 573 574 /** 575 * Return a new matrix with a copy of the canvas' current transformation 576 * matrix. 577 */ 578 @Deprecated 579 public final Matrix getMatrix() { 580 Matrix m = new Matrix(); 581 //noinspection deprecation 582 getMatrix(m); 583 return m; 584 } 585 586 /** 587 * Modify the current clip with the specified rectangle. 588 * 589 * @param rect The rect to intersect with the current clip 590 * @param op How the clip is modified 591 * @return true if the resulting clip is non-empty 592 */ 593 public boolean clipRect(RectF rect, Region.Op op) { 594 return native_clipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 595 op.nativeInt); 596 } 597 598 /** 599 * Modify the current clip with the specified rectangle, which is 600 * expressed in local coordinates. 601 * 602 * @param rect The rectangle to intersect with the current clip. 603 * @param op How the clip is modified 604 * @return true if the resulting clip is non-empty 605 */ 606 public boolean clipRect(Rect rect, Region.Op op) { 607 return native_clipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom, 608 op.nativeInt); 609 } 610 611 /** 612 * Intersect the current clip with the specified rectangle, which is 613 * expressed in local coordinates. 614 * 615 * @param rect The rectangle to intersect with the current clip. 616 * @return true if the resulting clip is non-empty 617 */ 618 public native boolean clipRect(RectF rect); 619 620 /** 621 * Intersect the current clip with the specified rectangle, which is 622 * expressed in local coordinates. 623 * 624 * @param rect The rectangle to intersect with the current clip. 625 * @return true if the resulting clip is non-empty 626 */ 627 public native boolean clipRect(Rect rect); 628 629 /** 630 * Modify the current clip with the specified rectangle, which is 631 * expressed in local coordinates. 632 * 633 * @param left The left side of the rectangle to intersect with the 634 * current clip 635 * @param top The top of the rectangle to intersect with the current 636 * clip 637 * @param right The right side of the rectangle to intersect with the 638 * current clip 639 * @param bottom The bottom of the rectangle to intersect with the current 640 * clip 641 * @param op How the clip is modified 642 * @return true if the resulting clip is non-empty 643 */ 644 public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) { 645 return native_clipRect(mNativeCanvasWrapper, left, top, right, bottom, op.nativeInt); 646 } 647 648 /** 649 * Intersect the current clip with the specified rectangle, which is 650 * expressed in local coordinates. 651 * 652 * @param left The left side of the rectangle to intersect with the 653 * current clip 654 * @param top The top of the rectangle to intersect with the current clip 655 * @param right The right side of the rectangle to intersect with the 656 * current clip 657 * @param bottom The bottom of the rectangle to intersect with the current 658 * clip 659 * @return true if the resulting clip is non-empty 660 */ 661 public native boolean clipRect(float left, float top, float right, float bottom); 662 663 /** 664 * Intersect the current clip with the specified rectangle, which is 665 * expressed in local coordinates. 666 * 667 * @param left The left side of the rectangle to intersect with the 668 * current clip 669 * @param top The top of the rectangle to intersect with the current clip 670 * @param right The right side of the rectangle to intersect with the 671 * current clip 672 * @param bottom The bottom of the rectangle to intersect with the current 673 * clip 674 * @return true if the resulting clip is non-empty 675 */ 676 public native boolean clipRect(int left, int top, int right, int bottom); 677 678 /** 679 * Modify the current clip with the specified path. 680 * 681 * @param path The path to operate on the current clip 682 * @param op How the clip is modified 683 * @return true if the resulting is non-empty 684 */ 685 public boolean clipPath(Path path, Region.Op op) { 686 return native_clipPath(mNativeCanvasWrapper, path.ni(), op.nativeInt); 687 } 688 689 /** 690 * Intersect the current clip with the specified path. 691 * 692 * @param path The path to intersect with the current clip 693 * @return true if the resulting is non-empty 694 */ 695 public boolean clipPath(Path path) { 696 return clipPath(path, Region.Op.INTERSECT); 697 } 698 699 /** 700 * Modify the current clip with the specified region. Note that unlike 701 * clipRect() and clipPath() which transform their arguments by the 702 * current matrix, clipRegion() assumes its argument is already in the 703 * coordinate system of the current layer's bitmap, and so not 704 * transformation is performed. 705 * 706 * @param region The region to operate on the current clip, based on op 707 * @param op How the clip is modified 708 * @return true if the resulting is non-empty 709 * 710 * @deprecated Unlike all other clip calls this API does not respect the 711 * current matrix. Use {@link #clipRect(Rect)} as an alternative. 712 */ 713 public boolean clipRegion(Region region, Region.Op op) { 714 return native_clipRegion(mNativeCanvasWrapper, region.ni(), op.nativeInt); 715 } 716 717 /** 718 * Intersect the current clip with the specified region. Note that unlike 719 * clipRect() and clipPath() which transform their arguments by the 720 * current matrix, clipRegion() assumes its argument is already in the 721 * coordinate system of the current layer's bitmap, and so not 722 * transformation is performed. 723 * 724 * @param region The region to operate on the current clip, based on op 725 * @return true if the resulting is non-empty 726 * 727 * @deprecated Unlike all other clip calls this API does not respect the 728 * current matrix. Use {@link #clipRect(Rect)} as an alternative. 729 */ 730 public boolean clipRegion(Region region) { 731 return clipRegion(region, Region.Op.INTERSECT); 732 } 733 734 public DrawFilter getDrawFilter() { 735 return mDrawFilter; 736 } 737 738 public void setDrawFilter(DrawFilter filter) { 739 long nativeFilter = 0; 740 if (filter != null) { 741 nativeFilter = filter.mNativeInt; 742 } 743 mDrawFilter = filter; 744 nativeSetDrawFilter(mNativeCanvasWrapper, nativeFilter); 745 } 746 747 public enum EdgeType { 748 749 /** 750 * Black-and-White: Treat edges by just rounding to nearest pixel boundary 751 */ 752 BW(0), //!< treat edges by just rounding to nearest pixel boundary 753 754 /** 755 * Antialiased: Treat edges by rounding-out, since they may be antialiased 756 */ 757 AA(1); 758 759 EdgeType(int nativeInt) { 760 this.nativeInt = nativeInt; 761 } 762 763 /** 764 * @hide 765 */ 766 public final int nativeInt; 767 } 768 769 /** 770 * Return true if the specified rectangle, after being transformed by the 771 * current matrix, would lie completely outside of the current clip. Call 772 * this to check if an area you intend to draw into is clipped out (and 773 * therefore you can skip making the draw calls). 774 * 775 * @param rect the rect to compare with the current clip 776 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 777 * since that means it may affect a larger area (more pixels) than 778 * non-antialiased ({@link Canvas.EdgeType#BW}). 779 * @return true if the rect (transformed by the canvas' matrix) 780 * does not intersect with the canvas' clip 781 */ 782 public boolean quickReject(RectF rect, EdgeType type) { 783 return native_quickReject(mNativeCanvasWrapper, rect); 784 } 785 786 /** 787 * Return true if the specified path, after being transformed by the 788 * current matrix, would lie completely outside of the current clip. Call 789 * this to check if an area you intend to draw into is clipped out (and 790 * therefore you can skip making the draw calls). Note: for speed it may 791 * return false even if the path itself might not intersect the clip 792 * (i.e. the bounds of the path intersects, but the path does not). 793 * 794 * @param path The path to compare with the current clip 795 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 796 * since that means it may affect a larger area (more pixels) than 797 * non-antialiased ({@link Canvas.EdgeType#BW}). 798 * @return true if the path (transformed by the canvas' matrix) 799 * does not intersect with the canvas' clip 800 */ 801 public boolean quickReject(Path path, EdgeType type) { 802 return native_quickReject(mNativeCanvasWrapper, path.ni()); 803 } 804 805 /** 806 * Return true if the specified rectangle, after being transformed by the 807 * current matrix, would lie completely outside of the current clip. Call 808 * this to check if an area you intend to draw into is clipped out (and 809 * therefore you can skip making the draw calls). 810 * 811 * @param left The left side of the rectangle to compare with the 812 * current clip 813 * @param top The top of the rectangle to compare with the current 814 * clip 815 * @param right The right side of the rectangle to compare with the 816 * current clip 817 * @param bottom The bottom of the rectangle to compare with the 818 * current clip 819 * @param type {@link Canvas.EdgeType#AA} if the path should be considered antialiased, 820 * since that means it may affect a larger area (more pixels) than 821 * non-antialiased ({@link Canvas.EdgeType#BW}). 822 * @return true if the rect (transformed by the canvas' matrix) 823 * does not intersect with the canvas' clip 824 */ 825 public boolean quickReject(float left, float top, float right, float bottom, 826 EdgeType type) { 827 return native_quickReject(mNativeCanvasWrapper, left, top, right, bottom); 828 } 829 830 /** 831 * Return the bounds of the current clip (in local coordinates) in the 832 * bounds parameter, and return true if it is non-empty. This can be useful 833 * in a way similar to quickReject, in that it tells you that drawing 834 * outside of these bounds will be clipped out. 835 * 836 * @param bounds Return the clip bounds here. If it is null, ignore it but 837 * still return true if the current clip is non-empty. 838 * @return true if the current clip is non-empty. 839 */ 840 public boolean getClipBounds(Rect bounds) { 841 return native_getClipBounds(mNativeCanvasWrapper, bounds); 842 } 843 844 /** 845 * Retrieve the bounds of the current clip (in local coordinates). 846 * 847 * @return the clip bounds, or [0, 0, 0, 0] if the clip is empty. 848 */ 849 public final Rect getClipBounds() { 850 Rect r = new Rect(); 851 getClipBounds(r); 852 return r; 853 } 854 855 /** 856 * Fill the entire canvas' bitmap (restricted to the current clip) with the 857 * specified RGB color, using srcover porterduff mode. 858 * 859 * @param r red component (0..255) of the color to draw onto the canvas 860 * @param g green component (0..255) of the color to draw onto the canvas 861 * @param b blue component (0..255) of the color to draw onto the canvas 862 */ 863 public void drawRGB(int r, int g, int b) { 864 native_drawRGB(mNativeCanvasWrapper, r, g, b); 865 } 866 867 /** 868 * Fill the entire canvas' bitmap (restricted to the current clip) with the 869 * specified ARGB color, using srcover porterduff mode. 870 * 871 * @param a alpha component (0..255) of the color to draw onto the canvas 872 * @param r red component (0..255) of the color to draw onto the canvas 873 * @param g green component (0..255) of the color to draw onto the canvas 874 * @param b blue component (0..255) of the color to draw onto the canvas 875 */ 876 public void drawARGB(int a, int r, int g, int b) { 877 native_drawARGB(mNativeCanvasWrapper, a, r, g, b); 878 } 879 880 /** 881 * Fill the entire canvas' bitmap (restricted to the current clip) with the 882 * specified color, using srcover porterduff mode. 883 * 884 * @param color the color to draw onto the canvas 885 */ 886 public void drawColor(int color) { 887 native_drawColor(mNativeCanvasWrapper, color); 888 } 889 890 /** 891 * Fill the entire canvas' bitmap (restricted to the current clip) with the 892 * specified color and porter-duff xfermode. 893 * 894 * @param color the color to draw with 895 * @param mode the porter-duff mode to apply to the color 896 */ 897 public void drawColor(int color, PorterDuff.Mode mode) { 898 native_drawColor(mNativeCanvasWrapper, color, mode.nativeInt); 899 } 900 901 /** 902 * Fill the entire canvas' bitmap (restricted to the current clip) with 903 * the specified paint. This is equivalent (but faster) to drawing an 904 * infinitely large rectangle with the specified paint. 905 * 906 * @param paint The paint used to draw onto the canvas 907 */ 908 public void drawPaint(Paint paint) { 909 native_drawPaint(mNativeCanvasWrapper, paint.mNativePaint); 910 } 911 912 /** 913 * Draw a series of points. Each point is centered at the coordinate 914 * specified by pts[], and its diameter is specified by the paint's stroke 915 * width (as transformed by the canvas' CTM), with special treatment for 916 * a stroke width of 0, which always draws exactly 1 pixel (or at most 4 917 * if antialiasing is enabled). The shape of the point is controlled by 918 * the paint's Cap type. The shape is a square, unless the cap type is 919 * Round, in which case the shape is a circle. 920 * 921 * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 922 * @param offset Number of values to skip before starting to draw. 923 * @param count The number of values to process, after skipping offset 924 * of them. Since one point uses two values, the number of 925 * "points" that are drawn is really (count >> 1). 926 * @param paint The paint used to draw the points 927 */ 928 public native void drawPoints(float[] pts, int offset, int count, Paint paint); 929 930 /** 931 * Helper for drawPoints() that assumes you want to draw the entire array 932 */ 933 public void drawPoints(float[] pts, Paint paint) { 934 drawPoints(pts, 0, pts.length, paint); 935 } 936 937 /** 938 * Helper for drawPoints() for drawing a single point. 939 */ 940 public native void drawPoint(float x, float y, Paint paint); 941 942 /** 943 * Draw a line segment with the specified start and stop x,y coordinates, 944 * using the specified paint. 945 * 946 * <p>Note that since a line is always "framed", the Style is ignored in the paint.</p> 947 * 948 * <p>Degenerate lines (length is 0) will not be drawn.</p> 949 * 950 * @param startX The x-coordinate of the start point of the line 951 * @param startY The y-coordinate of the start point of the line 952 * @param paint The paint used to draw the line 953 */ 954 public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { 955 native_drawLine(mNativeCanvasWrapper, startX, startY, stopX, stopY, paint.mNativePaint); 956 } 957 958 /** 959 * Draw a series of lines. Each line is taken from 4 consecutive values 960 * in the pts array. Thus to draw 1 line, the array must contain at least 4 961 * values. This is logically the same as drawing the array as follows: 962 * drawLine(pts[0], pts[1], pts[2], pts[3]) followed by 963 * drawLine(pts[4], pts[5], pts[6], pts[7]) and so on. 964 * 965 * @param pts Array of points to draw [x0 y0 x1 y1 x2 y2 ...] 966 * @param offset Number of values in the array to skip before drawing. 967 * @param count The number of values in the array to process, after 968 * skipping "offset" of them. Since each line uses 4 values, 969 * the number of "lines" that are drawn is really 970 * (count >> 2). 971 * @param paint The paint used to draw the points 972 */ 973 public native void drawLines(float[] pts, int offset, int count, Paint paint); 974 975 public void drawLines(float[] pts, Paint paint) { 976 drawLines(pts, 0, pts.length, paint); 977 } 978 979 /** 980 * Draw the specified Rect using the specified paint. The rectangle will 981 * be filled or framed based on the Style in the paint. 982 * 983 * @param rect The rect to be drawn 984 * @param paint The paint used to draw the rect 985 */ 986 public void drawRect(RectF rect, Paint paint) { 987 native_drawRect(mNativeCanvasWrapper, rect, paint.mNativePaint); 988 } 989 990 /** 991 * Draw the specified Rect using the specified Paint. The rectangle 992 * will be filled or framed based on the Style in the paint. 993 * 994 * @param r The rectangle to be drawn. 995 * @param paint The paint used to draw the rectangle 996 */ 997 public void drawRect(Rect r, Paint paint) { 998 drawRect(r.left, r.top, r.right, r.bottom, paint); 999 } 1000 1001 1002 /** 1003 * Draw the specified Rect using the specified paint. The rectangle will 1004 * be filled or framed based on the Style in the paint. 1005 * 1006 * @param left The left side of the rectangle to be drawn 1007 * @param top The top side of the rectangle to be drawn 1008 * @param right The right side of the rectangle to be drawn 1009 * @param bottom The bottom side of the rectangle to be drawn 1010 * @param paint The paint used to draw the rect 1011 */ 1012 public void drawRect(float left, float top, float right, float bottom, Paint paint) { 1013 native_drawRect(mNativeCanvasWrapper, left, top, right, bottom, paint.mNativePaint); 1014 } 1015 1016 /** 1017 * Draw the specified oval using the specified paint. The oval will be 1018 * filled or framed based on the Style in the paint. 1019 * 1020 * @param oval The rectangle bounds of the oval to be drawn 1021 */ 1022 public void drawOval(RectF oval, Paint paint) { 1023 if (oval == null) { 1024 throw new NullPointerException(); 1025 } 1026 native_drawOval(mNativeCanvasWrapper, oval, paint.mNativePaint); 1027 } 1028 1029 /** 1030 * Draw the specified circle using the specified paint. If radius is <= 0, 1031 * then nothing will be drawn. The circle will be filled or framed based 1032 * on the Style in the paint. 1033 * 1034 * @param cx The x-coordinate of the center of the cirle to be drawn 1035 * @param cy The y-coordinate of the center of the cirle to be drawn 1036 * @param radius The radius of the cirle to be drawn 1037 * @param paint The paint used to draw the circle 1038 */ 1039 public void drawCircle(float cx, float cy, float radius, Paint paint) { 1040 native_drawCircle(mNativeCanvasWrapper, cx, cy, radius, paint.mNativePaint); 1041 } 1042 1043 /** 1044 * <p>Draw the specified arc, which will be scaled to fit inside the 1045 * specified oval.</p> 1046 * 1047 * <p>If the start angle is negative or >= 360, the start angle is treated 1048 * as start angle modulo 360.</p> 1049 * 1050 * <p>If the sweep angle is >= 360, then the oval is drawn 1051 * completely. Note that this differs slightly from SkPath::arcTo, which 1052 * treats the sweep angle modulo 360. If the sweep angle is negative, 1053 * the sweep angle is treated as sweep angle modulo 360</p> 1054 * 1055 * <p>The arc is drawn clockwise. An angle of 0 degrees correspond to the 1056 * geometric angle of 0 degrees (3 o'clock on a watch.)</p> 1057 * 1058 * @param oval The bounds of oval used to define the shape and size 1059 * of the arc 1060 * @param startAngle Starting angle (in degrees) where the arc begins 1061 * @param sweepAngle Sweep angle (in degrees) measured clockwise 1062 * @param useCenter If true, include the center of the oval in the arc, and 1063 close it if it is being stroked. This will draw a wedge 1064 * @param paint The paint used to draw the arc 1065 */ 1066 public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, 1067 Paint paint) { 1068 if (oval == null) { 1069 throw new NullPointerException(); 1070 } 1071 native_drawArc(mNativeCanvasWrapper, oval, startAngle, sweepAngle, 1072 useCenter, paint.mNativePaint); 1073 } 1074 1075 /** 1076 * Draw the specified round-rect using the specified paint. The roundrect 1077 * will be filled or framed based on the Style in the paint. 1078 * 1079 * @param rect The rectangular bounds of the roundRect to be drawn 1080 * @param rx The x-radius of the oval used to round the corners 1081 * @param ry The y-radius of the oval used to round the corners 1082 * @param paint The paint used to draw the roundRect 1083 */ 1084 public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { 1085 drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint); 1086 } 1087 1088 /** 1089 * Draw the specified round-rect using the specified paint. The roundrect 1090 * will be filled or framed based on the Style in the paint. 1091 * 1092 * @param rx The x-radius of the oval used to round the corners 1093 * @param ry The y-radius of the oval used to round the corners 1094 * @param paint The paint used to draw the roundRect 1095 */ 1096 public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, 1097 Paint paint) { 1098 native_drawRoundRect(mNativeCanvasWrapper, left, top, right, bottom, rx, ry, paint.mNativePaint); 1099 } 1100 1101 /** 1102 * Draw the specified path using the specified paint. The path will be 1103 * filled or framed based on the Style in the paint. 1104 * 1105 * @param path The path to be drawn 1106 * @param paint The paint used to draw the path 1107 */ 1108 public void drawPath(Path path, Paint paint) { 1109 native_drawPath(mNativeCanvasWrapper, path.ni(), paint.mNativePaint); 1110 } 1111 1112 /** 1113 * @hide 1114 */ 1115 protected static void throwIfCannotDraw(Bitmap bitmap) { 1116 if (bitmap.isRecycled()) { 1117 throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap); 1118 } 1119 if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 && 1120 bitmap.hasAlpha()) { 1121 throw new RuntimeException("Canvas: trying to use a non-premultiplied bitmap " 1122 + bitmap); 1123 } 1124 } 1125 1126 /** 1127 * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1128 * 1129 * @param patch The ninepatch object to render 1130 * @param dst The destination rectangle. 1131 * @param paint The paint to draw the bitmap with. may be null 1132 * 1133 * @hide 1134 */ 1135 public void drawPatch(NinePatch patch, Rect dst, Paint paint) { 1136 patch.drawSoftware(this, dst, paint); 1137 } 1138 1139 /** 1140 * Draws the specified bitmap as an N-patch (most often, a 9-patches.) 1141 * 1142 * @param patch The ninepatch object to render 1143 * @param dst The destination rectangle. 1144 * @param paint The paint to draw the bitmap with. may be null 1145 * 1146 * @hide 1147 */ 1148 public void drawPatch(NinePatch patch, RectF dst, Paint paint) { 1149 patch.drawSoftware(this, dst, paint); 1150 } 1151 1152 /** 1153 * Draw the specified bitmap, with its top/left corner at (x,y), using 1154 * the specified paint, transformed by the current matrix. 1155 * 1156 * <p>Note: if the paint contains a maskfilter that generates a mask which 1157 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1158 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1159 * Thus the color outside of the original width/height will be the edge 1160 * color replicated. 1161 * 1162 * <p>If the bitmap and canvas have different densities, this function 1163 * will take care of automatically scaling the bitmap to draw at the 1164 * same density as the canvas. 1165 * 1166 * @param bitmap The bitmap to be drawn 1167 * @param left The position of the left side of the bitmap being drawn 1168 * @param top The position of the top side of the bitmap being drawn 1169 * @param paint The paint used to draw the bitmap (may be null) 1170 */ 1171 public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) { 1172 throwIfCannotDraw(bitmap); 1173 native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), left, top, 1174 paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, bitmap.mDensity); 1175 } 1176 1177 /** 1178 * Draw the specified bitmap, scaling/translating automatically to fill 1179 * the destination rectangle. If the source rectangle is not null, it 1180 * specifies the subset of the bitmap to draw. 1181 * 1182 * <p>Note: if the paint contains a maskfilter that generates a mask which 1183 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1184 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1185 * Thus the color outside of the original width/height will be the edge 1186 * color replicated. 1187 * 1188 * <p>This function <em>ignores the density associated with the bitmap</em>. 1189 * This is because the source and destination rectangle coordinate 1190 * spaces are in their respective densities, so must already have the 1191 * appropriate scaling factor applied. 1192 * 1193 * @param bitmap The bitmap to be drawn 1194 * @param src May be null. The subset of the bitmap to be drawn 1195 * @param dst The rectangle that the bitmap will be scaled/translated 1196 * to fit into 1197 * @param paint May be null. The paint used to draw the bitmap 1198 */ 1199 public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { 1200 if (dst == null) { 1201 throw new NullPointerException(); 1202 } 1203 throwIfCannotDraw(bitmap); 1204 native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), src, dst, 1205 paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); 1206 } 1207 1208 /** 1209 * Draw the specified bitmap, scaling/translating automatically to fill 1210 * the destination rectangle. If the source rectangle is not null, it 1211 * specifies the subset of the bitmap to draw. 1212 * 1213 * <p>Note: if the paint contains a maskfilter that generates a mask which 1214 * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), 1215 * then the bitmap will be drawn as if it were in a Shader with CLAMP mode. 1216 * Thus the color outside of the original width/height will be the edge 1217 * color replicated. 1218 * 1219 * <p>This function <em>ignores the density associated with the bitmap</em>. 1220 * This is because the source and destination rectangle coordinate 1221 * spaces are in their respective densities, so must already have the 1222 * appropriate scaling factor applied. 1223 * 1224 * @param bitmap The bitmap to be drawn 1225 * @param src May be null. The subset of the bitmap to be drawn 1226 * @param dst The rectangle that the bitmap will be scaled/translated 1227 * to fit into 1228 * @param paint May be null. The paint used to draw the bitmap 1229 */ 1230 public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { 1231 if (dst == null) { 1232 throw new NullPointerException(); 1233 } 1234 throwIfCannotDraw(bitmap); 1235 native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), src, dst, 1236 paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); 1237 } 1238 1239 /** 1240 * Treat the specified array of colors as a bitmap, and draw it. This gives 1241 * the same result as first creating a bitmap from the array, and then 1242 * drawing it, but this method avoids explicitly creating a bitmap object 1243 * which can be more efficient if the colors are changing often. 1244 * 1245 * @param colors Array of colors representing the pixels of the bitmap 1246 * @param offset Offset into the array of colors for the first pixel 1247 * @param stride The number of colors in the array between rows (must be 1248 * >= width or <= -width). 1249 * @param x The X coordinate for where to draw the bitmap 1250 * @param y The Y coordinate for where to draw the bitmap 1251 * @param width The width of the bitmap 1252 * @param height The height of the bitmap 1253 * @param hasAlpha True if the alpha channel of the colors contains valid 1254 * values. If false, the alpha byte is ignored (assumed to 1255 * be 0xFF for every pixel). 1256 * @param paint May be null. The paint used to draw the bitmap 1257 * 1258 * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 1259 * requires an internal copy of color buffer contents every time this method is called. Using a 1260 * Bitmap avoids this copy, and allows the application to more explicitly control the lifetime 1261 * and copies of pixel data. 1262 */ 1263 @Deprecated 1264 public void drawBitmap(int[] colors, int offset, int stride, float x, float y, 1265 int width, int height, boolean hasAlpha, Paint paint) { 1266 // check for valid input 1267 if (width < 0) { 1268 throw new IllegalArgumentException("width must be >= 0"); 1269 } 1270 if (height < 0) { 1271 throw new IllegalArgumentException("height must be >= 0"); 1272 } 1273 if (Math.abs(stride) < width) { 1274 throw new IllegalArgumentException("abs(stride) must be >= width"); 1275 } 1276 int lastScanline = offset + (height - 1) * stride; 1277 int length = colors.length; 1278 if (offset < 0 || (offset + width > length) || lastScanline < 0 1279 || (lastScanline + width > length)) { 1280 throw new ArrayIndexOutOfBoundsException(); 1281 } 1282 // quick escape if there's nothing to draw 1283 if (width == 0 || height == 0) { 1284 return; 1285 } 1286 // punch down to native for the actual draw 1287 native_drawBitmap(mNativeCanvasWrapper, colors, offset, stride, x, y, width, height, hasAlpha, 1288 paint != null ? paint.mNativePaint : 0); 1289 } 1290 1291 /** 1292 * Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y 1293 * 1294 * @deprecated Usage with a {@link #isHardwareAccelerated() hardware accelerated} canvas 1295 * requires an internal copy of color buffer contents every time this method is called. Using a 1296 * Bitmap avoids this copy, and allows the application to more explicitly control the lifetime 1297 * and copies of pixel data. 1298 */ 1299 @Deprecated 1300 public void drawBitmap(int[] colors, int offset, int stride, int x, int y, 1301 int width, int height, boolean hasAlpha, Paint paint) { 1302 // call through to the common float version 1303 drawBitmap(colors, offset, stride, (float)x, (float)y, width, height, 1304 hasAlpha, paint); 1305 } 1306 1307 /** 1308 * Draw the bitmap using the specified matrix. 1309 * 1310 * @param bitmap The bitmap to draw 1311 * @param matrix The matrix used to transform the bitmap when it is drawn 1312 * @param paint May be null. The paint used to draw the bitmap 1313 */ 1314 public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { 1315 nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.ni(), matrix.ni(), 1316 paint != null ? paint.mNativePaint : 0); 1317 } 1318 1319 /** 1320 * @hide 1321 */ 1322 protected static void checkRange(int length, int offset, int count) { 1323 if ((offset | count) < 0 || offset + count > length) { 1324 throw new ArrayIndexOutOfBoundsException(); 1325 } 1326 } 1327 1328 /** 1329 * Draw the bitmap through the mesh, where mesh vertices are evenly 1330 * distributed across the bitmap. There are meshWidth+1 vertices across, and 1331 * meshHeight+1 vertices down. The verts array is accessed in row-major 1332 * order, so that the first meshWidth+1 vertices are distributed across the 1333 * top of the bitmap from left to right. A more general version of this 1334 * method is drawVertices(). 1335 * 1336 * @param bitmap The bitmap to draw using the mesh 1337 * @param meshWidth The number of columns in the mesh. Nothing is drawn if 1338 * this is 0 1339 * @param meshHeight The number of rows in the mesh. Nothing is drawn if 1340 * this is 0 1341 * @param verts Array of x,y pairs, specifying where the mesh should be 1342 * drawn. There must be at least 1343 * (meshWidth+1) * (meshHeight+1) * 2 + vertOffset values 1344 * in the array 1345 * @param vertOffset Number of verts elements to skip before drawing 1346 * @param colors May be null. Specifies a color at each vertex, which is 1347 * interpolated across the cell, and whose values are 1348 * multiplied by the corresponding bitmap colors. If not null, 1349 * there must be at least (meshWidth+1) * (meshHeight+1) + 1350 * colorOffset values in the array. 1351 * @param colorOffset Number of color elements to skip before drawing 1352 * @param paint May be null. The paint used to draw the bitmap 1353 */ 1354 public void drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, 1355 float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint) { 1356 if ((meshWidth | meshHeight | vertOffset | colorOffset) < 0) { 1357 throw new ArrayIndexOutOfBoundsException(); 1358 } 1359 if (meshWidth == 0 || meshHeight == 0) { 1360 return; 1361 } 1362 int count = (meshWidth + 1) * (meshHeight + 1); 1363 // we mul by 2 since we need two floats per vertex 1364 checkRange(verts.length, vertOffset, count * 2); 1365 if (colors != null) { 1366 // no mul by 2, since we need only 1 color per vertex 1367 checkRange(colors.length, colorOffset, count); 1368 } 1369 nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.ni(), meshWidth, meshHeight, 1370 verts, vertOffset, colors, colorOffset, 1371 paint != null ? paint.mNativePaint : 0); 1372 } 1373 1374 public enum VertexMode { 1375 TRIANGLES(0), 1376 TRIANGLE_STRIP(1), 1377 TRIANGLE_FAN(2); 1378 1379 VertexMode(int nativeInt) { 1380 this.nativeInt = nativeInt; 1381 } 1382 1383 /** 1384 * @hide 1385 */ 1386 public final int nativeInt; 1387 } 1388 1389 /** 1390 * Draw the array of vertices, interpreted as triangles (based on mode). The 1391 * verts array is required, and specifies the x,y pairs for each vertex. If 1392 * texs is non-null, then it is used to specify the coordinate in shader 1393 * coordinates to use at each vertex (the paint must have a shader in this 1394 * case). If there is no texs array, but there is a color array, then each 1395 * color is interpolated across its corresponding triangle in a gradient. If 1396 * both texs and colors arrays are present, then they behave as before, but 1397 * the resulting color at each pixels is the result of multiplying the 1398 * colors from the shader and the color-gradient together. The indices array 1399 * is optional, but if it is present, then it is used to specify the index 1400 * of each triangle, rather than just walking through the arrays in order. 1401 * 1402 * @param mode How to interpret the array of vertices 1403 * @param vertexCount The number of values in the vertices array (and 1404 * corresponding texs and colors arrays if non-null). Each logical 1405 * vertex is two values (x, y), vertexCount must be a multiple of 2. 1406 * @param verts Array of vertices for the mesh 1407 * @param vertOffset Number of values in the verts to skip before drawing. 1408 * @param texs May be null. If not null, specifies the coordinates to sample 1409 * into the current shader (e.g. bitmap tile or gradient) 1410 * @param texOffset Number of values in texs to skip before drawing. 1411 * @param colors May be null. If not null, specifies a color for each 1412 * vertex, to be interpolated across the triangle. 1413 * @param colorOffset Number of values in colors to skip before drawing. 1414 * @param indices If not null, array of indices to reference into the 1415 * vertex (texs, colors) array. 1416 * @param indexCount number of entries in the indices array (if not null). 1417 * @param paint Specifies the shader to use if the texs array is non-null. 1418 */ 1419 public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset, 1420 float[] texs, int texOffset, int[] colors, int colorOffset, 1421 short[] indices, int indexOffset, int indexCount, Paint paint) { 1422 checkRange(verts.length, vertOffset, vertexCount); 1423 if (texs != null) { 1424 checkRange(texs.length, texOffset, vertexCount); 1425 } 1426 if (colors != null) { 1427 checkRange(colors.length, colorOffset, vertexCount / 2); 1428 } 1429 if (indices != null) { 1430 checkRange(indices.length, indexOffset, indexCount); 1431 } 1432 nativeDrawVertices(mNativeCanvasWrapper, mode.nativeInt, vertexCount, verts, 1433 vertOffset, texs, texOffset, colors, colorOffset, 1434 indices, indexOffset, indexCount, paint.mNativePaint); 1435 } 1436 1437 /** 1438 * Draw the text, with origin at (x,y), using the specified paint. The 1439 * origin is interpreted based on the Align setting in the paint. 1440 * 1441 * @param text The text to be drawn 1442 * @param x The x-coordinate of the origin of the text being drawn 1443 * @param y The y-coordinate of the origin of the text being drawn 1444 * @param paint The paint used for the text (e.g. color, size, style) 1445 */ 1446 public void drawText(char[] text, int index, int count, float x, float y, Paint paint) { 1447 if ((index | count | (index + count) | 1448 (text.length - index - count)) < 0) { 1449 throw new IndexOutOfBoundsException(); 1450 } 1451 native_drawText(mNativeCanvasWrapper, text, index, count, x, y, paint.mBidiFlags, 1452 paint.mNativePaint, paint.mNativeTypeface); 1453 } 1454 1455 /** 1456 * Draw the text, with origin at (x,y), using the specified paint. The 1457 * origin is interpreted based on the Align setting in the paint. 1458 * 1459 * @param text The text to be drawn 1460 * @param x The x-coordinate of the origin of the text being drawn 1461 * @param y The y-coordinate of the origin of the text being drawn 1462 * @param paint The paint used for the text (e.g. color, size, style) 1463 */ 1464 public void drawText(String text, float x, float y, Paint paint) { 1465 native_drawText(mNativeCanvasWrapper, text, 0, text.length(), x, y, paint.mBidiFlags, 1466 paint.mNativePaint, paint.mNativeTypeface); 1467 } 1468 1469 /** 1470 * Draw the text, with origin at (x,y), using the specified paint. 1471 * The origin is interpreted based on the Align setting in the paint. 1472 * 1473 * @param text The text to be drawn 1474 * @param start The index of the first character in text to draw 1475 * @param end (end - 1) is the index of the last character in text to draw 1476 * @param x The x-coordinate of the origin of the text being drawn 1477 * @param y The y-coordinate of the origin of the text being drawn 1478 * @param paint The paint used for the text (e.g. color, size, style) 1479 */ 1480 public void drawText(String text, int start, int end, float x, float y, Paint paint) { 1481 if ((start | end | (end - start) | (text.length() - end)) < 0) { 1482 throw new IndexOutOfBoundsException(); 1483 } 1484 native_drawText(mNativeCanvasWrapper, text, start, end, x, y, paint.mBidiFlags, 1485 paint.mNativePaint, paint.mNativeTypeface); 1486 } 1487 1488 /** 1489 * Draw the specified range of text, specified by start/end, with its 1490 * origin at (x,y), in the specified Paint. The origin is interpreted 1491 * based on the Align setting in the Paint. 1492 * 1493 * @param text The text to be drawn 1494 * @param start The index of the first character in text to draw 1495 * @param end (end - 1) is the index of the last character in text 1496 * to draw 1497 * @param x The x-coordinate of origin for where to draw the text 1498 * @param y The y-coordinate of origin for where to draw the text 1499 * @param paint The paint used for the text (e.g. color, size, style) 1500 */ 1501 public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) { 1502 if (text instanceof String || text instanceof SpannedString || 1503 text instanceof SpannableString) { 1504 native_drawText(mNativeCanvasWrapper, text.toString(), start, end, x, y, 1505 paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); 1506 } else if (text instanceof GraphicsOperations) { 1507 ((GraphicsOperations) text).drawText(this, start, end, x, y, 1508 paint); 1509 } else { 1510 char[] buf = TemporaryBuffer.obtain(end - start); 1511 TextUtils.getChars(text, start, end, buf, 0); 1512 native_drawText(mNativeCanvasWrapper, buf, 0, end - start, x, y, 1513 paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); 1514 TemporaryBuffer.recycle(buf); 1515 } 1516 } 1517 1518 /** 1519 * Render a run of all LTR or all RTL text, with shaping. This does not run 1520 * bidi on the provided text, but renders it as a uniform right-to-left or 1521 * left-to-right run, as indicated by dir. Alignment of the text is as 1522 * determined by the Paint's TextAlign value. 1523 * 1524 * @param text the text to render 1525 * @param index the start of the text to render 1526 * @param count the count of chars to render 1527 * @param contextIndex the start of the context for shaping. Must be 1528 * no greater than index. 1529 * @param contextCount the number of characters in the context for shaping. 1530 * ContexIndex + contextCount must be no less than index 1531 * + count. 1532 * @param x the x position at which to draw the text 1533 * @param y the y position at which to draw the text 1534 * @param dir the run direction, either {@link #DIRECTION_LTR} or 1535 * {@link #DIRECTION_RTL}. 1536 * @param paint the paint 1537 * @hide 1538 */ 1539 public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount, 1540 float x, float y, int dir, Paint paint) { 1541 1542 if (text == null) { 1543 throw new NullPointerException("text is null"); 1544 } 1545 if (paint == null) { 1546 throw new NullPointerException("paint is null"); 1547 } 1548 if ((index | count | text.length - index - count) < 0) { 1549 throw new IndexOutOfBoundsException(); 1550 } 1551 if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) { 1552 throw new IllegalArgumentException("unknown dir: " + dir); 1553 } 1554 1555 native_drawTextRun(mNativeCanvasWrapper, text, index, count, 1556 contextIndex, contextCount, x, y, dir, paint.mNativePaint, paint.mNativeTypeface); 1557 } 1558 1559 /** 1560 * Render a run of all LTR or all RTL text, with shaping. This does not run 1561 * bidi on the provided text, but renders it as a uniform right-to-left or 1562 * left-to-right run, as indicated by dir. Alignment of the text is as 1563 * determined by the Paint's TextAlign value. 1564 * 1565 * @param text the text to render 1566 * @param start the start of the text to render. Data before this position 1567 * can be used for shaping context. 1568 * @param end the end of the text to render. Data at or after this 1569 * position can be used for shaping context. 1570 * @param x the x position at which to draw the text 1571 * @param y the y position at which to draw the text 1572 * @param dir the run direction, either 0 for LTR or 1 for RTL. 1573 * @param paint the paint 1574 * @hide 1575 */ 1576 public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd, 1577 float x, float y, int dir, Paint paint) { 1578 1579 if (text == null) { 1580 throw new NullPointerException("text is null"); 1581 } 1582 if (paint == null) { 1583 throw new NullPointerException("paint is null"); 1584 } 1585 if ((start | end | end - start | text.length() - end) < 0) { 1586 throw new IndexOutOfBoundsException(); 1587 } 1588 1589 int flags = dir == 0 ? 0 : 1; 1590 1591 if (text instanceof String || text instanceof SpannedString || 1592 text instanceof SpannableString) { 1593 native_drawTextRun(mNativeCanvasWrapper, text.toString(), start, end, 1594 contextStart, contextEnd, x, y, flags, paint.mNativePaint, paint.mNativeTypeface); 1595 } else if (text instanceof GraphicsOperations) { 1596 ((GraphicsOperations) text).drawTextRun(this, start, end, 1597 contextStart, contextEnd, x, y, flags, paint); 1598 } else { 1599 int contextLen = contextEnd - contextStart; 1600 int len = end - start; 1601 char[] buf = TemporaryBuffer.obtain(contextLen); 1602 TextUtils.getChars(text, contextStart, contextEnd, buf, 0); 1603 native_drawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len, 1604 0, contextLen, x, y, flags, paint.mNativePaint, paint.mNativeTypeface); 1605 TemporaryBuffer.recycle(buf); 1606 } 1607 } 1608 1609 /** 1610 * Draw the text in the array, with each character's origin specified by 1611 * the pos array. 1612 * 1613 * This method does not support glyph composition and decomposition and 1614 * should therefore not be used to render complex scripts. 1615 * 1616 * @param text The text to be drawn 1617 * @param index The index of the first character to draw 1618 * @param count The number of characters to draw, starting from index. 1619 * @param pos Array of [x,y] positions, used to position each 1620 * character 1621 * @param paint The paint used for the text (e.g. color, size, style) 1622 */ 1623 @Deprecated 1624 public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { 1625 if (index < 0 || index + count > text.length || count*2 > pos.length) { 1626 throw new IndexOutOfBoundsException(); 1627 } 1628 native_drawPosText(mNativeCanvasWrapper, text, index, count, pos, 1629 paint.mNativePaint); 1630 } 1631 1632 /** 1633 * Draw the text in the array, with each character's origin specified by 1634 * the pos array. 1635 * 1636 * This method does not support glyph composition and decomposition and 1637 * should therefore not be used to render complex scripts. 1638 * 1639 * @param text The text to be drawn 1640 * @param pos Array of [x,y] positions, used to position each character 1641 * @param paint The paint used for the text (e.g. color, size, style) 1642 */ 1643 @Deprecated 1644 public void drawPosText(String text, float[] pos, Paint paint) { 1645 if (text.length()*2 > pos.length) { 1646 throw new ArrayIndexOutOfBoundsException(); 1647 } 1648 native_drawPosText(mNativeCanvasWrapper, text, pos, paint.mNativePaint); 1649 } 1650 1651 /** 1652 * Draw the text, with origin at (x,y), using the specified paint, along 1653 * the specified path. The paint's Align setting determins where along the 1654 * path to start the text. 1655 * 1656 * @param text The text to be drawn 1657 * @param path The path the text should follow for its baseline 1658 * @param hOffset The distance along the path to add to the text's 1659 * starting position 1660 * @param vOffset The distance above(-) or below(+) the path to position 1661 * the text 1662 * @param paint The paint used for the text (e.g. color, size, style) 1663 */ 1664 public void drawTextOnPath(char[] text, int index, int count, Path path, 1665 float hOffset, float vOffset, Paint paint) { 1666 if (index < 0 || index + count > text.length) { 1667 throw new ArrayIndexOutOfBoundsException(); 1668 } 1669 native_drawTextOnPath(mNativeCanvasWrapper, text, index, count, 1670 path.ni(), hOffset, vOffset, 1671 paint.mBidiFlags, paint.mNativePaint); 1672 } 1673 1674 /** 1675 * Draw the text, with origin at (x,y), using the specified paint, along 1676 * the specified path. The paint's Align setting determins where along the 1677 * path to start the text. 1678 * 1679 * @param text The text to be drawn 1680 * @param path The path the text should follow for its baseline 1681 * @param hOffset The distance along the path to add to the text's 1682 * starting position 1683 * @param vOffset The distance above(-) or below(+) the path to position 1684 * the text 1685 * @param paint The paint used for the text (e.g. color, size, style) 1686 */ 1687 public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) { 1688 if (text.length() > 0) { 1689 native_drawTextOnPath(mNativeCanvasWrapper, text, path.ni(), hOffset, vOffset, 1690 paint.mBidiFlags, paint.mNativePaint); 1691 } 1692 } 1693 1694 /** 1695 * Save the canvas state, draw the picture, and restore the canvas state. 1696 * This differs from picture.draw(canvas), which does not perform any 1697 * save/restore. 1698 * 1699 * <p> 1700 * <strong>Note:</strong> This forces the picture to internally call 1701 * {@link Picture#endRecording} in order to prepare for playback. 1702 * 1703 * @param picture The picture to be drawn 1704 */ 1705 public void drawPicture(Picture picture) { 1706 picture.endRecording(); 1707 int restoreCount = save(); 1708 picture.draw(this); 1709 restoreToCount(restoreCount); 1710 } 1711 1712 /** 1713 * Draw the picture, stretched to fit into the dst rectangle. 1714 */ 1715 public void drawPicture(Picture picture, RectF dst) { 1716 save(); 1717 translate(dst.left, dst.top); 1718 if (picture.getWidth() > 0 && picture.getHeight() > 0) { 1719 scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight()); 1720 } 1721 drawPicture(picture); 1722 restore(); 1723 } 1724 1725 /** 1726 * Draw the picture, stretched to fit into the dst rectangle. 1727 */ 1728 public void drawPicture(Picture picture, Rect dst) { 1729 save(); 1730 translate(dst.left, dst.top); 1731 if (picture.getWidth() > 0 && picture.getHeight() > 0) { 1732 scale((float) dst.width() / picture.getWidth(), 1733 (float) dst.height() / picture.getHeight()); 1734 } 1735 drawPicture(picture); 1736 restore(); 1737 } 1738 1739 /** 1740 * Releases the resources associated with this canvas. 1741 * 1742 * @hide 1743 */ 1744 public void release() { 1745 mFinalizer.dispose(); 1746 } 1747 1748 /** 1749 * Free up as much memory as possible from private caches (e.g. fonts, images) 1750 * 1751 * @hide 1752 */ 1753 public static native void freeCaches(); 1754 1755 /** 1756 * Free up text layout caches 1757 * 1758 * @hide 1759 */ 1760 public static native void freeTextLayoutCaches(); 1761 1762 private static native long initRaster(long nativeBitmapOrZero); 1763 private static native long initCanvas(long canvasHandle); 1764 private static native void native_setBitmap(long canvasHandle, 1765 long bitmapHandle, 1766 boolean copyState); 1767 private static native int native_saveLayer(long nativeCanvas, 1768 RectF bounds, 1769 long nativePaint, 1770 int layerFlags); 1771 private static native int native_saveLayer(long nativeCanvas, float l, 1772 float t, float r, float b, 1773 long nativePaint, 1774 int layerFlags); 1775 private static native int native_saveLayerAlpha(long nativeCanvas, 1776 RectF bounds, int alpha, 1777 int layerFlags); 1778 private static native int native_saveLayerAlpha(long nativeCanvas, float l, 1779 float t, float r, float b, 1780 int alpha, int layerFlags); 1781 1782 private static native void native_concat(long nativeCanvas, 1783 long nativeMatrix); 1784 private static native void native_setMatrix(long nativeCanvas, 1785 long nativeMatrix); 1786 private static native boolean native_clipRect(long nativeCanvas, 1787 float left, float top, 1788 float right, float bottom, 1789 int regionOp); 1790 private static native boolean native_clipPath(long nativeCanvas, 1791 long nativePath, 1792 int regionOp); 1793 private static native boolean native_clipRegion(long nativeCanvas, 1794 long nativeRegion, 1795 int regionOp); 1796 private static native void nativeSetDrawFilter(long nativeCanvas, 1797 long nativeFilter); 1798 private static native boolean native_getClipBounds(long nativeCanvas, 1799 Rect bounds); 1800 private static native void native_getCTM(long nativeCanvas, 1801 long nativeMatrix); 1802 private static native boolean native_quickReject(long nativeCanvas, 1803 RectF rect); 1804 private static native boolean native_quickReject(long nativeCanvas, 1805 long nativePath); 1806 private static native boolean native_quickReject(long nativeCanvas, 1807 float left, float top, 1808 float right, float bottom); 1809 private static native void native_drawRGB(long nativeCanvas, int r, int g, 1810 int b); 1811 private static native void native_drawARGB(long nativeCanvas, int a, int r, 1812 int g, int b); 1813 private static native void native_drawColor(long nativeCanvas, int color); 1814 private static native void native_drawColor(long nativeCanvas, int color, 1815 int mode); 1816 private static native void native_drawPaint(long nativeCanvas, 1817 long nativePaint); 1818 private static native void native_drawLine(long nativeCanvas, float startX, 1819 float startY, float stopX, 1820 float stopY, long nativePaint); 1821 private static native void native_drawRect(long nativeCanvas, RectF rect, 1822 long nativePaint); 1823 private static native void native_drawRect(long nativeCanvas, float left, 1824 float top, float right, 1825 float bottom, 1826 long nativePaint); 1827 private static native void native_drawOval(long nativeCanvas, RectF oval, 1828 long nativePaint); 1829 private static native void native_drawCircle(long nativeCanvas, float cx, 1830 float cy, float radius, 1831 long nativePaint); 1832 private static native void native_drawArc(long nativeCanvas, RectF oval, 1833 float startAngle, float sweep, 1834 boolean useCenter, 1835 long nativePaint); 1836 private static native void native_drawRoundRect(long nativeCanvas, 1837 float left, float top, float right, float bottom, 1838 float rx, float ry, long nativePaint); 1839 private static native void native_drawPath(long nativeCanvas, 1840 long nativePath, 1841 long nativePaint); 1842 private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, 1843 float left, float top, 1844 long nativePaintOrZero, 1845 int canvasDensity, 1846 int screenDensity, 1847 int bitmapDensity); 1848 private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, 1849 Rect src, RectF dst, 1850 long nativePaintOrZero, 1851 int screenDensity, 1852 int bitmapDensity); 1853 private static native void native_drawBitmap(long nativeCanvas, 1854 long nativeBitmap, 1855 Rect src, Rect dst, 1856 long nativePaintOrZero, 1857 int screenDensity, 1858 int bitmapDensity); 1859 private static native void native_drawBitmap(long nativeCanvas, int[] colors, 1860 int offset, int stride, float x, 1861 float y, int width, int height, 1862 boolean hasAlpha, 1863 long nativePaintOrZero); 1864 private static native void nativeDrawBitmapMatrix(long nativeCanvas, 1865 long nativeBitmap, 1866 long nativeMatrix, 1867 long nativePaint); 1868 private static native void nativeDrawBitmapMesh(long nativeCanvas, 1869 long nativeBitmap, 1870 int meshWidth, int meshHeight, 1871 float[] verts, int vertOffset, 1872 int[] colors, int colorOffset, 1873 long nativePaint); 1874 private static native void nativeDrawVertices(long nativeCanvas, int mode, int n, 1875 float[] verts, int vertOffset, float[] texs, int texOffset, 1876 int[] colors, int colorOffset, short[] indices, 1877 int indexOffset, int indexCount, long nativePaint); 1878 1879 private static native void native_drawText(long nativeCanvas, char[] text, 1880 int index, int count, float x, 1881 float y, int flags, long nativePaint, 1882 long nativeTypeface); 1883 private static native void native_drawText(long nativeCanvas, String text, 1884 int start, int end, float x, 1885 float y, int flags, long nativePaint, 1886 long nativeTypeface); 1887 1888 private static native void native_drawTextRun(long nativeCanvas, String text, 1889 int start, int end, int contextStart, int contextEnd, 1890 float x, float y, int flags, long nativePaint, long nativeTypeface); 1891 1892 private static native void native_drawTextRun(long nativeCanvas, char[] text, 1893 int start, int count, int contextStart, int contextCount, 1894 float x, float y, int flags, long nativePaint, long nativeTypeface); 1895 1896 private static native void native_drawPosText(long nativeCanvas, 1897 char[] text, int index, 1898 int count, float[] pos, 1899 long nativePaint); 1900 private static native void native_drawPosText(long nativeCanvas, 1901 String text, float[] pos, 1902 long nativePaint); 1903 private static native void native_drawTextOnPath(long nativeCanvas, 1904 char[] text, int index, 1905 int count, long nativePath, 1906 float hOffset, 1907 float vOffset, int bidiFlags, 1908 long nativePaint); 1909 private static native void native_drawTextOnPath(long nativeCanvas, 1910 String text, long nativePath, 1911 float hOffset, 1912 float vOffset, 1913 int flags, long nativePaint); 1914 private static native void finalizer(long nativeCanvas); 1915} 1916