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