SkCanvas.h revision 754de5f65b466f721d952a379194cc94de376f42
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 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBounder; 221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter; 2574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData; 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture; 274ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect; 2876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface; 2997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base; 30644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext; 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A Canvas encapsulates all of the state about drawing into a device (bitmap). 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This includes a reference to the device itself, and a stack of matrix/clip 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com values. For any given draw call (e.g. drawRect), the geometry of the object 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com being drawn is transformed by the concatenation of all the matrices in the 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stack. The transformed geometry is clipped by the intersection of all of 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the clips in the stack. 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com While the Canvas holds the state of the drawing device, the state (style) 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com of the object being drawn is held by the Paint, which is provided as a 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com parameter to each of the draw() methods. The Paint holds attributes such as 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com etc. 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 477ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt { 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 4915e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com SK_DECLARE_INST_COUNT(SkCanvas) 5015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 51e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 52e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates an empty canvas with no backing device/pixels, and zero 53e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * dimensions. 54e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 55cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com SkCanvas(); 568d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 57e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org /** 58e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * Creates a canvas of the specified dimensions, but explicitly not backed 59e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * by any device/pixels. Typically this use used by subclasses who handle 60e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org * the draw calls in some other way. 61e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org */ 62e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org SkCanvas(int width, int height); 63e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org 646dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com /** Construct a canvas with the specified device to draw into. 65e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 668d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org @param device Specifies a device for the canvas to draw into. 678d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org */ 681f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com explicit SkCanvas(SkBaseDevice* device); 698d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 704469938e92d779dff05e745559e67907bbf21e78reed@google.com /** Construct a canvas with the specified bitmap to draw into. 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap Specifies a bitmap for the canvas to draw into. Its 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com structure are copied to the canvas. 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com explicit SkCanvas(const SkBitmap& bitmap); 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkCanvas(); 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData& getMetaData(); 7874bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 79c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 80c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return ImageInfo for this canvas. If the canvas is not backed by pixels 81c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. 82c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 83c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo imageInfo() const; 84c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 87210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com /** 88bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org * Trigger the immediate execution of all pending draw operations. 89bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org */ 90bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org void flush(); 91bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org 92bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org /** 93c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * DEPRECATED: call imageInfo() instead. 94210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com * Return the width/height of the underlying device. The current drawable 95210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com * area may be small (due to clipping or saveLayer). For a canvas with 96210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com * no device, 0,0 will be returned. 97210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com */ 98210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com SkISize getDeviceSize() const; 99210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com 100c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 101c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * DEPRECATED. 102c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * Return the canvas' device object, which may be null. The device holds 103c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * the bitmap of the pixels that the canvas draws into. The reference count 104c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * of the returned device is not changed by this call. 105c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 1061f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* getDevice() const; 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1089266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com /** 1099266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * saveLayer() can create another device (which is later drawn onto 1109266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * the previous device). getTopDevice() returns the top-most device current 1119266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * installed. Note that this can change on other calls like save/restore, 1129266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * so do not access this device after subsequent canvas calls. 1139266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com * The reference count of the device is not changed. 1140b53d59a24f667350b4282f88470713902409030reed@google.com * 1150b53d59a24f667350b4282f88470713902409030reed@google.com * @param updateMatrixClip If this is true, then before the device is 1160b53d59a24f667350b4282f88470713902409030reed@google.com * returned, we ensure that its has been notified about the current 1170b53d59a24f667350b4282f88470713902409030reed@google.com * matrix and clip. Note: this happens automatically when the device 1180b53d59a24f667350b4282f88470713902409030reed@google.com * is drawn to, but is optional here, as there is a small perf hit 1190b53d59a24f667350b4282f88470713902409030reed@google.com * sometimes. 1209266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com */ 1211f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const; 1229266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com 12376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com /** 12476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com * Create a new surface matching the specified info, one that attempts to 12576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com * be maximally compatible when used with this canvas. 12676f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com */ 12776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com SkSurface* newSurface(const SkImageInfo&); 128e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 129644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org /** 130644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * Return the GPU context of the device that is associated with the canvas. 131644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org * For a canvas with non-GPU device, NULL is returned. 132644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org */ 133644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org GrContext* getGrContext(); 134644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org 1354b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /////////////////////////////////////////////////////////////////////////// 1364b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 137daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com /** 138c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the canvas has pixels (and is not recording to a picture or other 139c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * non-raster target) and has direct access to its pixels (i.e. they are in 140c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * local RAM) return the const-address of those pixels, and if not null, 141c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * return the ImageInfo and rowBytes. The returned address is only valid 142c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * while the canvas object is in scope and unchanged. Any API calls made on 143c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * canvas (or its parent surface if any) will invalidate the 144c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * returned address (and associated information). 145c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 146c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * On failure, returns NULL and the info and rowBytes parameters are 147c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * ignored. 148c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 149c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* peekPixels(SkImageInfo* info, size_t* rowBytes); 150c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 151c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org /** 152d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * This enum can be used with read/writePixels to perform a pixel ops to or 153d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * from an 8888 config other than Skia's native config (SkPMColor). There 154d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * are three byte orders supported: native, BGRA, and RGBA. Each has a 155d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * premultiplied and unpremultiplied variant. 156d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * 157d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * Components of a 8888 pixel can be packed/unpacked from a 32bit word using 158d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * either byte offsets or shift values. Byte offsets are endian-invariant 159d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * while shifts are not. BGRA and RGBA configs are defined by byte 160d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * orderings. The native config is defined by shift values (SK_A32_SHIFT, 161d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * ..., SK_B32_SHIFT). 1626850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com */ 1636850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com enum Config8888 { 1646850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com /** 1656850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * Skia's native order specified by: 1666850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * SK_A32_SHIFT, SK_R32_SHIFT, SK_G32_SHIFT, and SK_B32_SHIFT 1676850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * 1686850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * kNative_Premul_Config8888 is equivalent to SkPMColor 1696850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * kNative_Unpremul_Config8888 has the same component order as SkPMColor 1706850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * but is not premultiplied. 1716850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com */ 1726850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com kNative_Premul_Config8888, 1736850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com kNative_Unpremul_Config8888, 1746850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com /** 1756850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * low byte to high byte: B, G, R, A. 1766850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com */ 1776850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com kBGRA_Premul_Config8888, 1786850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com kBGRA_Unpremul_Config8888, 1796850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com /** 1806850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * low byte to high byte: R, G, B, A. 1816850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com */ 1826850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com kRGBA_Premul_Config8888, 1831f90287df3129cb267422e482c52ebeca6a8990ftomhudson@google.com kRGBA_Unpremul_Config8888 1846850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com }; 1856850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com 1866850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com /** 187daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * On success (returns true), copy the canvas pixels into the bitmap. 188daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * On failure, the bitmap parameter is left unchanged and false is 189daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * returned. 190daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * 1916850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * The canvas' pixels are converted to the bitmap's config. The only 1926850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * supported config is kARGB_8888_Config, though this is likely to be 1936850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * relaxed in the future. The meaning of config kARGB_8888_Config is 1946850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * modified by the enum param config8888. The default value interprets 1956850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * kARGB_8888_Config as SkPMColor 196daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * 197daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * If the bitmap has pixels already allocated, the canvas pixels will be 19874b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org * written there. If not, bitmap->allocPixels() will be called 199daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * automatically. If the bitmap is backed by a texture readPixels will 200daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * fail. 201daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * 202daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * The actual pixels written is the intersection of the canvas' bounds, and 203daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * the rectangle formed by the bitmap's width,height and the specified x,y. 204daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * If bitmap pixels extend outside of that intersection, they will not be 205daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * modified. 206daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com * 2076850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * Other failure conditions: 2086850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * * If the canvas is backed by a non-raster device (e.g. PDF) then 2096850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * readPixels will fail. 2106850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * * If bitmap is texture-backed then readPixels will fail. (This may be 2116850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * relaxed in the future.) 2126850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * 2136850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * Example that reads the entire canvas into a bitmap using the native 2146850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * SkPMColor: 2156850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * SkISize size = canvas->getDeviceSize(); 2166850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, 2176850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * size.fHeight); 2186850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * if (canvas->readPixels(bitmap, 0, 0)) { 2196850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * // use the pixels 2206850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com * } 221c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com */ 2226850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com bool readPixels(SkBitmap* bitmap, 2236850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com int x, int y, 2246850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com Config8888 config8888 = kNative_Premul_Config8888); 225c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com 2264b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com /** 227c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com * DEPRECATED: This will be removed as soon as webkit is no longer relying 228c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com * on it. The bitmap is resized to the intersection of srcRect and the 229c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com * canvas bounds. New pixels are always allocated on success. Bitmap is 230c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com * unmodified on failure. 23151df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com */ 23251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); 23351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com 23451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com /** 23551df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com * Similar to draw sprite, this method will copy the pixels in bitmap onto 236d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * the canvas, with the top/left corner specified by (x, y). The canvas' 237d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * pixel values are completely replaced: there is no blending. 238d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * 239d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * Currently if bitmap is backed by a texture this is a no-op. This may be 240d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * relaxed in the future. 241d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * 242d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * If the bitmap has config kARGB_8888_Config then the config8888 param 243d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * will determines how the pixel valuess are intepreted. If the bitmap is 244d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com * not kARGB_8888_Config then this parameter is ignored. 2454f1151ab27485aff393d16559086c4c461f137a4epoger@google.com * 2464f1151ab27485aff393d16559086c4c461f137a4epoger@google.com * Note: If you are recording drawing commands on this canvas to 2474f1151ab27485aff393d16559086c4c461f137a4epoger@google.com * SkPicture, writePixels() is ignored! 24851df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com */ 249d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com void writePixels(const SkBitmap& bitmap, 250d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com int x, int y, 251d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com Config8888 config8888 = kNative_Premul_Config8888); 2524b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 2548d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum SaveFlags { 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the matrix state, restoring it on restore() */ 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrix_SaveFlag = 0x01, 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** save the clip state, restoring it on restore() */ 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClip_SaveFlag = 0x02, 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support per-pixel alpha */ 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kHasAlphaLayer_SaveFlag = 0x04, 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer needs to support 8-bits per color component */ 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFullColorLayer_SaveFlag = 0x08, 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** the layer should clip against the bounds argument */ 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kClipToLayer_SaveFlag = 0x10, 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helper masks for common choices 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMatrixClip_SaveFlag = 0x03, 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_NoClipLayer_SaveFlag = 0x0F, 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kARGB_ClipLayer_SaveFlag = 0x1F 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 273dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com /** This call saves the current matrix, clip, and drawFilter, and pushes a 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com copy onto a private stack. Subsequent calls to translate, scale, 275dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com rotate, skew, concat or clipRect, clipPath, and setDrawFilter all 276dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com operate on this copy. 277dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com When the balancing call to restore() is made, the previous matrix, clip, 278dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com and drawFilter are restored. 279d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com @param flags The flags govern what portion of the Matrix/Clip/drawFilter 280d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com state the save (and matching restore) effect. For example, 281d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com if only kMatrix is specified, then only the matrix state 282d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com will be pushed and popped. Likewise for the clip if kClip 283d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com is specified. However, the drawFilter is always affected 284d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com by calls to save/restore. 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual int save(SaveFlags flags = kMatrixClip_SaveFlag); 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 292dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 293ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 294ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com limit the size of the offscreen, and thus drawing may be 295ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com clipped to it, though that clipping is not guaranteed to 296ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com happen. If exact clipping is desired, use clipRect(). 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint (may be null) This is copied, and is applied to the 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen when restore() is called 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual int saveLayer(const SkRect* bounds, const SkPaint* paint, 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SaveFlags flags = kARGB_ClipLayer_SaveFlag); 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This behaves the same as save(), but in addition it allocates an 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offscreen bitmap. All drawing calls are directed there, and only when 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the balancing call to restore() is made is that offscreen transfered to 308dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com the canvas (or the previous layer). 30940408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com @param bounds (may be null) This rect, if non-null, is used as a hint to 31040408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com limit the size of the offscreen, and thus drawing may be 31140408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com clipped to it, though that clipping is not guaranteed to 31240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com happen. If exact clipping is desired, use clipRect(). 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param alpha This is applied to the offscreen when restore() is called. 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param flags LayerFlags 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The value to pass to restoreToCount() to balance this save() 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SaveFlags flags = kARGB_ClipLayer_SaveFlag); 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** This call balances a previous call to save(), and is used to remove all 321dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com modifications to the matrix/clip/drawFilter state since the last save 322dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com call. 323dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com It is an error to call restore() more times than save() was called. 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void restore(); 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of matrix/clip states on the SkCanvas' private stack. 328ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org This will equal # save() calls - # restore() calls + 1. The save count on 329ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org a new canvas is 1. 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 331a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org int getSaveCount() const; 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Efficient way to pop any calls to save() that happened after the save 334ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org count reached saveCount. It is an error for saveCount to be greater than 335ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org getSaveCount(). To pop all the way back to the initial matrix/clip context 336ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org pass saveCount == 1. 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param saveCount The number of save() levels to restore from 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void restoreToCount(int saveCount); 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3417c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com /** Returns true if drawing is currently going to a layer (from saveLayer) 3427c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com * rather than to the root device. 3437c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com */ 3448f9ecbd3466d4330886b4c23b06e75b468c795adjunov@chromium.org virtual bool isDrawingToLayer() const; 3457c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified translation 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The distance to translate in X 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The distance to translate in Y 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool translate(SkScalar dx, SkScalar dy); 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified scale. 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to scale in X 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to scale in Y 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool scale(SkScalar sx, SkScalar sy); 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified rotation. 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param degrees The amount to rotate, in degrees 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool rotate(SkScalar degrees); 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified skew. 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sx The amount to skew in X 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sy The amount to skew in Y 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true if the operation succeeded (e.g. did not overflow) 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool skew(SkScalar sx, SkScalar sy); 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Preconcat the current matrix with the specified matrix. 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to preconcatenate with the current matrix 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the operation succeeded (e.g. did not overflow) 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool concat(const SkMatrix& matrix); 3784b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Replace the current matrix with a copy of the specified matrix. 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix that will be copied into the current matrix. 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void setMatrix(const SkMatrix& matrix); 3834b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for setMatrix(identity). Sets the current matrix to identity. 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetMatrix(); 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3884ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 3894ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified rectangle. 3904ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rect The rect to combine with the current clip 3914ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 3924ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 3934ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @return true if the canvas' clip is non-empty 3944ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipRect(const SkRect& rect, 396071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com SkRegion::Op op = SkRegion::kIntersect_Op, 397071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com bool doAntiAlias = false); 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3994ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4004ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified SkRRect. 4014ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The rrect to combine with the current clip 4024ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4034ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4044ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @return true if the canvas' clip is non-empty 4054ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 4064ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com virtual bool clipRRect(const SkRRect& rrect, 4074ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com SkRegion::Op op = SkRegion::kIntersect_Op, 4084ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com bool doAntiAlias = false); 4094ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 4104ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 4114ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Modify the current clip with the specified path. 4124ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param path The path to combine with the current clip 4134ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param op The region op to apply to the current clip 4144ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param doAntiAlias true if the clip should be antialiased 4154ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @return true if the canvas' new clip is non-empty 4164ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipPath(const SkPath& path, 418071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com SkRegion::Op op = SkRegion::kIntersect_Op, 419071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com bool doAntiAlias = false); 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4218f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com /** EXPERIMENTAL -- only used for testing 4228f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com Set to false to force clips to be hard, even if doAntiAlias=true is 4238f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com passed to clipRect or clipPath. 4248f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com */ 4258f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com void setAllowSoftClip(bool allow) { 4268f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com fAllowSoftClip = allow; 4278f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com } 4288f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com 42945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com /** EXPERIMENTAL -- only used for testing 43045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com Set to simplify clip stack using path ops. 43145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com */ 43245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com void setAllowSimplifyClip(bool allow) { 43345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com fAllowSimplifyClip = allow; 43445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com } 43545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Modify the current clip with the specified region. Note that unlike 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRect() and clipPath() which transform their arguments by the current 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix, clipRegion() assumes its argument is already in device 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinates, and so no transformation is performed. 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to apply to the current clip 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param op The region op to apply to the current clip 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the canvas' new clip is non-empty 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool clipRegion(const SkRegion& deviceRgn, 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Op op = SkRegion::kIntersect_Op); 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified region. This does not intersect or in any other way account 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for the existing clip region. 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param deviceRgn The region to copy into the current clip. 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the new clip region is non-empty 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setClipRegion(const SkRegion& deviceRgn) { 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->clipRegion(deviceRgn, SkRegion::kReplace_Op); 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified rectangle, after being transformed by the 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect the rect to compare with the current clip 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the rect (transformed by the canvas' matrix) does not 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4653b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkRect& rect) const; 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the specified path, after being transformed by the 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current matrix, would lie completely outside of the current clip. Call 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this to check if an area you intend to draw into is clipped out (and 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com therefore you can skip making the draw calls). Note, for speed it may 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false even if the path itself might not intersect the clip 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (i.e. the bounds of the path intersects, but the path does not). 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to compare with the current clip 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path (transformed by the canvas' matrix) does not 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com intersect with the canvas' clip 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4773b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickReject(const SkPath& path) const; 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the horizontal band specified by top and bottom is 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely clipped out. This is a conservative calculation, meaning 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that it is possible that if the method returns false, the band may still 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in fact be clipped out, but the converse is not true. If this method 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true, then the band is guaranteed to be clipped out. 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top of the horizontal band to compare with the clip 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom of the horizontal and to compare with the clip 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the horizontal band is completely clipped out (i.e. does 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not intersect the current clip) 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4893b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool quickRejectY(SkScalar top, SkScalar bottom) const { 490c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com SkASSERT(top <= bottom); 4919836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 4929836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT 4939836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // TODO: add a hasPerspective method similar to getLocalClipBounds. This 4949836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // would cache the SkMatrix::hasPerspective result. Alternatively, have 4959836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // the MC stack just set a hasPerspective boolean as it is updated. 4969836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org if (this->getTotalMatrix().hasPerspective()) { 497a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com // TODO: consider implementing some half-plane test between the 4989836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // two Y planes and the device-bounds (i.e., project the top and 4999836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // bottom Y planes and then determine if the clip bounds is completely 5009836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org // outside either one). 5019836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org return false; 5029836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org } 5039836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif 5049836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org 505c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& clipR = this->getLocalClipBounds(); 50692d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // In the case where the clip is empty and we are provided with a 50792d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // negative top and positive bottom parameter then this test will return 50892d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // false even though it will be clipped. We have chosen to exclude that 50992d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com // check as it is rare and would result double the comparisons. 510c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return top >= clipR.fBottom || bottom <= clipR.fTop; 51192d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com } 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the bounds of the current clip (in local coordinates) in the 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds parameter, and return true if it is non-empty. This can be useful 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in a way similar to quickReject, in that it tells you that drawing 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com outside of these bounds will be clipped out. 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5183b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com bool getClipBounds(SkRect* bounds) const; 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 520bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com /** Return the bounds of the current clip, in device coordinates; returns 521bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com true if non-empty. Maybe faster than getting the clip explicitly and 522bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com then taking its bounds. 523bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com */ 524bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com bool getClipDeviceBounds(SkIRect* bounds) const; 52574b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org 526bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 528845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified ARGB color, using the specified mode. 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param a the alpha component (0..255) of the color to fill the canvas 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param r the red component (0..255) of the color to fill the canvas 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param g the green component (0..255) of the color to fill the canvas 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param b the blue component (0..255) of the color to fill the canvas 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, 536845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Fill the entire canvas' bitmap (restricted to the current clip) with the 539845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com specified color and mode. 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color the color to draw with 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode the mode to apply the color in (defaults to SrcOver) 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawColor(SkColor color, 544845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode); 5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5462a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com /** 5472a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * This erases the entire drawing surface to the specified color, 5482a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * irrespective of the clip. It does not blend with the previous pixels, 5492a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * but always overwrites them. 5502a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * 5512a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * It is roughly equivalent to the following: 5522a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.save(); 5532a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.clipRect(hugeRect, kReplace_Op); 5542a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * paint.setColor(color); 5552a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * paint.setXfermodeMode(kSrc_Mode); 5562a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.drawPaint(paint); 5572a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * canvas.restore(); 5582a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * though it is almost always much more efficient. 5592a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com */ 5602a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com virtual void clear(SkColor); 5612a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com 5622a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com /** 5632a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * Fill the entire canvas' bitmap (restricted to the current clip) with the 5642a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * specified paint. 5652a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com * @param paint The paint used to fill the canvas 5662a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com */ 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPaint(const SkPaint& paint); 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum PointMode { 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each point separately */ 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPoints_PointMode, 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws each pair of points as a line segment */ 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLines_PointMode, 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** drawPoints draws the array of points as a polygon */ 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPolygon_PointMode 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a series of points, interpreted based on the PointMode mode. For 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com all modes, the count parameter is interpreted as the total number of 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com points. For kLine mode, count/2 line segments are drawn. 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPoint mode, each point is drawn centered at its coordinate, and its 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size is specified by the paint's stroke-width. It draws as a square, 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unless the paint's cap-type is round, in which the points are drawn as 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com circles. 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kLine mode, each pair of points is drawn as a line segment, 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com respecting the paint's settings for cap/join/width. 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com For kPolygon mode, the entire array is drawn as a series of connected 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line segments. 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Note that, while similar, kLine and kPolygon modes draw slightly 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com differently than the equivalent path built with a series of moveto, 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com lineto calls, in that the path will draw all of its contours at once, 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with no interactions if contours intersect each other (think XOR 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xfermode). drawPoints always draws each element one at a time. 5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param mode PointMode specifying how to draw the array of points. 5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param count The number of points in the array 5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts Array of points to draw 5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the points 5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper method for drawing a single point. See drawPoints() for a more 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com details. 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); 6064b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draws a single pixel in the specified color. 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The X coordinate of which pixel to draw 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The Y coordiante of which pixel to draw 6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param color The color to draw 6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawPoint(SkScalar x, SkScalar y, SkColor color); 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw a line segment with the specified start and stop x,y coordinates, 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com using the specified paint. NOTE: since a line is always "framed", the 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint's Style is ignored. 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x0 The x-coordinate of the start point of the line 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y0 The y-coordinate of the start point of the line 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the end point of the line 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the end point of the line 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the line 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or stroked based on the Style in the paint. 6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6317ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com virtual void drawRect(const SkRect& rect, const SkPaint& paint); 6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rect to be drawn 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 63887001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com void drawIRect(const SkIRect& rect, const SkPaint& paint) { 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(rect); // promotes the ints to scalars 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawRect(r, paint); 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6434b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified rectangle using the specified paint. The rectangle 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The left side of the rectangle to be drawn 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The top side of the rectangle to be drawn 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param right The right side of the rectangle to be drawn 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bottom The bottom side of the rectangle to be drawn 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the rect 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRectCoords(SkScalar left, SkScalar top, SkScalar right, 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar bottom, const SkPaint& paint); 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified oval using the specified paint. The oval will be 6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The rectangle bounds of the oval to be drawn 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the oval 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6604ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com virtual void drawOval(const SkRect& oval, const SkPaint&); 6614ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 6624ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 6634ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * Draw the specified RRect using the specified paint The rrect will be filled or stroked 6644ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * based on the Style in the paint. 6654ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * 6664ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param rrect The round-rect to draw 6674ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com * @param paint The paint used to draw the round-rect 6684ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 6694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint); 6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 671ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org /** 672ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * Draw the annulus formed by the outer and inner rrects. The results 673ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * are undefined if the outer does not contain the inner. 674ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org */ 675ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&); 676ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified circle using the specified paint. If radius is <= 0, 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com then nothing will be drawn. The circle will be filled 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com or framed based on the Style in the paint. 6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cx The x-coordinate of the center of the cirle to be drawn 6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param cy The y-coordinate of the center of the cirle to be drawn 6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param radius The radius of the cirle to be drawn 6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the circle 6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, 6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified arc, which will be scaled to fit inside the 6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified oval. If the sweep angle is >= 360, then the oval is drawn 6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com completely. Note that this differs slightly from SkPath::arcTo, which 6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com treats the sweep angle mod 360. 6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the shape of the arc 6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param useCenter true means include the center of the oval. For filling 6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this will draw a wedge. False means just use the arc. 6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the arc 6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, 7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool useCenter, const SkPaint& paint); 7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified round-rect using the specified paint. The round-rect 7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will be filled or framed based on the Style in the paint. 7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rect The rectangular bounds of the roundRect to be drawn 7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param rx The x-radius of the oval used to round the corners 7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ry The y-radius of the oval used to round the corners 7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the roundRect 7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified path using the specified paint. The path will be 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com filled or framed based on the Style in the paint. 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path to be drawn 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the path 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7177ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com virtual void drawPath(const SkPath& path, const SkPaint& paint); 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), using the 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com specified paint, transformed by the current matrix. Note: if the paint 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 72591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 72691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org If a shader is present on the paint it will be ignored, except in the 72791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org case where the bitmap is kA8_Config. In that case, the color is 72891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org generated by the shader. 72991246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 738eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org enum DrawBitmapRectFlags { 73931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kNone_DrawBitmapRectFlag = 0x0, 7407475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com /** 741eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * When filtering is enabled, allow the color samples outside of 7427475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com * the src rect (but still in the src bitmap) to bleed into the 743eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org * drawn portion 744eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org */ 74531acc11977815402e4ef2681350f8559285bec97robertphillips@google.com kBleed_DrawBitmapRectFlag = 0x1, 746eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org }; 747eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with the specified matrix applied (before the 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas' matrix is applied). 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src Optional: specify the subset of the bitmap to be drawn 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The destination rectangle where the scaled/translated 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com image will be drawn 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7567112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 7577112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com const SkRect& dst, 758eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkPaint* paint = NULL, 75931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag); 7607112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com 7617112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, 762eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkPaint* paint = NULL) { 76331acc11977815402e4ef2681350f8559285bec97robertphillips@google.com this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag); 7647112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7667112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc, 767eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint = NULL, 76831acc11977815402e4ef2681350f8559285bec97robertphillips@google.com DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) { 7697112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect realSrcStorage; 7707112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com SkRect* realSrcPtr = NULL; 7717112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com if (isrc) { 7727112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcStorage.set(*isrc); 7737112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com realSrcPtr = &realSrcStorage; 7747112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 775eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags); 7767112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com } 777c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 7804b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 781f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com /** 782f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Draw the bitmap stretched differentially to fit into dst. 783f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * center is a rect within the bitmap, and logically divides the bitmap 784f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * into 9 sections (3x3). For example, if the middle pixel of a [5x5] 785f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * bitmap is the "center", then the center-rect should be [2, 2, 3, 3]. 786f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * 787f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * If the dst is >= the bitmap size, then... 7889bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The 4 corners are not stretched at all. 7899bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The sides are stretched in only one axis. 7909bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com * - The center is stretched in both axes. 791f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * Else, for each axis where dst < bitmap, 792f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The corners shrink proportionally 793f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com * - The sides (along the shrink axis) and center are not drawn 794f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com */ 795f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 796f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com const SkRect& dst, const SkPaint* paint = NULL); 797f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the specified bitmap, with its top/left corner at (x,y), 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com NOT transformed by the current matrix. Note: if the paint 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contains a maskfilter that generates a mask which extends beyond the 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap's original width/height, then the bitmap will be drawn as if it 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com were in a Shader with CLAMP mode. Thus the color outside of the original 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com width/height will be the edge color replicated. 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bitmap The bitmap to be drawn 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param left The position of the left side of the bitmap being drawn 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param top The position of the top side of the bitmap being drawn 8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used to draw the bitmap, or NULL 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* paint = NULL); 8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint. 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The origin is interpreted based on the Align setting in the paint. 8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the origin of the text being drawn 8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the origin of the text being drawn 8188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 8198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawText(const void* text, size_t byteLength, SkScalar x, 8218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar y, const SkPaint& paint); 8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the pos[] 8244b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com array. The origin is interpreted by the Align setting in the paint. 8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 8278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pos Array of positions, used to position each character 8288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 8298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPosText(const void* text, size_t byteLength, 8318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint pos[], const SkPaint& paint); 8324b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 8338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with each character/glyph origin specified by the x 8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinate taken from the xpos[] array, and the y from the constY param. 8354b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com The origin is interpreted by the Align setting in the paint. 8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 8378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xpos Array of x-positions, used to position each character 8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param constY The shared Y coordinate for all of the positions 8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text (e.g. color, size, style) 8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPosTextH(const void* text, size_t byteLength, 8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar xpos[], SkScalar constY, 8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 8454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 8498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 8508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 8518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 8528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param hOffset The distance along the path to add to the text's 8538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com starting position 8548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vOffset The distance above(-) or below(+) the path to 8558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com position the text 8568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 8578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void drawTextOnPathHV(const void* text, size_t byteLength, 8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, SkScalar hOffset, 8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar vOffset, const SkPaint& paint); 8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the text, with origin at (x,y), using the specified paint, along 8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the specified path. The paint's Align setting determins where along the 8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to start the text. 8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param text The text to be drawn 8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param byteLength The number of bytes to read from the text parameter 8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param path The path the text should follow for its baseline 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix (may be null) Applied to the text before it is 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mapped onto the path 8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param paint The paint used for the text 8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawTextOnPath(const void* text, size_t byteLength, 8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& path, const SkMatrix* matrix, 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the picture into this canvas. This method effective brackets the 8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com playback of the picture's draw calls with save/restore, so the state 878a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com of this canvas will be unchanged after this call. 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param picture The recorded drawing commands to playback into this 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com canvas. 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawPicture(SkPicture& picture); 8834b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum VertexMode { 8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangles_VertexMode, 8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleStrip_VertexMode, 8878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kTriangleFan_VertexMode 8888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 8894b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Draw the array of vertices, interpreted as triangles (based on mode). 8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vmode How to interpret the array of vertices 8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertexCount The number of points in the vertices array (and 8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com corresponding texs and colors arrays if non-null) 8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param vertices Array of vertices for the mesh 8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param texs May be null. If not null, specifies the coordinate 896631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com in _texture_ space (not uv space) for each vertex. 8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param colors May be null. If not null, specifies a color for each 8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex, to be interpolated across the triangle. 8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param xmode Used if both texs and colors are present. In this 9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case the colors are combined with the texture using mode, 9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com before being drawn using the paint. If mode is null, then 9028d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com kModulate_Mode is used. 9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indices If not null, array of indices to reference into the 9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com vertex (texs, colors) array. 9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param indexCount number of entries in the indices array (if not null) 9064b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com @param paint Specifies the shader/texture if present. 9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void drawVertices(VertexMode vmode, int vertexCount, 9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint texs[], 9108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint); 9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 914cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com /** Send a blob of data to the canvas. 915cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com For canvases that draw, this call is effectively a no-op, as the data 916cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com is not parsed, but just ignored. However, this call exists for 917cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com subclasses like SkPicture's recording canvas, that can store the data 918cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com and then play it back later (via another call to drawData). 919cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com */ 9200a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void drawData(const void* data, size_t length) { 9210a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something with the data 9220a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 9230a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 924a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com /** Add comments. beginCommentGroup/endCommentGroup open/close a new group. 925a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com Each comment added via addComment is notionally attached to its 9260a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com enclosing group. Top-level comments simply belong to no group. 9270a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */ 9280a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void beginCommentGroup(const char* description) { 9290a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 9300a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 9310a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void addComment(const char* kywd, const char* value) { 9320a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 9330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 9340a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com virtual void endCommentGroup() { 9350a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com // do nothing. Subclasses may do something 9360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 9370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 938cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 9404b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current bounder object. 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The bounder's reference count is unchaged. 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canva's bounder (or NULL). 9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBounder* getBounder() const { return fBounder; } 9468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set a new bounder (or NULL). 9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Pass NULL to clear any previous bounder. 9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter passed is also returned. 9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If a previous bounder exists, its reference count is decremented. 9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If bounder is not NULL, its reference count is incremented. 9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param bounder the new bounder (or NULL) to be installed in the canvas 9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the set bounder object 9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkBounder* setBounder(SkBounder* bounder); 9564b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Get the current filter object. The filter's reference count is not 958dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com affected. The filter is saved/restored, just like the matrix and clip. 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the canvas' filter (or NULL). 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawFilter* getDrawFilter() const; 9624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the new filter (or NULL). Pass NULL to clear any existing filter. 9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com As a convenience, the parameter is returned. If an existing filter 9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com exists, its refcnt is decrement. If the new filter is not null, its 966dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com refcnt is incremented. The filter is saved/restored, just like the 967dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com matrix and clip. 9688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param filter the new filter (or NULL) 9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the new filter 9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); 9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ////////////////////////////////////////////////////////////////////////// 9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 975754de5f65b466f721d952a379194cc94de376f42reed@google.com /** 976754de5f65b466f721d952a379194cc94de376f42reed@google.com * Return true if the current clip is empty (i.e. nothing will draw). 977754de5f65b466f721d952a379194cc94de376f42reed@google.com * Note: this is not always a free call, so it should not be used 978754de5f65b466f721d952a379194cc94de376f42reed@google.com * more often than necessary. However, once the canvas has computed this 979754de5f65b466f721d952a379194cc94de376f42reed@google.com * result, subsequent calls will be cheap (until the clip state changes, 980754de5f65b466f721d952a379194cc94de376f42reed@google.com * which can happen on any clip..() or restore() call. 981754de5f65b466f721d952a379194cc94de376f42reed@google.com */ 982754de5f65b466f721d952a379194cc94de376f42reed@google.com bool isClipEmpty() const; 983754de5f65b466f721d952a379194cc94de376f42reed@google.com 9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the current matrix on the canvas. 9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This does not account for the translate in any of the devices. 9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The current matrix on the canvas. 9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 988a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org const SkMatrix& getTotalMatrix() const; 9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 990bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com enum ClipType { 991bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kEmpty_ClipType = 0, 992bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kRect_ClipType, 993bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com kComplex_ClipType 994bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com }; 995bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 996bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com /** Returns a description of the total clip; may be cheaper than 997bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com getting the clip and querying it directly. 998bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com */ 999bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com ClipType getClipType() const; 1000bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com 10014469938e92d779dff05e745559e67907bbf21e78reed@google.com /** DEPRECATED -- need to move this guy to private/friend 10024469938e92d779dff05e745559e67907bbf21e78reed@google.com * Return the current device clip (concatenation of all clip calls). 1003a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com * This does not account for the translate in any of the devices. 1004a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com * @return the current device clip (concatenation of all clip calls). 10055e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com */ 1006a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com const SkRegion& getTotalClip() const; 10075e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com 100840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com /** Return the clip stack. The clip stack stores all the individual 100940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * clips organized by the save/restore frame in which they were 101040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * added. 101140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com * @return the current clip stack ("list" of individual clip elements) 101240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com */ 101340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com const SkClipStack* getClipStack() const { 101440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com return &fClipStack; 101540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com } 101640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com 101790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com class ClipVisitor { 101890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com public: 101920a550c6ea947f0ab239da1d4ecba209d76a98fdjustinlin@google.com virtual ~ClipVisitor(); 102090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1021e5b2af955b7d06815ddd405659ad62a2a8355ca3commit-bot@chromium.org virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 102290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 102390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com }; 102490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com 10255e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com /** 102690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * Replays the clip operations, back to front, that have been applied to 102790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * the canvas, calling the appropriate method on the visitor for each 102890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com * clip. All clips have already been transformed into device space. 10297d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com */ 103090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com void replayClips(ClipVisitor*) const; 10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /////////////////////////////////////////////////////////////////////////// 10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After calling saveLayer(), there can be any number of devices that make 10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com up the top-most drawing area. LayerIter can be used to iterate through 10368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com those devices. Note that the iterator is only valid until the next API 10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call made on the canvas. Ownership of all pointers in the iterator stays 10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the canvas, so none of them should be modified or deleted. 10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10407ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org class SK_API LayerIter /*: SkNoncopyable*/ { 10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Initialize iterator with canvas, and set values for 1st device */ 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com LayerIter(SkCanvas*, bool skipEmptyClips); 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~LayerIter(); 10454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return true if the iterator is done */ 10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool done() const { return fDone; } 10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Cycle to the next device */ 10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void next(); 10504b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // These reflect the current device in the iterator 10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10531f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* device() const; 10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix() const; 10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion& clip() const; 10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint() const; 10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x() const; 10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y() const; 10594b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 10608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // used to embed the SkDrawIter object directly in our instance, w/o 10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // having to expose that class def to the public. There is an assert 10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // in our constructor to ensure that fStorage is large enough 10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (though needs to be a compile-time-assert!). We use intptr_t to work 10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // safely with 32 and 64 bit machines (to ensure the storage is enough) 1066f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com intptr_t fStorage[32]; 10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class SkDrawIter* fImpl; // this points at fStorage 10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint fDefaultPaint; 10698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDone; 10708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 107376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com // default impl defers to getDevice()->newSurface(info) 107476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com virtual SkSurface* onNewSurface(const SkImageInfo&); 107576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com 1076c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // default impl defers to its device 1077c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes); 1078c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1079ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); 1080ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 108174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org // Returns the canvas to be used by DrawIter. Default implementation 10824370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // returns this. Subclasses that encapsulate an indirect canvas may 10834370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // need to overload this method. The impl must keep track of this, as it 10844370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com // is not released or deleted by the caller. 10854370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com virtual SkCanvas* canvasForDrawIter(); 10864370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com 1087a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // Clip rectangle bounds. Called internally by saveLayer. 1088a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org // returns false if the entire rectangle is entirely clipped out 1089c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // If non-NULL, The imageFilter parameter will be used to expand the clip 1090c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org // and offscreen bounds for any margin required by the filter DAG. 1091a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org bool clipRectBounds(const SkRect* bounds, SaveFlags flags, 1092c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org SkIRect* intersection, 1093c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org const SkImageFilter* imageFilter = NULL); 1094a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org 1095ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org // Called by child classes that override clipPath and clipRRect to only 1096ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org // track fast conservative clip bounds, rather than exact clips. 1097ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org bool updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op, 1098ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org bool inverseFilled); 1099ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org 110097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // notify our surface (if we have one) that we are about to draw, so it 110197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com // can perform copy-on-write or invalidate any cached images 110297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void predrawNotify(); 110397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com 11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 11058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class MCRec; 11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11075c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com SkClipStack fClipStack; 11088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDeque fMCStack; 11098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // points to top of stack 11108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MCRec* fMCRec; 11118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the first N recs that can fit here mean we won't call malloc 11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fMCRecStorage[32]; 11138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBounder* fBounder; 1115b0a7ace7cb2a7559bbc254a7c93698bc71bbd245junov@chromium.org int fSaveLayerCount; // number of successful saveLayer calls 11168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 111774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org SkMetaData* fMetaData; 111874bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org 111997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* fSurfaceBase; 112097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } 112197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com void setSurfaceBase(SkSurface_Base* sb) { 112297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com fSurfaceBase = sb; 112397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com } 112497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com friend class SkSurface_Base; 112545c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org friend class SkSurface_Gpu; 1126fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com 11278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fDeviceCMDirty; // cleared by updateDeviceCMCache() 11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void updateDeviceCMCache(); 11298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkDrawIter; // needs setupDrawForLayerDevice() 11318926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com friend class AutoDrawLooper; 11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 113315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkBaseDevice* createLayerDevice(const SkImageInfo&); 1134e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com 11351f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBaseDevice* init(SkBaseDevice*); 1136f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com 1137403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org /** 1138403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * DEPRECATED 1139403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * 1140403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * Specify a device for this canvas to draw into. If it is not null, its 1141403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * reference count is incremented. If the canvas was already holding a 1142403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org * device, its reference count is decremented. The new device is returned. 1143403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org */ 1144403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org SkBaseDevice* setRootDevice(SkBaseDevice* device); 114531acdeabce094e9d42f0d6db8eebcf788aaba11askia.committer@gmail.com 1146403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org 1147f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // internal methods are not virtual, so they can safely be called by other 1148f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com // canvas apis, without confusing subclasses (like SkPictureRecording) 11499bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint); 11507112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1151eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org const SkRect& dst, const SkPaint* paint, 1152eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org DrawBitmapRectFlags flags); 1153f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 1154f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com const SkRect& dst, const SkPaint* paint); 1155fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com void internalDrawPaint(const SkPaint& paint); 11568926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com int internalSaveLayer(const SkRect* bounds, const SkPaint* paint, 11578926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com SaveFlags, bool justForImageFilter); 11581f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); 1159fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com 11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // shared by save() and saveLayer() 11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int internalSave(SaveFlags flags); 11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void internalRestore(); 116352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawRect(const SkDraw& draw, const SkPaint& paint, 116452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const SkRect& r, SkScalar textSize); 116552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, 116652c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com const char text[], size_t byteLength, 116752c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkScalar x, SkScalar y); 11684b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com 11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* These maintain a cache of the clip bounds in local coordinates, 11708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (converted to 2s-compliment if floats are slow). 11718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1172c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable SkRect fCachedLocalClipBounds; 1173c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com mutable bool fCachedLocalClipBoundsDirty; 11748f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com bool fAllowSoftClip; 117545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com bool fAllowSimplifyClip; 11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1177c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com const SkRect& getLocalClipBounds() const { 1178c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (fCachedLocalClipBoundsDirty) { 1179c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com if (!this->getClipBounds(&fCachedLocalClipBounds)) { 1180c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBounds.setEmpty(); 1181c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com } 1182c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com fCachedLocalClipBoundsDirty = false; 11838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1184c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com return fCachedLocalClipBounds; 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 118645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com 11875c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com class AutoValidateClip : ::SkNoncopyable { 11885c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com public: 11895c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { 11905c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com fCanvas->validateClip(); 11915c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com } 11925c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com ~AutoValidateClip() { fCanvas->validateClip(); } 11935c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 11945c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com private: 11955c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com const SkCanvas* fCanvas; 11965c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com }; 11975c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com 11985c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG 11995c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const; 12005c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else 12015c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com void validateClip() const {} 12025c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif 120315e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com 120415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com typedef SkRefCnt INHERITED; 12058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas 12088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com when this object goes out of scope. Use this to guarantee that the canvas 12098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is restored to a known state. 12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable { 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 12132887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) { 12142887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (fCanvas) { 12152887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org fSaveCount = canvas->getSaveCount(); 12162887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org if (doSave) { 12172887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org canvas->save(); 12182887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org } 12198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoCanvasRestore() { 1222f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1223f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1224f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1225f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 1226f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com 1227f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com /** 1228f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * Perform the restore now, instead of waiting for the destructor. Will 1229f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com * only do this once. 1230f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com */ 1231f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com void restore() { 1232f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com if (fCanvas) { 1233f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas->restoreToCount(fSaveCount); 1234f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com fCanvas = NULL; 1235f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com } 12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas* fCanvas; 12408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fSaveCount; 12418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1242e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) 12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com/** Stack helper class to automatically open and close a comment block 12450a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */ 12460a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comclass SkAutoCommentBlock : SkNoncopyable { 12470a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.compublic: 12480a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com SkAutoCommentBlock(SkCanvas* canvas, const char* description) { 12490a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas = canvas; 12500a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com if (NULL != fCanvas) { 12510a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas->beginCommentGroup(description); 12520a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 12530a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 12540a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 12550a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com ~SkAutoCommentBlock() { 12560a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com if (NULL != fCanvas) { 12570a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com fCanvas->endCommentGroup(); 12580a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 12590a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com } 12600a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 12610a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comprivate: 12620a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com SkCanvas* fCanvas; 12630a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com}; 1264e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) 12650a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com 1266c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/** 1267c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the caller wants read-only access to the pixels in a canvas, it can just 1268c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * call canvas->peekPixels(), since that is the fastest way to "peek" at the 1269c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * pixels on a raster-backed canvas. 1270c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1271c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * If the canvas has pixels, but they are not readily available to the CPU 1272c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will 1273c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * succeed (though be slower, since it will return a copy of the pixels). 1274c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1275c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * SkAutoROCanvasPixels encapsulates these two techniques, trying first to call 1276c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * peekPixels() (for performance), but if that fails, calling readPixels() and 1277c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * storing the copy locally. 1278c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * 1279c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * The caller must respect the restrictions associated with peekPixels(), since 1280c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * that may have been called: The returned information is invalidated if... 1281c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - any API is called on the canvas (or its parent surface if present) 1282c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org * - the canvas goes out of scope 1283c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */ 1284c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable { 1285c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic: 1286c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkAutoROCanvasPixels(SkCanvas* canvas); 1287c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1288c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // returns NULL on failure 1289c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* addr() const { return fAddr; } 129002d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1291c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1292c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t rowBytes() const { return fRowBytes; } 129302d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 1294c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // undefined if addr() == NULL 1295c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const SkImageInfo& info() const { return fInfo; } 1296c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1297c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // helper that, if returns true, installs the pixels into the bitmap. Note 1298c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // that the bitmap may reference the address returned by peekPixels(), so 1299c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org // the caller must respect the restrictions associated with peekPixels(). 1300c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org bool asROBitmap(SkBitmap*) const; 1301c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 1302c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate: 1303c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkBitmap fBitmap; // used if peekPixels() fails 1304c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org const void* fAddr; // NULL on failure 1305c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkImageInfo fInfo; 1306c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org size_t fRowBytes; 1307c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org}; 1308c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 13098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1310