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 | |
f(malita)
2015/07/09 21:28:36
For some reason I recall trying this same approach
| |
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 }; | |
f(malita)
2015/07/09 21:28:36
Awesome documentation!
| |
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 = NULL, |
834 SrcRectConstraint constraint = kStrict_SrcRectConstraint) ; | |
f(malita)
2015/07/09 21:28:36
I don't feel strongly, but aren't multiple default
reed1
2015/07/10 15:07:50
Good point. Fixed.
| |
792 | 835 |
793 /** | 836 /** |
794 * Draw the image stretched differentially to fit into dst. | 837 * Draw the image stretched differentially to fit into dst. |
795 * center is a rect within the image, and logically divides the image | 838 * 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] | 839 * 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]. | 840 * image is the "center", then the center-rect should be [2, 2, 3, 3]. |
798 * | 841 * |
799 * If the dst is >= the image size, then... | 842 * If the dst is >= the image size, then... |
800 * - The 4 corners are not stretched at all. | 843 * - The 4 corners are not stretched at all. |
801 * - The sides are stretched in only one axis. | 844 * - The sides are stretched in only one axis. |
(...skipping 17 matching lines...) Expand all Loading... | |
819 generated by the shader. | 862 generated by the shader. |
820 | 863 |
821 @param bitmap The bitmap to be drawn | 864 @param bitmap The bitmap to be drawn |
822 @param left The position of the left side of the bitmap being drawn | 865 @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 | 866 @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 | 867 @param paint The paint used to draw the bitmap, or NULL |
825 */ | 868 */ |
826 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, | 869 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
827 const SkPaint* paint = NULL); | 870 const SkPaint* paint = NULL); |
828 | 871 |
872 /** Draw the specified bitmap, scaling and translating so that it fills the specified | |
873 * dst rect. If the src rect is non-null, only that subset of the bitmap is transformed | |
874 * and drawn. | |
875 * | |
876 * @param bitmap The bitmap to be drawn | |
877 * @param src Optional: specify the subset of the bitmap to be drawn | |
878 * @param dst The destination rectangle where the scaled/translated | |
879 * bitmap will be drawn | |
880 * @param paint The paint used to draw the bitmap, or NULL | |
881 * @param constraint Control the tradeoff between speed and exactness w.r.t . the src-rect. | |
882 */ | |
883 void drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, | |
884 const SkPaint* paint, SrcRectConstraint constraint); | |
885 | |
829 enum DrawBitmapRectFlags { | 886 enum DrawBitmapRectFlags { |
830 kNone_DrawBitmapRectFlag = 0x0, | 887 kNone_DrawBitmapRectFlag = 0x0, |
831 /** | 888 /** |
832 * When filtering is enabled, allow the color samples outside of | 889 * When filtering is enabled, allow the color samples outside of |
833 * the src rect (but still in the src bitmap) to bleed into the | 890 * the src rect (but still in the src bitmap) to bleed into the |
834 * drawn portion | 891 * drawn portion |
835 */ | 892 */ |
836 kBleed_DrawBitmapRectFlag = 0x1, | 893 kBleed_DrawBitmapRectFlag = 0x1, |
837 }; | 894 }; |
838 | 895 |
839 /** Draw the specified bitmap, with the specified matrix applied (before the | 896 /** Draw the specified bitmap, with the specified matrix applied (before the |
840 canvas' matrix is applied). | 897 canvas' matrix is applied). |
841 @param bitmap The bitmap to be drawn | 898 @param bitmap The bitmap to be drawn |
842 @param src Optional: specify the subset of the bitmap to be drawn | 899 @param src Optional: specify the subset of the bitmap to be drawn |
843 @param dst The destination rectangle where the scaled/translated | 900 @param dst The destination rectangle where the scaled/translated |
844 image will be drawn | 901 image will be drawn |
845 @param paint The paint used to draw the bitmap, or NULL | 902 @param paint The paint used to draw the bitmap, or NULL |
846 */ | 903 */ |
847 void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const S kRect& dst, | 904 void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const S kRect& dst, |
848 const SkPaint* paint = NULL, | 905 const SkPaint* paint = NULL, |
849 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFl ag); | 906 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFl ag); |
f(malita)
2015/07/09 21:28:36
Are we going to switch this to the new enum at som
reed1
2015/07/10 15:07:50
Plan to switch, as I now expose a version of drawB
| |
850 | 907 |
851 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, | 908 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, |
852 const SkPaint* paint = NULL) { | 909 const SkPaint* paint = NULL) { |
853 this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRec tFlag); | 910 this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRec tFlag); |
854 } | 911 } |
855 | 912 |
856 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, | 913 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, |
857 const SkRect& dst, const SkPaint* paint = NULL, | 914 const SkRect& dst, const SkPaint* paint = NULL, |
858 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { | 915 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { |
859 SkRect realSrcStorage; | 916 SkRect realSrcStorage; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1238 virtual void onDrawRRect(const SkRRect&, const SkPaint&); | 1295 virtual void onDrawRRect(const SkRRect&, const SkPaint&); |
1239 virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], cons t SkPaint&); | 1296 virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], cons t SkPaint&); |
1240 virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint verti ces[], | 1297 virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint verti ces[], |
1241 const SkPoint texs[], const SkColor colors[], Sk Xfermode*, | 1298 const SkPoint texs[], const SkColor colors[], Sk Xfermode*, |
1242 const uint16_t indices[], int indexCount, const SkPaint&); | 1299 const uint16_t indices[], int indexCount, const SkPaint&); |
1243 | 1300 |
1244 virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], | 1301 virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], |
1245 int count, SkXfermode::Mode, const SkRect* cull, co nst SkPaint*); | 1302 int count, SkXfermode::Mode, const SkRect* cull, co nst SkPaint*); |
1246 virtual void onDrawPath(const SkPath&, const SkPaint&); | 1303 virtual void onDrawPath(const SkPath&, const SkPaint&); |
1247 virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkP aint*); | 1304 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*); | 1305 virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, c onst SkPaint* |
1306 SRC_RECT_CONSTRAINT_PARAM(constraint)); | |
1249 virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const Sk Rect& dst, | 1307 virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const Sk Rect& dst, |
1250 const SkPaint*); | 1308 const SkPaint*); |
1251 | 1309 |
1252 virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const S kPaint*); | 1310 virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const S kPaint*); |
1253 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, | 1311 virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, |
1254 DrawBitmapRectFlags); | 1312 DrawBitmapRectFlags); |
1255 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, | 1313 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, |
1256 const SkPaint*); | 1314 const SkPaint*); |
1257 virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint* ); | 1315 virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint* ); |
1258 | 1316 |
(...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. | 1416 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas. |
1359 */ | 1417 */ |
1360 SkISize getTopLayerSize() const; | 1418 SkISize getTopLayerSize() const; |
1361 SkIPoint getTopLayerOrigin() const; | 1419 SkIPoint getTopLayerOrigin() const; |
1362 | 1420 |
1363 // internal methods are not virtual, so they can safely be called by other | 1421 // internal methods are not virtual, so they can safely be called by other |
1364 // canvas apis, without confusing subclasses (like SkPictureRecording) | 1422 // canvas apis, without confusing subclasses (like SkPictureRecording) |
1365 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p aint); | 1423 void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* p aint); |
1366 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1424 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1367 const SkRect& dst, const SkPaint* paint, | 1425 const SkRect& dst, const SkPaint* paint, |
1368 DrawBitmapRectFlags flags); | 1426 SrcRectConstraint); |
1369 void internalDrawPaint(const SkPaint& paint); | 1427 void internalDrawPaint(const SkPaint& paint); |
1370 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save LayerStrategy); | 1428 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save LayerStrategy); |
1371 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); | 1429 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); |
1372 | 1430 |
1373 // shared by save() and saveLayer() | 1431 // shared by save() and saveLayer() |
1374 void internalSave(); | 1432 void internalSave(); |
1375 void internalRestore(); | 1433 void internalRestore(); |
1376 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1434 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1377 const SkRect& r, SkScalar textSize); | 1435 const SkRect& r, SkScalar textSize); |
1378 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1436 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1514 | 1572 |
1515 class SkCanvasClipVisitor { | 1573 class SkCanvasClipVisitor { |
1516 public: | 1574 public: |
1517 virtual ~SkCanvasClipVisitor(); | 1575 virtual ~SkCanvasClipVisitor(); |
1518 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1576 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1519 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1577 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1520 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1578 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1521 }; | 1579 }; |
1522 | 1580 |
1523 #endif | 1581 #endif |
OLD | NEW |