SkCanvas.h revision cb60844b34766aad4151df5e87c144d4a57e9abe
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License"); 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * http://www.apache.org/licenses/LICENSE-2.0 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS, 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License. 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkCanvas_DEFINED 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkCanvas_DEFINED 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h" 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h" 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalarCompare.h" 28845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h" 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBounder; 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDevice; 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw; 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter; 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture; 35f76bacff7f66724072c67edb185abf9e3add11a0reed@android.comclass SkShape; 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A Canvas encapsulates all of the state about drawing into a device (bitmap). 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This includes a reference to the device itself, and a stack of matrix/clip 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com values. For any given draw call (e.g. drawRect), the geometry of the object 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com being drawn is transformed by the concatenation of all the matrices in the 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stack. The transformed geometry is clipped by the intersection of all of 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the clips in the stack. 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com While the Canvas holds the state of the drawing device, the state (style) 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of the object being drawn is held by the Paint, which is provided as a 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com parameter to each of the draw() methods. The Paint holds attributes such as 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com etc. 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas : public SkRefCnt { 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Construct a canvas with the specified bitmap to draw into. 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap Specifies a bitmap for the canvas to draw into. Its 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com structure are copied to the canvas. 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkCanvas(const SkBitmap& bitmap); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Construct a canvas with the specified device to draw into. 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param device Specifies a device for the canvas to draw into. The 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device may be null. 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkCanvas(SkDevice* device = NULL); 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkCanvas(); 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If this subclass of SkCanvas supports GL viewports, return true and set 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size (if not null) to the size of the viewport. If it is not supported, 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ignore vp and return false. 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool getViewport(SkIPoint* size) const; 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If this subclass of SkCanvas supports GL viewports, return true and set 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the viewport to the specified x and y dimensions. If it is not 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com supported, ignore x and y and return false. 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool setViewport(int x, int y); 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the canvas' device object, which may be null. The device holds 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the bitmap of the pixels that the canvas draws into. The reference count 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of the returned device is not changed by this call. 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDevice* getDevice() const; 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specify a device for this canvas to draw into. If it is not null, its 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com reference count is incremented. If the canvas was already holding a 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device, its reference count is decremented. The new device is returned. 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDevice* setDevice(SkDevice* device); 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specify a bitmap for the canvas to draw into. This is a help method for 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com setDevice(), and it creates a device for the bitmap by calling 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com createDevice(). The structure of the bitmap is copied into the device. 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum SaveFlags { 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the matrix state, restoring it on restore() */ 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrix_SaveFlag = 0x01, 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the clip state, restoring it on restore() */ 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClip_SaveFlag = 0x02, 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support per-pixel alpha */ 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kHasAlphaLayer_SaveFlag = 0x04, 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support 8-bits per color component */ 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFullColorLayer_SaveFlag = 0x08, 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer should clip against the bounds argument */ 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClipToLayer_SaveFlag = 0x10, 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helper masks for common choices 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrixClip_SaveFlag = 0x03, 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_NoClipLayer_SaveFlag = 0x0F, 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_ClipLayer_SaveFlag = 0x1F 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This call saves the current matrix and clip information, and pushes a 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy onto a private stack. Subsequent calls to translate, scale, 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rotate, skew, concat or clipRect, clipPath all operate on this copy. 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com When the balancing call to restore() is made, this copy is deleted and 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the previous matrix/clip state is restored. 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual int save(SaveFlags flags = kMatrixClip_SaveFlag); 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the canvas (or the previous layer). Subsequent calls to translate, 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale, rotate, skew, concat or clipRect, clipPath all operate on this 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy. When the balancing call to restore() is made, this copy is deleted 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and the previous matrix/clip state is restored. 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bounds (may be null) the maximum size the offscreen bitmap needs 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com to be (in local coordinates) 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint (may be null) This is copied, and is applied to the 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen when restore() is called 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SaveFlags flags = kARGB_ClipLayer_SaveFlag); 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the canvas (or the previous layer). Subsequent calls to translate, 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale, rotate, skew, concat or clipRect, clipPath all operate on this 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy. When the balancing call to restore() is made, this copy is deleted 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and the previous matrix/clip state is restored. 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bounds (may be null) the maximum size the offscreen bitmap needs 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com to be (in local coordinates) 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param alpha This is applied to the offscreen when restore() is called. 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SaveFlags flags = kARGB_ClipLayer_SaveFlag); 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This call balances a previous call to save(), and is used to remove all 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com modifications to the matrix/clip state since the last save call. It is 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com an error to call restore() more times than save() was called. 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void restore(); 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of matrix/clip states on the SkCanvas' private stack. 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This will equal # save() calls - # restore() calls. 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int getSaveCount() const; 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Efficient way to pop any calls to save() that happened after the save 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count reached saveCount. It is an error for saveCount to be less than 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com getSaveCount() 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param saveCount The number of save() levels to restore from 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void restoreToCount(int saveCount); 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified translation 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The distance to translate in X 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The distance to translate in Y 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool translate(SkScalar dx, SkScalar dy); 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified scale. 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to scale in X 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to scale in Y 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool scale(SkScalar sx, SkScalar sy); 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified rotation. 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param degrees The amount to rotate, in degrees 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool rotate(SkScalar degrees); 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified skew. 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to skew in X 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to skew in Y 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool skew(SkScalar sx, SkScalar sy); 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified matrix. 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to preconcatenate with the current matrix 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the operation succeeded (e.g. did not overflow) 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool concat(const SkMatrix& matrix); 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Replace the current matrix with a copy of the specified matrix. 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix that will be copied into the current matrix. 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void setMatrix(const SkMatrix& matrix); 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for setMatrix(identity). Sets the current matrix to identity. 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetMatrix(); 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified rectangle. 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to intersect with the current clip 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the canvas' clip is non-empty 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipRect(const SkRect& rect, 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Op op = SkRegion::kIntersect_Op); 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified path. 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to apply to the current clip 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the canvas' new clip is non-empty 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipPath(const SkPath& path, 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Op op = SkRegion::kIntersect_Op); 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified region. Note that unlike 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRect() and clipPath() which transform their arguments by the current 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix, clipRegion() assumes its argument is already in device 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinates, and so no transformation is performed. 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to apply to the current clip 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the canvas' new clip is non-empty 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipRegion(const SkRegion& deviceRgn, 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Op op = SkRegion::kIntersect_Op); 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified region. This does not intersect or in any other way account 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for the existing clip region. 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to copy into the current clip. 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the new clip region is non-empty 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setClipRegion(const SkRegion& deviceRgn) { 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->clipRegion(deviceRgn, SkRegion::kReplace_Op); 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Enum describing how to treat edges when performing quick-reject tests 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of a geometry against the current clip. Treating them as antialiased 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (kAA_EdgeType) will take into account the extra pixels that may be drawn 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if the edge does not lie exactly on a device pixel boundary (after being 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com transformed by the current matrix). 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum EdgeType { 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Treat the edges as B&W (not antialiased) for the purposes of testing 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com against the current clip 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBW_EdgeType, 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Treat the edges as antialiased for the purposes of testing 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com against the current clip 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kAA_EdgeType 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified rectangle, after being transformed by the 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect the rect to compare with the current clip 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param et specifies how to treat the edges (see EdgeType) 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the rect (transformed by the canvas' matrix) does not 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool quickReject(const SkRect& rect, EdgeType et) const; 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified path, after being transformed by the 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). Note, for speed it may 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false even if the path itself might not intersect the clip 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (i.e. the bounds of the path intersects, but the path does not). 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to compare with the current clip 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param et specifies how to treat the edges (see EdgeType) 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path (transformed by the canvas' matrix) does not 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool quickReject(const SkPath& path, EdgeType et) const; 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the horizontal band specified by top and bottom is 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely clipped out. This is a conservative calculation, meaning 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that it is possible that if the method returns false, the band may still 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in fact be clipped out, but the converse is not true. If this method 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true, then the band is guaranteed to be clipped out. 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top of the horizontal band to compare with the clip 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom of the horizontal and to compare with the clip 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the horizontal band is completely clipped out (i.e. does 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not intersect the current clip) 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool quickRejectY(SkScalar top, SkScalar bottom, EdgeType et) const; 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the bounds of the current clip (in local coordinates) in the 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds parameter, and return true if it is non-empty. This can be useful 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in a way similar to quickReject, in that it tells you that drawing 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com outside of these bounds will be clipped out. 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool getClipBounds(SkRect* bounds, EdgeType et = kAA_EdgeType) const; 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 318845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified ARGB color, using the specified mode. 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param a the alpha component (0..255) of the color to fill the canvas 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param r the red component (0..255) of the color to fill the canvas 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param g the green component (0..255) of the color to fill the canvas 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param b the blue component (0..255) of the color to fill the canvas 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, 326845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 329845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified color and mode. 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color the color to draw with 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawColor(SkColor color, 334845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified paint. 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to fill the canvas 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPaint(const SkPaint& paint); 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum PointMode { 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each point separately */ 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPoints_PointMode, 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each pair of points as a line segment */ 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLines_PointMode, 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws the array of points as a polygon */ 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPolygon_PointMode 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a series of points, interpreted based on the PointMode mode. For 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com all modes, the count parameter is interpreted as the total number of 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com points. For kLine mode, count/2 line segments are drawn. 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPoint mode, each point is drawn centered at its coordinate, and its 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size is specified by the paint's stroke-width. It draws as a square, 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unless the paint's cap-type is round, in which the points are drawn as 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com circles. 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kLine mode, each pair of points is drawn as a line segment, 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com respecting the paint's settings for cap/join/width. 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPolygon mode, the entire array is drawn as a series of connected 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line segments. 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note that, while similar, kLine and kPolygon modes draw slightly 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com differently than the equivalent path built with a series of moveto, 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com lineto calls, in that the path will draw all of its contours at once, 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with no interactions if contours intersect each other (think XOR 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xfermode). drawPoints always draws each element one at a time. 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode PointMode specifying how to draw the array of points. 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param count The number of points in the array 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts Array of points to draw 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the points 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper method for drawing a single point. See drawPoints() for a more 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com details. 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draws a single pixel in the specified color. 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The X coordinate of which pixel to draw 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The Y coordiante of which pixel to draw 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color The color to draw 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, SkColor color); 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a line segment with the specified start and stop x,y coordinates, 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com using the specified paint. NOTE: since a line is always "framed", the 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint's Style is ignored. 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x0 The x-coordinate of the start point of the line 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y0 The y-coordinate of the start point of the line 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the end point of the line 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the end point of the line 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the line 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or stroked based on the Style in the paint. 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawRect(const SkRect& rect, const SkPaint& paint); 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawIRect(const SkIRect& rect, const SkPaint& paint) 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(rect); // promotes the ints to scalars 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawRect(r, paint); 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The left side of the rectangle to be drawn 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top side of the rectangle to be drawn 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param right The right side of the rectangle to be drawn 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom side of the rectangle to be drawn 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRectCoords(SkScalar left, SkScalar top, SkScalar right, 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar bottom, const SkPaint& paint); 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified oval using the specified paint. The oval will be 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The rectangle bounds of the oval to be drawn 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the oval 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawOval(const SkRect& oval, const SkPaint&); 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified circle using the specified paint. If radius is <= 0, 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com then nothing will be drawn. The circle will be filled 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or framed based on the Style in the paint. 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cx The x-coordinate of the center of the cirle to be drawn 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cy The y-coordinate of the center of the cirle to be drawn 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param radius The radius of the cirle to be drawn 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the circle 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified arc, which will be scaled to fit inside the 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified oval. If the sweep angle is >= 360, then the oval is drawn 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely. Note that this differs slightly from SkPath::arcTo, which 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com treats the sweep angle mod 360. 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the shape of the arc 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param useCenter true means include the center of the oval. For filling 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this will draw a wedge. False means just use the arc. 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the arc 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool useCenter, const SkPaint& paint); 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified round-rect using the specified paint. The round-rect 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rectangular bounds of the roundRect to be drawn 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rx The x-radius of the oval used to round the corners 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ry The y-radius of the oval used to round the corners 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the roundRect 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified path using the specified paint. The path will be 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to be drawn 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the path 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPath(const SkPath& path, const SkPaint& paint); 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), using the 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified paint, transformed by the current matrix. Note: if the paint 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with the specified matrix applied (before the 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas' matrix is applied). 4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src Optional: specify the subset of the bitmap to be drawn 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The destination rectangle where the scaled/translated 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com image will be drawn 4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& dst, const SkPaint* paint = NULL); 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOT transformed by the current matrix. Note: if the paint 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint. 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The origin is interpreted based on the Align setting in the paint. 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the origin of the text being drawn 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the origin of the text being drawn 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawText(const void* text, size_t byteLength, SkScalar x, 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar y, const SkPaint& paint); 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the pos[] 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com array. The origin is interpreted by the Align setting in the paint. 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pos Array of positions, used to position each character 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPosText(const void* text, size_t byteLength, 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint pos[], const SkPaint& paint); 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the x 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinate taken from the xpos[] array, and the y from the constY param. 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The origin is interpreted by the Align setting in the paint. 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xpos Array of x-positions, used to position each character 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param constY The shared Y coordinate for all of the positions 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPosTextH(const void* text, size_t byteLength, 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar xpos[], SkScalar constY, 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param hOffset The distance along the path to add to the text's 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com starting position 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vOffset The distance above(-) or below(+) the path to 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com position the text 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawTextOnPathHV(const void* text, size_t byteLength, 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, SkScalar hOffset, 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar vOffset, const SkPaint& paint); 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix (may be null) Applied to the text before it is 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mapped onto the path 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawTextOnPath(const void* text, size_t byteLength, 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, const SkMatrix* matrix, 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the picture into this canvas. This method effective brackets the 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com playback of the picture's draw calls with save/restore, so the state 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of this canvas will be unchanged after this call. This contrasts with 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the more immediate method SkPicture::draw(), which does not bracket 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the canvas with save/restore, thus the canvas may be left in a changed 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state after the call. 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param picture The recorded drawing commands to playback into this 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas. 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPicture(SkPicture& picture); 5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 595f76bacff7f66724072c67edb185abf9e3add11a0reed@android.com /** Draws the specified shape 596f76bacff7f66724072c67edb185abf9e3add11a0reed@android.com */ 597f76bacff7f66724072c67edb185abf9e3add11a0reed@android.com virtual void drawShape(SkShape*); 598f76bacff7f66724072c67edb185abf9e3add11a0reed@android.com 5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum VertexMode { 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangles_VertexMode, 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleStrip_VertexMode, 6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleFan_VertexMode 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the array of vertices, interpreted as triangles (based on mode). 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vmode How to interpret the array of vertices 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertexCount The number of points in the vertices array (and 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com corresponding texs and colors arrays if non-null) 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertices Array of vertices for the mesh 6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param texs May be null. If not null, specifies the coordinate 6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in texture space for each vertex. 6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param colors May be null. If not null, specifies a color for each 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex, to be interpolated across the triangle. 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xmode Used if both texs and colors are present. In this 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case the colors are combined with the texture using mode, 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com before being drawn using the paint. If mode is null, then 617845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com kMultiply_Mode is used. 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indices If not null, array of indices to reference into the 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex (texs, colors) array. 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indexCount number of entries in the indices array (if not null) 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint Specifies the shader/texture if present. 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawVertices(VertexMode vmode, int vertexCount, 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint texs[], 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 629cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com /** Send a blob of data to the canvas. 630cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com For canvases that draw, this call is effectively a no-op, as the data 631cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com is not parsed, but just ignored. However, this call exists for 632cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com subclasses like SkPicture's recording canvas, that can store the data 633cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com and then play it back later (via another call to drawData). 634cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com */ 635cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com virtual void drawData(const void* data, size_t length); 636cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current bounder object. 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The bounder's reference count is unchaged. 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canva's bounder (or NULL). 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBounder* getBounder() const { return fBounder; } 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set a new bounder (or NULL). 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Pass NULL to clear any previous bounder. 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter passed is also returned. 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If a previous bounder exists, its reference count is decremented. 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If bounder is not NULL, its reference count is incremented. 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bounder the new bounder (or NULL) to be installed in the canvas 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the set bounder object 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkBounder* setBounder(SkBounder* bounder); 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current filter object. The filter's reference count is not 6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com affected. The filter is part of the state this is affected by 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com save/restore. 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canvas' filter (or NULL). 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawFilter* getDrawFilter() const; 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the new filter (or NULL). Pass NULL to clear any existing filter. 6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter is returned. If an existing filter 6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com exists, its refcnt is decrement. If the new filter is not null, its 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com refcnt is incremented. The filter is part of the state this is affected 6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com by save/restore. 6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param filter the new filter (or NULL) 6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the new filter 6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); 6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the current matrix on the canvas. 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This does not account for the translate in any of the devices. 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The current matrix on the canvas. 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& getTotalMatrix() const; 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the current device clip (concatenation of all clip calls). 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This does not account for the translate in any of the devices. 6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the current device clip (concatenation of all clip calls). 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion& getTotalClip() const; 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** May be overridden by subclasses. This returns a compatible device 6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for this canvas, with the specified config/width/height. If isOpaque 6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is true, then the underlying bitmap is optimized to assume that every 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixel will be drawn to, and thus it does not need to clear the alpha 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com channel ahead of time (assuming the specified config supports per-pixel 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alpha.) If isOpaque is false, then the bitmap should clear its alpha 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com channel. 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDevice* createDevice(SkBitmap::Config, int width, int height, 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isOpaque, bool isForLayer); 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After calling saveLayer(), there can be any number of devices that make 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com up the top-most drawing area. LayerIter can be used to iterate through 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com those devices. Note that the iterator is only valid until the next API 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call made on the canvas. Ownership of all pointers in the iterator stays 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the canvas, so none of them should be modified or deleted. 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class LayerIter /*: SkNoncopyable*/ { 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize iterator with canvas, and set values for 1st device */ 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com LayerIter(SkCanvas*, bool skipEmptyClips); 7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~LayerIter(); 7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the iterator is done */ 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool done() const { return fDone; } 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Cycle to the next device */ 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void next(); 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // These reflect the current device in the iterator 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDevice* device() const; 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix() const; 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion& clip() const; 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint() const; 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x() const; 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y() const; 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // used to embed the SkDrawIter object directly in our instance, w/o 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // having to expose that class def to the public. There is an assert 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // in our constructor to ensure that fStorage is large enough 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (though needs to be a compile-time-assert!). We use intptr_t to work 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // safely with 32 and 64 bit machines (to ensure the storage is enough) 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intptr_t fStorage[12]; 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class SkDrawIter* fImpl; // this points at fStorage 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint fDefaultPaint; 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDone; 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // all of the drawBitmap variants call this guy 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void commonDrawBitmap(const SkBitmap&, const SkMatrix& m, 7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class MCRec; 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDeque fMCStack; 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // points to top of stack 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MCRec* fMCRec; 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the first N recs that can fit here mean we won't call malloc 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fMCRecStorage[32]; 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBounder* fBounder; 752199f108f14a5f60a9c2205ffa79b26102a206ad0reed@android.com SkDevice* fLastDeviceToGainFocus; 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void prepareForDeviceDraw(SkDevice*); 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updateDeviceCMCache(); 7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkDrawIter; // needs setupDrawForLayerDevice() 7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDevice* init(SkDevice*); 7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint); 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawDevice(SkDevice*, int x, int y, const SkPaint*); 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // shared by save() and saveLayer() 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int internalSave(SaveFlags flags); 7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void internalRestore(); 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* These maintain a cache of the clip bounds in local coordinates, 7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (converted to 2s-compliment if floats are slow). 7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkRectCompareType fLocalBoundsCompareType; 7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable bool fLocalBoundsCompareTypeDirty; 7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRectCompareType& getLocalClipBoundsCompareType() const { 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fLocalBoundsCompareTypeDirty) { 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->computeLocalClipBoundsCompareType(); 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fLocalBoundsCompareTypeDirty = false; 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fLocalBoundsCompareType; 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void computeLocalClipBoundsCompareType() const; 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com when this object goes out of scope. Use this to guarantee that the canvas 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is restored to a known state. 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable { 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas) { 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(canvas); 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fSaveCount = canvas->getSaveCount(); 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doSave) { 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas->save(); 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoCanvasRestore() { 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCanvas->restoreToCount(fSaveCount); 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas* fCanvas; 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSaveCount; 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 809