SkCanvas.h revision fbfa25802709139c2f14e304319c9541da65ca27
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"
14e8597a4dd07d78eb0e7a45d6502896c1b9a8bfebmsarett#include "SkImage.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
184a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h"
19845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h"
2095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#include "SkLights.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
22d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass GrContext;
23175dd9b5e3d7d749738dac743d2ac360b5340187robertphillipsclass GrDrawContext;
241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
256a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor;
26d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkClipStack;
27f70b531daaf47db1ee95c70da9843f1dd1f418d3reedclass SkData;
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
293cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
31d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkImageFilter;
3274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
33d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPath;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
35d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPixmap;
361e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreedclass SkRasterClip;
374ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
3871c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform;
3976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
4100d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
42fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
587ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt {
59bada1885da479d948f065182d6dfa85a1140bda5reed    enum PrivateSaveLayerFlags {
60952538ed50661ad7dff6ec2b7af3f921e1d91b52caryclark        kDontClipToLayer_PrivateSaveLayerFlag   = 1U << 31,
61bada1885da479d948f065182d6dfa85a1140bda5reed    };
62bada1885da479d948f065182d6dfa85a1140bda5reed
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
64e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
6542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
6642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
6742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
6842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
6942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
7042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
7142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
7242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
7344977485bdac75c055c3fa638f118874ccd2d22freed     *      - kUnknown_SkAlphaType
7442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
7542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
7742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
7842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
7942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
8042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
8142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
8242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org        return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
8342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    }
8442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
8542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
86e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
87e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
88e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
89cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
908d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
91e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
92e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
93e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
94e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
95e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
9696a857ef5a40b3d0751ec9ebaaa96d9f20b82b21reed    SkCanvas(int width, int height, const SkSurfaceProps* = NULL);
97e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
986dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
99e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1008d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
1018d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
1021f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
1038d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
1044469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
1093d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1103d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    /** Construct a canvas with the specified bitmap to draw into.
1113d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1123d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita                        structure are copied to the canvas.
1133d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param props    New canvas surface properties.
1143d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    */
1153d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
1163d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11974bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
12074bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
121c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
122c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
123c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
124c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
125c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
126c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
127898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    /**
128898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps
129898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  for the canvas to the location supplied by the caller, and returns true. Otherwise,
130898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  return false and leave the supplied props unchanged.
131898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     */
132898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    bool getProps(SkSurfaceProps*) const;
133898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
136210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
137e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  Trigger the immediate execution of all pending draw operations. For the GPU
138e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  backend this will resolve all rendering to the GPU surface backing the
139e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  SkSurface that owns this canvas.
140bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
141bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
142bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
143bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1444ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1454ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1464ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
147210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
14868260fa1e913cb1f1f4f07755acd11357a47dc6ftomhudson    virtual SkISize getBaseLayerSize() const;
1494ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1504ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1514ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1524ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1534ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
154210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
155c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
156c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
157c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
158c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
159c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
160c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
16152d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#ifndef SK_SUPPORT_LEGACY_GETDEVICE
16252d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedprotected:  // Can we make this private?
16352d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#endif
1641f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
16552d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedpublic:
16641e010cb901c0da9066c4df562030808c9ccd7f8reed    SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing() const {
16741e010cb901c0da9066c4df562030808c9ccd7f8reed        return this->getDevice();
16841e010cb901c0da9066c4df562030808c9ccd7f8reed    }
1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1709266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1719266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1729266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1739266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1749266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1759266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
1760b53d59a24f667350b4282f88470713902409030reed@google.com     *
1770b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
1780b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
1790b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
1800b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
1810b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1829266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1839c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
1849c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
1859c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
1861f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
1879c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
1889266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
18976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
19076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
191cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
192cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
1934a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
1944a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
1954a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
1964a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
19776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
198e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
199e8f3062a36d3682f4019309a32b5b84dc9eddf8creed#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
200e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    SkSurface* newSurface(const SkImageInfo& info, const SkSurfaceProps* props = NULL);
201e8f3062a36d3682f4019309a32b5b84dc9eddf8creed#endif
202e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
203644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
204644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
205644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
206644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
207644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
208644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
2094b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
2104b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
211daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
2129c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
2139c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2149c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
2156b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
2169c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
2179c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
2189c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
2199c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
2206b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
2219c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
2226b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
2239c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
2249c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2259c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
2269c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2276ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  local RAM) return true, and if not null, return in the pixmap parameter information about
2286ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  the pixels. The pixmap's pixel address is only valid
229c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
2306ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  canvas (or its parent surface if any) will invalidate the pixel address
2316ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  (and associated information).
232c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
2336ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  On failure, returns false and the pixmap parameter will be ignored.
234c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
2356ceeebd37a43d879c120b6ba100ae1febdd67a18reed    bool peekPixels(SkPixmap*);
2366ceeebd37a43d879c120b6ba100ae1febdd67a18reed
2376ceeebd37a43d879c120b6ba100ae1febdd67a18reed#ifdef SK_SUPPORT_LEGACY_PEEKPIXELS_PARMS
238c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
2396ceeebd37a43d879c120b6ba100ae1febdd67a18reed#endif
240c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
244b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
246b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
248b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
250b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
251b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
252b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
253b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
256b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
257a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
260b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
261b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
262a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
263a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
264a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
265a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
266a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
267a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
268b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(SkBitmap* bitmap, int srcX, int srcY);
269c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2704b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
271a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
272a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
273a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
274a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
27551df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
27651df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
27751df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2914cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2924cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2934cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2944cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2954cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2964cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2974cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2984cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2994cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
3004cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
3014cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
3024cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
3034b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
3058d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
306dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
308dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
309dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
310dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
311dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
312d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
313d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
314d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
315d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
316d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
320dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
321ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
322ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
323ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
324ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
327d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
328d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
329d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
330021f631dc66da06dbe4aed21df2f27daecce9db7reed    int saveLayer(const SkRect& bounds, const SkPaint* paint) {
331021f631dc66da06dbe4aed21df2f27daecce9db7reed        return this->saveLayer(&bounds, paint);
332021f631dc66da06dbe4aed21df2f27daecce9db7reed    }
333d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
33470ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    /**
33570ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Temporary name.
33670ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Will allow any requests for LCD text to be respected, so the caller must be careful to
33770ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  only draw on top of opaque sections of the layer to get good results.
33870ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     */
33970ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
34070ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed
3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
344dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
34540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
34640408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
34740408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
34840408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
350d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
351d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
352d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
353d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3544960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    enum {
3554960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kIsOpaque_SaveLayerFlag         = 1 << 0,
3564960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kPreserveLCDText_SaveLayerFlag  = 1 << 1,
357bada1885da479d948f065182d6dfa85a1140bda5reed
358bada1885da479d948f065182d6dfa85a1140bda5reed#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
359bada1885da479d948f065182d6dfa85a1140bda5reed        kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
360bada1885da479d948f065182d6dfa85a1140bda5reed#endif
3614960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3624960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    typedef uint32_t SaveLayerFlags;
3634960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3644960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    struct SaveLayerRec {
365bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec()
366bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(nullptr), fPaint(nullptr), fBackdrop(nullptr), fSaveLayerFlags(0)
367bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
3684960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
3694960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            : fBounds(bounds)
3704960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fPaint(paint)
371bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(nullptr)
372bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fSaveLayerFlags(saveLayerFlags)
373bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
374bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
375bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed                     SaveLayerFlags saveLayerFlags)
376bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(bounds)
377bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fPaint(paint)
378bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(backdrop)
3794960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fSaveLayerFlags(saveLayerFlags)
3804960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        {}
3814960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
382bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkRect*           fBounds;    // optional
383bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkPaint*          fPaint;     // optional
384bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkImageFilter*    fBackdrop;  // optional
385bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerFlags          fSaveLayerFlags;
3864960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3874960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3884960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    int saveLayer(const SaveLayerRec&);
3894960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
391dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
392dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
393dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
395e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
398ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
399ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
401a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
404ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
405ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
406ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41592362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42192362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4237438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about the origin.
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42692362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4287438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about a given point.
4297438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param degrees  The amount to rotate, in degrees
4307438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param px  The x coordinate of the point to rotate about.
4317438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param py  The y coordinate of the point to rotate about.
4327438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    */
4337438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    void rotate(SkScalar degrees, SkScalar px, SkScalar py);
4347438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43992362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44944c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4504b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
45595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
456e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Add the specified translation to the current draw depth of the canvas.
457e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack        @param z    The distance to translate in Z.
458e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Negative into screen, positive out of screen.
459e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Without translation, the draw depth defaults to 0.
460e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    */
461e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    void translateZ(SkScalar z);
462e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
46395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Set the current set of lights in the canvas.
46495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack        @param lights   The lights that we want the canvas to have.
46595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    */
46695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void setLights(sk_sp<SkLights> lights);
46795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
46895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Returns the current set of lights the canvas uses
46995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack      */
47095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> getLights() const;
47195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
47295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
4734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4744ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4754ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4764ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4774ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4784ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
479759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRect(const SkRect& rect,
480759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
481759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4834ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4844ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4854ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4864ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4874ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4884ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
489759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRRect(const SkRRect& rrect,
490759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   SkRegion::Op op = SkRegion::kIntersect_Op,
491759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   bool doAntiAlias = false);
4924ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4934ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4944ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4954ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
4964ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4974ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4984ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
499759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipPath(const SkPath& path,
500759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
501759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5038f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
5048f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        Set to false to force clips to be hard, even if doAntiAlias=true is
5058f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        passed to clipRect or clipPath.
5068f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com     */
5078f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    void setAllowSoftClip(bool allow) {
5088f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        fAllowSoftClip = allow;
5098f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    }
5108f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com
51145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    /** EXPERIMENTAL -- only used for testing
51245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
51345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
51445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
51545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
51645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
51745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
5236e998e6137e6b25f047b5c5943f2b02485165e3emtklein        @param op The region op to apply to the current clip
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
525759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRegion(const SkRegion& deviceRgn,
526759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                    SkRegion::Op op = SkRegion::kIntersect_Op);
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified region. This does not intersect or in any other way account
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for the existing clip region.
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn The region to copy into the current clip.
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5338f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    void setClipRegion(const SkRegion& deviceRgn) {
5348f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5453b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5573b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5648f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
566bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
567bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
568bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
569bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
5708f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
57174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
572bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
574845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
582845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
585845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5898eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    void drawColor(SkColor color, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
591f4e0d9eb2d72fe92c30237de978936113143dc16reed    /**
592f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  Helper method for drawing a color in SRC mode, completely replacing all the pixels
593f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  in the current clip with this color.
594f4e0d9eb2d72fe92c30237de978936113143dc16reed     */
595f4e0d9eb2d72fe92c30237de978936113143dc16reed    void clear(SkColor color) {
5968eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed        this->drawColor(color, SkXfermode::kSrc_Mode);
5978eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    }
5982a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
5992a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
60028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
60128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
60228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
603a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * dependent and one legal implementation is to do nothing. This method
604a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * ignores the current clip.
60528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
60628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
60728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
60828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
60928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
61028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
61128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
61228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
61328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
614a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     *  Fill the entire canvas (restricted to the current clip) with the
6152a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6162a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6172a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6180846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPaint(const SkPaint& paint);
6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6500846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6564b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6810846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRect(const SkRect& rect, const SkPaint& paint);
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
68887001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6934b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7100846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawOval(const SkRect& oval, const SkPaint&);
7114ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7124ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7134ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7144ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7154ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7164ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7174ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7184ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7190846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
721ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
722ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
723ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
724ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
725ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
726ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified oval. If the sweep angle is >= 360, then the oval is drawn
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely. Note that this differs slightly from SkPath::arcTo, which
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        treats the sweep angle mod 360.
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the shape of the arc
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param useCenter true means include the center of the oval. For filling
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         this will draw a wedge. False means just use the arc.
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7670846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPath(const SkPath& path, const SkPaint& paint);
7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
769d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with its top/left corner at (x,y), using the
770d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        specified paint, transformed by the current matrix.
771d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr
772d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image    The image to be drawn
773d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param left     The position of the left side of the image being drawn
774d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param top      The position of the top side of the image being drawn
775d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
776d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr     */
7770846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
778f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
779f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkPaint* paint = NULL) {
780f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImage(image.get(), left, top, paint);
781f8053da25981c6b3152b637c1c91f43cff194c25reed    }
782b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
783a5517e2b190a8083b38964972b031c13e99f1012reed    /**
784a5517e2b190a8083b38964972b031c13e99f1012reed     *  Controls the behavior at the edge of the src-rect, when specified in drawImageRect,
785a5517e2b190a8083b38964972b031c13e99f1012reed     *  trading off speed for exactness.
786a5517e2b190a8083b38964972b031c13e99f1012reed     *
787a5517e2b190a8083b38964972b031c13e99f1012reed     *  When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around
788a5517e2b190a8083b38964972b031c13e99f1012reed     *  the pixels in the image. If there is a src-rect specified, it is intended to restrict the
789a5517e2b190a8083b38964972b031c13e99f1012reed     *  pixels that will be read. However, for performance reasons, some implementations may slow
790a5517e2b190a8083b38964972b031c13e99f1012reed     *  down if they cannot read 1-pixel past the src-rect boundary at times.
791a5517e2b190a8083b38964972b031c13e99f1012reed     *
792a5517e2b190a8083b38964972b031c13e99f1012reed     *  This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable.
793a5517e2b190a8083b38964972b031c13e99f1012reed     *  If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect
794a5517e2b190a8083b38964972b031c13e99f1012reed     *  must be strictly respected, the caller should pass kStrict.
795a5517e2b190a8083b38964972b031c13e99f1012reed     */
796a5517e2b190a8083b38964972b031c13e99f1012reed    enum SrcRectConstraint {
797a5517e2b190a8083b38964972b031c13e99f1012reed        /**
798a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kStrict is specified, the implementation must respect the src-rect
799a5517e2b190a8083b38964972b031c13e99f1012reed         *  (if specified) strictly, and will never sample outside of those bounds during sampling
800a5517e2b190a8083b38964972b031c13e99f1012reed         *  even when filtering. This may be slower than kFast.
801a5517e2b190a8083b38964972b031c13e99f1012reed         */
802a5517e2b190a8083b38964972b031c13e99f1012reed        kStrict_SrcRectConstraint,
803a5517e2b190a8083b38964972b031c13e99f1012reed
804a5517e2b190a8083b38964972b031c13e99f1012reed        /**
805a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kFast is specified, the implementation may sample outside of the src-rect
80619e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon         *  (if specified) by half the width of filter. This allows greater flexibility
807a5517e2b190a8083b38964972b031c13e99f1012reed         *  to the implementation and can make the draw much faster.
808a5517e2b190a8083b38964972b031c13e99f1012reed         */
809a5517e2b190a8083b38964972b031c13e99f1012reed        kFast_SrcRectConstraint,
810a5517e2b190a8083b38964972b031c13e99f1012reed    };
811a5517e2b190a8083b38964972b031c13e99f1012reed
812a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified image, scaling and translating so that it fills the specified
813a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the image is transformed
814a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
815a5517e2b190a8083b38964972b031c13e99f1012reed     *
816a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param image      The image to be drawn
817a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the image to be drawn
818a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
819a5517e2b190a8083b38964972b031c13e99f1012reed     *                    image will be drawn
820a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the image, or NULL
821a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
822a5517e2b190a8083b38964972b031c13e99f1012reed     */
823e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
824e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint,
825e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
826e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that takes src SkIRect
827e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
828e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
829e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that assumes src == image-bounds
830e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
831e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint = kStrict_SrcRectConstraint);
83284984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
833f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
834f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint,
835f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
836f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), src, dst, paint, constraint);
837f8053da25981c6b3152b637c1c91f43cff194c25reed    }
838f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
839f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) {
840f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), isrc, dst, paint, cons);
841f8053da25981c6b3152b637c1c91f43cff194c25reed    }
842f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
843f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint cons = kStrict_SrcRectConstraint) {
844f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), dst, paint, cons);
845f8053da25981c6b3152b637c1c91f43cff194c25reed    }
846f8053da25981c6b3152b637c1c91f43cff194c25reed
8474c21dc5ddf3b482293ed34eead876d8d61a662c3reed    /**
8484c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  Draw the image stretched differentially to fit into dst.
8494c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  center is a rect within the image, and logically divides the image
8504c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
8514c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  image is the "center", then the center-rect should be [2, 2, 3, 3].
8524c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *
8534c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  If the dst is >= the image size, then...
8544c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The 4 corners are not stretched at all.
8554c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides are stretched in only one axis.
8564c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The center is stretched in both axes.
8574c21dc5ddf3b482293ed34eead876d8d61a662c3reed     * Else, for each axis where dst < image,
8584c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The corners shrink proportionally
8594c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides (along the shrink axis) and center are not drawn
8604c21dc5ddf3b482293ed34eead876d8d61a662c3reed     */
8614c21dc5ddf3b482293ed34eead876d8d61a662c3reed    void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
862f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr);
863f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
864f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr) {
865f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageNine(image.get(), center, dst, paint);
866f8053da25981c6b3152b637c1c91f43cff194c25reed    }
8674c21dc5ddf3b482293ed34eead876d8d61a662c3reed
8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
87491246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
87591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
876f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
87791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
87891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8840846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
8850846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                    const SkPaint* paint = NULL);
8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
887a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified bitmap, scaling and translating so that it fills the specified
888a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
889a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
890a5517e2b190a8083b38964972b031c13e99f1012reed     *
891a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param bitmap     The bitmap to be drawn
892a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the bitmap to be drawn
893a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
894a5517e2b190a8083b38964972b031c13e99f1012reed     *                    bitmap will be drawn
895a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the bitmap, or NULL
896a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
897a5517e2b190a8083b38964972b031c13e99f1012reed     */
898e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
89984984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
900e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant where src is SkIRect
90184984efeb64787b88c5f8bd6929cfe2d58a3ba06reed    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
90284984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
903e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
90419e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon                        SrcRectConstraint = kStrict_SrcRectConstraint);
90584984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
906f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
907c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
908f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
909f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
910f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
911f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
912f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
9139bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
9149bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
9159bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
916f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
917f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
918f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
919f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
9200846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
9210846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                        const SkPaint* paint = NULL);
922f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
923c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
924c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
925c573a40ed5024b463e47088d307e3164a486dba5msarett     */
926c573a40ed5024b463e47088d307e3164a486dba5msarett    struct Lattice {
927c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of x-coordinates that divide the bitmap vertically.
928c573a40ed5024b463e47088d307e3164a486dba5msarett        // These must be unique, increasing, and in the set [0, width].
929c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
930c573a40ed5024b463e47088d307e3164a486dba5msarett        const int* fXDivs;
931c573a40ed5024b463e47088d307e3164a486dba5msarett
932c573a40ed5024b463e47088d307e3164a486dba5msarett        // The number of fXDivs.
933c573a40ed5024b463e47088d307e3164a486dba5msarett        int        fXCount;
934c573a40ed5024b463e47088d307e3164a486dba5msarett
935c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of y-coordinates that divide the bitmap horizontally.
936c573a40ed5024b463e47088d307e3164a486dba5msarett        // These must be unique, increasing, and in the set [0, height].
937c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
938c573a40ed5024b463e47088d307e3164a486dba5msarett        const int* fYDivs;
939c573a40ed5024b463e47088d307e3164a486dba5msarett
940c573a40ed5024b463e47088d307e3164a486dba5msarett        // The number of fYDivs.
941c573a40ed5024b463e47088d307e3164a486dba5msarett        int        fYCount;
942c573a40ed5024b463e47088d307e3164a486dba5msarett    };
943c573a40ed5024b463e47088d307e3164a486dba5msarett
944c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
945c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
946c573a40ed5024b463e47088d307e3164a486dba5msarett     *
947c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Moving horizontally across the bitmap, alternating rects will be "scalable"
948c573a40ed5024b463e47088d307e3164a486dba5msarett     *  (in the x-dimension) to fit into dst or must be left "fixed".  The first rect
949c573a40ed5024b463e47088d307e3164a486dba5msarett     *  is treated as "fixed", but it's possible to specify an empty first rect by
950c573a40ed5024b463e47088d307e3164a486dba5msarett     *  making lattice.fXDivs[0] = 0.
951c573a40ed5024b463e47088d307e3164a486dba5msarett     *
952c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The scale factor for all "scalable" rects will be the same, and may be greater
953c573a40ed5024b463e47088d307e3164a486dba5msarett     *  than or less than 1 (meaning we can stretch or shrink).  If the number of
954c573a40ed5024b463e47088d307e3164a486dba5msarett     *  "fixed" pixels is greater than the width of the dst, we will collapse all of
955c573a40ed5024b463e47088d307e3164a486dba5msarett     *  the "scalable" regions and appropriately downscale the "fixed" regions.
956c573a40ed5024b463e47088d307e3164a486dba5msarett     *
957c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The same interpretation also applies to the y-dimension.
958c573a40ed5024b463e47088d307e3164a486dba5msarett     */
959c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
960c573a40ed5024b463e47088d307e3164a486dba5msarett                           const SkPaint* paint = nullptr);
961c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
962c573a40ed5024b463e47088d307e3164a486dba5msarett                          const SkPaint* paint = nullptr);
963c573a40ed5024b463e47088d307e3164a486dba5msarett
9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
9668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
972f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
973f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                  const SkPaint& paint);
9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
9764b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
9778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
9808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
982f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
983f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                     const SkPaint& paint);
9844b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
9874b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
994f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
995f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                      const SkPaint& paint);
9964b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1009f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1022f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
1023f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                        const SkMatrix* matrix, const SkPaint& paint);
10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
102545561a0b15fe045ba272c328684c3f7ae290785areed    /**
102645561a0b15fe045ba272c328684c3f7ae290785areed     *  Draw the text with each character/glyph individually transformed by its xform.
102745561a0b15fe045ba272c328684c3f7ae290785areed     *  If cullRect is not null, it is a conservative bounds of what will be drawn
102863f30d90498ca1a48868421b528036f3be30e2adreed     *  taking into account the xforms and the paint, and will be used to accelerate culling.
102945561a0b15fe045ba272c328684c3f7ae290785areed     */
103045561a0b15fe045ba272c328684c3f7ae290785areed    void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
103145561a0b15fe045ba272c328684c3f7ae290785areed                         const SkRect* cullRect, const SkPaint& paint);
103245561a0b15fe045ba272c328684c3f7ae290785areed
103300d5c2c6523321d25b32905ff4822f083a4173eefmalita    /** Draw the text blob, offset by (x,y), using the specified paint.
103400d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param blob     The text blob to be drawn
103500d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param x        The x-offset of the text being drawn
103600d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param y        The y-offset of the text being drawn
103700d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param paint    The paint used for the text (e.g. color, size, style)
103800d5c2c6523321d25b32905ff4822f083a4173eefmalita    */
103900d5c2c6523321d25b32905ff4822f083a4173eefmalita    void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
10402ab9057b31ee92060b9769ea1adfada51c11c010reed    void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
10412ab9057b31ee92060b9769ea1adfada51c11c010reed        this->drawTextBlob(blob.get(), x, y, paint);
10422ab9057b31ee92060b9769ea1adfada51c11c010reed    }
104300d5c2c6523321d25b32905ff4822f083a4173eefmalita
10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
1046a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10501c2c441fede0ae9573afc098017011e3439624a9reed    void drawPicture(const SkPicture* picture) {
10511c2c441fede0ae9573afc098017011e3439624a9reed        this->drawPicture(picture, NULL, NULL);
10521c2c441fede0ae9573afc098017011e3439624a9reed    }
1053ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture) {
1054f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get());
1055f8053da25981c6b3152b637c1c91f43cff194c25reed    }
10569b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
1057d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    /**
1058d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  Draw the picture into this canvas.
1059d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1060d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
1061d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  logically equivalent to
1062d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      save/concat/drawPicture/restore
1063d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1064d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1065d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1066d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  This is logically equivalent to
1067d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      saveLayer(paint)/drawPicture/restore
1068d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     */
1069d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
1070ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
1071f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get(), matrix, paint);
1072f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1073d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed
107495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
107595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /**
107695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  Draw the picture into this canvas.
107795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
107895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  We will use the canvas's lights along with the picture information (draw depths of
107995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
108095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  then use that set of shadowmaps to render the scene with shadows.
108195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
108295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
108395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  logically equivalent to
108495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      save/concat/drawPicture/restore
108595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
108695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
108795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
108895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  This is logically equivalent to
108995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      saveLayer(paint)/drawPicture/restore
109095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
109195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     */
109295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const SkPicture*,
109395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
109495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkPaint* paint);
109595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const sk_sp<SkPicture>& picture,
109695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
109795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkPaint* paint) {
109895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack        this->drawShadowedPicture(picture.get(), matrix, paint);
109995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    }
110095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
110195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
11028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
11038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
11058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11074b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
1109559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
1110559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        If both textures and vertex-colors are NULL, it strokes hairlines with
1111559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the paint's color. This behavior is a useful debugging mode to visualize
1112559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the mesh.
1113559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
11168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
11178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
11188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
1119631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
11208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
11218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
11228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xmode Used if both texs and colors are present. In this
11238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
11248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    before being drawn using the paint. If mode is null, then
11258d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com                    kModulate_Mode is used.
11268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
11278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
11294b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11310846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawVertices(VertexMode vmode, int vertexCount,
11320846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPoint vertices[], const SkPoint texs[],
11330846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkColor colors[], SkXfermode* xmode,
11340846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const uint16_t indices[], int indexCount,
11350846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPaint& paint);
1136cfb6bdf767796c950f89985445738d2d8e7f12b0reed    void drawVertices(VertexMode vmode, int vertexCount,
1137cfb6bdf767796c950f89985445738d2d8e7f12b0reed                      const SkPoint vertices[], const SkPoint texs[],
113892d48830852f3e34644561dbbfaf10364836482dmtklein                      const SkColor colors[], const sk_sp<SkXfermode>& xmode,
1139cfb6bdf767796c950f89985445738d2d8e7f12b0reed                      const uint16_t indices[], int indexCount,
1140cfb6bdf767796c950f89985445738d2d8e7f12b0reed                      const SkPaint& paint) {
1141cfb6bdf767796c950f89985445738d2d8e7f12b0reed        this->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode.get(),
1142cfb6bdf767796c950f89985445738d2d8e7f12b0reed                           indices, indexCount, paint);
1143cfb6bdf767796c950f89985445738d2d8e7f12b0reed    }
11446cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1145b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1146b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
11476cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1148b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1149b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1150b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1151b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
11526cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1153b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
11546cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param xmode specifies how are the colors and the textures combined if both of them are
1155b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1156963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1157963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1158b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
1159b3c9d1c33caf325aada244204215eb790c228c12dandov                   const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
1160cfb6bdf767796c950f89985445738d2d8e7f12b0reed    void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
1161cfb6bdf767796c950f89985445738d2d8e7f12b0reed                   const sk_sp<SkXfermode>& xmode, const SkPaint& paint) {
1162cfb6bdf767796c950f89985445738d2d8e7f12b0reed        this->drawPatch(cubics, colors, texCoords, xmode.get(), paint);
1163cfb6bdf767796c950f89985445738d2d8e7f12b0reed    }
11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11653cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
116671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
116771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
116871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  into a quad.
116971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
117071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *      xform maps [0, 0, tex.width, tex.height] -> quad
117171c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
117271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The color array is optional. When specified, each color modulates the pixels in its
117371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  corresponding quad (via the specified SkXfermode::Mode).
117471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
117571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The cullRect is optional. When specified, it must be a conservative bounds of all of the
117671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
117771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  intersect the current clip.
117871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
117971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
118071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  and xfermode are used to affect each of the quads.
118171c3c760a83123ee0b3127b8c65c6394ce541c50reed     */
118271c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
118371c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkColor colors[], int count, SkXfermode::Mode, const SkRect* cullRect,
118471c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkPaint* paint);
118571c3c760a83123ee0b3127b8c65c6394ce541c50reed
118671c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
118771c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkRect* cullRect, const SkPaint* paint) {
118871c3c760a83123ee0b3127b8c65c6394ce541c50reed        this->drawAtlas(atlas, xform, tex, NULL, count, SkXfermode::kDst_Mode, cullRect, paint);
118971c3c760a83123ee0b3127b8c65c6394ce541c50reed    }
119071c3c760a83123ee0b3127b8c65c6394ce541c50reed
1191f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
1192f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkColor colors[], int count, SkXfermode::Mode mode, const SkRect* cull,
1193f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkPaint* paint) {
1194f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cull, paint);
1195f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1196f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
1197f8053da25981c6b3152b637c1c91f43cff194c25reed                   int count, const SkRect* cullRect, const SkPaint* paint) {
1198f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkXfermode::kDst_Mode,
1199f8053da25981c6b3152b637c1c91f43cff194c25reed                        cullRect, paint);
1200f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1201f8053da25981c6b3152b637c1c91f43cff194c25reed
120271c3c760a83123ee0b3127b8c65c6394ce541c50reed    /**
12033cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
12043cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
12053cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
12063cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
12073cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
12083cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
12093cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
1210a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
1211a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
12126a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1213f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    /**
1214f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
1215f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a null-terminated utf8 string, and the value is a blob of data stored in an SkData
1216f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  (which may be null). The annotation is associated with the specified rectangle.
1217f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1218f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  The caller still retains its ownership of the data (if any).
1219f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1220f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
1221f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a picture or drawing to a PDF document) will pass on this information.
1222f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     */
1223f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    void drawAnnotation(const SkRect&, const char key[], SkData* value);
12240fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
12250fba3b97b5b0e3707b31931ab9325030b81c940fmtklein        this->drawAnnotation(rect, key, value.get());
12260fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    }
1227f70b531daaf47db1ee95c70da9843f1dd1f418d3reed
12288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12297765000709dc64eb23be7df47d1f995d1f787115fmalita#ifdef SK_INTERNAL
123053d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
123153d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita    #define SK_SUPPORT_LEGACY_DRAWFILTER
12327765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12337765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12344b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
123553d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1237dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12407765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated")
12418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
12424b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
12448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1246dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1247dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
12488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12517765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
12537765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1256754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1257754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1258754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1259754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1260754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1261754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1262754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
12638f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1264754de5f65b466f721d952a379194cc94de376f42reed@google.com
12655c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
12665c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
12675c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
12685c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
12695c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
12705c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
12718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1275a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
127740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
127840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
127940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
128040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
128140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
128240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
1283687fa1c745febb57f42b0d5f03d7c1f4be2530careed        return fClipStack;
128440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
128540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1286c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
12875e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
128890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
128990c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
129090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
12917d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
129290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
12938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
129636736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
1297175dd9b5e3d7d749738dac743d2ac360b5340187robertphillips    GrDrawContext* internal_private_accessTopLayerDrawContext();
129836736a2dae94947e075ac9503d5de7799772a5f7robertphillips
129936736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
130036736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
130136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetIgnoreSaveLayerBounds();
130236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
130336736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetTreatSpriteAsBitmap();
130436736a2dae94947e075ac9503d5de7799772a5f7robertphillips
130536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // TEMP helpers until we switch virtual over to const& for src-rect
130636736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
130736736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              const SkPaint* paint,
130836736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              SrcRectConstraint constraint = kStrict_SrcRectConstraint);
130936736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
131036736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               const SkPaint* paint,
131136736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               SrcRectConstraint constraint = kStrict_SrcRectConstraint);
131236736a2dae94947e075ac9503d5de7799772a5f7robertphillips
1313cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    // expose minimum amount of information necessary for transitional refactoring
1314cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    /**
1315cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     * Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates.
1316cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     */
1317cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds);
1318cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson
1319da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillipsprotected:
132095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1321e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Returns the current (cumulative) draw depth of the canvas.
1322e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack      */
1323e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    SkScalar getZ() const;
1324e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
132595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> fLights;
132695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
132795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After calling saveLayer(), there can be any number of devices that make
13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        up the top-most drawing area. LayerIter can be used to iterate through
13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        those devices. Note that the iterator is only valid until the next API
13318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call made on the canvas. Ownership of all pointers in the iterator stays
13328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with the canvas, so none of them should be modified or deleted.
13338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
133436736a2dae94947e075ac9503d5de7799772a5f7robertphillips    class LayerIter /*: SkNoncopyable*/ {
13358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Initialize iterator with canvas, and set values for 1st device */
13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        LayerIter(SkCanvas*, bool skipEmptyClips);
13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~LayerIter();
13394b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
13408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return true if the iterator is done */
13418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool done() const { return fDone; }
13428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Cycle to the next device */
13438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void next();
13444b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // These reflect the current device in the iterator
13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13471f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com        SkBaseDevice*   device() const;
13488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkMatrix& matrix() const;
13491e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreed        const SkRasterClip& clip() const;
13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPaint&  paint() const;
13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             x() const;
13528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             y() const;
13534b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
13548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
13558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // used to embed the SkDrawIter object directly in our instance, w/o
13568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // having to expose that class def to the public. There is an assert
13578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // in our constructor to ensure that fStorage is large enough
13588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // (though needs to be a compile-time-assert!). We use intptr_t to work
13598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // safely with 32 and 64 bit machines (to ensure the storage is enough)
1360f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        intptr_t          fStorage[32];
13618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        class SkDrawIter* fImpl;    // this points at fStorage
13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint           fDefaultPaint;
13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool              fDone;
13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
13658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
136676f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
1367e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
136876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1369c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1370884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onPeekPixels(SkPixmap*);
1371884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onAccessTopLayerPixels(SkPixmap*);
1372ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual SkImageInfo onImageInfo() const;
1373ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual bool onGetProps(SkSurfaceProps*) const;
1374ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual void onFlush();
1375c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1376e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1377e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13784960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // getSaveLayerStrategy()'s return value may suppress full layer allocation.
1379e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1380e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
13814960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kNoLayer_SaveLayerStrategy,
1382e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1383e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
13846ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
13854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13864960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
13874960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        return kFullLayer_SaveLayerStrategy;
13884960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    }
1389fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
13906cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
1391fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1392fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
139395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
139495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1395e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    virtual void didTranslateZ(SkScalar) {}
139695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
139744c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
1398f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
1399ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1400ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1401e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1402e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1403b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1404e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1405e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1406b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1407e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1408e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1409e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1410b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1411e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1412e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1413e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
141445561a0b15fe045ba272c328684c3f7ae290785areed    virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
141545561a0b15fe045ba272c328684c3f7ae290785areed                                   const SkRect* cullRect, const SkPaint& paint);
14166cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
141700d5c2c6523321d25b32905ff4822f083a4173eefmalita    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
141800d5c2c6523321d25b32905ff4822f083a4173eefmalita                                const SkPaint& paint);
141900d5c2c6523321d25b32905ff4822f083a4173eefmalita
1420b3c9d1c33caf325aada244204215eb790c228c12dandov    virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
1421b3c9d1c33caf325aada244204215eb790c228c12dandov                           const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
1422e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1423a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
14246a070dc06af4e9f305f9d08a69e34d18ade473cbreed
142541af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPaint(const SkPaint&);
142641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRect(const SkRect&, const SkPaint&);
142741af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawOval(const SkRect&, const SkPaint&);
142841af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRRect(const SkRRect&, const SkPaint&);
142941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
143041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
143141af966ab338e95eee81ab618ab28195075338f7reed                                const SkPoint texs[], const SkColor colors[], SkXfermode*,
143241af966ab338e95eee81ab618ab28195075338f7reed                                const uint16_t indices[], int indexCount, const SkPaint&);
14332766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein
143471c3c760a83123ee0b3127b8c65c6394ce541c50reed    virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
143571c3c760a83123ee0b3127b8c65c6394ce541c50reed                             int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*);
143641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPath(const SkPath&, const SkPaint&);
143741af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
1438562fe4767cc73e08a4e039362bc0336aea66ecfbreed    virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
1439562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                 SrcRectConstraint);
14404c21dc5ddf3b482293ed34eead876d8d61a662c3reed    virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
14414c21dc5ddf3b482293ed34eead876d8d61a662c3reed                                 const SkPaint*);
14424c21dc5ddf3b482293ed34eead876d8d61a662c3reed
144341af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
144441af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
1445562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                  SrcRectConstraint);
144641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
144741af966ab338e95eee81ab618ab28195075338f7reed                                  const SkPaint*);
1448c573a40ed5024b463e47088d307e3164a486dba5msarett    virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
1449c573a40ed5024b463e47088d307e3164a486dba5msarett                                    const SkPaint*);
145041af966ab338e95eee81ab618ab28195075338f7reed
14518f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
14528f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
14538f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
14548f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
14558f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
14568f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
14578f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
14588f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle);
14598f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
14608f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
146128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
146228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
1463d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
14649b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
146595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
146695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    virtual void onDrawShadowedPicture(const SkPicture*,
146795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                                       const SkMatrix*,
146895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                                       const SkPaint*);
146995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
14705bfee98c8cf59db8d71aa6672088b107f0abf8c9vjiaoblack
147174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    // Returns the canvas to be used by DrawIter. Default implementation
14724370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // returns this. Subclasses that encapsulate an indirect canvas may
14734370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // need to overload this method. The impl must keep track of this, as it
14744370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // is not released or deleted by the caller.
14754370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    virtual SkCanvas* canvasForDrawIter();
14764370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com
1477a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1478a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1479c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1480c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
14814960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection,
1482c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1483a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1484c83a29759a5c2966da5ab973e4fd90763e4c962breedprivate:
14854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    static bool BoundsAffectsClip(SaveLayerFlags);
1486bada1885da479d948f065182d6dfa85a1140bda5reed    static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
14874960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
1488a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed    static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
1489a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     SkBaseDevice* dst, const SkMatrix& ctm,
1490a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     const SkClipStack* clipStack);
1491a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed
1492c83a29759a5c2966da5ab973e4fd90763e4c962breed    enum ShaderOverrideOpacity {
1493c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
1494c83a29759a5c2966da5ab973e4fd90763e4c962breed        kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
1495c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
1496c83a29759a5c2966da5ab973e4fd90763e4c962breed    };
1497c83a29759a5c2966da5ab973e4fd90763e4c962breed
149897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
149997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
1500c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(bool willOverwritesEntireSurface = false);
1501c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
1502c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
1503c83a29759a5c2966da5ab973e4fd90763e4c962breed        this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1504c83a29759a5c2966da5ab973e4fd90763e4c962breed                                                                : kNotOpaque_ShaderOverrideOpacity);
1505c83a29759a5c2966da5ab973e4fd90763e4c962breed    }
150697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
15078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1509687fa1c745febb57f42b0d5f03d7c1f4be2530careed    SkAutoTUnref<SkClipStack> fClipStack;
15108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
15118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
15128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
15138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
1514b679ca8926a832274b14fdb512f88f64b61d32eareed    enum {
1515a499f905e9340e4935447f2562fd92e8853382b1reed        kMCRecSize      = 128,  // most recent measurement
151631b80a9dc60ae5411ad6abd10269c4f88c635ec2reed        kMCRecCount     = 32,   // common depth for save/restores
15178c30a8196dd5903d2d23b4d0a5dc888e802bf698reed        kDeviceCMSize   = 176,  // most recent measurement
1518b679ca8926a832274b14fdb512f88f64b61d32eareed    };
1519b679ca8926a832274b14fdb512f88f64b61d32eareed    intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
1520a499f905e9340e4935447f2562fd92e8853382b1reed    intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
15218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15224a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
15234a8126e7f81384526629b1e21bf89b632ea13cd9reed
15242ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
15258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
152674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
152774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
152897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
152997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
153097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
153197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
153297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
153397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
153445c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1535fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
15368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
15378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
15388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15392ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
15402ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
15418c30a8196dd5903d2d23b4d0a5dc888e802bf698reed    void internalSetMatrix(const SkMatrix&);
15422ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
1543da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillips    friend class CanvasTestingAccess; // for testing
15449c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
15458926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
15469c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
15472a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
154852d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1549d954498c01ccf0417feacf89e45d0c62a06a813breed    friend class SkRecorder;        // InitFlags
15509c5052f16b249d2b7674ea86bd24ed0038ccc61fmtklein    friend class SkLiteRecorder;        // InitFlags
1551d954498c01ccf0417feacf89e45d0c62a06a813breed    friend class SkNoSaveLayerCanvas;   // InitFlags
15522d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1553c83a29759a5c2966da5ab973e4fd90763e4c962breed    friend class SkPictureRecord;   // predrawNotify (why does it need it? <reed>)
15544960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
1555b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1556d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1557d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1558d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1559d954498c01ccf0417feacf89e45d0c62a06a813breed    };
156078e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
1561fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips    SkCanvas(SkBaseDevice* device, InitFlags);
1562d954498c01ccf0417feacf89e45d0c62a06a813breed
1563feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein    void resetForNextPicture(const SkIRect& bounds);
1564feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein
15658f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1566a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1567b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
15684a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
15694a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
15704a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
15714a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
15724a8126e7f81384526629b1e21bf89b632ea13cd9reed
1573d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1574f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1575403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1576afc7cce5d68663934128d76963cd501f771d71desenorblanco     * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
15774ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
15784ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1579afc7cce5d68663934128d76963cd501f771d71desenorblanco    SkIRect getTopLayerBounds() const;
1580403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
15817112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1582eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1583a5517e2b190a8083b38964972b031c13e99f1012reed                                SrcRectConstraint);
1584fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
15854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
15867503d60847c4ad22df87458aecd917772b23d293reed    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1587fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
15888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
15892ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
15908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
159152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
159252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
159352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
159452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
159552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
15964b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1597fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    // only for canvasutils
1598fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    const SkRegion& internal_private_getTotalClip() const;
1599fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
1600c83a29759a5c2966da5ab973e4fd90763e4c962breed    /*
1601c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  Returns true if drawing the specified rect (or all if it is null) with the specified
1602c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  paint (or default if null) would overwrite the entire root device of the canvas
1603c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  (i.e. the canvas' surface if it had one).
1604c83a29759a5c2966da5ab973e4fd90763e4c962breed     */
1605c83a29759a5c2966da5ab973e4fd90763e4c962breed    bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
1606c83a29759a5c2966da5ab973e4fd90763e4c962breed
1607262a71b7f95ce98ff3dd8dba845afbd724470903reed    /**
1608262a71b7f95ce98ff3dd8dba845afbd724470903reed     *  Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
1609262a71b7f95ce98ff3dd8dba845afbd724470903reed     */
1610262a71b7f95ce98ff3dd8dba845afbd724470903reed    bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
1611c83a29759a5c2966da5ab973e4fd90763e4c962breed
1612fbfa25802709139c2f14e304319c9541da65ca27msarett
1613fbfa25802709139c2f14e304319c9541da65ca27msarett    /**
1614fbfa25802709139c2f14e304319c9541da65ca27msarett     *  Keep track of the device clip bounds and if the matrix is scale-translate.  This allows
1615fbfa25802709139c2f14e304319c9541da65ca27msarett     *  us to do a fast quick reject in the common case.
16168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
1617fbfa25802709139c2f14e304319c9541da65ca27msarett    bool   fConservativeIsScaleTranslate;
1618fbfa25802709139c2f14e304319c9541da65ca27msarett    SkRect fDeviceClipBounds;
1619fbfa25802709139c2f14e304319c9541da65ca27msarett
16208f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
162145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
162242b73eb00367c8315974b1c374308d20efa78897reed    const bool fConservativeRasterClip;
16238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16245c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
16255c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
16265c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
16275c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
16285c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
16295c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
16305c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16315c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
16325c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
16335c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
16345c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16355c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
16365c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
16375c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
16385c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
16395c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
164015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
164115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
16428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
16438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
16458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
16468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
16478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
16498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
16502887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
16512887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
16522887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
16532887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
16542887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
16552887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
16568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
16578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
16588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1659f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1660f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1661f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1662f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1663f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1664f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1665f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1666f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1667f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1668f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1669f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1670f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1671f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1672f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
16738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
16748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
16768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
16778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
16788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1679e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
16808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1681c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1682c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1683c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
1684c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1685c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1686c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1687c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
16882a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
16898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1690