SkCanvas.h revision c1f7774e8d327e3c98b4094c9c01d26e27013f71
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"
12374772bd61951f01bf84fe17bf53d8867681c9aereed#include "SkBlendMode.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
1473603f3c52ffd89fe9d035be827b566a0e7d3b79reed#include "SkClipOp.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h"
16e8597a4dd07d78eb0e7a45d6502896c1b9a8bfebmsarett#include "SkImage.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
204a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h"
2195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#include "SkLights.h"
22e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack#include "../private/SkShadowParams.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
24d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass GrContext;
251105224f9701e57ec5ce0354d6a380b664f5c638Brian Osmanclass GrRenderTargetContext;
261f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
276a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor;
28d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkClipStack;
29f70b531daaf47db1ee95c70da9843f1dd1f418d3reedclass SkData;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
313cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
33d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkImageFilter;
3474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
35d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPath;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
37d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPixmap;
381e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreedclass SkRasterClip;
394ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
4071c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform;
4176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
4300d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
44fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
6002b7349af7ce61c3f7d301148b54e17877233030Mike Reedclass SK_API SkCanvas : SkNoncopyable {
61bada1885da479d948f065182d6dfa85a1140bda5reed    enum PrivateSaveLayerFlags {
62952538ed50661ad7dff6ec2b7af3f921e1d91b52caryclark        kDontClipToLayer_PrivateSaveLayerFlag   = 1U << 31,
63bada1885da479d948f065182d6dfa85a1140bda5reed    };
6473603f3c52ffd89fe9d035be827b566a0e7d3b79reed
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
66e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
6742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
6842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
6942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
7042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
7242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
7342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
7442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
7544977485bdac75c055c3fa638f118874ccd2d22freed     *      - kUnknown_SkAlphaType
7642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
7742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
7942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
8042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
815df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
825df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed
835df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
845df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed                                                         size_t rowBytes) {
855df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed        return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
865df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    }
875df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed
8842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
89e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
90e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
91e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
92cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
938d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
94e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
95e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
96e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
97e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
98e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
9996a857ef5a40b3d0751ec9ebaaa96d9f20b82b21reed    SkCanvas(int width, int height, const SkSurfaceProps* = NULL);
100e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
1016dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
102e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1038d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
1048d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
1051f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
1068d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
1074469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
1123d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1133d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    /** Construct a canvas with the specified bitmap to draw into.
1143d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1153d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita                        structure are copied to the canvas.
1163d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param props    New canvas surface properties.
1173d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    */
1183d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
1193d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
12374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
124c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
125c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
126c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
127c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
128c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
129c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
130898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    /**
131898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps
132898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  for the canvas to the location supplied by the caller, and returns true. Otherwise,
133898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  return false and leave the supplied props unchanged.
134898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     */
135898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    bool getProps(SkSurfaceProps*) const;
136898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman
1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
139210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
140e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  Trigger the immediate execution of all pending draw operations. For the GPU
141e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  backend this will resolve all rendering to the GPU surface backing the
142e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  SkSurface that owns this canvas.
143bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
144bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
145bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
146bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1474ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1484ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1494ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
150210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
15168260fa1e913cb1f1f4f07755acd11357a47dc6ftomhudson    virtual SkISize getBaseLayerSize() const;
1524ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1534ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1544ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1554ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1564ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
157210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
158c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
159c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
160c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
161c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
162c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
163c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
16452d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#ifndef SK_SUPPORT_LEGACY_GETDEVICE
16552d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedprotected:  // Can we make this private?
16652d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#endif
1671f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
16852d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedpublic:
16941e010cb901c0da9066c4df562030808c9ccd7f8reed    SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing() const {
17041e010cb901c0da9066c4df562030808c9ccd7f8reed        return this->getDevice();
17141e010cb901c0da9066c4df562030808c9ccd7f8reed    }
1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1739266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1749266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1759266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1769266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1779266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1789266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
1790b53d59a24f667350b4282f88470713902409030reed@google.com     *
1800b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
1810b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
1820b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
1830b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
1840b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1859266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1869c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
1879c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
1889c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
1891f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
1909c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
1919266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
19276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
19376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
194cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
195cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
1964a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
1974a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
1984a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
1994a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
20076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
201e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
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
237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
238a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
240b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
242b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
244b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
246b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
247b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
248b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
249b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
251a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
252b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
253a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
256b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
257b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
260a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
261a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
262a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
263a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
264b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(SkBitmap* bitmap, int srcX, int srcY);
265c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2664b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
267a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
268a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
269a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
270a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
27151df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
27251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
27351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2914cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2924cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2934cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2944cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2954cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2964cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2974cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2984cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
2994b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
3018d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
302dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
304dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
305dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
306dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
307dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
308d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
309d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
310d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
311d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
312d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
316dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
317ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
318ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
319ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
320ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
323d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
324d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
325d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
326021f631dc66da06dbe4aed21df2f27daecce9db7reed    int saveLayer(const SkRect& bounds, const SkPaint* paint) {
327021f631dc66da06dbe4aed21df2f27daecce9db7reed        return this->saveLayer(&bounds, paint);
328021f631dc66da06dbe4aed21df2f27daecce9db7reed    }
329d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
33070ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    /**
33170ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Temporary name.
33270ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Will allow any requests for LCD text to be respected, so the caller must be careful to
33370ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  only draw on top of opaque sections of the layer to get good results.
33470ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     */
33570ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
33670ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed
3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
340dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
34140408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
34240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
34340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
34440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
346d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
347d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
348d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
349d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3504960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    enum {
3514960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kIsOpaque_SaveLayerFlag         = 1 << 0,
3524960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kPreserveLCDText_SaveLayerFlag  = 1 << 1,
353bada1885da479d948f065182d6dfa85a1140bda5reed
354bada1885da479d948f065182d6dfa85a1140bda5reed#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
355bada1885da479d948f065182d6dfa85a1140bda5reed        kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
356bada1885da479d948f065182d6dfa85a1140bda5reed#endif
3574960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3584960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    typedef uint32_t SaveLayerFlags;
3594960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3604960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    struct SaveLayerRec {
361bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec()
362bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(nullptr), fPaint(nullptr), fBackdrop(nullptr), fSaveLayerFlags(0)
363bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
3644960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
3654960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            : fBounds(bounds)
3664960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fPaint(paint)
367bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(nullptr)
368bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fSaveLayerFlags(saveLayerFlags)
369bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
370bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
371bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed                     SaveLayerFlags saveLayerFlags)
372bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(bounds)
373bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fPaint(paint)
374bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(backdrop)
3754960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fSaveLayerFlags(saveLayerFlags)
3764960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        {}
3774960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
378bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkRect*           fBounds;    // optional
379bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkPaint*          fPaint;     // optional
380bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkImageFilter*    fBackdrop;  // optional
381bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerFlags          fSaveLayerFlags;
3824960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3834960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3844960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    int saveLayer(const SaveLayerRec&);
3854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
387dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
388dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
389dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
391e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
394ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
395ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
397a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
400ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
401ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
402ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41192362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41792362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4197438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about the origin.
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42292362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4247438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about a given point.
4257438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param degrees  The amount to rotate, in degrees
4267438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param px  The x coordinate of the point to rotate about.
4277438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param py  The y coordinate of the point to rotate about.
4287438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    */
4297438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    void rotate(SkScalar degrees, SkScalar px, SkScalar py);
4307438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43592362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44092362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4414b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44544c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
45195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
452e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Add the specified translation to the current draw depth of the canvas.
453e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack        @param z    The distance to translate in Z.
454e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Negative into screen, positive out of screen.
455e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Without translation, the draw depth defaults to 0.
456e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    */
457e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    void translateZ(SkScalar z);
458e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
45995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Set the current set of lights in the canvas.
46095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack        @param lights   The lights that we want the canvas to have.
46195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    */
46295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void setLights(sk_sp<SkLights> lights);
46395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
46495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Returns the current set of lights the canvas uses
46595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack      */
46695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> getLights() const;
46795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
46895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
4694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4744ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
475c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias);
476c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRect(const SkRect& rect, SkClipOp op) {
477669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRect(rect, op, false);
478669983856d99b9312be3166b7dd1f8483a90c315reed    }
479669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, bool doAntiAlias = false) {
480c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed        this->clipRect(rect, kIntersect_SkClipOp, doAntiAlias);
481669983856d99b9312be3166b7dd1f8483a90c315reed    }
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     */
489c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
490c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op) {
491669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRRect(rrect, op, false);
492669983856d99b9312be3166b7dd1f8483a90c315reed    }
493669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
494c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed        this->clipRRect(rrect, kIntersect_SkClipOp, doAntiAlias);
495669983856d99b9312be3166b7dd1f8483a90c315reed    }
4964ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4974ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4984ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4994ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
5004ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
5014ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
5024ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
503c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
504c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipPath(const SkPath& path, SkClipOp op) {
505669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipPath(path, op, false);
506669983856d99b9312be3166b7dd1f8483a90c315reed    }
507669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, bool doAntiAlias = false) {
508c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed        this->clipPath(path, kIntersect_SkClipOp, doAntiAlias);
509669983856d99b9312be3166b7dd1f8483a90c315reed    }
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5118f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@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    */
525c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRegion(const SkRegion& deviceRgn, SkClipOp op = kIntersect_SkClipOp);
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5353b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, 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). Note, for speed it may
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5473b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5548f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
556bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
557bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
558bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
559bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
5608f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
56174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
562bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
564845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
571374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkBlendMode mode = SkBlendMode::kSrcOver);
5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
574845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
578374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
580f4e0d9eb2d72fe92c30237de978936113143dc16reed    /**
581f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  Helper method for drawing a color in SRC mode, completely replacing all the pixels
582f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  in the current clip with this color.
583f4e0d9eb2d72fe92c30237de978936113143dc16reed     */
584f4e0d9eb2d72fe92c30237de978936113143dc16reed    void clear(SkColor color) {
585374772bd61951f01bf84fe17bf53d8867681c9aereed        this->drawColor(color, SkBlendMode::kSrc);
5868eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    }
5872a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
5882a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
58928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
59028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
59128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
592a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * dependent and one legal implementation is to do nothing. This method
593a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * ignores the current clip.
59428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
59528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
59628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
59728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
59828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
59928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
60028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
60128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
60228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
603a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     *  Fill the entire canvas (restricted to the current clip) with the
6042a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6052a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6062a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6070846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPaint(const SkPaint& paint);
6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6390846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6700846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRect(const SkRect& rect, const SkPaint& paint);
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
67787001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6824b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.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 left     The left side of the rectangle to be drawn
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
69444df651ebefc284acc2f66425dff3ea0b0e14b36msarett    /** Draw the outline of the specified region using the specified paint.
69544df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param region   The region to be drawn
69644df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param paint    The paint used to draw the region
69744df651ebefc284acc2f66425dff3ea0b0e14b36msarett    */
698dca352e2d42cfe698573947b3d11abc1eaade160msarett    void drawRegion(const SkRegion& region, const SkPaint& paint);
69944df651ebefc284acc2f66425dff3ea0b0e14b36msarett
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7050846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawOval(const SkRect& oval, const SkPaint&);
7064ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7074ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7084ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7094ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7104ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7114ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7124ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7134ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7140846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
716ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
717ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
718ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
719ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
720ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
721ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
73421af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        specified oval. Sweep angles are not treated as modulo 360 and thus can
73521af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        exceed a full sweep of the oval. Note that this differs slightly from
73621af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty
73721af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        or the sweep angle is zero nothing is drawn. If useCenter is true the oval
73821af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        center is inserted into the implied path before the arc and the path is
73921af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        closed back to the, center forming a wedge. Otherwise, the implied path
74021af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        contains just the arc and is not closed.
741ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param oval The bounds of oval used to define the shape of the arc.
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
743ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param sweepAngle Sweep angle (in degrees) measured clockwise.
74421af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        @param useCenter true means include the center of the oval.
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7650846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPath(const SkPath& path, const SkPaint& paint);
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
767d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with its top/left corner at (x,y), using the
768d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        specified paint, transformed by the current matrix.
769d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr
770d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image    The image to be drawn
771d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param left     The position of the left side of the image being drawn
772d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param top      The position of the top side of the image being drawn
773d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
774d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr     */
7750846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
776f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
777f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkPaint* paint = NULL) {
778f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImage(image.get(), left, top, paint);
779f8053da25981c6b3152b637c1c91f43cff194c25reed    }
780b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
781a5517e2b190a8083b38964972b031c13e99f1012reed    /**
782a5517e2b190a8083b38964972b031c13e99f1012reed     *  Controls the behavior at the edge of the src-rect, when specified in drawImageRect,
783a5517e2b190a8083b38964972b031c13e99f1012reed     *  trading off speed for exactness.
784a5517e2b190a8083b38964972b031c13e99f1012reed     *
785a5517e2b190a8083b38964972b031c13e99f1012reed     *  When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around
786a5517e2b190a8083b38964972b031c13e99f1012reed     *  the pixels in the image. If there is a src-rect specified, it is intended to restrict the
787a5517e2b190a8083b38964972b031c13e99f1012reed     *  pixels that will be read. However, for performance reasons, some implementations may slow
788a5517e2b190a8083b38964972b031c13e99f1012reed     *  down if they cannot read 1-pixel past the src-rect boundary at times.
789a5517e2b190a8083b38964972b031c13e99f1012reed     *
790a5517e2b190a8083b38964972b031c13e99f1012reed     *  This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable.
791a5517e2b190a8083b38964972b031c13e99f1012reed     *  If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect
792a5517e2b190a8083b38964972b031c13e99f1012reed     *  must be strictly respected, the caller should pass kStrict.
793a5517e2b190a8083b38964972b031c13e99f1012reed     */
794a5517e2b190a8083b38964972b031c13e99f1012reed    enum SrcRectConstraint {
795a5517e2b190a8083b38964972b031c13e99f1012reed        /**
796a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kStrict is specified, the implementation must respect the src-rect
797a5517e2b190a8083b38964972b031c13e99f1012reed         *  (if specified) strictly, and will never sample outside of those bounds during sampling
798a5517e2b190a8083b38964972b031c13e99f1012reed         *  even when filtering. This may be slower than kFast.
799a5517e2b190a8083b38964972b031c13e99f1012reed         */
800a5517e2b190a8083b38964972b031c13e99f1012reed        kStrict_SrcRectConstraint,
801a5517e2b190a8083b38964972b031c13e99f1012reed
802a5517e2b190a8083b38964972b031c13e99f1012reed        /**
803a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kFast is specified, the implementation may sample outside of the src-rect
80419e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon         *  (if specified) by half the width of filter. This allows greater flexibility
805a5517e2b190a8083b38964972b031c13e99f1012reed         *  to the implementation and can make the draw much faster.
806a5517e2b190a8083b38964972b031c13e99f1012reed         */
807a5517e2b190a8083b38964972b031c13e99f1012reed        kFast_SrcRectConstraint,
808a5517e2b190a8083b38964972b031c13e99f1012reed    };
809a5517e2b190a8083b38964972b031c13e99f1012reed
810a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified image, scaling and translating so that it fills the specified
811a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the image is transformed
812a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
813a5517e2b190a8083b38964972b031c13e99f1012reed     *
814a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param image      The image to be drawn
815a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the image to be drawn
816a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
817a5517e2b190a8083b38964972b031c13e99f1012reed     *                    image will be drawn
818a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the image, or NULL
819a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
820a5517e2b190a8083b38964972b031c13e99f1012reed     */
821e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
822e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint,
823e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
824e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that takes src SkIRect
825e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
826e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
827e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that assumes src == image-bounds
828e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
829e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint = kStrict_SrcRectConstraint);
83084984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
831f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
832f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint,
833f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
834f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), src, dst, paint, constraint);
835f8053da25981c6b3152b637c1c91f43cff194c25reed    }
836f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
837f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) {
838f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), isrc, dst, paint, cons);
839f8053da25981c6b3152b637c1c91f43cff194c25reed    }
840f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
841f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint cons = kStrict_SrcRectConstraint) {
842f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), dst, paint, cons);
843f8053da25981c6b3152b637c1c91f43cff194c25reed    }
844f8053da25981c6b3152b637c1c91f43cff194c25reed
8454c21dc5ddf3b482293ed34eead876d8d61a662c3reed    /**
8464c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  Draw the image stretched differentially to fit into dst.
8474c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  center is a rect within the image, and logically divides the image
8484c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
8494c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  image is the "center", then the center-rect should be [2, 2, 3, 3].
8504c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *
8514c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  If the dst is >= the image size, then...
8524c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The 4 corners are not stretched at all.
8534c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides are stretched in only one axis.
8544c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The center is stretched in both axes.
8554c21dc5ddf3b482293ed34eead876d8d61a662c3reed     * Else, for each axis where dst < image,
8564c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The corners shrink proportionally
8574c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides (along the shrink axis) and center are not drawn
8584c21dc5ddf3b482293ed34eead876d8d61a662c3reed     */
8594c21dc5ddf3b482293ed34eead876d8d61a662c3reed    void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
860f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr);
861f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
862f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr) {
863f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageNine(image.get(), center, dst, paint);
864f8053da25981c6b3152b637c1c91f43cff194c25reed    }
8654c21dc5ddf3b482293ed34eead876d8d61a662c3reed
8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
87291246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
87391246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
874f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
87591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
87691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8820846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
8830846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                    const SkPaint* paint = NULL);
8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
885a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified bitmap, scaling and translating so that it fills the specified
886a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
887a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
888a5517e2b190a8083b38964972b031c13e99f1012reed     *
889a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param bitmap     The bitmap to be drawn
890a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the bitmap to be drawn
891a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
892a5517e2b190a8083b38964972b031c13e99f1012reed     *                    bitmap will be drawn
893a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the bitmap, or NULL
894a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
895a5517e2b190a8083b38964972b031c13e99f1012reed     */
896e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
89784984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
898e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant where src is SkIRect
89984984efeb64787b88c5f8bd6929cfe2d58a3ba06reed    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
90084984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
901e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
90219e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon                        SrcRectConstraint = kStrict_SrcRectConstraint);
90384984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
904f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
905c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
906f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
907f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
908f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
909f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
910f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
9119bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
9129bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
9139bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
914f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
915f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
916f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
917f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
9180846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
9190846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                        const SkPaint* paint = NULL);
920f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
921c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
922c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
92371df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *
92471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  If the lattice divs or bounds are invalid, the entire lattice
92571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  struct will be ignored on the draw call.
926c573a40ed5024b463e47088d307e3164a486dba5msarett     */
927c573a40ed5024b463e47088d307e3164a486dba5msarett    struct Lattice {
9280764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        enum Flags : uint8_t {
9290764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            // If set, indicates that we should not draw corresponding rect.
9300764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            kTransparent_Flags = 1 << 0,
9310764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        };
9320764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
933c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of x-coordinates that divide the bitmap vertically.
93471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight).
935c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
93671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fXDivs;
937c573a40ed5024b463e47088d307e3164a486dba5msarett
938c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of y-coordinates that divide the bitmap horizontally.
93971df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom).
940c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
94171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fYDivs;
9420764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9430764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // If non-null, the length of this array must be equal to
9440764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // (fXCount + 1) * (fYCount + 1).  Note that we allow the first rect
94571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft).
94671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // In this case, the caller still must specify a flag (as a placeholder)
94771df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // for these empty rects.
9480764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The flags correspond to the rects in the lattice, first moving
9490764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // left to right and then top to bottom.
95071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const Flags*   fFlags;
9510764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9520764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The number of fXDivs.
95371df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fXCount;
954c573a40ed5024b463e47088d307e3164a486dba5msarett
955c573a40ed5024b463e47088d307e3164a486dba5msarett        // The number of fYDivs.
95671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fYCount;
95771df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett
95871df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // The bound to draw from.  Must be contained by the src that is being drawn,
95971df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // non-empty, and non-inverted.
96071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // If nullptr, the bounds are the entire src.
96171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const SkIRect* fBounds;
962c573a40ed5024b463e47088d307e3164a486dba5msarett    };
963c573a40ed5024b463e47088d307e3164a486dba5msarett
964c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
965c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
966c573a40ed5024b463e47088d307e3164a486dba5msarett     *
967c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Moving horizontally across the bitmap, alternating rects will be "scalable"
968c573a40ed5024b463e47088d307e3164a486dba5msarett     *  (in the x-dimension) to fit into dst or must be left "fixed".  The first rect
969c573a40ed5024b463e47088d307e3164a486dba5msarett     *  is treated as "fixed", but it's possible to specify an empty first rect by
970c573a40ed5024b463e47088d307e3164a486dba5msarett     *  making lattice.fXDivs[0] = 0.
971c573a40ed5024b463e47088d307e3164a486dba5msarett     *
972c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The scale factor for all "scalable" rects will be the same, and may be greater
973c573a40ed5024b463e47088d307e3164a486dba5msarett     *  than or less than 1 (meaning we can stretch or shrink).  If the number of
974c573a40ed5024b463e47088d307e3164a486dba5msarett     *  "fixed" pixels is greater than the width of the dst, we will collapse all of
975c573a40ed5024b463e47088d307e3164a486dba5msarett     *  the "scalable" regions and appropriately downscale the "fixed" regions.
976c573a40ed5024b463e47088d307e3164a486dba5msarett     *
977c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The same interpretation also applies to the y-dimension.
978c573a40ed5024b463e47088d307e3164a486dba5msarett     */
979c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
980c573a40ed5024b463e47088d307e3164a486dba5msarett                           const SkPaint* paint = nullptr);
981c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
982c573a40ed5024b463e47088d307e3164a486dba5msarett                          const SkPaint* paint = nullptr);
983c573a40ed5024b463e47088d307e3164a486dba5msarett
9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
992f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
993f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                  const SkPaint& paint);
9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
9964b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1002f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
1003f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                     const SkPaint& paint);
10044b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
10074b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1014f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
1015f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                      const SkPaint& paint);
10164b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1029f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1042f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
1043f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                        const SkMatrix* matrix, const SkPaint& paint);
10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
104545561a0b15fe045ba272c328684c3f7ae290785areed    /**
104645561a0b15fe045ba272c328684c3f7ae290785areed     *  Draw the text with each character/glyph individually transformed by its xform.
104745561a0b15fe045ba272c328684c3f7ae290785areed     *  If cullRect is not null, it is a conservative bounds of what will be drawn
104863f30d90498ca1a48868421b528036f3be30e2adreed     *  taking into account the xforms and the paint, and will be used to accelerate culling.
104945561a0b15fe045ba272c328684c3f7ae290785areed     */
105045561a0b15fe045ba272c328684c3f7ae290785areed    void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
105145561a0b15fe045ba272c328684c3f7ae290785areed                         const SkRect* cullRect, const SkPaint& paint);
105245561a0b15fe045ba272c328684c3f7ae290785areed
105300d5c2c6523321d25b32905ff4822f083a4173eefmalita    /** Draw the text blob, offset by (x,y), using the specified paint.
105400d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param blob     The text blob to be drawn
105500d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param x        The x-offset of the text being drawn
105600d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param y        The y-offset of the text being drawn
105700d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param paint    The paint used for the text (e.g. color, size, style)
105800d5c2c6523321d25b32905ff4822f083a4173eefmalita    */
105900d5c2c6523321d25b32905ff4822f083a4173eefmalita    void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
10602ab9057b31ee92060b9769ea1adfada51c11c010reed    void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
10612ab9057b31ee92060b9769ea1adfada51c11c010reed        this->drawTextBlob(blob.get(), x, y, paint);
10622ab9057b31ee92060b9769ea1adfada51c11c010reed    }
106300d5c2c6523321d25b32905ff4822f083a4173eefmalita
10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
1066a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
10698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10701c2c441fede0ae9573afc098017011e3439624a9reed    void drawPicture(const SkPicture* picture) {
10711c2c441fede0ae9573afc098017011e3439624a9reed        this->drawPicture(picture, NULL, NULL);
10721c2c441fede0ae9573afc098017011e3439624a9reed    }
1073ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture) {
1074f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get());
1075f8053da25981c6b3152b637c1c91f43cff194c25reed    }
10769b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
1077d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    /**
1078d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  Draw the picture into this canvas.
1079d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1080d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
1081d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  logically equivalent to
1082d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      save/concat/drawPicture/restore
1083d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1084d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1085d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1086d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  This is logically equivalent to
1087d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      saveLayer(paint)/drawPicture/restore
1088d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     */
1089d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
1090ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
1091f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get(), matrix, paint);
1092f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1093d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed
109495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
109595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /**
1096e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  Draw the picture into this canvas, with shadows!
109795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
109895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  We will use the canvas's lights along with the picture information (draw depths of
109995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
110095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  then use that set of shadowmaps to render the scene with shadows.
110195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
110295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
110395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  logically equivalent to
110495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      save/concat/drawPicture/restore
110595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
110695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
110795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
110895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  This is logically equivalent to
110995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      saveLayer(paint)/drawPicture/restore
111095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
1111e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  We also support using variance shadow maps for blurred shadows; the user can specify
1112e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  what shadow mapping algorithm to use with params.
1113e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1114e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - Then, the shadow map can be blurred, and when reading from it, the fragment shader
1115e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      can calculate the variance of the depth at a position by doing E(x^2) - E(x)^2.
1116e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1117e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      of the probability that the current surface is shadowed by using Chebyshev's
1118e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      inequality, and then use that to shade the fragment.
1119e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *
1120e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - There are a few problems with VSM.
1121e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1122e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                         will cause their shadow penumbras to overwrite otherwise solid
1123e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                         shadows.
1124e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      * Shape Distortion | We can combat Light Bleeding by biasing the shadow (setting
1125e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           mostly shaded fragments to completely shaded) and increasing
1126e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           the minimum allowed variance. However, this warps and rounds
1127e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           out the shape of the shadow.
112895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     */
112995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const SkPicture*,
113095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
1131e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkPaint* paint,
1132e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkShadowParams& params);
113395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const sk_sp<SkPicture>& picture,
113495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
1135e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkPaint* paint,
1136e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkShadowParams& params) {
1137e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack        this->drawShadowedPicture(picture.get(), matrix, paint, params);
113895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    }
113995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
114095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
1148559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
1149559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        If both textures and vertex-colors are NULL, it strokes hairlines with
1150559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the paint's color. This behavior is a useful debugging mode to visualize
1151559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the mesh.
1152559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
1158631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
11617d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        @param mode Used if both texs and colors are present. In this
11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
11637d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                    before being drawn using the paint.
11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
11674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11690846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawVertices(VertexMode vmode, int vertexCount,
11700846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPoint vertices[], const SkPoint texs[],
11717d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkColor colors[], SkBlendMode mode,
11720846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const uint16_t indices[], int indexCount,
11730846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPaint& paint);
1174cfb6bdf767796c950f89985445738d2d8e7f12b0reed    void drawVertices(VertexMode vmode, int vertexCount,
1175cfb6bdf767796c950f89985445738d2d8e7f12b0reed                      const SkPoint vertices[], const SkPoint texs[],
11767d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkColor colors[], const uint16_t indices[], int indexCount,
11777d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkPaint& paint) {
11787d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawVertices(vmode, vertexCount, vertices, texs, colors, SkBlendMode::kModulate,
11797d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                           indices, indexCount, paint);
11807d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
11817d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
1182b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1183b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
11846cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1185b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1186b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1187b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1188b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
11896cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1190b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
11917d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     @param mode specifies how are the colors and the textures combined if both of them are
1192b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1193963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1194963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1195b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
11967d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
11977d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
11987d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], const SkPaint& paint) {
11997d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
12007d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12017d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
12023cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
120371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
120471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
120571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  into a quad.
120671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
120771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *      xform maps [0, 0, tex.width, tex.height] -> quad
120871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
120971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The color array is optional. When specified, each color modulates the pixels in its
12107d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  corresponding quad (via the specified SkBlendMode).
121171c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
121271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The cullRect is optional. When specified, it must be a conservative bounds of all of the
121371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
121471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  intersect the current clip.
121571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
121671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
12177d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  and blendmode are used to affect each of the quads.
121871c3c760a83123ee0b3127b8c65c6394ce541c50reed     */
121971c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
12207d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect,
122171c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkPaint* paint);
12227d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12237d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
12247d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPaint* paint) {
12257d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
12267d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
122771c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
122871c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkRect* cullRect, const SkPaint* paint) {
12297d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
123071c3c760a83123ee0b3127b8c65c6394ce541c50reed    }
1231f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12327d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   int count, const SkRect* cullRect, const SkPaint* paint) {
12337d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
12347d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                        cullRect, paint);
12357d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12367d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
123771c3c760a83123ee0b3127b8c65c6394ce541c50reed    /**
12383cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
12393cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
12403cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
12413cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
12423cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
12433cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
12443cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
1245a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
1246a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
12476a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1248f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    /**
1249f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
1250f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a null-terminated utf8 string, and the value is a blob of data stored in an SkData
1251f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  (which may be null). The annotation is associated with the specified rectangle.
1252f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1253f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  The caller still retains its ownership of the data (if any).
1254f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1255f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
1256f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a picture or drawing to a PDF document) will pass on this information.
1257f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     */
1258f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    void drawAnnotation(const SkRect&, const char key[], SkData* value);
12590fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
12600fba3b97b5b0e3707b31931ab9325030b81c940fmtklein        this->drawAnnotation(rect, key, value.get());
12610fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    }
1262f70b531daaf47db1ee95c70da9843f1dd1f418d3reed
12638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12647765000709dc64eb23be7df47d1f995d1f787115fmalita#ifdef SK_INTERNAL
126553d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
126653d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita    #define SK_SUPPORT_LEGACY_DRAWFILTER
12677765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12687765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12694b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
127053d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
12718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1272dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12757765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated")
12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
12774b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1281dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1282dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12867765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
12887765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1291754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1292754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1293754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1294754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1295754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1296754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1297754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
12988f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1299754de5f65b466f721d952a379194cc94de376f42reed@google.com
13005c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
13015c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
13025c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
13035c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
13045c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
13055c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
13088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
13098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1310a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
13118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
131240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
131340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
131440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
131540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
131640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
131740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
13186bd5284415bd983b0628c4941dff5def40018f5abungeman        return fClipStack.get();
131940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
132040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1321c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
13225e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
132390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
132490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
132590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
13267d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
132790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
133136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
13321105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
133336736a2dae94947e075ac9503d5de7799772a5f7robertphillips
133436736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
133536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
133636736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetIgnoreSaveLayerBounds();
133736736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
133836736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetTreatSpriteAsBitmap();
133936736a2dae94947e075ac9503d5de7799772a5f7robertphillips
134036736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // TEMP helpers until we switch virtual over to const& for src-rect
134136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
134236736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              const SkPaint* paint,
134336736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              SrcRectConstraint constraint = kStrict_SrcRectConstraint);
134436736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
134536736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               const SkPaint* paint,
134636736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               SrcRectConstraint constraint = kStrict_SrcRectConstraint);
134736736a2dae94947e075ac9503d5de7799772a5f7robertphillips
1348cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    // expose minimum amount of information necessary for transitional refactoring
1349cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    /**
1350cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     * Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates.
1351cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     */
1352cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds);
1353cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson
1354da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillipsprotected:
135595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1356e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Returns the current (cumulative) draw depth of the canvas.
1357e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack      */
1358e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    SkScalar getZ() const;
1359e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
136095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> fLights;
136195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
136295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
136376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
1364e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
136576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1366c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1367884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onPeekPixels(SkPixmap*);
1368884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onAccessTopLayerPixels(SkPixmap*);
1369ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual SkImageInfo onImageInfo() const;
1370ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual bool onGetProps(SkSurfaceProps*) const;
1371ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual void onFlush();
1372c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1373e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1374e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13754960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // getSaveLayerStrategy()'s return value may suppress full layer allocation.
1376e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1377e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
13784960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kNoLayer_SaveLayerStrategy,
1379e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1380e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
13816ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
13824960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13834960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
13844960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        return kFullLayer_SaveLayerStrategy;
13854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    }
1386fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
13876cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
1388fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1389fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
1390cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    virtual void didTranslate(SkScalar dx, SkScalar dy) {
1391cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein        this->didConcat(SkMatrix::MakeTrans(dx, dy));
1392cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    }
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],
1421faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                           const SkPoint texCoords[4], SkBlendMode, 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&);
142744df651ebefc284acc2f66425dff3ea0b0e14b36msarett    virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
142841af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawOval(const SkRect&, const SkPaint&);
1429ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon    virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
1430ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon                           const SkPaint&);
143141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRRect(const SkRRect&, const SkPaint&);
143241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
143341af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
1434faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                                const SkPoint texs[], const SkColor colors[], SkBlendMode,
143541af966ab338e95eee81ab618ab28195075338f7reed                                const uint16_t indices[], int indexCount, const SkPaint&);
14362766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein
143771c3c760a83123ee0b3127b8c65c6394ce541c50reed    virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
1438faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                             int count, SkBlendMode, const SkRect* cull, const SkPaint*);
143941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPath(const SkPath&, const SkPaint&);
144041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
1441562fe4767cc73e08a4e039362bc0336aea66ecfbreed    virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
1442562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                 SrcRectConstraint);
14434c21dc5ddf3b482293ed34eead876d8d61a662c3reed    virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
14444c21dc5ddf3b482293ed34eead876d8d61a662c3reed                                 const SkPaint*);
1445168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
1446168820625c35a8c19f66c661efcbce7a5e334837msarett                                    const SkPaint*);
14474c21dc5ddf3b482293ed34eead876d8d61a662c3reed
144841af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
144941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
1450562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                  SrcRectConstraint);
145141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
145241af966ab338e95eee81ab618ab28195075338f7reed                                  const SkPaint*);
1453168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
1454168820625c35a8c19f66c661efcbce7a5e334837msarett                                     const SkPaint*);
145541af966ab338e95eee81ab618ab28195075338f7reed
14568f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
14578f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
14588f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
14598f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
14608f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
1461c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle);
1462c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle);
1463c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle);
1464c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp);
14658f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
146628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
146728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
1468d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
14699b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
147095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
147195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    virtual void onDrawShadowedPicture(const SkPicture*,
147295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                                       const SkMatrix*,
1473e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkPaint*,
1474e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkShadowParams& params);
147595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
14761356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
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:
14853aafe111b6cc388400092851cc53bbbdfcb8a81creed    /** After calling saveLayer(), there can be any number of devices that make
14863aafe111b6cc388400092851cc53bbbdfcb8a81creed     up the top-most drawing area. LayerIter can be used to iterate through
14873aafe111b6cc388400092851cc53bbbdfcb8a81creed     those devices. Note that the iterator is only valid until the next API
14883aafe111b6cc388400092851cc53bbbdfcb8a81creed     call made on the canvas. Ownership of all pointers in the iterator stays
14893aafe111b6cc388400092851cc53bbbdfcb8a81creed     with the canvas, so none of them should be modified or deleted.
14903aafe111b6cc388400092851cc53bbbdfcb8a81creed     */
14913aafe111b6cc388400092851cc53bbbdfcb8a81creed    class LayerIter /*: SkNoncopyable*/ {
14923aafe111b6cc388400092851cc53bbbdfcb8a81creed    public:
14933aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Initialize iterator with canvas, and set values for 1st device */
14943aafe111b6cc388400092851cc53bbbdfcb8a81creed        LayerIter(SkCanvas*);
14953aafe111b6cc388400092851cc53bbbdfcb8a81creed        ~LayerIter();
14963aafe111b6cc388400092851cc53bbbdfcb8a81creed
14973aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Return true if the iterator is done */
14983aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool done() const { return fDone; }
14993aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Cycle to the next device */
15003aafe111b6cc388400092851cc53bbbdfcb8a81creed        void next();
15013aafe111b6cc388400092851cc53bbbdfcb8a81creed
15023aafe111b6cc388400092851cc53bbbdfcb8a81creed        // These reflect the current device in the iterator
15033aafe111b6cc388400092851cc53bbbdfcb8a81creed
15043aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkBaseDevice*   device() const;
15053aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkMatrix& matrix() const;
15063aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkRasterClip& clip() const;
15073aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkPaint&  paint() const;
15083aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             x() const;
15093aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             y() const;
15103aafe111b6cc388400092851cc53bbbdfcb8a81creed
15113aafe111b6cc388400092851cc53bbbdfcb8a81creed    private:
15123aafe111b6cc388400092851cc53bbbdfcb8a81creed        // used to embed the SkDrawIter object directly in our instance, w/o
15133aafe111b6cc388400092851cc53bbbdfcb8a81creed        // having to expose that class def to the public. There is an assert
15143aafe111b6cc388400092851cc53bbbdfcb8a81creed        // in our constructor to ensure that fStorage is large enough
15153aafe111b6cc388400092851cc53bbbdfcb8a81creed        // (though needs to be a compile-time-assert!). We use intptr_t to work
15163aafe111b6cc388400092851cc53bbbdfcb8a81creed        // safely with 32 and 64 bit machines (to ensure the storage is enough)
15173aafe111b6cc388400092851cc53bbbdfcb8a81creed        intptr_t          fStorage[32];
15183aafe111b6cc388400092851cc53bbbdfcb8a81creed        class SkDrawIter* fImpl;    // this points at fStorage
15193aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkPaint           fDefaultPaint;
15203aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool              fDone;
15213aafe111b6cc388400092851cc53bbbdfcb8a81creed    };
15221356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
15234960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    static bool BoundsAffectsClip(SaveLayerFlags);
1524bada1885da479d948f065182d6dfa85a1140bda5reed    static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
15254960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
1526a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed    static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
1527a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     SkBaseDevice* dst, const SkMatrix& ctm,
1528a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     const SkClipStack* clipStack);
1529a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed
1530c83a29759a5c2966da5ab973e4fd90763e4c962breed    enum ShaderOverrideOpacity {
1531c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
1532c83a29759a5c2966da5ab973e4fd90763e4c962breed        kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
1533c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
1534c83a29759a5c2966da5ab973e4fd90763e4c962breed    };
1535c83a29759a5c2966da5ab973e4fd90763e4c962breed
153697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
153797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
1538c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(bool willOverwritesEntireSurface = false);
1539c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
1540c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
1541c83a29759a5c2966da5ab973e4fd90763e4c962breed        this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1542c83a29759a5c2966da5ab973e4fd90763e4c962breed                                                                : kNotOpaque_ShaderOverrideOpacity);
1543c83a29759a5c2966da5ab973e4fd90763e4c962breed    }
154497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
15458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
15468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15476bd5284415bd983b0628c4941dff5def40018f5abungeman    sk_sp<SkClipStack> fClipStack;
15488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
15498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
15508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
15518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
1552b679ca8926a832274b14fdb512f88f64b61d32eareed    enum {
1553a499f905e9340e4935447f2562fd92e8853382b1reed        kMCRecSize      = 128,  // most recent measurement
155431b80a9dc60ae5411ad6abd10269c4f88c635ec2reed        kMCRecCount     = 32,   // common depth for save/restores
15558c30a8196dd5903d2d23b4d0a5dc888e802bf698reed        kDeviceCMSize   = 176,  // most recent measurement
1556b679ca8926a832274b14fdb512f88f64b61d32eareed    };
1557b679ca8926a832274b14fdb512f88f64b61d32eareed    intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
1558a499f905e9340e4935447f2562fd92e8853382b1reed    intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15604a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
15614a8126e7f81384526629b1e21bf89b632ea13cd9reed
15622ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
156474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
156574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
156697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
156797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
156897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
156997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
157097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
157197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
157245c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1573fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
15758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
15768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15772ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
15782ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
15798c30a8196dd5903d2d23b4d0a5dc888e802bf698reed    void internalSetMatrix(const SkMatrix&);
15802ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
15819c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
15828926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
15839c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
15842a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
158552d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1586439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkRecorder;        // resetForNextPicture
1587439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkLiteRecorder;    // resetForNextPicture
1588439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkNoDrawCanvas;    // InitFlags
15892d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1590c83a29759a5c2966da5ab973e4fd90763e4c962breed    friend class SkPictureRecord;   // predrawNotify (why does it need it? <reed>)
15914960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
15921356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby    friend class SkDeferredCanvas;  // For use of resetForNextPicture
159322886c493596655d8fd9512951f9010869b7fbc5Matt Sarett    friend class SkOverdrawCanvas;
1594b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1595d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1596d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1597d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1598d954498c01ccf0417feacf89e45d0c62a06a813breed    };
159978e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
1600fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips    SkCanvas(SkBaseDevice* device, InitFlags);
1601d954498c01ccf0417feacf89e45d0c62a06a813breed
1602feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein    void resetForNextPicture(const SkIRect& bounds);
1603feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein
16048f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1605a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1606b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
16074a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
16084a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
16094a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
16104a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
16114a8126e7f81384526629b1e21bf89b632ea13cd9reed
1612d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1613f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1614403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1615afc7cce5d68663934128d76963cd501f771d71desenorblanco     * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
16164ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
16174ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1618afc7cce5d68663934128d76963cd501f771d71desenorblanco    SkIRect getTopLayerBounds() const;
1619403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
16207112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1621eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1622a5517e2b190a8083b38964972b031c13e99f1012reed                                SrcRectConstraint);
1623fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
16244960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
16257503d60847c4ad22df87458aecd917772b23d293reed    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1626fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
16278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
16282ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
16298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
163052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
163152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
163252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
163352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
163452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
16354b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1636fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    // only for canvasutils
1637fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    const SkRegion& internal_private_getTotalClip() const;
1638fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
1639c83a29759a5c2966da5ab973e4fd90763e4c962breed    /*
1640c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  Returns true if drawing the specified rect (or all if it is null) with the specified
1641c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  paint (or default if null) would overwrite the entire root device of the canvas
1642c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  (i.e. the canvas' surface if it had one).
1643c83a29759a5c2966da5ab973e4fd90763e4c962breed     */
1644c83a29759a5c2966da5ab973e4fd90763e4c962breed    bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
1645c83a29759a5c2966da5ab973e4fd90763e4c962breed
1646262a71b7f95ce98ff3dd8dba845afbd724470903reed    /**
1647262a71b7f95ce98ff3dd8dba845afbd724470903reed     *  Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
1648262a71b7f95ce98ff3dd8dba845afbd724470903reed     */
1649262a71b7f95ce98ff3dd8dba845afbd724470903reed    bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
1650c83a29759a5c2966da5ab973e4fd90763e4c962breed
1651fbfa25802709139c2f14e304319c9541da65ca27msarett
1652fbfa25802709139c2f14e304319c9541da65ca27msarett    /**
1653fbfa25802709139c2f14e304319c9541da65ca27msarett     *  Keep track of the device clip bounds and if the matrix is scale-translate.  This allows
1654fbfa25802709139c2f14e304319c9541da65ca27msarett     *  us to do a fast quick reject in the common case.
16558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
16569637ea91b88ff8f8e95325bfc41417ffc4d5ee0bmsarett    bool   fIsScaleTranslate;
1657fbfa25802709139c2f14e304319c9541da65ca27msarett    SkRect fDeviceClipBounds;
1658fbfa25802709139c2f14e304319c9541da65ca27msarett
16598f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
166045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
166142b73eb00367c8315974b1c374308d20efa78897reed    const bool fConservativeRasterClip;
16628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16635c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
16645c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
16655c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
16665c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
16675c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
16685c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
16695c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16705c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
16715c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
16725c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
16735c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16745c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
16755c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
16765c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
16775c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
16785c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
167915e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
168015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
16818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
16828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
16848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
16858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
16868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
16878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
16888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
16892887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
16902887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
16912887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
16922887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
16932887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
16942887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
16958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
16968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
16978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1698f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1699f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1700f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1701f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1702f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1703f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1704f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1705f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1706f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1707f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1708f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1709f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1710f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1711f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
17128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
17138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
17158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
17168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
17178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1718e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
17198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1720c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1721c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1722c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
1723c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipRect(const SkRect&, SkClipOp, bool antialias) = 0;
1724c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipRRect(const SkRRect&, SkClipOp, bool antialias) = 0;
1725c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipPath(const SkPath&, SkClipOp, bool antialias) = 0;
1726c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
17272a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
17288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1729