SkCanvas.h revision a5517e2b190a8083b38964972b031c13e99f1012
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkCanvas_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkCanvas_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h" 145c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#include "SkClipStack.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 194a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h" 20845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice; 236a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw; 253cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable; 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter; 27b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixrclass SkImage; 2874bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData; 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture; 304ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect; 3171c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform; 3276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface; 3397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base; 3400d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob; 35644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext; 369c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comclass GrRenderTarget; 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 38a5517e2b190a8083b38964972b031c13e99f1012reed//#define SK_SUPPORT_LEGACY_ONDRAWIMAGERECT 39a5517e2b190a8083b38964972b031c13e99f1012reed 40fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereedclass SkCanvasState; 41fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed 42a5517e2b190a8083b38964972b031c13e99f1012reed#ifdef SK_SUPPORT_LEGACY_ONDRAWIMAGERECT 43a5517e2b190a8083b38964972b031c13e99f1012reed #define SK_VIRTUAL_CONSTRAINT_TYPE SkCanvas::DrawBitmapRectFlags 44a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_PARAM(param) 45a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_ARG(arg) 46a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(var) SkCanvas::SrcRectConstraint var = SkCanvas::kStrict_SrcRectConstraint; 47a5517e2b190a8083b38964972b031c13e99f1012reed#else 48a5517e2b190a8083b38964972b031c13e99f1012reed #define SK_VIRTUAL_CONSTRAINT_TYPE SkCanvas::SrcRectConstraint 49a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_PARAM(param) , SrcRectConstraint param 50a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_ARG(arg) , arg 51a5517e2b190a8083b38964972b031c13e99f1012reed #define SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(var) 52a5517e2b190a8083b38964972b031c13e99f1012reed#endif 53a5517e2b190a8083b38964972b031c13e99f1012reed 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A Canvas encapsulates all of the state about drawing into a device (bitmap). 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This includes a reference to the device itself, and a stack of matrix/clip 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com values. For any given draw call (e.g. drawRect), the geometry of the object 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com being drawn is transformed by the concatenation of all the matrices in the 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stack. The transformed geometry is clipped by the intersection of all of 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the clips in the stack. 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com While the Canvas holds the state of the drawing device, the state (style) 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of the object being drawn is held by the Paint, which is provided as a 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com parameter to each of the draw() methods. The Paint holds attributes such as 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com etc. 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 697ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt { 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 71e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 7242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the 7342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * specified pixels. To access the pixels after drawing to them, the caller should call 7442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * flush() or call peekPixels(...). 7542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 7642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * On failure, return NULL. This can fail for several reasons: 7742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 1. invalid ImageInfo (e.g. negative dimensions) 7842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 2. unsupported ImageInfo for a canvas 7942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * - kUnknown_SkColorType, kIndex_8_SkColorType 8044977485bdac75c055c3fa638f118874ccd2d22freed * - kUnknown_SkAlphaType 8142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * - this list is not complete, so others may also be unsupported 8242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 8342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * Note: it is valid to request a supported ImageInfo, but with zero 8442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * dimensions. 8542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org */ 8642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t); 8742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org 8842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) { 8942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes); 9042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org } 9142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org 9242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org /** 93e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates an empty canvas with no backing device/pixels, and zero 94e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * dimensions. 95e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 96cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com SkCanvas(); 978d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 98e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 99e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates a canvas of the specified dimensions, but explicitly not backed 100e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * by any device/pixels. Typically this use used by subclasses who handle 101e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * the draw calls in some other way. 102e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 10396a857ef5a40b3d0751ec9ebaaa96d9f20b82b21reed SkCanvas(int width, int height, const SkSurfaceProps* = NULL); 104e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org 1056dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com /** Construct a canvas with the specified device to draw into. 106e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 1078d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org @param device Specifies a device for the canvas to draw into. 1088d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org */ 1091f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com explicit SkCanvas(SkBaseDevice* device); 1108d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 1114469938e92d779dff05e745559e67907bbf21e78reed@google.com /** Construct a canvas with the specified bitmap to draw into. 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap Specifies a bitmap for the canvas to draw into. Its 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com structure are copied to the canvas. 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkCanvas(const SkBitmap& bitmap); 1163d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita 1173d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita /** Construct a canvas with the specified bitmap to draw into. 1183d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita @param bitmap Specifies a bitmap for the canvas to draw into. Its 1193d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita structure are copied to the canvas. 1203d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita @param props New canvas surface properties. 1213d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita */ 1223d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props); 1233d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkCanvas(); 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData& getMetaData(); 12774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 128c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 129c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return ImageInfo for this canvas. If the canvas is not backed by pixels 130c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. 131c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 132c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo imageInfo() const; 133c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 136210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com /** 137bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org * Trigger the immediate execution of all pending draw operations. 138bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org */ 139bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org void flush(); 140bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org 141bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org /** 1424ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * Gets the size of the base or root layer in global canvas coordinates. The 1434ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * origin of the base layer is always (0,0). The current drawable area may be 1444ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * smaller (due to clipping or saveLayer). 145210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com */ 14668260fa1e913cb1f1f4f07755acd11357a47dc6ftomhudson virtual SkISize getBaseLayerSize() const; 1474ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com 1484ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com /** 1494ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * DEPRECATED: call getBaseLayerSize 1504ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com */ 1514ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkISize getDeviceSize() const { return this->getBaseLayerSize(); } 152210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com 153c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 154c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * DEPRECATED. 155c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return the canvas' device object, which may be null. The device holds 156c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * the bitmap of the pixels that the canvas draws into. The reference count 157c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * of the returned device is not changed by this call. 158c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 15952d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#ifndef SK_SUPPORT_LEGACY_GETDEVICE 16052d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedprotected: // Can we make this private? 16152d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#endif 1621f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* getDevice() const; 16352d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedpublic: 16441e010cb901c0da9066c4df562030808c9ccd7f8reed SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing() const { 16541e010cb901c0da9066c4df562030808c9ccd7f8reed return this->getDevice(); 16641e010cb901c0da9066c4df562030808c9ccd7f8reed } 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1689266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com /** 1699266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * saveLayer() can create another device (which is later drawn onto 1709266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * the previous device). getTopDevice() returns the top-most device current 1719266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * installed. Note that this can change on other calls like save/restore, 1729266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * so do not access this device after subsequent canvas calls. 1739266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * The reference count of the device is not changed. 1740b53d59a24f667350b4282f88470713902409030reed@google.com * 1750b53d59a24f667350b4282f88470713902409030reed@google.com * @param updateMatrixClip If this is true, then before the device is 1760b53d59a24f667350b4282f88470713902409030reed@google.com * returned, we ensure that its has been notified about the current 1770b53d59a24f667350b4282f88470713902409030reed@google.com * matrix and clip. Note: this happens automatically when the device 1780b53d59a24f667350b4282f88470713902409030reed@google.com * is drawn to, but is optional here, as there is a small perf hit 1790b53d59a24f667350b4282f88470713902409030reed@google.com * sometimes. 1809266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com */ 1819c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE 1829c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate: 1839c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif 1841f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const; 1859c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic: 1869266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com 18776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com /** 18876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com * Create a new surface matching the specified info, one that attempts to 189cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org * be maximally compatible when used with this canvas. If there is no matching Surface type, 190cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org * NULL is returned. 1914a8126e7f81384526629b1e21bf89b632ea13cd9reed * 1924a8126e7f81384526629b1e21bf89b632ea13cd9reed * If surfaceprops is specified, those are passed to the new surface, otherwise the new surface 1934a8126e7f81384526629b1e21bf89b632ea13cd9reed * inherits the properties of the surface that owns this canvas. If this canvas has no parent 1944a8126e7f81384526629b1e21bf89b632ea13cd9reed * surface, then the new surface is created with default properties. 19576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com */ 1964a8126e7f81384526629b1e21bf89b632ea13cd9reed SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps* = NULL); 197e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 198644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org /** 199644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * Return the GPU context of the device that is associated with the canvas. 200644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * For a canvas with non-GPU device, NULL is returned. 201644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org */ 202644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org GrContext* getGrContext(); 203644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org 2044b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /////////////////////////////////////////////////////////////////////////// 2054b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 206daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com /** 2079c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * If the canvas has writable pixels in its top layer (and is not recording to a picture 2089c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * or other non-raster target) and has direct access to its pixels (i.e. they are in 2099c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * local RAM) return the address of those pixels, and if not null, 2106b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org * return the ImageInfo, rowBytes and origin. The returned address is only valid 2119c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * while the canvas object is in scope and unchanged. Any API calls made on 2129c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * canvas (or its parent surface if any) will invalidate the 2139c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * returned address (and associated information). 2149c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * 2156b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org * On failure, returns NULL and the info, rowBytes, and origin parameters are ignored. 2169c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com */ 2176b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL); 2189c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com 2199c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com /** 2209c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * If the canvas has readable pixels in its base layer (and is not recording to a picture 2219c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * or other non-raster target) and has direct access to its pixels (i.e. they are in 222c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * local RAM) return the const-address of those pixels, and if not null, 223c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * return the ImageInfo and rowBytes. The returned address is only valid 224c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * while the canvas object is in scope and unchanged. Any API calls made on 225c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * canvas (or its parent surface if any) will invalidate the 226c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * returned address (and associated information). 227c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 228c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * On failure, returns NULL and the info and rowBytes parameters are 229c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * ignored. 230c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 231c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* peekPixels(SkImageInfo* info, size_t* rowBytes); 232c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org /** 234a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), 235a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * converting them into the requested format (SkImageInfo). The base-layer pixels are read 236b184f7f52b2a94e95aee326a3ca37110d2e43336reed * starting at the specified (srcX,srcY) location in the coordinate system of the base-layer. 237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 238b184f7f52b2a94e95aee326a3ca37110d2e43336reed * The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle 239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 240b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); 241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 242b184f7f52b2a94e95aee326a3ca37110d2e43336reed * srcR is intersected with the bounds of the base-layer. If this intersection is not empty, 243b184f7f52b2a94e95aee326a3ca37110d2e43336reed * then we have two sets of pixels (of equal size). Replace the dst pixels with the 244b184f7f52b2a94e95aee326a3ca37110d2e43336reed * corresponding src pixels, performing any colortype/alphatype transformations needed 245b184f7f52b2a94e95aee326a3ca37110d2e43336reed * (in the case where the src and dst have different colortypes or alphatypes). 246a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * This call can fail, returning false, for several reasons: 248b184f7f52b2a94e95aee326a3ca37110d2e43336reed * - If srcR does not intersect the base-layer bounds. 249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * - If the requested colortype/alphatype cannot be converted from the base-layer's types. 250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * - If this canvas is not backed by pixels (e.g. picture or PDF) 251a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org */ 252b184f7f52b2a94e95aee326a3ca37110d2e43336reed bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 253b184f7f52b2a94e95aee326a3ca37110d2e43336reed int srcX, int srcY); 254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org /** 256a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated. 257a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * If not, it will attempt to call allocPixels(). If this fails, it will return false. If not, 258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * it calls through to readPixels(info, ...) and returns its result. 259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org */ 260b184f7f52b2a94e95aee326a3ca37110d2e43336reed bool readPixels(SkBitmap* bitmap, int srcX, int srcY); 261c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com 2624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /** 263a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized 264a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * to the intersection of srcRect and the base-layer bounds. On success, pixels will be 265a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * allocated in bitmap and true returned. On failure, false is returned and bitmap will be 266a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * set to empty. 26751df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com */ 26851df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); 26951df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com 2704cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org /** 2714cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * This method affects the pixels in the base-layer, and operates in pixel coordinates, 2724cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * ignoring the matrix and clip. 2734cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * The specified ImageInfo and (x,y) offset specifies a rectangle: target. 2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * target.setXYWH(x, y, info.width(), info.height()); 2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * Target is intersected with the bounds of the base-layer. If this intersection is not empty, 2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes 2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src 2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * pixels, performing any colortype/alphatype transformations needed (in the case where the 2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * src and dst have different colortypes or alphatypes). 2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * This call can fail, returning false, for several reasons: 2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * - If the src colortype/alphatype cannot be converted to the canvas' types 2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * - If this canvas is not backed by pixels (e.g. picture or PDF) 2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org */ 2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y); 2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 2904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org /** 2914cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap 2924cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * is just wrapping a texture, returns false and does nothing. 2934cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org */ 2944cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org bool writePixels(const SkBitmap& bitmap, int x, int y); 2954b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 2978d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum SaveFlags { 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the matrix state, restoring it on restore() */ 3005f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita // [deprecated] kMatrix_SaveFlag = 0x01, 301696d3611760b0465caaebf6243824960034c3592fmalita kMatrix_SaveFlag = 0x01, 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the clip state, restoring it on restore() */ 3035f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita // [deprecated] kClip_SaveFlag = 0x02, 304696d3611760b0465caaebf6243824960034c3592fmalita kClip_SaveFlag = 0x02, 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support per-pixel alpha */ 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kHasAlphaLayer_SaveFlag = 0x04, 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support 8-bits per color component */ 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFullColorLayer_SaveFlag = 0x08, 309b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com /** 310b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * the layer should clip against the bounds argument 311b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * 312b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on. 313b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com */ 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClipToLayer_SaveFlag = 0x10, 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helper masks for common choices 3175f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita // [deprecated] kMatrixClip_SaveFlag = 0x03, 318696d3611760b0465caaebf6243824960034c3592fmalita kMatrixClip_SaveFlag = 0x03, 319b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_NoClipLayer_SaveFlag = 0x0F, 321b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#endif 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_ClipLayer_SaveFlag = 0x1F 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 325dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com /** This call saves the current matrix, clip, and drawFilter, and pushes a 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy onto a private stack. Subsequent calls to translate, scale, 327dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com rotate, skew, concat or clipRect, clipPath, and setDrawFilter all 328dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com operate on this copy. 329dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com When the balancing call to restore() is made, the previous matrix, clip, 330dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com and drawFilter are restored. 331d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 332d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 333d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 334d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int save(); 335d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 339dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 340ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 341ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com limit the size of the offscreen, and thus drawing may be 342ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com clipped to it, though that clipping is not guaranteed to 343ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com happen. If exact clipping is desired, use clipRect(). 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint (may be null) This is copied, and is applied to the 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen when restore() is called 346d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 347d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 348d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayer(const SkRect* bounds, const SkPaint* paint); 349d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 350d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. 351d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 352d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org This behaves the same as saveLayer(const SkRect*, const SkPaint*), 353d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org but it allows fine-grained control of which state bits to be saved 354d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org (and subsequently restored). 355d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 356d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param bounds (may be null) This rect, if non-null, is used as a hint to 357d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org limit the size of the offscreen, and thus drawing may be 358d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org clipped to it, though that clipping is not guaranteed to 359d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org happen. If exact clipping is desired, use clipRect(). 360d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param paint (may be null) This is copied, and is applied to the 361d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org offscreen when restore() is called 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 365d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 366d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 371dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 37240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 37340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com limit the size of the offscreen, and thus drawing may be 37440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com clipped to it, though that clipping is not guaranteed to 37540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com happen. If exact clipping is desired, use clipRect(). 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param alpha This is applied to the offscreen when restore() is called. 377d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 378d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 379d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); 380d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 381d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. 382d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 383d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), 384d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org but it allows fine-grained control of which state bits to be saved 385d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org (and subsequently restored). 386d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 387d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param bounds (may be null) This rect, if non-null, is used as a hint to 388d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org limit the size of the offscreen, and thus drawing may be 389d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org clipped to it, though that clipping is not guaranteed to 390d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org happen. If exact clipping is desired, use clipRect(). 391d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param alpha This is applied to the offscreen when restore() is called. 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 395d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 396d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This call balances a previous call to save(), and is used to remove all 399dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com modifications to the matrix/clip/drawFilter state since the last save 400dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com call. 401dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com It is an error to call restore() more times than save() was called. 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 403e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org void restore(); 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of matrix/clip states on the SkCanvas' private stack. 406ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org This will equal # save() calls - # restore() calls + 1. The save count on 407ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org a new canvas is 1. 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 409a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org int getSaveCount() const; 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Efficient way to pop any calls to save() that happened after the save 412ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org count reached saveCount. It is an error for saveCount to be greater than 413ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org getSaveCount(). To pop all the way back to the initial matrix/clip context 414ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org pass saveCount == 1. 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param saveCount The number of save() levels to restore from 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void restoreToCount(int saveCount); 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified translation 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The distance to translate in X 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The distance to translate in Y 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 42392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void translate(SkScalar dx, SkScalar dy); 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified scale. 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to scale in X 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to scale in Y 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 42992362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void scale(SkScalar sx, SkScalar sy); 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified rotation. 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param degrees The amount to rotate, in degrees 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 43492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void rotate(SkScalar degrees); 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified skew. 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to skew in X 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to skew in Y 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 44092362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void skew(SkScalar sx, SkScalar sy); 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified matrix. 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to preconcatenate with the current matrix 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 44592362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void concat(const SkMatrix& matrix); 4464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Replace the current matrix with a copy of the specified matrix. 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix that will be copied into the current matrix. 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 45044c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org void setMatrix(const SkMatrix& matrix); 4514b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for setMatrix(identity). Sets the current matrix to identity. 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetMatrix(); 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4574ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified rectangle. 4584ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rect The rect to combine with the current clip 4594ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4604ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4614ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 462759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRect(const SkRect& rect, 463759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 464759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4664ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4674ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified SkRRect. 4684ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The rrect to combine with the current clip 4694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 472759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRRect(const SkRRect& rrect, 473759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 474759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4754ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 4764ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4774ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified path. 4784ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param path The path to combine with the current clip 4794ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4804ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4814ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 482759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipPath(const SkPath& path, 483759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 484759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4868f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com /** EXPERIMENTAL -- only used for testing 4878f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com Set to false to force clips to be hard, even if doAntiAlias=true is 4888f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com passed to clipRect or clipPath. 4898f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com */ 4908f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com void setAllowSoftClip(bool allow) { 4918f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com fAllowSoftClip = allow; 4928f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com } 4938f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com 49445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com /** EXPERIMENTAL -- only used for testing 49545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com Set to simplify clip stack using path ops. 49645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com */ 49745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com void setAllowSimplifyClip(bool allow) { 49845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com fAllowSimplifyClip = allow; 49945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com } 50045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified region. Note that unlike 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRect() and clipPath() which transform their arguments by the current 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix, clipRegion() assumes its argument is already in device 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinates, and so no transformation is performed. 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to apply to the current clip 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 508759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRegion(const SkRegion& deviceRgn, 509759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op); 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified region. This does not intersect or in any other way account 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for the existing clip region. 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to copy into the current clip. 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5168f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com void setClipRegion(const SkRegion& deviceRgn) { 5178f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com this->clipRegion(deviceRgn, SkRegion::kReplace_Op); 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified rectangle, after being transformed by the 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect the rect to compare with the current clip 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the rect (transformed by the canvas' matrix) does not 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5283b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkRect& rect) const; 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified path, after being transformed by the 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). Note, for speed it may 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false even if the path itself might not intersect the clip 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (i.e. the bounds of the path intersects, but the path does not). 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to compare with the current clip 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path (transformed by the canvas' matrix) does not 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5403b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkPath& path) const; 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the horizontal band specified by top and bottom is 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely clipped out. This is a conservative calculation, meaning 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that it is possible that if the method returns false, the band may still 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in fact be clipped out, but the converse is not true. If this method 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true, then the band is guaranteed to be clipped out. 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top of the horizontal band to compare with the clip 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom of the horizontal and to compare with the clip 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the horizontal band is completely clipped out (i.e. does 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not intersect the current clip) 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5523b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickRejectY(SkScalar top, SkScalar bottom) const { 553c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com SkASSERT(top <= bottom); 5549836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 5559836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT 5569836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // TODO: add a hasPerspective method similar to getLocalClipBounds. This 5579836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // would cache the SkMatrix::hasPerspective result. Alternatively, have 5589836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // the MC stack just set a hasPerspective boolean as it is updated. 5599836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org if (this->getTotalMatrix().hasPerspective()) { 560a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com // TODO: consider implementing some half-plane test between the 5619836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // two Y planes and the device-bounds (i.e., project the top and 5629836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // bottom Y planes and then determine if the clip bounds is completely 5639836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // outside either one). 5649836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org return false; 5659836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org } 5669836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif 5679836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 568c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& clipR = this->getLocalClipBounds(); 56992d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // In the case where the clip is empty and we are provided with a 57092d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // negative top and positive bottom parameter then this test will return 57192d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // false even though it will be clipped. We have chosen to exclude that 57292d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // check as it is rare and would result double the comparisons. 573c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return top >= clipR.fBottom || bottom <= clipR.fTop; 57492d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com } 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the bounds of the current clip (in local coordinates) in the 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds parameter, and return true if it is non-empty. This can be useful 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in a way similar to quickReject, in that it tells you that drawing 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com outside of these bounds will be clipped out. 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5818f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool getClipBounds(SkRect* bounds) const; 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 583bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com /** Return the bounds of the current clip, in device coordinates; returns 584bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com true if non-empty. Maybe faster than getting the clip explicitly and 585bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com then taking its bounds. 586bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com */ 5878f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool getClipDeviceBounds(SkIRect* bounds) const; 58874b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org 589bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 591845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified ARGB color, using the specified mode. 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param a the alpha component (0..255) of the color to fill the canvas 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param r the red component (0..255) of the color to fill the canvas 5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param g the green component (0..255) of the color to fill the canvas 5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param b the blue component (0..255) of the color to fill the canvas 5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, 599845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 602845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified color and mode. 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color the color to draw with 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6068eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed void drawColor(SkColor color, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 608f4e0d9eb2d72fe92c30237de978936113143dc16reed /** 609f4e0d9eb2d72fe92c30237de978936113143dc16reed * Helper method for drawing a color in SRC mode, completely replacing all the pixels 610f4e0d9eb2d72fe92c30237de978936113143dc16reed * in the current clip with this color. 611f4e0d9eb2d72fe92c30237de978936113143dc16reed */ 612f4e0d9eb2d72fe92c30237de978936113143dc16reed void clear(SkColor color) { 6138eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed this->drawColor(color, SkXfermode::kSrc_Mode); 6148eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed } 6152a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com 6162a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com /** 61728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * This makes the contents of the canvas undefined. Subsequent calls that 61828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * require reading the canvas contents will produce undefined results. Examples 61928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * include blending and readPixels. The actual implementation is backend- 62028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * dependent and one legal implementation is to do nothing. Like clear(), this 62128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * ignores the clip. 62228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * 62328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * This function should only be called if the caller intends to subsequently 62428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * draw to the canvas. The canvas may do real work at discard() time in order 62528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * to optimize performance on subsequent draws. Thus, if you call this and then 62628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * never draw to the canvas subsequently you may pay a perfomance penalty. 62728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org */ 62828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org void discard() { this->onDiscard(); } 62928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 63028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org /** 6312a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * Fill the entire canvas' bitmap (restricted to the current clip) with the 6322a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * specified paint. 6332a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * @param paint The paint used to fill the canvas 6342a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com */ 6350846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawPaint(const SkPaint& paint); 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum PointMode { 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each point separately */ 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPoints_PointMode, 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each pair of points as a line segment */ 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLines_PointMode, 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws the array of points as a polygon */ 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPolygon_PointMode 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a series of points, interpreted based on the PointMode mode. For 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com all modes, the count parameter is interpreted as the total number of 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com points. For kLine mode, count/2 line segments are drawn. 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPoint mode, each point is drawn centered at its coordinate, and its 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size is specified by the paint's stroke-width. It draws as a square, 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unless the paint's cap-type is round, in which the points are drawn as 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com circles. 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kLine mode, each pair of points is drawn as a line segment, 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com respecting the paint's settings for cap/join/width. 6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPolygon mode, the entire array is drawn as a series of connected 6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line segments. 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note that, while similar, kLine and kPolygon modes draw slightly 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com differently than the equivalent path built with a series of moveto, 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com lineto calls, in that the path will draw all of its contours at once, 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with no interactions if contours intersect each other (think XOR 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xfermode). drawPoints always draws each element one at a time. 6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode PointMode specifying how to draw the array of points. 6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param count The number of points in the array 6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts Array of points to draw 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the points 6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6670846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint); 6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper method for drawing a single point. See drawPoints() for a more 6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com details. 6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); 6734b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draws a single pixel in the specified color. 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The X coordinate of which pixel to draw 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The Y coordiante of which pixel to draw 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color The color to draw 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, SkColor color); 6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a line segment with the specified start and stop x,y coordinates, 6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com using the specified paint. NOTE: since a line is always "framed", the 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint's Style is ignored. 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x0 The x-coordinate of the start point of the line 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y0 The y-coordinate of the start point of the line 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the end point of the line 6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the end point of the line 6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the line 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or stroked based on the Style in the paint. 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6980846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawRect(const SkRect& rect, const SkPaint& paint); 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 70587001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com void drawIRect(const SkIRect& rect, const SkPaint& paint) { 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(rect); // promotes the ints to scalars 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawRect(r, paint); 7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7104b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The left side of the rectangle to be drawn 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top side of the rectangle to be drawn 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param right The right side of the rectangle to be drawn 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom side of the rectangle to be drawn 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRectCoords(SkScalar left, SkScalar top, SkScalar right, 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar bottom, const SkPaint& paint); 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified oval using the specified paint. The oval will be 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The rectangle bounds of the oval to be drawn 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the oval 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7270846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawOval(const SkRect& oval, const SkPaint&); 7284ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 7294ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 7304ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Draw the specified RRect using the specified paint The rrect will be filled or stroked 7314ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * based on the Style in the paint. 7324ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * 7334ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The round-rect to draw 7344ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param paint The paint used to draw the round-rect 7354ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 7360846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawRRect(const SkRRect& rrect, const SkPaint& paint); 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 738ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org /** 739ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * Draw the annulus formed by the outer and inner rrects. The results 740ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * are undefined if the outer does not contain the inner. 741ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org */ 742ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&); 743ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified circle using the specified paint. If radius is <= 0, 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com then nothing will be drawn. The circle will be filled 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or framed based on the Style in the paint. 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cx The x-coordinate of the center of the cirle to be drawn 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cy The y-coordinate of the center of the cirle to be drawn 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param radius The radius of the cirle to be drawn 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the circle 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified arc, which will be scaled to fit inside the 7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified oval. If the sweep angle is >= 360, then the oval is drawn 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely. Note that this differs slightly from SkPath::arcTo, which 7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com treats the sweep angle mod 360. 7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the shape of the arc 7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param useCenter true means include the center of the oval. For filling 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this will draw a wedge. False means just use the arc. 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the arc 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, 7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool useCenter, const SkPaint& paint); 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified round-rect using the specified paint. The round-rect 7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rectangular bounds of the roundRect to be drawn 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rx The x-radius of the oval used to round the corners 7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ry The y-radius of the oval used to round the corners 7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the roundRect 7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified path using the specified paint. The path will be 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to be drawn 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the path 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7840846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawPath(const SkPath& path, const SkPaint& paint); 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 786d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr /** Draw the specified image, with its top/left corner at (x,y), using the 787d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr specified paint, transformed by the current matrix. 788d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr 789d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr @param image The image to be drawn 790d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr @param left The position of the left side of the image being drawn 791d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr @param top The position of the top side of the image being drawn 792d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr @param paint The paint used to draw the image, or NULL 793d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr */ 7940846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL); 795b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr 796a5517e2b190a8083b38964972b031c13e99f1012reed /** 797a5517e2b190a8083b38964972b031c13e99f1012reed * Controls the behavior at the edge of the src-rect, when specified in drawImageRect, 798a5517e2b190a8083b38964972b031c13e99f1012reed * trading off speed for exactness. 799a5517e2b190a8083b38964972b031c13e99f1012reed * 800a5517e2b190a8083b38964972b031c13e99f1012reed * When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around 801a5517e2b190a8083b38964972b031c13e99f1012reed * the pixels in the image. If there is a src-rect specified, it is intended to restrict the 802a5517e2b190a8083b38964972b031c13e99f1012reed * pixels that will be read. However, for performance reasons, some implementations may slow 803a5517e2b190a8083b38964972b031c13e99f1012reed * down if they cannot read 1-pixel past the src-rect boundary at times. 804a5517e2b190a8083b38964972b031c13e99f1012reed * 805a5517e2b190a8083b38964972b031c13e99f1012reed * This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable. 806a5517e2b190a8083b38964972b031c13e99f1012reed * If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect 807a5517e2b190a8083b38964972b031c13e99f1012reed * must be strictly respected, the caller should pass kStrict. 808a5517e2b190a8083b38964972b031c13e99f1012reed */ 809a5517e2b190a8083b38964972b031c13e99f1012reed enum SrcRectConstraint { 810a5517e2b190a8083b38964972b031c13e99f1012reed /** 811a5517e2b190a8083b38964972b031c13e99f1012reed * If kStrict is specified, the implementation must respect the src-rect 812a5517e2b190a8083b38964972b031c13e99f1012reed * (if specified) strictly, and will never sample outside of those bounds during sampling 813a5517e2b190a8083b38964972b031c13e99f1012reed * even when filtering. This may be slower than kFast. 814a5517e2b190a8083b38964972b031c13e99f1012reed */ 815a5517e2b190a8083b38964972b031c13e99f1012reed kStrict_SrcRectConstraint, 816a5517e2b190a8083b38964972b031c13e99f1012reed 817a5517e2b190a8083b38964972b031c13e99f1012reed /** 818a5517e2b190a8083b38964972b031c13e99f1012reed * If kFast is specified, the implementation may sample outside of the src-rect 819a5517e2b190a8083b38964972b031c13e99f1012reed * (if specified) by at most 1 pixel when filtering. This allows greater flexibility 820a5517e2b190a8083b38964972b031c13e99f1012reed * to the implementation and can make the draw much faster. 821a5517e2b190a8083b38964972b031c13e99f1012reed */ 822a5517e2b190a8083b38964972b031c13e99f1012reed kFast_SrcRectConstraint, 823a5517e2b190a8083b38964972b031c13e99f1012reed }; 824a5517e2b190a8083b38964972b031c13e99f1012reed 825a5517e2b190a8083b38964972b031c13e99f1012reed /** Draw the specified image, scaling and translating so that it fills the specified 826a5517e2b190a8083b38964972b031c13e99f1012reed * dst rect. If the src rect is non-null, only that subset of the image is transformed 827a5517e2b190a8083b38964972b031c13e99f1012reed * and drawn. 828a5517e2b190a8083b38964972b031c13e99f1012reed * 829a5517e2b190a8083b38964972b031c13e99f1012reed * @param image The image to be drawn 830a5517e2b190a8083b38964972b031c13e99f1012reed * @param src Optional: specify the subset of the image to be drawn 831a5517e2b190a8083b38964972b031c13e99f1012reed * @param dst The destination rectangle where the scaled/translated 832a5517e2b190a8083b38964972b031c13e99f1012reed * image will be drawn 833a5517e2b190a8083b38964972b031c13e99f1012reed * @param paint The paint used to draw the image, or NULL 834a5517e2b190a8083b38964972b031c13e99f1012reed * @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect. 835a5517e2b190a8083b38964972b031c13e99f1012reed */ 8360846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 837a5517e2b190a8083b38964972b031c13e99f1012reed const SkPaint* paint, SrcRectConstraint); 838a5517e2b190a8083b38964972b031c13e99f1012reed 839a5517e2b190a8083b38964972b031c13e99f1012reed void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 840a5517e2b190a8083b38964972b031c13e99f1012reed const SkPaint* paint = NULL) { 841a5517e2b190a8083b38964972b031c13e99f1012reed this->drawImageRect(image, src, dst, paint, kStrict_SrcRectConstraint); 842a5517e2b190a8083b38964972b031c13e99f1012reed } 843a5517e2b190a8083b38964972b031c13e99f1012reed 844a5517e2b190a8083b38964972b031c13e99f1012reed void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint = NULL) { 845a5517e2b190a8083b38964972b031c13e99f1012reed // With no src-rect, the constraint value is ignored, so we just use the default. 846a5517e2b190a8083b38964972b031c13e99f1012reed this->drawImageRect(image, NULL, dst, paint, kStrict_SrcRectConstraint); 847a5517e2b190a8083b38964972b031c13e99f1012reed } 848b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr 8494c21dc5ddf3b482293ed34eead876d8d61a662c3reed /** 8504c21dc5ddf3b482293ed34eead876d8d61a662c3reed * Draw the image stretched differentially to fit into dst. 8514c21dc5ddf3b482293ed34eead876d8d61a662c3reed * center is a rect within the image, and logically divides the image 8524c21dc5ddf3b482293ed34eead876d8d61a662c3reed * into 9 sections (3x3). For example, if the middle pixel of a [5x5] 8534c21dc5ddf3b482293ed34eead876d8d61a662c3reed * image is the "center", then the center-rect should be [2, 2, 3, 3]. 8544c21dc5ddf3b482293ed34eead876d8d61a662c3reed * 8554c21dc5ddf3b482293ed34eead876d8d61a662c3reed * If the dst is >= the image size, then... 8564c21dc5ddf3b482293ed34eead876d8d61a662c3reed * - The 4 corners are not stretched at all. 8574c21dc5ddf3b482293ed34eead876d8d61a662c3reed * - The sides are stretched in only one axis. 8584c21dc5ddf3b482293ed34eead876d8d61a662c3reed * - The center is stretched in both axes. 8594c21dc5ddf3b482293ed34eead876d8d61a662c3reed * Else, for each axis where dst < image, 8604c21dc5ddf3b482293ed34eead876d8d61a662c3reed * - The corners shrink proportionally 8614c21dc5ddf3b482293ed34eead876d8d61a662c3reed * - The sides (along the shrink axis) and center are not drawn 8624c21dc5ddf3b482293ed34eead876d8d61a662c3reed */ 8634c21dc5ddf3b482293ed34eead876d8d61a662c3reed void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, 8644c21dc5ddf3b482293ed34eead876d8d61a662c3reed const SkPaint* paint = NULL); 8654c21dc5ddf3b482293ed34eead876d8d61a662c3reed 8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), using the 8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified paint, transformed by the current matrix. Note: if the paint 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 87291246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 87391246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org If a shader is present on the paint it will be ignored, except in the 874f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com case where the bitmap is kAlpha_8_SkColorType. In that case, the color is 87591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org generated by the shader. 87691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8820846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 8830846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkPaint* paint = NULL); 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 885a5517e2b190a8083b38964972b031c13e99f1012reed /** Draw the specified bitmap, scaling and translating so that it fills the specified 886a5517e2b190a8083b38964972b031c13e99f1012reed * dst rect. If the src rect is non-null, only that subset of the bitmap is transformed 887a5517e2b190a8083b38964972b031c13e99f1012reed * and drawn. 888a5517e2b190a8083b38964972b031c13e99f1012reed * 889a5517e2b190a8083b38964972b031c13e99f1012reed * @param bitmap The bitmap to be drawn 890a5517e2b190a8083b38964972b031c13e99f1012reed * @param src Optional: specify the subset of the bitmap to be drawn 891a5517e2b190a8083b38964972b031c13e99f1012reed * @param dst The destination rectangle where the scaled/translated 892a5517e2b190a8083b38964972b031c13e99f1012reed * bitmap will be drawn 893a5517e2b190a8083b38964972b031c13e99f1012reed * @param paint The paint used to draw the bitmap, or NULL 894a5517e2b190a8083b38964972b031c13e99f1012reed * @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect. 895a5517e2b190a8083b38964972b031c13e99f1012reed */ 896a5517e2b190a8083b38964972b031c13e99f1012reed void drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 897a5517e2b190a8083b38964972b031c13e99f1012reed const SkPaint* paint, SrcRectConstraint); 898a5517e2b190a8083b38964972b031c13e99f1012reed 899a5517e2b190a8083b38964972b031c13e99f1012reed void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint = NULL) { 900a5517e2b190a8083b38964972b031c13e99f1012reed this->drawBitmapRect(bitmap, NULL, dst, paint, kStrict_SrcRectConstraint); 901a5517e2b190a8083b38964972b031c13e99f1012reed } 902a5517e2b190a8083b38964972b031c13e99f1012reed 903a5517e2b190a8083b38964972b031c13e99f1012reed // IMPORTANT that thse be value-equal with SrcRectConstraint (during transition period) 904eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org enum DrawBitmapRectFlags { 90531acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kNone_DrawBitmapRectFlag = 0x0, 9067475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com /** 907eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * When filtering is enabled, allow the color samples outside of 9087475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com * the src rect (but still in the src bitmap) to bleed into the 909eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * drawn portion 910eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org */ 91131acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kBleed_DrawBitmapRectFlag = 0x1, 912eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org }; 913eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org 9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with the specified matrix applied (before the 9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas' matrix is applied). 9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src Optional: specify the subset of the bitmap to be drawn 9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The destination rectangle where the scaled/translated 9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com image will be drawn 9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9220846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 9230846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkPaint* paint = NULL, 9240846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag); 9257112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com 9267112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, 927eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint = NULL, 92831acc11977815402e4ef2681350f8559285bec97robertphillips@google.com DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { 9297112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect realSrcStorage; 9307112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect* realSrcPtr = NULL; 9317112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com if (isrc) { 9327112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcStorage.set(*isrc); 9337112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcPtr = &realSrcStorage; 9347112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 935eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags); 9367112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 937c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com 938f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com /** 939f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Draw the bitmap stretched differentially to fit into dst. 940f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * center is a rect within the bitmap, and logically divides the bitmap 941f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * into 9 sections (3x3). For example, if the middle pixel of a [5x5] 942f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * bitmap is the "center", then the center-rect should be [2, 2, 3, 3]. 943f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * 944f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * If the dst is >= the bitmap size, then... 9459bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The 4 corners are not stretched at all. 9469bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The sides are stretched in only one axis. 9479bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The center is stretched in both axes. 948f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Else, for each axis where dst < bitmap, 949f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The corners shrink proportionally 950f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The sides (along the shrink axis) and center are not drawn 951f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com */ 9520846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, 9530846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkPaint* paint = NULL); 954f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), 9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOT transformed by the current matrix. Note: if the paint 9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 9588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9660846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint = NULL); 9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint. 9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The origin is interpreted based on the Align setting in the paint. 9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the origin of the text being drawn 9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the origin of the text being drawn 9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 976f7430ccfc0e7b445a44b840c1453c9ef5988a656reed void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 977f7430ccfc0e7b445a44b840c1453c9ef5988a656reed const SkPaint& paint); 9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the pos[] 9804b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com array. The origin is interpreted by the Align setting in the paint. 9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pos Array of positions, used to position each character 9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 986f7430ccfc0e7b445a44b840c1453c9ef5988a656reed void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], 987f7430ccfc0e7b445a44b840c1453c9ef5988a656reed const SkPaint& paint); 9884b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the x 9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinate taken from the xpos[] array, and the y from the constY param. 9914b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com The origin is interpreted by the Align setting in the paint. 9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xpos Array of x-positions, used to position each character 9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param constY The shared Y coordinate for all of the positions 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 998f7430ccfc0e7b445a44b840c1453c9ef5988a656reed void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, 999f7430ccfc0e7b445a44b840c1453c9ef5988a656reed const SkPaint& paint); 10004b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param hOffset The distance along the path to add to the text's 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com starting position 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vOffset The distance above(-) or below(+) the path to 10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com position the text 10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1013f7430ccfc0e7b445a44b840c1453c9ef5988a656reed void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset, 10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar vOffset, const SkPaint& paint); 10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 10178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix (may be null) Applied to the text before it is 10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mapped onto the path 10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1026f7430ccfc0e7b445a44b840c1453c9ef5988a656reed void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, 1027f7430ccfc0e7b445a44b840c1453c9ef5988a656reed const SkMatrix* matrix, const SkPaint& paint); 10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 102900d5c2c6523321d25b32905ff4822f083a4173eefmalita /** Draw the text blob, offset by (x,y), using the specified paint. 103000d5c2c6523321d25b32905ff4822f083a4173eefmalita @param blob The text blob to be drawn 103100d5c2c6523321d25b32905ff4822f083a4173eefmalita @param x The x-offset of the text being drawn 103200d5c2c6523321d25b32905ff4822f083a4173eefmalita @param y The y-offset of the text being drawn 103300d5c2c6523321d25b32905ff4822f083a4173eefmalita @param paint The paint used for the text (e.g. color, size, style) 103400d5c2c6523321d25b32905ff4822f083a4173eefmalita */ 103500d5c2c6523321d25b32905ff4822f083a4173eefmalita void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint); 103600d5c2c6523321d25b32905ff4822f083a4173eefmalita 10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the picture into this canvas. This method effective brackets the 10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com playback of the picture's draw calls with save/restore, so the state 1039a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com of this canvas will be unchanged after this call. 10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param picture The recorded drawing commands to playback into this 10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas. 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10431c2c441fede0ae9573afc098017011e3439624a9reed void drawPicture(const SkPicture* picture) { 10441c2c441fede0ae9573afc098017011e3439624a9reed this->drawPicture(picture, NULL, NULL); 10451c2c441fede0ae9573afc098017011e3439624a9reed } 10469b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips 1047d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed /** 1048d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * Draw the picture into this canvas. 1049d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * 1050d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is 1051d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * logically equivalent to 1052d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * save/concat/drawPicture/restore 1053d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * 1054d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1055d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. 1056d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * This is logically equivalent to 1057d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed * saveLayer(paint)/drawPicture/restore 1058d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed */ 1059d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint); 1060d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed 10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum VertexMode { 10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangles_VertexMode, 10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleStrip_VertexMode, 10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleFan_VertexMode 10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 10664b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the array of vertices, interpreted as triangles (based on mode). 1068559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 1069559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org If both textures and vertex-colors are NULL, it strokes hairlines with 1070559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org the paint's color. This behavior is a useful debugging mode to visualize 1071559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org the mesh. 1072559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 10738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vmode How to interpret the array of vertices 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertexCount The number of points in the vertices array (and 10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com corresponding texs and colors arrays if non-null) 10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertices Array of vertices for the mesh 10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param texs May be null. If not null, specifies the coordinate 1078631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com in _texture_ space (not uv space) for each vertex. 10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param colors May be null. If not null, specifies a color for each 10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex, to be interpolated across the triangle. 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xmode Used if both texs and colors are present. In this 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case the colors are combined with the texture using mode, 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com before being drawn using the paint. If mode is null, then 10848d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com kModulate_Mode is used. 10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indices If not null, array of indices to reference into the 10868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex (texs, colors) array. 10878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indexCount number of entries in the indices array (if not null) 10884b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com @param paint Specifies the shader/texture if present. 10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10900846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed void drawVertices(VertexMode vmode, int vertexCount, 10910846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkPoint vertices[], const SkPoint texs[], 10920846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkColor colors[], SkXfermode* xmode, 10930846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const uint16_t indices[], int indexCount, 10940846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed const SkPaint& paint); 10956cfa73a29a26edf1d03bca224ad6860396308ffcmtklein 1096b3c9d1c33caf325aada244204215eb790c228c12dandov /** 1097b3c9d1c33caf325aada244204215eb790c228c12dandov Draw a cubic coons patch 10986cfa73a29a26edf1d03bca224ad6860396308ffcmtklein 1099b3c9d1c33caf325aada244204215eb790c228c12dandov @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order 1100b3c9d1c33caf325aada244204215eb790c228c12dandov starting at the top left corner. 1101b3c9d1c33caf325aada244204215eb790c228c12dandov @param colors specifies the colors for the corners which will be bilerp across the patch, 1102b3c9d1c33caf325aada244204215eb790c228c12dandov their order is clockwise starting at the top left corner. 11036cfa73a29a26edf1d03bca224ad6860396308ffcmtklein @param texCoords specifies the texture coordinates that will be bilerp across the patch, 1104b3c9d1c33caf325aada244204215eb790c228c12dandov their order is the same as the colors. 11056cfa73a29a26edf1d03bca224ad6860396308ffcmtklein @param xmode specifies how are the colors and the textures combined if both of them are 1106b3c9d1c33caf325aada244204215eb790c228c12dandov present. 1107963137b75c0a1fe91f35e9826742f36309f5e65ddandov @param paint Specifies the shader/texture if present. 1108963137b75c0a1fe91f35e9826742f36309f5e65ddandov */ 1109b3c9d1c33caf325aada244204215eb790c228c12dandov void drawPatch(const SkPoint cubics[12], const SkColor colors[4], 1110b3c9d1c33caf325aada244204215eb790c228c12dandov const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint); 11118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11123cb3840c9af6f70896cf5565a38d4ee03c02d767reed /** 111371c3c760a83123ee0b3127b8c65c6394ce541c50reed * Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the 111471c3c760a83123ee0b3127b8c65c6394ce541c50reed * coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle 111571c3c760a83123ee0b3127b8c65c6394ce541c50reed * into a quad. 111671c3c760a83123ee0b3127b8c65c6394ce541c50reed * 111771c3c760a83123ee0b3127b8c65c6394ce541c50reed * xform maps [0, 0, tex.width, tex.height] -> quad 111871c3c760a83123ee0b3127b8c65c6394ce541c50reed * 111971c3c760a83123ee0b3127b8c65c6394ce541c50reed * The color array is optional. When specified, each color modulates the pixels in its 112071c3c760a83123ee0b3127b8c65c6394ce541c50reed * corresponding quad (via the specified SkXfermode::Mode). 112171c3c760a83123ee0b3127b8c65c6394ce541c50reed * 112271c3c760a83123ee0b3127b8c65c6394ce541c50reed * The cullRect is optional. When specified, it must be a conservative bounds of all of the 112371c3c760a83123ee0b3127b8c65c6394ce541c50reed * resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not 112471c3c760a83123ee0b3127b8c65c6394ce541c50reed * intersect the current clip. 112571c3c760a83123ee0b3127b8c65c6394ce541c50reed * 112671c3c760a83123ee0b3127b8c65c6394ce541c50reed * The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter 112771c3c760a83123ee0b3127b8c65c6394ce541c50reed * and xfermode are used to affect each of the quads. 112871c3c760a83123ee0b3127b8c65c6394ce541c50reed */ 112971c3c760a83123ee0b3127b8c65c6394ce541c50reed void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], 113071c3c760a83123ee0b3127b8c65c6394ce541c50reed const SkColor colors[], int count, SkXfermode::Mode, const SkRect* cullRect, 113171c3c760a83123ee0b3127b8c65c6394ce541c50reed const SkPaint* paint); 113271c3c760a83123ee0b3127b8c65c6394ce541c50reed 113371c3c760a83123ee0b3127b8c65c6394ce541c50reed void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count, 113471c3c760a83123ee0b3127b8c65c6394ce541c50reed const SkRect* cullRect, const SkPaint* paint) { 113571c3c760a83123ee0b3127b8c65c6394ce541c50reed this->drawAtlas(atlas, xform, tex, NULL, count, SkXfermode::kDst_Mode, cullRect, paint); 113671c3c760a83123ee0b3127b8c65c6394ce541c50reed } 113771c3c760a83123ee0b3127b8c65c6394ce541c50reed 113871c3c760a83123ee0b3127b8c65c6394ce541c50reed /** 11393cb3840c9af6f70896cf5565a38d4ee03c02d767reed * Draw the contents of this drawable into the canvas. If the canvas is async 11403cb3840c9af6f70896cf5565a38d4ee03c02d767reed * (e.g. it is recording into a picture) then the drawable will be referenced instead, 11413cb3840c9af6f70896cf5565a38d4ee03c02d767reed * to have its draw() method called when the picture is finalized. 11423cb3840c9af6f70896cf5565a38d4ee03c02d767reed * 11433cb3840c9af6f70896cf5565a38d4ee03c02d767reed * If the intent is to force the contents of the drawable into this canvas immediately, 11443cb3840c9af6f70896cf5565a38d4ee03c02d767reed * then drawable->draw(canvas) may be called. 11453cb3840c9af6f70896cf5565a38d4ee03c02d767reed */ 1146a8db72864a43ad1fbba3c2892cf5cd88060a43efreed void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL); 1147a8db72864a43ad1fbba3c2892cf5cd88060a43efreed void drawDrawable(SkDrawable*, SkScalar x, SkScalar y); 11486a070dc06af4e9f305f9d08a69e34d18ade473cbreed 11498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 11504b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current filter object. The filter's reference count is not 1152dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com affected. The filter is saved/restored, just like the matrix and clip. 11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canvas' filter (or NULL). 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawFilter* getDrawFilter() const; 11564b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the new filter (or NULL). Pass NULL to clear any existing filter. 11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter is returned. If an existing filter 11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com exists, its refcnt is decrement. If the new filter is not null, its 1160dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com refcnt is incremented. The filter is saved/restored, just like the 1161dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com matrix and clip. 11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param filter the new filter (or NULL) 11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the new filter 11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); 11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1169754de5f65b466f721d952a379194cc94de376f42reed@google.com /** 1170754de5f65b466f721d952a379194cc94de376f42reed@google.com * Return true if the current clip is empty (i.e. nothing will draw). 1171754de5f65b466f721d952a379194cc94de376f42reed@google.com * Note: this is not always a free call, so it should not be used 1172754de5f65b466f721d952a379194cc94de376f42reed@google.com * more often than necessary. However, once the canvas has computed this 1173754de5f65b466f721d952a379194cc94de376f42reed@google.com * result, subsequent calls will be cheap (until the clip state changes, 1174754de5f65b466f721d952a379194cc94de376f42reed@google.com * which can happen on any clip..() or restore() call. 1175754de5f65b466f721d952a379194cc94de376f42reed@google.com */ 11768f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool isClipEmpty() const; 1177754de5f65b466f721d952a379194cc94de376f42reed@google.com 11785c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org /** 11795c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org * Returns true if the current clip is just a (non-empty) rectangle. 11805c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org * Returns false if the clip is empty, or if it is complex. 11815c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org */ 11825c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org virtual bool isClipRect() const; 11835c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org 11848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the current matrix on the canvas. 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This does not account for the translate in any of the devices. 11868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The current matrix on the canvas. 11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1188a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org const SkMatrix& getTotalMatrix() const; 11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 119040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com /** Return the clip stack. The clip stack stores all the individual 119140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * clips organized by the save/restore frame in which they were 119240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * added. 119340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * @return the current clip stack ("list" of individual clip elements) 119440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com */ 119540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com const SkClipStack* getClipStack() const { 1196687fa1c745febb57f42b0d5f03d7c1f4be2530careed return fClipStack; 119740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com } 119840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com 1199c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita typedef SkCanvasClipVisitor ClipVisitor; 12005e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com /** 120190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * Replays the clip operations, back to front, that have been applied to 120290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * the canvas, calling the appropriate method on the visitor for each 120390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * clip. All clips have already been transformed into device space. 12047d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com */ 120590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com void replayClips(ClipVisitor*) const; 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 12088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After calling saveLayer(), there can be any number of devices that make 12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com up the top-most drawing area. LayerIter can be used to iterate through 12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com those devices. Note that the iterator is only valid until the next API 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call made on the canvas. Ownership of all pointers in the iterator stays 12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the canvas, so none of them should be modified or deleted. 12148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 12157ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org class SK_API LayerIter /*: SkNoncopyable*/ { 12168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 12178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize iterator with canvas, and set values for 1st device */ 12188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com LayerIter(SkCanvas*, bool skipEmptyClips); 12198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~LayerIter(); 12204b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the iterator is done */ 12228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool done() const { return fDone; } 12238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Cycle to the next device */ 12248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void next(); 12254b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 12268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // These reflect the current device in the iterator 12278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12281f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* device() const; 12298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix() const; 12308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion& clip() const; 12318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint() const; 12328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x() const; 12338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y() const; 12344b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 12358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // used to embed the SkDrawIter object directly in our instance, w/o 12378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // having to expose that class def to the public. There is an assert 12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // in our constructor to ensure that fStorage is large enough 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (though needs to be a compile-time-assert!). We use intptr_t to work 12408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // safely with 32 and 64 bit machines (to ensure the storage is enough) 1241f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com intptr_t fStorage[32]; 12428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class SkDrawIter* fImpl; // this points at fStorage 12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint fDefaultPaint; 12448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDone; 12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 12468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12475c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org // don't call 12489c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com GrRenderTarget* internal_private_accessTopLayerRenderTarget(); 12495c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org 1250d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed // don't call 1251d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed static void Internal_Private_SetIgnoreSaveLayerBounds(bool); 1252d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed static bool Internal_Private_GetIgnoreSaveLayerBounds(); 12530acf1b4b3645772d220c720313821bac389751b5reed static void Internal_Private_SetTreatSpriteAsBitmap(bool); 12540acf1b4b3645772d220c720313821bac389751b5reed static bool Internal_Private_GetTreatSpriteAsBitmap(); 1255d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed 12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 125776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com // default impl defers to getDevice()->newSurface(info) 12584a8126e7f81384526629b1e21bf89b632ea13cd9reed virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&); 125976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com 1260c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // default impl defers to its device 1261884e97cb04db7ed053a866567ee9c6e4c01f993areed virtual bool onPeekPixels(SkPixmap*); 1262884e97cb04db7ed053a866567ee9c6e4c01f993areed virtual bool onAccessTopLayerPixels(SkPixmap*); 1263c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1264e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // Subclass save/restore notifiers. 1265e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // Overriders should call the corresponding INHERITED method up the inheritance chain. 1266e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // willSaveLayer()'s return value may suppress full layer allocation. 1267e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org enum SaveLayerStrategy { 1268e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org kFullLayer_SaveLayerStrategy, 1269e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org kNoLayer_SaveLayerStrategy 1270e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org }; 1271e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org 12726ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita virtual void willSave() {} 1273fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) { 1274fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org return kFullLayer_SaveLayerStrategy; 1275fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org } 1276fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void willRestore() {} 12776cfa73a29a26edf1d03bca224ad6860396308ffcmtklein virtual void didRestore() {} 1278fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void didConcat(const SkMatrix&) {} 1279fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void didSetMatrix(const SkMatrix&) {} 128044c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org 1281ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1282ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 1283e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, 1284e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SkScalar y, const SkPaint& paint); 1285b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1286e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawPosText(const void* text, size_t byteLength, 1287e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPoint pos[], const SkPaint& paint); 1288b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1289e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawPosTextH(const void* text, size_t byteLength, 1290e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkScalar xpos[], SkScalar constY, 1291e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPaint& paint); 1292b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1293e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawTextOnPath(const void* text, size_t byteLength, 1294e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPath& path, const SkMatrix* matrix, 1295e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPaint& paint); 12966cfa73a29a26edf1d03bca224ad6860396308ffcmtklein 129700d5c2c6523321d25b32905ff4822f083a4173eefmalita virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 129800d5c2c6523321d25b32905ff4822f083a4173eefmalita const SkPaint& paint); 129900d5c2c6523321d25b32905ff4822f083a4173eefmalita 1300b3c9d1c33caf325aada244204215eb790c228c12dandov virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 1301b3c9d1c33caf325aada244204215eb790c228c12dandov const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint); 1302e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com 1303a8db72864a43ad1fbba3c2892cf5cd88060a43efreed virtual void onDrawDrawable(SkDrawable*, const SkMatrix*); 13046a070dc06af4e9f305f9d08a69e34d18ade473cbreed 130541af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawPaint(const SkPaint&); 130641af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawRect(const SkRect&, const SkPaint&); 130741af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawOval(const SkRect&, const SkPaint&); 130841af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawRRect(const SkRRect&, const SkPaint&); 130941af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&); 131041af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[], 131141af966ab338e95eee81ab618ab28195075338f7reed const SkPoint texs[], const SkColor colors[], SkXfermode*, 131241af966ab338e95eee81ab618ab28195075338f7reed const uint16_t indices[], int indexCount, const SkPaint&); 13132766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 131471c3c760a83123ee0b3127b8c65c6394ce541c50reed virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], 131571c3c760a83123ee0b3127b8c65c6394ce541c50reed int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*); 131641af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawPath(const SkPath&, const SkPaint&); 131741af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*); 1318a5517e2b190a8083b38964972b031c13e99f1012reed virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint* 1319a5517e2b190a8083b38964972b031c13e99f1012reed SRC_RECT_CONSTRAINT_PARAM(constraint)); 13204c21dc5ddf3b482293ed34eead876d8d61a662c3reed virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, 13214c21dc5ddf3b482293ed34eead876d8d61a662c3reed const SkPaint*); 13224c21dc5ddf3b482293ed34eead876d8d61a662c3reed 132341af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*); 132441af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, 1325a5517e2b190a8083b38964972b031c13e99f1012reed SK_VIRTUAL_CONSTRAINT_TYPE); 132641af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 132741af966ab338e95eee81ab618ab28195075338f7reed const SkPaint*); 132841af966ab338e95eee81ab618ab28195075338f7reed virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*); 132941af966ab338e95eee81ab618ab28195075338f7reed 13308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com enum ClipEdgeStyle { 13318f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com kHard_ClipEdgeStyle, 13328f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com kSoft_ClipEdgeStyle 13338f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com }; 13348f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 13358f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle); 13368f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle); 13378f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle); 13388f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 13398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 134028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org virtual void onDiscard(); 134128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 1342d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*); 13439b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips 134474b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org // Returns the canvas to be used by DrawIter. Default implementation 13454370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // returns this. Subclasses that encapsulate an indirect canvas may 13464370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // need to overload this method. The impl must keep track of this, as it 13474370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // is not released or deleted by the caller. 13484370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com virtual SkCanvas* canvasForDrawIter(); 13494370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com 1350a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // Clip rectangle bounds. Called internally by saveLayer. 1351a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // returns false if the entire rectangle is entirely clipped out 1352c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // If non-NULL, The imageFilter parameter will be used to expand the clip 1353c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // and offscreen bounds for any margin required by the filter DAG. 1354a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org bool clipRectBounds(const SkRect* bounds, SaveFlags flags, 1355c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org SkIRect* intersection, 1356c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org const SkImageFilter* imageFilter = NULL); 1357a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org 135897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // notify our surface (if we have one) that we are about to draw, so it 135997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // can perform copy-on-write or invalidate any cached images 136097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void predrawNotify(); 136197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com 13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class MCRec; 13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1365687fa1c745febb57f42b0d5f03d7c1f4be2530careed SkAutoTUnref<SkClipStack> fClipStack; 13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDeque fMCStack; 13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // points to top of stack 13688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MCRec* fMCRec; 13698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the first N recs that can fit here mean we won't call malloc 1370b679ca8926a832274b14fdb512f88f64b61d32eareed enum { 1371a499f905e9340e4935447f2562fd92e8853382b1reed kMCRecSize = 128, // most recent measurement 1372a499f905e9340e4935447f2562fd92e8853382b1reed kMCRecCount = 8, // common depth for save/restores 137386a17e7716c8db858e219a46b9db3817bb770beereed kDeviceCMSize = 136, // most recent measurement 1374b679ca8926a832274b14fdb512f88f64b61d32eareed }; 1375b679ca8926a832274b14fdb512f88f64b61d32eareed intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)]; 1376a499f905e9340e4935447f2562fd92e8853382b1reed intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)]; 13778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13784a8126e7f81384526629b1e21bf89b632ea13cd9reed const SkSurfaceProps fProps; 13794a8126e7f81384526629b1e21bf89b632ea13cd9reed 13802ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed int fSaveCount; // value returned by getSaveCount() 13818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData* fMetaData; 138374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 138497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* fSurfaceBase; 138597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } 138697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void setSurfaceBase(SkSurface_Base* sb) { 138797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com fSurfaceBase = sb; 138897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com } 138997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com friend class SkSurface_Base; 139045c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org friend class SkSurface_Gpu; 1391fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com 13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updateDeviceCMCache(); 13948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13952ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed void doSave(); 13962ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed void checkForDeferredSave(); 13972ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed 13989c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkDrawIter; // needs setupDrawForLayerDevice() 13998926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com friend class AutoDrawLooper; 14009c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkLua; // needs top layer size and offset 14012a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip 14029c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkDeferredDevice; // needs getTopDevice() 140352d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed friend class SkSurface_Raster; // needs getDevice() 1404d954498c01ccf0417feacf89e45d0c62a06a813breed friend class SkRecorder; // InitFlags 1405d954498c01ccf0417feacf89e45d0c62a06a813breed friend class SkNoSaveLayerCanvas; // InitFlags 14062d97bc139a7de5813468bd3dbfd0037351ae5606fmalita friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags) 1407b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr 1408d954498c01ccf0417feacf89e45d0c62a06a813breed enum InitFlags { 1409d954498c01ccf0417feacf89e45d0c62a06a813breed kDefault_InitFlags = 0, 1410d954498c01ccf0417feacf89e45d0c62a06a813breed kConservativeRasterClip_InitFlag = 1 << 0, 1411d954498c01ccf0417feacf89e45d0c62a06a813breed }; 141278e276889795454891cbba48ab11927968114953reed SkCanvas(const SkIRect& bounds, InitFlags); 1413fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips SkCanvas(SkBaseDevice* device, InitFlags); 1414d954498c01ccf0417feacf89e45d0c62a06a813breed 1415feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein void resetForNextPicture(const SkIRect& bounds); 1416feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein 14178f2e791baa1287bd321217c88756695c41699a7ereed // needs gettotalclip() 1418a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina friend class SkCanvasStateUtils; 1419b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr 14204a8126e7f81384526629b1e21bf89b632ea13cd9reed // call this each time we attach ourselves to a device 14214a8126e7f81384526629b1e21bf89b632ea13cd9reed // - constructor 14224a8126e7f81384526629b1e21bf89b632ea13cd9reed // - internalSaveLayer 14234a8126e7f81384526629b1e21bf89b632ea13cd9reed void setupDevice(SkBaseDevice*); 14244a8126e7f81384526629b1e21bf89b632ea13cd9reed 1425d954498c01ccf0417feacf89e45d0c62a06a813breed SkBaseDevice* init(SkBaseDevice*, InitFlags); 1426f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 1427403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org /** 14284ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this 14294ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * to be public because it exposes decisions about layer sizes that are internal to the canvas. 14304ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com */ 14314ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkISize getTopLayerSize() const; 14324ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkIPoint getTopLayerOrigin() const; 1433403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org 1434f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // internal methods are not virtual, so they can safely be called by other 1435f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // canvas apis, without confusing subclasses (like SkPictureRecording) 14369bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint); 14377112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1438eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint, 1439a5517e2b190a8083b38964972b031c13e99f1012reed SrcRectConstraint); 1440fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com void internalDrawPaint(const SkPaint& paint); 144176033be81b82c44fd5d4fdf2672eb22e505da1f0reed void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, SaveLayerStrategy); 144261f501f8c675da8d5915e5e7fd32dfdb113f1cfbreed void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool isBitmapDevice); 1443fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com 14448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // shared by save() and saveLayer() 14452ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed void internalSave(); 14468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void internalRestore(); 144752c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawRect(const SkDraw& draw, const SkPaint& paint, 144852c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const SkRect& r, SkScalar textSize); 144952c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, 145052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const char text[], size_t byteLength, 145152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkScalar x, SkScalar y); 14524b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 1453fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed // only for canvasutils 1454fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed const SkRegion& internal_private_getTotalClip() const; 1455fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed 14568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* These maintain a cache of the clip bounds in local coordinates, 14578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (converted to 2s-compliment if floats are slow). 14588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1459c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable SkRect fCachedLocalClipBounds; 1460c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable bool fCachedLocalClipBoundsDirty; 14618f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com bool fAllowSoftClip; 146245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com bool fAllowSimplifyClip; 1463d954498c01ccf0417feacf89e45d0c62a06a813breed bool fConservativeRasterClip; 14648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1465c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& getLocalClipBounds() const { 1466c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (fCachedLocalClipBoundsDirty) { 1467c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (!this->getClipBounds(&fCachedLocalClipBounds)) { 1468c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBounds.setEmpty(); 1469c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com } 1470c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBoundsDirty = false; 14718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1472c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return fCachedLocalClipBounds; 14738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 147445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 14755c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com class AutoValidateClip : ::SkNoncopyable { 14765c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com public: 14775c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { 14785c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com fCanvas->validateClip(); 14795c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com } 14805c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com ~AutoValidateClip() { fCanvas->validateClip(); } 14815c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 14825c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com private: 14835c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com const SkCanvas* fCanvas; 14845c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com }; 14855c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 14865c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG 14875c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const; 14885c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else 14895c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const {} 14905c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif 149115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 149215e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 14938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 14948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas 14968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com when this object goes out of scope. Use this to guarantee that the canvas 14978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is restored to a known state. 14988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 14998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable { 15008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 15012887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) { 15022887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (fCanvas) { 15032887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org fSaveCount = canvas->getSaveCount(); 15042887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (doSave) { 15052887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org canvas->save(); 15062887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org } 15078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoCanvasRestore() { 1510f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1511f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1512f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1513f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1514f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com 1515f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com /** 1516f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * Perform the restore now, instead of waiting for the destructor. Will 1517f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * only do this once. 1518f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com */ 1519f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com void restore() { 1520f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1521f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1522f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas = NULL; 1523f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 15248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 15278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas* fCanvas; 15288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSaveCount; 15298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1530e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) 15318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1532c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/** 1533c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the caller wants read-only access to the pixels in a canvas, it can just 1534c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * call canvas->peekPixels(), since that is the fastest way to "peek" at the 1535c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * pixels on a raster-backed canvas. 1536c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1537c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the canvas has pixels, but they are not readily available to the CPU 1538c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will 1539c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * succeed (though be slower, since it will return a copy of the pixels). 1540c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1541c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * SkAutoROCanvasPixels encapsulates these two techniques, trying first to call 1542c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * peekPixels() (for performance), but if that fails, calling readPixels() and 1543c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * storing the copy locally. 1544c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1545c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * The caller must respect the restrictions associated with peekPixels(), since 1546c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * that may have been called: The returned information is invalidated if... 1547c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - any API is called on the canvas (or its parent surface if present) 1548c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - the canvas goes out of scope 1549c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 1550c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable { 1551c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic: 1552c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkAutoROCanvasPixels(SkCanvas* canvas); 1553c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1554c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // returns NULL on failure 1555c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* addr() const { return fAddr; } 155602d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1557c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1558c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t rowBytes() const { return fRowBytes; } 155902d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1560c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1561c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const SkImageInfo& info() const { return fInfo; } 1562c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1563c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // helper that, if returns true, installs the pixels into the bitmap. Note 1564c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // that the bitmap may reference the address returned by peekPixels(), so 1565c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // the caller must respect the restrictions associated with peekPixels(). 1566c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org bool asROBitmap(SkBitmap*) const; 1567c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1568c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate: 1569c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkBitmap fBitmap; // used if peekPixels() fails 1570c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* fAddr; // NULL on failure 1571c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo fInfo; 1572c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t fRowBytes; 1573c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org}; 1574c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 15752a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, 15762a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org const SkCanvas::SaveFlags rhs) { 157792a8916540b14549213332c5f9f0cd44ec12de75commit-bot@chromium.org return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast<int>(rhs)); 15782a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org} 15792a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 15802a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, 15812a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org const SkCanvas::SaveFlags rhs) { 15822a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org lhs = lhs | rhs; 15832a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org return lhs; 15842a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org} 15852a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 1586c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor { 1587c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic: 1588c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita virtual ~SkCanvasClipVisitor(); 1589c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1590c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1591c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1592c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita}; 15932a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 15948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1595