OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkCanvas_DEFINED | 8 #ifndef SkCanvas_DEFINED |
9 #define SkCanvas_DEFINED | 9 #define SkCanvas_DEFINED |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 class SkRRect; | 30 class SkRRect; |
31 struct SkRSXform; | 31 struct SkRSXform; |
32 class SkSurface; | 32 class SkSurface; |
33 class SkSurface_Base; | 33 class SkSurface_Base; |
34 class SkTextBlob; | 34 class SkTextBlob; |
35 class GrContext; | 35 class GrContext; |
36 class GrRenderTarget; | 36 class GrRenderTarget; |
37 | 37 |
38 class SkCanvasState; | 38 class SkCanvasState; |
39 | 39 |
| 40 #ifdef SK_SUPPORT_LEGACY_ONDRAWIMAGERECT |
| 41 #define SRC_RECT_CONSTRAINT_PARAM(param) |
| 42 #define SRC_RECT_CONSTRAINT_ARG(arg) |
| 43 #define SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(var) SkCanvas::SrcRectConstraint
var = SkCanvas::kStrict_SrcRectConstraint; |
| 44 #else |
| 45 #define SRC_RECT_CONSTRAINT_PARAM(param) , SrcRectConstraint param |
| 46 #define SRC_RECT_CONSTRAINT_ARG(arg) , arg |
| 47 #define SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(var) |
| 48 #endif |
| 49 |
40 /** \class SkCanvas | 50 /** \class SkCanvas |
41 | 51 |
42 A Canvas encapsulates all of the state about drawing into a device (bitmap). | 52 A Canvas encapsulates all of the state about drawing into a device (bitmap). |
43 This includes a reference to the device itself, and a stack of matrix/clip | 53 This includes a reference to the device itself, and a stack of matrix/clip |
44 values. For any given draw call (e.g. drawRect), the geometry of the object | 54 values. For any given draw call (e.g. drawRect), the geometry of the object |
45 being drawn is transformed by the concatenation of all the matrices in the | 55 being drawn is transformed by the concatenation of all the matrices in the |
46 stack. The transformed geometry is clipped by the intersection of all of | 56 stack. The transformed geometry is clipped by the intersection of all of |
47 the clips in the stack. | 57 the clips in the stack. |
48 | 58 |
49 While the Canvas holds the state of the drawing device, the state (style) | 59 While the Canvas holds the state of the drawing device, the state (style) |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 781 |
772 /** Draw the specified image, with its top/left corner at (x,y), using the | 782 /** Draw the specified image, with its top/left corner at (x,y), using the |
773 specified paint, transformed by the current matrix. | 783 specified paint, transformed by the current matrix. |
774 | 784 |
775 @param image The image to be drawn | 785 @param image The image to be drawn |
776 @param left The position of the left side of the image being drawn | 786 @param left The position of the left side of the image being drawn |
777 @param top The position of the top side of the image being drawn | 787 @param top The position of the top side of the image being drawn |
778 @param paint The paint used to draw the image, or NULL | 788 @param paint The paint used to draw the image, or NULL |
779 */ | 789 */ |
780 void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPa
int* paint = NULL); | 790 void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPa
int* paint = NULL); |
781 /** Draw the specified image, with the specified matrix applied (before the | |
782 canvas' matrix is applied). | |
783 | 791 |
784 @param image The image to be drawn | 792 /** |
785 @param src Optional: specify the subset of the image to be drawn | 793 * Controls the behavior at the edge of the src-rect, when specified in dra
wImageRect, |
786 @param dst The destination rectangle where the scaled/translated | 794 * trading off speed for exactness. |
787 image will be drawn | 795 * |
788 @param paint The paint used to draw the image, or NULL | 796 * When filtering is enabled (in the Paint), skia may need to sample in a n
eighborhood around |
789 */ | 797 * the pixels in the image. If there is a src-rect specified, it is intende
d to restrict the |
| 798 * pixels that will be read. However, for performance reasons, some impleme
ntations may slow |
| 799 * down if they cannot read 1-pixel past the src-rect boundary at times. |
| 800 * |
| 801 * This enum allows the caller to specify if such a 1-pixel "slop" will be
visually acceptable. |
| 802 * If it is, the caller should pass kFast, and it may result in a faster dr
aw. If the src-rect |
| 803 * must be strictly respected, the caller should pass kStrict. |
| 804 */ |
| 805 enum SrcRectConstraint { |
| 806 /** |
| 807 * If kStrict is specified, the implementation must respect the src-rec
t |
| 808 * (if specified) strictly, and will never sample outside of those boun
ds during sampling |
| 809 * even when filtering. This may be slower than kFast. |
| 810 */ |
| 811 kStrict_SrcRectConstraint, |
| 812 |
| 813 /** |
| 814 * If kFast is specified, the implementation may sample outside of the
src-rect |
| 815 * (if specified) by at most 1 pixel when filtering. This allows greate
r flexibility |
| 816 * to the implementation and can make the draw much faster. |
| 817 */ |
| 818 kFast_SrcRectConstraint, |
| 819 }; |
| 820 |
| 821 /** Draw the specified image, scaling and translating so that it fills the s
pecified |
| 822 * dst rect. If the src rect is non-null, only that subset of the image is
transformed |
| 823 * and drawn. |
| 824 * |
| 825 * @param image The image to be drawn |
| 826 * @param src Optional: specify the subset of the image to be drawn |
| 827 * @param dst The destination rectangle where the scaled/translated |
| 828 * image will be drawn |
| 829 * @param paint The paint used to draw the image, or NULL |
| 830 * @param constraint Control the tradeoff between speed and exactness w.r.t
. the src-rect. |
| 831 */ |
790 void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& ds
t, | 832 void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& ds
t, |
791 const SkPaint* paint = NULL); | 833 const SkPaint* paint, SrcRectConstraint); |
| 834 |
| 835 void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& ds
t, |
| 836 const SkPaint* paint = NULL) { |
| 837 this->drawImageRect(image, src, dst, paint, kStrict_SrcRectConstraint); |
| 838 } |
| 839 |
| 840 void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* p
aint = NULL) { |
| 841 // With no src-rect, the constraint value is ignored, so we just use the
default. |
| 842 this->drawImageRect(image, NULL, dst, paint, kStrict_SrcRectConstraint); |
| 843 } |
792 | 844 |
793 /** | 845 /** |
794 * Draw the image stretched differentially to fit into dst. | 846 * Draw the image stretched differentially to fit into dst. |
795 * center is a rect within the image, and logically divides the image | 847 * center is a rect within the image, and logically divides the image |
796 * into 9 sections (3x3). For example, if the middle pixel of a [5x5] | 848 * into 9 sections (3x3). For example, if the middle pixel of a [5x5] |
797 * image is the "center", then the center-rect should be [2, 2, 3, 3]. | 849 * image is the "center", then the center-rect should be [2, 2, 3, 3]. |
798 * | 850 * |
799 * If the dst is >= the image size, then... | 851 * If the dst is >= the image size, then... |
800 * - The 4 corners are not stretched at all. | 852 * - The 4 corners are not stretched at all. |
801 * - The sides are stretched in only one axis. | 853 * - The sides are stretched in only one axis. |
(...skipping 17 matching lines...) Expand all Loading... |
819 generated by the shader. | 871 generated by the shader. |
820 | 872 |
821 @param bitmap The bitmap to be drawn | 873 @param bitmap The bitmap to be drawn |
822 @param left The position of the left side of the bitmap being drawn | 874 @param left The position of the left side of the bitmap being drawn |
823 @param top The position of the top side of the bitmap being drawn | 875 @param top The position of the top side of the bitmap being drawn |
824 @param paint The paint used to draw the bitmap, or NULL | 876 @param paint The paint used to draw the bitmap, or NULL |
825 */ | 877 */ |
826 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, | 878 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
827 const SkPaint* paint = NULL); | 879 const SkPaint* paint = NULL); |
828 | 880 |
| 881 /** Draw the specified bitmap, scaling and translating so that it fills the
specified |
| 882 * dst rect. If the src rect is non-null, only that subset of the bitmap is
transformed |
| 883 * and drawn. |
| 884 * |
| 885 * @param bitmap The bitmap to be drawn |
| 886 * @param src Optional: specify the subset of the bitmap to be drawn |
| 887 * @param dst The destination rectangle where the scaled/translated |
| 888 * bitmap will be drawn |
| 889 * @param paint The paint used to draw the bitmap, or NULL |
| 890 * @param constraint Control the tradeoff between speed and exactness w.r.t
. the src-rect. |
| 891 */ |
| 892 void drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect&
dst, |
| 893 const SkPaint* paint, SrcRectConstraint); |
| 894 |
829 enum DrawBitmapRectFlags { | 895 enum DrawBitmapRectFlags { |
830 kNone_DrawBitmapRectFlag = 0x0, | 896 kNone_DrawBitmapRectFlag = 0x0, |
831 /** | 897 /** |
832 * When filtering is enabled, allow the color samples outside of | 898 * When filtering is enabled, allow the color samples outside of |
833 * the src rect (but still in the src bitmap) to bleed into the | 899 * the src rect (but still in the src bitmap) to bleed into the |
834 * drawn portion | 900 * drawn portion |
835 */ | 901 */ |
836 kBleed_DrawBitmapRectFlag = 0x1, | 902 kBleed_DrawBitmapRectFlag = 0x1, |
837 }; | 903 }; |
838 | 904 |
839 /** Draw the specified bitmap, with the specified matrix applied (before the | 905 /** Draw the specified bitmap, with the specified matrix applied (before the |
840 canvas' matrix is applied). | 906 canvas' matrix is applied). |
841 @param bitmap The bitmap to be drawn | 907 @param bitmap The bitmap to be drawn |
842 @param src Optional: specify the subset of the bitmap to be drawn | 908 @param src Optional: specify the subset of the bitmap to be drawn |
843 @param dst The destination rectangle where the scaled/translated | 909 @param dst The destination rectangle where the scaled/translated |
844 image will be drawn | 910 image will be drawn |
845 @param paint The paint used to draw the bitmap, or NULL | 911 @param paint The paint used to draw the bitmap, or NULL |
846 */ | 912 */ |
847 void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const S
kRect& dst, | 913 void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const S
kRect& dst, |
848 const SkPaint* paint = NULL, | 914 const SkPaint* paint = NULL, |
849 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFl
ag); | 915 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFl
ag); |
850 | 916 |
851 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, | 917 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint
* paint = NULL) { |
852 const SkPaint* paint = NULL) { | 918 this->drawBitmapRect(bitmap, NULL, dst, paint, kStrict_SrcRectConstraint
); |
853 this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRec
tFlag); | |
854 } | 919 } |
855 | 920 |
856 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, | 921 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, |
857 const SkRect& dst, const SkPaint* paint = NULL, | 922 const SkRect& dst, const SkPaint* paint = NULL, |
858 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { | 923 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { |
859 SkRect realSrcStorage; | 924 SkRect realSrcStorage; |
860 SkRect* realSrcPtr = NULL; | 925 SkRect* realSrcPtr = NULL; |
861 if (isrc) { | 926 if (isrc) { |
862 realSrcStorage.set(*isrc); | 927 realSrcStorage.set(*isrc); |
863 realSrcPtr = &realSrcStorage; | 928 realSrcPtr = &realSrcStorage; |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 virtual void onDrawRRect(const SkRRect&, const SkPaint&); | 1303 virtual void onDrawRRect(const SkRRect&, const SkPaint&); |
1239 virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], cons
t SkPaint&); | 1304 virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], cons
t SkPaint&); |
1240 virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint verti
ces[], | 1305 virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint verti
ces[], |
1241 const SkPoint texs[], const SkColor colors[], Sk
Xfermode*, | 1306 const SkPoint texs[], const SkColor colors[], Sk
Xfermode*, |
1242 const uint16_t indices[], int indexCount, const
SkPaint&); | 1307 const uint16_t indices[], int indexCount, const
SkPaint&); |
1243 | 1308 |
1244 virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[],
const SkColor[], | 1309 virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[],
const SkColor[], |
1245 int count, SkXfermode::Mode, const SkRect* cull, co
nst SkPaint*); | 1310 int count, SkXfermode::Mode, const SkRect* cull, co
nst SkPaint*); |
1246 virtual void onDrawPath(const SkPath&, const SkPaint&); | 1311 virtual void onDrawPath(const SkPath&, const SkPaint&); |
1247 virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkP
aint*); | 1312 virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkP
aint*); |
1248 virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, c
onst SkPaint*); | 1313 virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, c
onst SkPaint* |
| 1314 SRC_RECT_CONSTRAINT_PARAM(constraint)); |
1249 virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const Sk
Rect& dst, | 1315 virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const Sk
Rect& dst, |
1250 const SkPaint*); | 1316 const SkPaint*); |
1251 | 1317 |
1252 virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const S
kPaint*); | 1318 virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const S
kPaint*); |
1253 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&,
const SkPaint*, | 1319 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&,
const SkPaint*, |
1254 DrawBitmapRectFlags); | 1320 DrawBitmapRectFlags); |
1255 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const
SkRect& dst, | 1321 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const
SkRect& dst, |
1256 const SkPaint*); | 1322 const SkPaint*); |
1257 virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*
); | 1323 virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*
); |
1258 | 1324 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 * to be public because it exposes decisions about layer sizes that are inte
rnal to the canvas. | 1424 * to be public because it exposes decisions about layer sizes that are inte
rnal to the canvas. |
1359 */ | 1425 */ |
1360 SkISize getTopLayerSize() const; | 1426 SkISize getTopLayerSize() const; |
1361 SkIPoint getTopLayerOrigin() const; | 1427 SkIPoint getTopLayerOrigin() const; |
1362 | 1428 |
1363 // internal methods are not virtual, so they can safely be called by other | 1429 // internal methods are not virtual, so they can safely be called by other |
1364 // canvas apis, without confusing subclasses (like SkPictureRecording) | 1430 // canvas apis, without confusing subclasses (like SkPictureRecording) |
1365 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); | 1431 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p
aint); |
1366 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1432 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1367 const SkRect& dst, const SkPaint* paint, | 1433 const SkRect& dst, const SkPaint* paint, |
1368 DrawBitmapRectFlags flags); | 1434 SrcRectConstraint); |
1369 void internalDrawPaint(const SkPaint& paint); | 1435 void internalDrawPaint(const SkPaint& paint); |
1370 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save
LayerStrategy); | 1436 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save
LayerStrategy); |
1371 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is
BitmapDevice); | 1437 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is
BitmapDevice); |
1372 | 1438 |
1373 // shared by save() and saveLayer() | 1439 // shared by save() and saveLayer() |
1374 void internalSave(); | 1440 void internalSave(); |
1375 void internalRestore(); | 1441 void internalRestore(); |
1376 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1442 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1377 const SkRect& r, SkScalar textSize); | 1443 const SkRect& r, SkScalar textSize); |
1378 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1444 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 | 1580 |
1515 class SkCanvasClipVisitor { | 1581 class SkCanvasClipVisitor { |
1516 public: | 1582 public: |
1517 virtual ~SkCanvasClipVisitor(); | 1583 virtual ~SkCanvasClipVisitor(); |
1518 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1584 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1519 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1585 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1520 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1586 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1521 }; | 1587 }; |
1522 | 1588 |
1523 #endif | 1589 #endif |
OLD | NEW |