SkCanvas.h revision 9b14f26d0f3a974f3dd626c8354e1db1cfcd322f
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" 19845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h" 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL 22e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com #define SK_LEGACY_DRAWTEXT_VIRTUAL virtual 23e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#else 24e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com #define SK_LEGACY_DRAWTEXT_VIRTUAL 25e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#endif 26e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com 271f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice; 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw; 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter; 3074bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData; 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture; 324ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect; 3376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface; 3497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base; 35644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext; 369c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comclass GrRenderTarget; 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A Canvas encapsulates all of the state about drawing into a device (bitmap). 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This includes a reference to the device itself, and a stack of matrix/clip 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com values. For any given draw call (e.g. drawRect), the geometry of the object 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com being drawn is transformed by the concatenation of all the matrices in the 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stack. The transformed geometry is clipped by the intersection of all of 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the clips in the stack. 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com While the Canvas holds the state of the drawing device, the state (style) 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of the object being drawn is held by the Paint, which is provided as a 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com parameter to each of the draw() methods. The Paint holds attributes such as 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com etc. 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 537ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt { 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 5515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(SkCanvas) 5615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 57e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 583107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * Attempt to allocate an offscreen raster canvas, matching the ImageInfo. 593107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * On success, return a new canvas that will draw into that offscreen. 603107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 613107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * The caller can access the pixels after drawing into this canvas by 623107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * calling readPixels() or peekPixels(). 633107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 643107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * If the requested ImageInfo is opaque (either the colortype is 653107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * intrinsically opaque like RGB_565, or the info's alphatype is kOpaque) 663107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * then the pixel memory may be uninitialized. Otherwise, the pixel memory 673107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * will be initialized to 0, which is interpreted as transparent. 683107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 693107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * On failure, return NULL. This can fail for several reasons: 703107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 1. the memory allocation failed (e.g. request is too large) 713107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 2. invalid ImageInfo (e.g. negative dimensions) 723107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 3. unsupported ImageInfo for a canvas 733107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * - kUnknown_SkColorType, kIndex_8_SkColorType 743107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * - kIgnore_SkAlphaType 753107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * - this list is not complete, so others may also be unsupported 763107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * 773107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * Note: it is valid to request a supported ImageInfo, but with zero 783107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org * dimensions. 793107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org */ 803107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org static SkCanvas* NewRaster(const SkImageInfo&); 813107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org 823107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org static SkCanvas* NewRasterN32(int width, int height) { 833107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org return NewRaster(SkImageInfo::MakeN32Premul(width, height)); 843107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org } 853107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org 863107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org /** 8742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the 8842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * specified pixels. To access the pixels after drawing to them, the caller should call 8942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * flush() or call peekPixels(...). 9042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 9142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * On failure, return NULL. This can fail for several reasons: 9242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 1. invalid ImageInfo (e.g. negative dimensions) 9342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 2. unsupported ImageInfo for a canvas 9442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * - kUnknown_SkColorType, kIndex_8_SkColorType 9542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * - kIgnore_SkAlphaType 9642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * - this list is not complete, so others may also be unsupported 9742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * 9842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * Note: it is valid to request a supported ImageInfo, but with zero 9942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org * dimensions. 10042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org */ 10142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t); 10242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org 10342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) { 10442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes); 10542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org } 10642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org 10742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org /** 108e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates an empty canvas with no backing device/pixels, and zero 109e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * dimensions. 110e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 111cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com SkCanvas(); 1128d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 113e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 114e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates a canvas of the specified dimensions, but explicitly not backed 115e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * by any device/pixels. Typically this use used by subclasses who handle 116e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * the draw calls in some other way. 117e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 118e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org SkCanvas(int width, int height); 119e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org 1206dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com /** Construct a canvas with the specified device to draw into. 121e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 1228d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org @param device Specifies a device for the canvas to draw into. 1238d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org */ 1241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com explicit SkCanvas(SkBaseDevice* device); 1258d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 1264469938e92d779dff05e745559e67907bbf21e78reed@google.com /** Construct a canvas with the specified bitmap to draw into. 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap Specifies a bitmap for the canvas to draw into. Its 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com structure are copied to the canvas. 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkCanvas(const SkBitmap& bitmap); 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkCanvas(); 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData& getMetaData(); 13474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 135c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 136c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return ImageInfo for this canvas. If the canvas is not backed by pixels 137c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. 138c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 139c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo imageInfo() const; 140c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 143210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com /** 144bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org * Trigger the immediate execution of all pending draw operations. 145bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org */ 146bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org void flush(); 147bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org 148bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org /** 1494ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * Gets the size of the base or root layer in global canvas coordinates. The 1504ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * origin of the base layer is always (0,0). The current drawable area may be 1514ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * smaller (due to clipping or saveLayer). 152210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com */ 1534ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkISize getBaseLayerSize() const; 1544ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com 1554ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com /** 1564ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * DEPRECATED: call getBaseLayerSize 1574ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com */ 1584ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkISize getDeviceSize() const { return this->getBaseLayerSize(); } 159210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com 160c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 161c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * DEPRECATED. 162c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return the canvas' device object, which may be null. The device holds 163c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * the bitmap of the pixels that the canvas draws into. The reference count 164c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * of the returned device is not changed by this call. 165c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 1661f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* getDevice() const; 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. 19176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com */ 19276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com SkSurface* newSurface(const SkImageInfo&); 193e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 194644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org /** 195644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * Return the GPU context of the device that is associated with the canvas. 196644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * For a canvas with non-GPU device, NULL is returned. 197644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org */ 198644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org GrContext* getGrContext(); 199644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org 2004b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /////////////////////////////////////////////////////////////////////////// 2014b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 202daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com /** 2039c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * If the canvas has writable pixels in its top layer (and is not recording to a picture 2049c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * or other non-raster target) and has direct access to its pixels (i.e. they are in 2059c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * local RAM) return the address of those pixels, and if not null, 2066b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org * return the ImageInfo, rowBytes and origin. The returned address is only valid 2079c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * while the canvas object is in scope and unchanged. Any API calls made on 2089c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * canvas (or its parent surface if any) will invalidate the 2099c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * returned address (and associated information). 2109c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * 2116b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org * On failure, returns NULL and the info, rowBytes, and origin parameters are ignored. 2129c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com */ 2136b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL); 2149c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com 2159c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com /** 2169c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * If the canvas has readable pixels in its base layer (and is not recording to a picture 2179c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com * or other non-raster target) and has direct access to its pixels (i.e. they are in 218c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * local RAM) return the const-address of those pixels, and if not null, 219c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * return the ImageInfo and rowBytes. The returned address is only valid 220c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * while the canvas object is in scope and unchanged. Any API calls made on 221c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * canvas (or its parent surface if any) will invalidate the 222c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * returned address (and associated information). 223c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 224c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * On failure, returns NULL and the info and rowBytes parameters are 225c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * ignored. 226c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 227c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* peekPixels(SkImageInfo* info, size_t* rowBytes); 228c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 229a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org /** 230a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), 231a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * converting them into the requested format (SkImageInfo). The base-layer pixels are read 232a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * starting at the specified (x,y) location in the coordinate system of the base-layer. 233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 234a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * The specified ImageInfo and (x,y) offset specifies a source rectangle 235a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 236a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * srcR(x, y, info.width(), info.height()); 237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 238a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * SrcR is intersected with the bounds of the base-layer. If this intersection is not empty, 239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * then we have two sets of pixels (of equal size), the "src" specified by base-layer at (x,y) 240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * and the "dst" by info+pixels+rowBytes. Replace the dst pixels with the corresponding src 241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * pixels, performing any colortype/alphatype transformations needed (in the case where the 242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * src and dst have different colortypes or alphatypes). 243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * 244a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * This call can fail, returning false, for several reasons: 245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * - If the requested colortype/alphatype cannot be converted from the base-layer's types. 246a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * - If this canvas is not backed by pixels (e.g. picture or PDF) 247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org */ 248a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org bool readPixels(const SkImageInfo&, void* pixels, size_t rowBytes, int x, int y); 249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org /** 251a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated. 252a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * If not, it will attempt to call allocPixels(). If this fails, it will return false. If not, 253a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * it calls through to readPixels(info, ...) and returns its result. 254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org */ 255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org bool readPixels(SkBitmap* bitmap, int x, int y); 256c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com 2574b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /** 258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized 259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * to the intersection of srcRect and the base-layer bounds. On success, pixels will be 260a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * allocated in bitmap and true returned. On failure, false is returned and bitmap will be 261a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org * set to empty. 26251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com */ 26351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); 26451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com 2654cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org /** 2664cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * This method affects the pixels in the base-layer, and operates in pixel coordinates, 2674cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * ignoring the matrix and clip. 2684cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2694cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * The specified ImageInfo and (x,y) offset specifies a rectangle: target. 2704cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2714cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * target.setXYWH(x, y, info.width(), info.height()); 2724cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2734cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * Target is intersected with the bounds of the base-layer. If this intersection is not empty, 2744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes 2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src 2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * pixels, performing any colortype/alphatype transformations needed (in the case where the 2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * src and dst have different colortypes or alphatypes). 2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * 2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * This call can fail, returning false, for several reasons: 2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * - If the src colortype/alphatype cannot be converted to the canvas' types 2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * - If this canvas is not backed by pixels (e.g. picture or PDF) 2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org */ 2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y); 2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org /** 2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap 2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org * is just wrapping a texture, returns false and does nothing. 2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org */ 2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org bool writePixels(const SkBitmap& bitmap, int x, int y); 2904b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 2928d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum SaveFlags { 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the matrix state, restoring it on restore() */ 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrix_SaveFlag = 0x01, 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the clip state, restoring it on restore() */ 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClip_SaveFlag = 0x02, 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support per-pixel alpha */ 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kHasAlphaLayer_SaveFlag = 0x04, 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support 8-bits per color component */ 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFullColorLayer_SaveFlag = 0x08, 302b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com /** 303b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * the layer should clip against the bounds argument 304b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * 305b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on. 306b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com */ 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClipToLayer_SaveFlag = 0x10, 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helper masks for common choices 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrixClip_SaveFlag = 0x03, 311b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_NoClipLayer_SaveFlag = 0x0F, 313b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#endif 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_ClipLayer_SaveFlag = 0x1F 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 317dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com /** This call saves the current matrix, clip, and drawFilter, and pushes a 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy onto a private stack. Subsequent calls to translate, scale, 319dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com rotate, skew, concat or clipRect, clipPath, and setDrawFilter all 320dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com operate on this copy. 321dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com When the balancing call to restore() is made, the previous matrix, clip, 322dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com and drawFilter are restored. 323d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 324d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 325d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 326d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int save(); 327d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 328d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org /** DEPRECATED - use save() instead. 329d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 330d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org This behaves the same as save(), but it allows fine-grained control of 331d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org which state bits to be saved (and subsequently restored). 332d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 333d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com @param flags The flags govern what portion of the Matrix/Clip/drawFilter 334d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com state the save (and matching restore) effect. For example, 335d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com if only kMatrix is specified, then only the matrix state 336d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com will be pushed and popped. Likewise for the clip if kClip 337d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com is specified. However, the drawFilter is always affected 338d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com by calls to save/restore. 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 341d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 342d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int save(SaveFlags flags); 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 347dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 348ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 349ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com limit the size of the offscreen, and thus drawing may be 350ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com clipped to it, though that clipping is not guaranteed to 351ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com happen. If exact clipping is desired, use clipRect(). 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint (may be null) This is copied, and is applied to the 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen when restore() is called 354d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 355d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 356d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayer(const SkRect* bounds, const SkPaint* paint); 357d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 358d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. 359d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 360d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org This behaves the same as saveLayer(const SkRect*, const SkPaint*), 361d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org but it allows fine-grained control of which state bits to be saved 362d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org (and subsequently restored). 363d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 364d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param bounds (may be null) This rect, if non-null, is used as a hint to 365d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org limit the size of the offscreen, and thus drawing may be 366d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org clipped to it, though that clipping is not guaranteed to 367d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org happen. If exact clipping is desired, use clipRect(). 368d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param paint (may be null) This is copied, and is applied to the 369d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org offscreen when restore() is called 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 373d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 374d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 379dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 38040408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 38140408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com limit the size of the offscreen, and thus drawing may be 38240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com clipped to it, though that clipping is not guaranteed to 38340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com happen. If exact clipping is desired, use clipRect(). 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param alpha This is applied to the offscreen when restore() is called. 385d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @return The value to pass to restoreToCount() to balance this save() 386d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org */ 387d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); 388d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 389d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. 390d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 391d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), 392d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org but it allows fine-grained control of which state bits to be saved 393d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org (and subsequently restored). 394d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org 395d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param bounds (may be null) This rect, if non-null, is used as a hint to 396d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org limit the size of the offscreen, and thus drawing may be 397d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org clipped to it, though that clipping is not guaranteed to 398d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org happen. If exact clipping is desired, use clipRect(). 399d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org @param alpha This is applied to the offscreen when restore() is called. 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 403d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 404d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This call balances a previous call to save(), and is used to remove all 407dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com modifications to the matrix/clip/drawFilter state since the last save 408dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com call. 409dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com It is an error to call restore() more times than save() was called. 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 411e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org void restore(); 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of matrix/clip states on the SkCanvas' private stack. 414ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org This will equal # save() calls - # restore() calls + 1. The save count on 415ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org a new canvas is 1. 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 417a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org int getSaveCount() const; 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Efficient way to pop any calls to save() that happened after the save 420ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org count reached saveCount. It is an error for saveCount to be greater than 421ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org getSaveCount(). To pop all the way back to the initial matrix/clip context 422ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org pass saveCount == 1. 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param saveCount The number of save() levels to restore from 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void restoreToCount(int saveCount); 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4277c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com /** Returns true if drawing is currently going to a layer (from saveLayer) 4287c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com * rather than to the root device. 4297c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com */ 4308f9ecbd3466d4330886b4c23b06e75b468c795adjunov@chromium.org virtual bool isDrawingToLayer() const; 4317c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified translation 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The distance to translate in X 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The distance to translate in Y 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 43692362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void translate(SkScalar dx, SkScalar dy); 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified scale. 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to scale in X 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to scale in Y 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 44292362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void scale(SkScalar sx, SkScalar sy); 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified rotation. 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param degrees The amount to rotate, in degrees 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 44792362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void rotate(SkScalar degrees); 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified skew. 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to skew in X 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to skew in Y 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 45392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void skew(SkScalar sx, SkScalar sy); 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified matrix. 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to preconcatenate with the current matrix 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 45892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org void concat(const SkMatrix& matrix); 4594b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Replace the current matrix with a copy of the specified matrix. 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix that will be copied into the current matrix. 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 46344c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org void setMatrix(const SkMatrix& matrix); 4644b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for setMatrix(identity). Sets the current matrix to identity. 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetMatrix(); 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified rectangle. 4714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rect The rect to combine with the current clip 4724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4744ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 475759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRect(const SkRect& rect, 476759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 477759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4794ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4804ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified SkRRect. 4814ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The rrect to combine with the current clip 4824ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4834ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4844ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 485759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRRect(const SkRRect& rrect, 486759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 487759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4884ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 4894ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4904ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified path. 4914ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param path The path to combine with the current clip 4924ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4934ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4944ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 495759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipPath(const SkPath& path, 496759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op, 497759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org bool doAntiAlias = false); 4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4998f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com /** EXPERIMENTAL -- only used for testing 5008f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com Set to false to force clips to be hard, even if doAntiAlias=true is 5018f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com passed to clipRect or clipPath. 5028f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com */ 5038f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com void setAllowSoftClip(bool allow) { 5048f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com fAllowSoftClip = allow; 5058f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com } 5068f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com 50745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com /** EXPERIMENTAL -- only used for testing 50845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com Set to simplify clip stack using path ops. 50945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com */ 51045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com void setAllowSimplifyClip(bool allow) { 51145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com fAllowSimplifyClip = allow; 51245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com } 51345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified region. Note that unlike 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRect() and clipPath() which transform their arguments by the current 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix, clipRegion() assumes its argument is already in device 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinates, and so no transformation is performed. 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to apply to the current clip 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 521759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void clipRegion(const SkRegion& deviceRgn, 522759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org SkRegion::Op op = SkRegion::kIntersect_Op); 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified region. This does not intersect or in any other way account 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for the existing clip region. 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to copy into the current clip. 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5298f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com void setClipRegion(const SkRegion& deviceRgn) { 5308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com this->clipRegion(deviceRgn, SkRegion::kReplace_Op); 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified rectangle, after being transformed by the 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect the rect to compare with the current clip 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the rect (transformed by the canvas' matrix) does not 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5413b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkRect& rect) const; 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified path, after being transformed by the 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). Note, for speed it may 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false even if the path itself might not intersect the clip 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (i.e. the bounds of the path intersects, but the path does not). 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to compare with the current clip 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path (transformed by the canvas' matrix) does not 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5533b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkPath& path) const; 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the horizontal band specified by top and bottom is 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely clipped out. This is a conservative calculation, meaning 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that it is possible that if the method returns false, the band may still 5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in fact be clipped out, but the converse is not true. If this method 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true, then the band is guaranteed to be clipped out. 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top of the horizontal band to compare with the clip 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom of the horizontal and to compare with the clip 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the horizontal band is completely clipped out (i.e. does 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not intersect the current clip) 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5653b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickRejectY(SkScalar top, SkScalar bottom) const { 566c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com SkASSERT(top <= bottom); 5679836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 5689836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT 5699836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // TODO: add a hasPerspective method similar to getLocalClipBounds. This 5709836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // would cache the SkMatrix::hasPerspective result. Alternatively, have 5719836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // the MC stack just set a hasPerspective boolean as it is updated. 5729836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org if (this->getTotalMatrix().hasPerspective()) { 573a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com // TODO: consider implementing some half-plane test between the 5749836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // two Y planes and the device-bounds (i.e., project the top and 5759836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // bottom Y planes and then determine if the clip bounds is completely 5769836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // outside either one). 5779836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org return false; 5789836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org } 5799836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif 5809836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 581c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& clipR = this->getLocalClipBounds(); 58292d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // In the case where the clip is empty and we are provided with a 58392d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // negative top and positive bottom parameter then this test will return 58492d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // false even though it will be clipped. We have chosen to exclude that 58592d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // check as it is rare and would result double the comparisons. 586c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return top >= clipR.fBottom || bottom <= clipR.fTop; 58792d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com } 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the bounds of the current clip (in local coordinates) in the 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds parameter, and return true if it is non-empty. This can be useful 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in a way similar to quickReject, in that it tells you that drawing 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com outside of these bounds will be clipped out. 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5948f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool getClipBounds(SkRect* bounds) const; 5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 596bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com /** Return the bounds of the current clip, in device coordinates; returns 597bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com true if non-empty. Maybe faster than getting the clip explicitly and 598bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com then taking its bounds. 599bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com */ 6008f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool getClipDeviceBounds(SkIRect* bounds) const; 60174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org 602bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 604845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified ARGB color, using the specified mode. 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param a the alpha component (0..255) of the color to fill the canvas 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param r the red component (0..255) of the color to fill the canvas 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param g the green component (0..255) of the color to fill the canvas 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param b the blue component (0..255) of the color to fill the canvas 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, 612845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 615845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified color and mode. 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color the color to draw with 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawColor(SkColor color, 620845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6222a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com /** 6232a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * This erases the entire drawing surface to the specified color, 6242a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * irrespective of the clip. It does not blend with the previous pixels, 6252a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * but always overwrites them. 6262a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * 6272a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * It is roughly equivalent to the following: 6282a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.save(); 6292a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.clipRect(hugeRect, kReplace_Op); 6302a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * paint.setColor(color); 6312a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * paint.setXfermodeMode(kSrc_Mode); 6322a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.drawPaint(paint); 6332a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.restore(); 6342a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * though it is almost always much more efficient. 6352a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com */ 6362a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com virtual void clear(SkColor); 6372a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com 6382a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com /** 63928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * This makes the contents of the canvas undefined. Subsequent calls that 64028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * require reading the canvas contents will produce undefined results. Examples 64128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * include blending and readPixels. The actual implementation is backend- 64228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * dependent and one legal implementation is to do nothing. Like clear(), this 64328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * ignores the clip. 64428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * 64528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * This function should only be called if the caller intends to subsequently 64628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * draw to the canvas. The canvas may do real work at discard() time in order 64728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * to optimize performance on subsequent draws. Thus, if you call this and then 64828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org * never draw to the canvas subsequently you may pay a perfomance penalty. 64928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org */ 65028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org void discard() { this->onDiscard(); } 65128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 65228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org /** 6532a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * Fill the entire canvas' bitmap (restricted to the current clip) with the 6542a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * specified paint. 6552a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * @param paint The paint used to fill the canvas 6562a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com */ 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPaint(const SkPaint& paint); 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum PointMode { 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each point separately */ 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPoints_PointMode, 6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each pair of points as a line segment */ 6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLines_PointMode, 6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws the array of points as a polygon */ 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPolygon_PointMode 6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a series of points, interpreted based on the PointMode mode. For 6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com all modes, the count parameter is interpreted as the total number of 6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com points. For kLine mode, count/2 line segments are drawn. 6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPoint mode, each point is drawn centered at its coordinate, and its 6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size is specified by the paint's stroke-width. It draws as a square, 6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unless the paint's cap-type is round, in which the points are drawn as 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com circles. 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kLine mode, each pair of points is drawn as a line segment, 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com respecting the paint's settings for cap/join/width. 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPolygon mode, the entire array is drawn as a series of connected 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line segments. 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note that, while similar, kLine and kPolygon modes draw slightly 6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com differently than the equivalent path built with a series of moveto, 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com lineto calls, in that the path will draw all of its contours at once, 6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with no interactions if contours intersect each other (think XOR 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xfermode). drawPoints always draws each element one at a time. 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode PointMode specifying how to draw the array of points. 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param count The number of points in the array 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts Array of points to draw 6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the points 6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper method for drawing a single point. See drawPoints() for a more 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com details. 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); 6964b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draws a single pixel in the specified color. 6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The X coordinate of which pixel to draw 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The Y coordiante of which pixel to draw 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color The color to draw 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, SkColor color); 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a line segment with the specified start and stop x,y coordinates, 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com using the specified paint. NOTE: since a line is always "framed", the 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint's Style is ignored. 7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x0 The x-coordinate of the start point of the line 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y0 The y-coordinate of the start point of the line 7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the end point of the line 7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the end point of the line 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the line 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or stroked based on the Style in the paint. 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7217ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com virtual void drawRect(const SkRect& rect, const SkPaint& paint); 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 72887001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com void drawIRect(const SkIRect& rect, const SkPaint& paint) { 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(rect); // promotes the ints to scalars 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawRect(r, paint); 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7334b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The left side of the rectangle to be drawn 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top side of the rectangle to be drawn 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param right The right side of the rectangle to be drawn 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom side of the rectangle to be drawn 7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRectCoords(SkScalar left, SkScalar top, SkScalar right, 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar bottom, const SkPaint& paint); 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified oval using the specified paint. The oval will be 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The rectangle bounds of the oval to be drawn 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the oval 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7504ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com virtual void drawOval(const SkRect& oval, const SkPaint&); 7514ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 7524ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 7534ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Draw the specified RRect using the specified paint The rrect will be filled or stroked 7544ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * based on the Style in the paint. 7554ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * 7564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The round-rect to draw 7574ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param paint The paint used to draw the round-rect 7584ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 7594ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint); 7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 761ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org /** 762ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * Draw the annulus formed by the outer and inner rrects. The results 763ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * are undefined if the outer does not contain the inner. 764ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org */ 765ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&); 766ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified circle using the specified paint. If radius is <= 0, 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com then nothing will be drawn. The circle will be filled 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or framed based on the Style in the paint. 7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cx The x-coordinate of the center of the cirle to be drawn 7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cy The y-coordinate of the center of the cirle to be drawn 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param radius The radius of the cirle to be drawn 7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the circle 7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified arc, which will be scaled to fit inside the 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified oval. If the sweep angle is >= 360, then the oval is drawn 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely. Note that this differs slightly from SkPath::arcTo, which 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com treats the sweep angle mod 360. 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the shape of the arc 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param useCenter true means include the center of the oval. For filling 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this will draw a wedge. False means just use the arc. 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the arc 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool useCenter, const SkPaint& paint); 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified round-rect using the specified paint. The round-rect 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rectangular bounds of the roundRect to be drawn 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rx The x-radius of the oval used to round the corners 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ry The y-radius of the oval used to round the corners 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the roundRect 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified path using the specified paint. The path will be 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to be drawn 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the path 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8077ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com virtual void drawPath(const SkPath& path, const SkPaint& paint); 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), using the 8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified paint, transformed by the current matrix. Note: if the paint 8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 81591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 81691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org If a shader is present on the paint it will be ignored, except in the 817f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com case where the bitmap is kAlpha_8_SkColorType. In that case, the color is 81891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org generated by the shader. 81991246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 8218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 8248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 8278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 828eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org enum DrawBitmapRectFlags { 82931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kNone_DrawBitmapRectFlag = 0x0, 8307475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com /** 831eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * When filtering is enabled, allow the color samples outside of 8327475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com * the src rect (but still in the src bitmap) to bleed into the 833eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * drawn portion 834eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org */ 83531acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kBleed_DrawBitmapRectFlag = 0x1, 836eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org }; 837eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org 8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with the specified matrix applied (before the 8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas' matrix is applied). 8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src Optional: specify the subset of the bitmap to be drawn 8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The destination rectangle where the scaled/translated 8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com image will be drawn 8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 8458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8467112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 8477112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com const SkRect& dst, 848eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkPaint* paint = NULL, 84931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag); 8507112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com 8517112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, 852eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkPaint* paint = NULL) { 85331acc11977815402e4ef2681350f8559285bec97robertphillips@google.com this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag); 8547112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 8558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8567112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, 857eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint = NULL, 85831acc11977815402e4ef2681350f8559285bec97robertphillips@google.com DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { 8597112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect realSrcStorage; 8607112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect* realSrcPtr = NULL; 8617112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com if (isrc) { 8627112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcStorage.set(*isrc); 8637112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcPtr = &realSrcStorage; 8647112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 865eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags); 8667112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 867c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 8704b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 871f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com /** 872f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Draw the bitmap stretched differentially to fit into dst. 873f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * center is a rect within the bitmap, and logically divides the bitmap 874f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * into 9 sections (3x3). For example, if the middle pixel of a [5x5] 875f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * bitmap is the "center", then the center-rect should be [2, 2, 3, 3]. 876f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * 877f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * If the dst is >= the bitmap size, then... 8789bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The 4 corners are not stretched at all. 8799bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The sides are stretched in only one axis. 8809bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The center is stretched in both axes. 881f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Else, for each axis where dst < bitmap, 882f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The corners shrink proportionally 883f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The sides (along the shrink axis) and center are not drawn 884f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com */ 885f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 886f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com const SkRect& dst, const SkPaint* paint = NULL); 887f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 8888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), 8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOT transformed by the current matrix. Note: if the paint 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 8968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint. 9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The origin is interpreted based on the Align setting in the paint. 9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the origin of the text being drawn 9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the origin of the text being drawn 9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 910e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SK_LEGACY_DRAWTEXT_VIRTUAL void drawText(const void* text, size_t byteLength, SkScalar x, 9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar y, const SkPaint& paint); 9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the pos[] 9144b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com array. The origin is interpreted by the Align setting in the paint. 9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pos Array of positions, used to position each character 9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 920e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosText(const void* text, size_t byteLength, 9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint pos[], const SkPaint& paint); 9224b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the x 9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinate taken from the xpos[] array, and the y from the constY param. 9254b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com The origin is interpreted by the Align setting in the paint. 9268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xpos Array of x-positions, used to position each character 9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param constY The shared Y coordinate for all of the positions 9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 932e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosTextH(const void* text, size_t byteLength, 9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar xpos[], SkScalar constY, 9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 9354b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param hOffset The distance along the path to add to the text's 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com starting position 9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vOffset The distance above(-) or below(+) the path to 9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com position the text 9468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawTextOnPathHV(const void* text, size_t byteLength, 9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, SkScalar hOffset, 9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar vOffset, const SkPaint& paint); 9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 9588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix (may be null) Applied to the text before it is 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mapped onto the path 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 962e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SK_LEGACY_DRAWTEXT_VIRTUAL void drawTextOnPath(const void* text, size_t byteLength, 9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, const SkMatrix* matrix, 9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 966145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org /** PRIVATE / EXPERIMENTAL -- do not call 967145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org Perform back-end analysis/optimization of a picture. This may attach 968145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org optimization data to the picture which can be used by a later 969145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org drawPicture call. 970145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org @param picture The recorded drawing commands to analyze/optimize 971145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org */ 9729b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips void EXPERIMENTAL_optimize(const SkPicture* picture); 973145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org 974c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org /** PRIVATE / EXPERIMENTAL -- do not call 975c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org Purge all the discardable optimization information associated with 976c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org 'picture'. If NULL is passed in, purge all discardable information. 977c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org */ 9789b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips void EXPERIMENTAL_purge(const SkPicture* picture); 979c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org 9808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the picture into this canvas. This method effective brackets the 9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com playback of the picture's draw calls with save/restore, so the state 982a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com of this canvas will be unchanged after this call. 9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param picture The recorded drawing commands to playback into this 9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas. 9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9869b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips void drawPicture(const SkPicture* picture); 9879b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips 9889b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips#ifdef SK_SUPPORT_LEGACY_DRAWPICTURE_API 9899b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips virtual void drawPicture(SkPicture& picture) { 9909b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips this->drawPicture(&picture); 9919b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips } 9929b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips#endif 9934b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum VertexMode { 9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangles_VertexMode, 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleStrip_VertexMode, 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleFan_VertexMode 9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 9994b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the array of vertices, interpreted as triangles (based on mode). 1001559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 1002559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org If both textures and vertex-colors are NULL, it strokes hairlines with 1003559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org the paint's color. This behavior is a useful debugging mode to visualize 1004559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org the mesh. 1005559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vmode How to interpret the array of vertices 10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertexCount The number of points in the vertices array (and 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com corresponding texs and colors arrays if non-null) 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertices Array of vertices for the mesh 10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param texs May be null. If not null, specifies the coordinate 1011631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com in _texture_ space (not uv space) for each vertex. 10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param colors May be null. If not null, specifies a color for each 10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex, to be interpolated across the triangle. 10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xmode Used if both texs and colors are present. In this 10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case the colors are combined with the texture using mode, 10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com before being drawn using the paint. If mode is null, then 10178d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com kModulate_Mode is used. 10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indices If not null, array of indices to reference into the 10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex (texs, colors) array. 10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indexCount number of entries in the indices array (if not null) 10214b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com @param paint Specifies the shader/texture if present. 10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawVertices(VertexMode vmode, int vertexCount, 10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint texs[], 10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1029cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com /** Send a blob of data to the canvas. 1030cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com For canvases that draw, this call is effectively a no-op, as the data 1031cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com is not parsed, but just ignored. However, this call exists for 1032cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com subclasses like SkPicture's recording canvas, that can store the data 1033cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com and then play it back later (via another call to drawData). 1034cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com */ 10350a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void drawData(const void* data, size_t length) { 10360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something with the data 10370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 10380a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 1039a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com /** Add comments. beginCommentGroup/endCommentGroup open/close a new group. 1040a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com Each comment added via addComment is notionally attached to its 10410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com enclosing group. Top-level comments simply belong to no group. 10420a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */ 10430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void beginCommentGroup(const char* description) { 10440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 10450a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 10460a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void addComment(const char* kywd, const char* value) { 10470a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 10480a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 10490a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void endCommentGroup() { 10500a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 10510a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 10520a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 1053210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org /** 1054210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org * With this call the client asserts that subsequent draw operations (up to the 1055210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org * matching popCull()) are fully contained within the given bounding box. The assertion 1056210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org * is not enforced, but the information might be used to quick-reject command blocks, 1057210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org * so an incorrect bounding box may result in incomplete rendering. 1058210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org */ 1059520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org void pushCull(const SkRect& cullRect); 1060cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com 1061210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org /** 1062210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org * Terminates the current culling block, and restores the previous one (if any). 1063210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org */ 1064520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org void popCull(); 1065520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org 10668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 10674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current filter object. The filter's reference count is not 1069dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com affected. The filter is saved/restored, just like the matrix and clip. 10708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canvas' filter (or NULL). 10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawFilter* getDrawFilter() const; 10734b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the new filter (or NULL). Pass NULL to clear any existing filter. 10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter is returned. If an existing filter 10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com exists, its refcnt is decrement. If the new filter is not null, its 1077dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com refcnt is incremented. The filter is saved/restored, just like the 1078dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com matrix and clip. 10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param filter the new filter (or NULL) 10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the new filter 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1086754de5f65b466f721d952a379194cc94de376f42reed@google.com /** 1087754de5f65b466f721d952a379194cc94de376f42reed@google.com * Return true if the current clip is empty (i.e. nothing will draw). 1088754de5f65b466f721d952a379194cc94de376f42reed@google.com * Note: this is not always a free call, so it should not be used 1089754de5f65b466f721d952a379194cc94de376f42reed@google.com * more often than necessary. However, once the canvas has computed this 1090754de5f65b466f721d952a379194cc94de376f42reed@google.com * result, subsequent calls will be cheap (until the clip state changes, 1091754de5f65b466f721d952a379194cc94de376f42reed@google.com * which can happen on any clip..() or restore() call. 1092754de5f65b466f721d952a379194cc94de376f42reed@google.com */ 10938f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual bool isClipEmpty() const; 1094754de5f65b466f721d952a379194cc94de376f42reed@google.com 10955c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org /** 10965c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org * Returns true if the current clip is just a (non-empty) rectangle. 10975c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org * Returns false if the clip is empty, or if it is complex. 10985c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org */ 10995c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org virtual bool isClipRect() const; 11005c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org 11018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the current matrix on the canvas. 11028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This does not account for the translate in any of the devices. 11038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The current matrix on the canvas. 11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1105a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org const SkMatrix& getTotalMatrix() const; 11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11075c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE 1108bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com enum ClipType { 1109bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kEmpty_ClipType = 0, 1110bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kRect_ClipType, 1111bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kComplex_ClipType 1112bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com }; 1113bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com /** Returns a description of the total clip; may be cheaper than 1114bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com getting the clip and querying it directly. 1115bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com */ 11168f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual ClipType getClipType() const; 11175c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif 1118bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 11195c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP 11204469938e92d779dff05e745559e67907bbf21e78reed@google.com /** DEPRECATED -- need to move this guy to private/friend 11214469938e92d779dff05e745559e67907bbf21e78reed@google.com * Return the current device clip (concatenation of all clip calls). 1122a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com * This does not account for the translate in any of the devices. 1123a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com * @return the current device clip (concatenation of all clip calls). 11245e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com */ 1125a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com const SkRegion& getTotalClip() const; 11265c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif 11275e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com 112840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com /** Return the clip stack. The clip stack stores all the individual 112940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * clips organized by the save/restore frame in which they were 113040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * added. 113140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * @return the current clip stack ("list" of individual clip elements) 113240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com */ 113340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com const SkClipStack* getClipStack() const { 113440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com return &fClipStack; 113540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com } 113640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com 113790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com class ClipVisitor { 113890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com public: 113920a550c6ea947f0ab239da1d4ecba209d76a98fdjustinlin@google.com virtual ~ClipVisitor(); 114090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1141e5b2af955b7d06815ddd405659ad62a2a8355ca3commit-bot@chromium.org virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 114290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 114390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com }; 114490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com 11455e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com /** 114690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * Replays the clip operations, back to front, that have been applied to 114790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * the canvas, calling the appropriate method on the visitor for each 114890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * clip. All clips have already been transformed into device space. 11497d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com */ 115090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com void replayClips(ClipVisitor*) const; 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After calling saveLayer(), there can be any number of devices that make 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com up the top-most drawing area. LayerIter can be used to iterate through 11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com those devices. Note that the iterator is only valid until the next API 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call made on the canvas. Ownership of all pointers in the iterator stays 11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the canvas, so none of them should be modified or deleted. 11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 11607ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org class SK_API LayerIter /*: SkNoncopyable*/ { 11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize iterator with canvas, and set values for 1st device */ 11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com LayerIter(SkCanvas*, bool skipEmptyClips); 11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~LayerIter(); 11654b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the iterator is done */ 11678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool done() const { return fDone; } 11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Cycle to the next device */ 11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void next(); 11704b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // These reflect the current device in the iterator 11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11731f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* device() const; 11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix() const; 11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion& clip() const; 11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint() const; 11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x() const; 11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y() const; 11794b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 11818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // used to embed the SkDrawIter object directly in our instance, w/o 11828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // having to expose that class def to the public. There is an assert 11838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // in our constructor to ensure that fStorage is large enough 11848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (though needs to be a compile-time-assert!). We use intptr_t to work 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // safely with 32 and 64 bit machines (to ensure the storage is enough) 1186f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com intptr_t fStorage[32]; 11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class SkDrawIter* fImpl; // this points at fStorage 11888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint fDefaultPaint; 11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDone; 11908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 11918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11925c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org // don't call 11935c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org const SkRegion& internal_private_getTotalClip() const; 11945c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org // don't call 11955c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org void internal_private_getTotalClipAsPath(SkPath*) const; 11969c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com // don't call 11979c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com GrRenderTarget* internal_private_accessTopLayerRenderTarget(); 11985c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org 11998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 120076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com // default impl defers to getDevice()->newSurface(info) 120176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com virtual SkSurface* onNewSurface(const SkImageInfo&); 120276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com 1203c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // default impl defers to its device 1204c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); 12059c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes); 1206c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1207e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // Subclass save/restore notifiers. 1208e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // Overriders should call the corresponding INHERITED method up the inheritance chain. 1209e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org // willSaveLayer()'s return value may suppress full layer allocation. 1210e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org enum SaveLayerStrategy { 1211e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org kFullLayer_SaveLayerStrategy, 1212e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org kNoLayer_SaveLayerStrategy 1213e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org }; 1214e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org 1215fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void willSave(SaveFlags) {} 1216fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) { 1217fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org return kFullLayer_SaveLayerStrategy; 1218fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org } 1219fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void willRestore() {} 1220fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void didConcat(const SkMatrix&) {} 1221fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org virtual void didSetMatrix(const SkMatrix&) {} 122244c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org 1223ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1224ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 1225e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, 1226e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SkScalar y, const SkPaint& paint); 1227b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1228e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawPosText(const void* text, size_t byteLength, 1229e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPoint pos[], const SkPaint& paint); 1230b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1231e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawPosTextH(const void* text, size_t byteLength, 1232e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkScalar xpos[], SkScalar constY, 1233e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPaint& paint); 1234b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com 1235e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com virtual void onDrawTextOnPath(const void* text, size_t byteLength, 1236e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPath& path, const SkMatrix* matrix, 1237e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com const SkPaint& paint); 1238e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com 12398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com enum ClipEdgeStyle { 12408f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com kHard_ClipEdgeStyle, 12418f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com kSoft_ClipEdgeStyle 12428f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com }; 12438f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 12448f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle); 12458f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle); 12468f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle); 12478f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 12488f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 124928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org virtual void onDiscard(); 125028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org 12519b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips virtual void onDrawPicture(const SkPicture* picture); 12529b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips 125374b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org // Returns the canvas to be used by DrawIter. Default implementation 12544370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // returns this. Subclasses that encapsulate an indirect canvas may 12554370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // need to overload this method. The impl must keep track of this, as it 12564370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // is not released or deleted by the caller. 12574370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com virtual SkCanvas* canvasForDrawIter(); 12584370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com 1259a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // Clip rectangle bounds. Called internally by saveLayer. 1260a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // returns false if the entire rectangle is entirely clipped out 1261c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // If non-NULL, The imageFilter parameter will be used to expand the clip 1262c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // and offscreen bounds for any margin required by the filter DAG. 1263a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org bool clipRectBounds(const SkRect* bounds, SaveFlags flags, 1264c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org SkIRect* intersection, 1265c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org const SkImageFilter* imageFilter = NULL); 1266a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org 1267ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org // Called by child classes that override clipPath and clipRRect to only 1268ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org // track fast conservative clip bounds, rather than exact clips. 1269759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org void updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op, 1270ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org bool inverseFilled); 1271ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org 127297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // notify our surface (if we have one) that we are about to draw, so it 127397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // can perform copy-on-write or invalidate any cached images 127497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void predrawNotify(); 127597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com 1276210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org virtual void onPushCull(const SkRect& cullRect); 1277210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org virtual void onPopCull(); 1278210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org 12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class MCRec; 12818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12825c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com SkClipStack fClipStack; 12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDeque fMCStack; 12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // points to top of stack 12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MCRec* fMCRec; 12868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the first N recs that can fit here mean we won't call malloc 12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fMCRecStorage[32]; 12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1289b0a7ace7cb2a7559bbc254a7c93698bc71bbd245junov@chromium.org int fSaveLayerCount; // number of successful saveLayer calls 1290210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org int fCullCount; // number of active culls 12918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 129274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData* fMetaData; 129374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 129497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* fSurfaceBase; 129597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } 129697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void setSurfaceBase(SkSurface_Base* sb) { 129797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com fSurfaceBase = sb; 129897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com } 129997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com friend class SkSurface_Base; 130045c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org friend class SkSurface_Gpu; 1301fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com 13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 13038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updateDeviceCMCache(); 13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13059c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkDrawIter; // needs setupDrawForLayerDevice() 13068926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com friend class AutoDrawLooper; 13079c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkLua; // needs top layer size and offset 13082a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip 13099c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com friend class SkDeferredDevice; // needs getTopDevice() 13108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 131115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkBaseDevice* createLayerDevice(const SkImageInfo&); 1312e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 13131f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* init(SkBaseDevice*); 1314f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 1315403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org /** 1316403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * DEPRECATED 1317403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * 1318403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * Specify a device for this canvas to draw into. If it is not null, its 1319403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * reference count is incremented. If the canvas was already holding a 1320403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * device, its reference count is decremented. The new device is returned. 1321403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org */ 1322403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org SkBaseDevice* setRootDevice(SkBaseDevice* device); 132331acdeabce094e9d42f0d6db8eebcf788aaba11askia.committer@gmail.com 13244ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com /** 13254ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this 13264ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com * to be public because it exposes decisions about layer sizes that are internal to the canvas. 13274ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com */ 13284ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkISize getTopLayerSize() const; 13294ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com SkIPoint getTopLayerOrigin() const; 1330403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org 1331f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // internal methods are not virtual, so they can safely be called by other 1332f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // canvas apis, without confusing subclasses (like SkPictureRecording) 13339bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint); 13347112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1335eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint, 1336eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org DrawBitmapRectFlags flags); 1337f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 1338f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com const SkRect& dst, const SkPaint* paint); 1339fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com void internalDrawPaint(const SkPaint& paint); 13408926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, 1341e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org SaveFlags, bool justForImageFilter, SaveLayerStrategy strategy); 13421f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); 1343fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com 13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // shared by save() and saveLayer() 13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int internalSave(SaveFlags flags); 13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void internalRestore(); 134752c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawRect(const SkDraw& draw, const SkPaint& paint, 134852c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const SkRect& r, SkScalar textSize); 134952c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, 135052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const char text[], size_t byteLength, 135152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkScalar x, SkScalar y); 13524b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 13538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* These maintain a cache of the clip bounds in local coordinates, 13548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (converted to 2s-compliment if floats are slow). 13558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1356c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable SkRect fCachedLocalClipBounds; 1357c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable bool fCachedLocalClipBoundsDirty; 13588f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com bool fAllowSoftClip; 135945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com bool fAllowSimplifyClip; 13608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1361c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& getLocalClipBounds() const { 1362c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (fCachedLocalClipBoundsDirty) { 1363c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (!this->getClipBounds(&fCachedLocalClipBounds)) { 1364c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBounds.setEmpty(); 1365c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com } 1366c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBoundsDirty = false; 13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1368c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return fCachedLocalClipBounds; 13698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 137045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 13715c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com class AutoValidateClip : ::SkNoncopyable { 13725c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com public: 13735c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { 13745c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com fCanvas->validateClip(); 13755c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com } 13765c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com ~AutoValidateClip() { fCanvas->validateClip(); } 13775c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 13785c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com private: 13795c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com const SkCanvas* fCanvas; 13805c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com }; 13815c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 13825c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG 1383520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org // The cull stack rects are in device-space 1384520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org SkTDArray<SkIRect> fCullStack; 1385520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org void validateCull(const SkIRect&); 13865c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const; 13875c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else 13885c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const {} 13895c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif 139015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 139115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas 13958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com when this object goes out of scope. Use this to guarantee that the canvas 13968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is restored to a known state. 13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 13988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable { 13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 14002887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) { 14012887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (fCanvas) { 14022887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org fSaveCount = canvas->getSaveCount(); 14032887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (doSave) { 14042887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org canvas->save(); 14052887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org } 14068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoCanvasRestore() { 1409f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1410f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1411f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1412f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1413f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com 1414f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com /** 1415f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * Perform the restore now, instead of waiting for the destructor. Will 1416f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * only do this once. 1417f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com */ 1418f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com void restore() { 1419f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1420f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1421f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas = NULL; 1422f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 14238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 14268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas* fCanvas; 14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSaveCount; 14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1429e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) 14308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14310a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com/** Stack helper class to automatically open and close a comment block 14320a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */ 14330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comclass SkAutoCommentBlock : SkNoncopyable { 14340a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.compublic: 14350a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com SkAutoCommentBlock(SkCanvas* canvas, const char* description) { 14360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas = canvas; 14370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com if (NULL != fCanvas) { 14380a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas->beginCommentGroup(description); 14390a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 14400a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 14410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 14420a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com ~SkAutoCommentBlock() { 14430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com if (NULL != fCanvas) { 14440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas->endCommentGroup(); 14450a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 14460a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 14470a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 14480a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comprivate: 14490a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com SkCanvas* fCanvas; 14500a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com}; 1451e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) 14520a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 1453c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/** 1454c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the caller wants read-only access to the pixels in a canvas, it can just 1455c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * call canvas->peekPixels(), since that is the fastest way to "peek" at the 1456c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * pixels on a raster-backed canvas. 1457c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1458c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the canvas has pixels, but they are not readily available to the CPU 1459c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will 1460c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * succeed (though be slower, since it will return a copy of the pixels). 1461c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1462c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * SkAutoROCanvasPixels encapsulates these two techniques, trying first to call 1463c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * peekPixels() (for performance), but if that fails, calling readPixels() and 1464c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * storing the copy locally. 1465c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1466c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * The caller must respect the restrictions associated with peekPixels(), since 1467c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * that may have been called: The returned information is invalidated if... 1468c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - any API is called on the canvas (or its parent surface if present) 1469c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - the canvas goes out of scope 1470c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 1471c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable { 1472c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic: 1473c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkAutoROCanvasPixels(SkCanvas* canvas); 1474c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1475c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // returns NULL on failure 1476c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* addr() const { return fAddr; } 147702d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1478c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1479c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t rowBytes() const { return fRowBytes; } 148002d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1481c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1482c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const SkImageInfo& info() const { return fInfo; } 1483c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1484c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // helper that, if returns true, installs the pixels into the bitmap. Note 1485c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // that the bitmap may reference the address returned by peekPixels(), so 1486c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // the caller must respect the restrictions associated with peekPixels(). 1487c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org bool asROBitmap(SkBitmap*) const; 1488c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1489c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate: 1490c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkBitmap fBitmap; // used if peekPixels() fails 1491c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* fAddr; // NULL on failure 1492c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo fInfo; 1493c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t fRowBytes; 1494c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org}; 1495c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 14962a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, 14972a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org const SkCanvas::SaveFlags rhs) { 149892a8916540b14549213332c5f9f0cd44ec12de75commit-bot@chromium.org return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast<int>(rhs)); 14992a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org} 15002a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 15012a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, 15022a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org const SkCanvas::SaveFlags rhs) { 15032a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org lhs = lhs | rhs; 15042a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org return lhs; 15052a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org} 15062a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 15072a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org 15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1509