SkCanvas.h revision c61abeed8958a757c6b49937f28b63066148dd67
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
11374772bd61951f01bf84fe17bf53d8867681c9aereed#include "SkBlendMode.h"
1273603f3c52ffd89fe9d035be827b566a0e7d3b79reed#include "SkClipOp.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
15356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed#include "SkRasterHandleAllocator.h"
164a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h"
1795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#include "SkLights.h"
18e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack#include "../private/SkShadowParams.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
20d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass GrContext;
211105224f9701e57ec5ce0354d6a380b664f5c638Brian Osmanclass GrRenderTargetContext;
221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
23267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkBitmap;
246a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor;
25d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkClipStack;
26f70b531daaf47db1ee95c70da9843f1dd1f418d3reedclass SkData;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
283cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
30267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkImage;
31d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkImageFilter;
3274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
33d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPath;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
35d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPixmap;
361e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreedclass SkRasterClip;
37267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkRegion;
384ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
3971c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform;
4076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
4200d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
43199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomonclass SkVertices;
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
1533661bc997620899695041010a750d11dbe8a972dMike Reed#ifdef SK_SUPPORT_LEGACY_CANVAS_HELPERS
1544ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1554ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1564ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1574ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
1583661bc997620899695041010a750d11dbe8a972dMike Reed#endif
159210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
160c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
16176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
162cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
163cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
1644a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
1654a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
1664a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
1674a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
16876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
169e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
170e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
171644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
172644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
173644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
174644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
175644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
176644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
1774b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
1784b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
179daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
1809c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
1819c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
1829c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
1836b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
1849c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
1859c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
1869c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
1879c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
1886b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
1899c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
1906b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
1919c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
192356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
193356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed
1949c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
1959c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
1969c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
1976ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  local RAM) return true, and if not null, return in the pixmap parameter information about
1986ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  the pixels. The pixmap's pixel address is only valid
199c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
2006ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  canvas (or its parent surface if any) will invalidate the pixel address
2016ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  (and associated information).
202c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
2036ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  On failure, returns false and the pixmap parameter will be ignored.
204c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
2056ceeebd37a43d879c120b6ba100ae1febdd67a18reed    bool peekPixels(SkPixmap*);
2066ceeebd37a43d879c120b6ba100ae1febdd67a18reed
207a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
208a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
209a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
210b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
211a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
212b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
213a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
214b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
215a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
216b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
217b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
218b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
219b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
220a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
221a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
222b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
223a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
224a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
225a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
226b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
227b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
228a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
229a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
230a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
231a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
232a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
234b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(SkBitmap* bitmap, int srcX, int srcY);
235c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2364b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
238a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
24151df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
24251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
24351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2444cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2454cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2464cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2474cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2484cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2494cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2504cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2514cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2524cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2534cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2544cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2554cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2564cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2574cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2584cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2594cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2604cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2614cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2624cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2634cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2644cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2654cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2664cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2674cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2684cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
2694b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
2718d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
272dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
274dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
275dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
276dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
277dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
278d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
279d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
280d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
281d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
282d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
286dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
287ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
288ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
289ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
290ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
293d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
294d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
295d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
296021f631dc66da06dbe4aed21df2f27daecce9db7reed    int saveLayer(const SkRect& bounds, const SkPaint* paint) {
297021f631dc66da06dbe4aed21df2f27daecce9db7reed        return this->saveLayer(&bounds, paint);
298021f631dc66da06dbe4aed21df2f27daecce9db7reed    }
299d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
30070ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    /**
30170ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Temporary name.
30270ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Will allow any requests for LCD text to be respected, so the caller must be careful to
30370ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  only draw on top of opaque sections of the layer to get good results.
30470ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     */
30570ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
30670ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
310dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
31140408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
31240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
31340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
31440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
316d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
317d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
318d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
319d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3204960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    enum {
3214960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kIsOpaque_SaveLayerFlag         = 1 << 0,
3224960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kPreserveLCDText_SaveLayerFlag  = 1 << 1,
323bada1885da479d948f065182d6dfa85a1140bda5reed
324c61abeed8958a757c6b49937f28b63066148dd67Mike Reed        /** initialize the new layer with the contents of the previous layer */
325c61abeed8958a757c6b49937f28b63066148dd67Mike Reed        kInitWithPrevious_SaveLayerFlag = 1 << 2,
326c61abeed8958a757c6b49937f28b63066148dd67Mike Reed
327bada1885da479d948f065182d6dfa85a1140bda5reed#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
328bada1885da479d948f065182d6dfa85a1140bda5reed        kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
329bada1885da479d948f065182d6dfa85a1140bda5reed#endif
3304960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3314960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    typedef uint32_t SaveLayerFlags;
3324960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3334960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    struct SaveLayerRec {
334bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec()
335bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(nullptr), fPaint(nullptr), fBackdrop(nullptr), fSaveLayerFlags(0)
336bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
3374960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
3384960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            : fBounds(bounds)
3394960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fPaint(paint)
340bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(nullptr)
341bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fSaveLayerFlags(saveLayerFlags)
342bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
343bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
344bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed                     SaveLayerFlags saveLayerFlags)
345bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(bounds)
346bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fPaint(paint)
347bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(backdrop)
3484960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fSaveLayerFlags(saveLayerFlags)
3494960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        {}
3504960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
351bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkRect*           fBounds;    // optional
352bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkPaint*          fPaint;     // optional
353bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkImageFilter*    fBackdrop;  // optional
354bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerFlags          fSaveLayerFlags;
3554960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3564960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3574960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    int saveLayer(const SaveLayerRec&);
3584960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
360dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
361dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
362dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
364e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
367ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
368ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
370a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
373ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
374ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
375ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
38492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
39092362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3927438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about the origin.
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
39592362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3977438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about a given point.
3987438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param degrees  The amount to rotate, in degrees
3997438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param px  The x coordinate of the point to rotate about.
4007438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param py  The y coordinate of the point to rotate about.
4017438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    */
4027438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    void rotate(SkScalar degrees, SkScalar px, SkScalar py);
4037438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman
4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
40892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4144b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41844c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4194b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
42495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
425e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Add the specified translation to the current draw depth of the canvas.
426e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack        @param z    The distance to translate in Z.
427e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Negative into screen, positive out of screen.
428e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Without translation, the draw depth defaults to 0.
429e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    */
430e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    void translateZ(SkScalar z);
431e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
43295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Set the current set of lights in the canvas.
43395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack        @param lights   The lights that we want the canvas to have.
43495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    */
43595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void setLights(sk_sp<SkLights> lights);
43695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
43795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Returns the current set of lights the canvas uses
43895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack      */
43995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> getLights() const;
44095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
44195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
4424ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4434ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4444ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4454ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4464ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4474ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
448c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias);
449c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRect(const SkRect& rect, SkClipOp op) {
450669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRect(rect, op, false);
451669983856d99b9312be3166b7dd1f8483a90c315reed    }
452669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, bool doAntiAlias = false) {
4532dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
454669983856d99b9312be3166b7dd1f8483a90c315reed    }
4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4575f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * Sets the max clip rectangle, which can be set by clipRect, clipRRect and
4585f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * clipPath and intersect the current clip with the specified rect.
4595f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * The max clip affects only future ops (it is not retroactive).
4605f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * We DON'T record the clip restriction in pictures.
4615f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * This is private API to be used only by Android framework.
4625f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * @param rect   The maximum allowed clip in device coordinates.
4635f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     *               Empty rect means max clip is not enforced.
4645f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     */
4655f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
4665f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev
4675f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    /**
4684ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
473c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
474c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op) {
475669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRRect(rrect, op, false);
476669983856d99b9312be3166b7dd1f8483a90c315reed    }
477669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
4782dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
479669983856d99b9312be3166b7dd1f8483a90c315reed    }
4804ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4814ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4824ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4834ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
4844ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4854ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4864ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
487c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
488c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipPath(const SkPath& path, SkClipOp op) {
489669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipPath(path, op, false);
490669983856d99b9312be3166b7dd1f8483a90c315reed    }
491669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, bool doAntiAlias = false) {
4922dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
493669983856d99b9312be3166b7dd1f8483a90c315reed    }
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4958f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
49645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
49745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
49845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
49945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
50045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
50145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
5076e998e6137e6b25f047b5c5943f2b02485165e3emtklein        @param op The region op to apply to the current clip
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5092dc523722ec27003ced0735618531f9f2aed1f01Mike Reed    void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5193b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5313b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
533918e144408ba218df919528f8b48c544f4767883Mike Reed    /**
534918e144408ba218df919528f8b48c544f4767883Mike Reed     *  Return the bounds of the current clip in local coordinates. If the clip is empty,
535918e144408ba218df919528f8b48c544f4767883Mike Reed     *  return { 0, 0, 0, 0 }.
536918e144408ba218df919528f8b48c544f4767883Mike Reed     */
53742e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); }
5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
539918e144408ba218df919528f8b48c544f4767883Mike Reed    /**
5406f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     *  Returns true if the clip bounds are non-empty.
5416f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     */
5426f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    bool getLocalClipBounds(SkRect* bounds) const {
5436f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        *bounds = this->onGetLocalClipBounds();
5446f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        return !bounds->isEmpty();
5456f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    }
5466f4a9b294868a94e5b1e06a8e855833614355bccMike Reed
5476f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    /**
548918e144408ba218df919528f8b48c544f4767883Mike Reed     *  Return the bounds of the current clip in device coordinates. If the clip is empty,
549918e144408ba218df919528f8b48c544f4767883Mike Reed     *  return { 0, 0, 0, 0 }.
550918e144408ba218df919528f8b48c544f4767883Mike Reed     */
55142e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); }
55242e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
5536f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    /**
5546f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     *  Returns true if the clip bounds are non-empty.
5556f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     */
5566f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    bool getDeviceClipBounds(SkIRect* bounds) const {
5576f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        *bounds = this->onGetDeviceClipBounds();
5586f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        return !bounds->isEmpty();
5596f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    }
5606f4a9b294868a94e5b1e06a8e855833614355bccMike Reed
5613661bc997620899695041010a750d11dbe8a972dMike Reed#ifdef SK_SUPPORT_LEGACY_CANVAS_HELPERS
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
563845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
570374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkBlendMode mode = SkBlendMode::kSrcOver);
5713661bc997620899695041010a750d11dbe8a972dMike Reed#endif
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
6413661bc997620899695041010a750d11dbe8a972dMike Reed    /** Helper method for drawing a single point. See drawPoints() for more details.
6423661bc997620899695041010a750d11dbe8a972dMike Reed     */
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6444b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6453661bc997620899695041010a750d11dbe8a972dMike Reed#ifdef SK_SUPPORT_LEGACY_CANVAS_HELPERS
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);
6523661bc997620899695041010a750d11dbe8a972dMike Reed#endif
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6633661bc997620899695041010a750d11dbe8a972dMike Reed    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, 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
6833661bc997620899695041010a750d11dbe8a972dMike Reed#ifdef SK_SUPPORT_LEGACY_CANVAS_HELPERS
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
6943661bc997620899695041010a750d11dbe8a972dMike Reed#endif
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
69644df651ebefc284acc2f66425dff3ea0b0e14b36msarett    /** Draw the outline of the specified region using the specified paint.
69744df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param region   The region to be drawn
69844df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param paint    The paint used to draw the region
69944df651ebefc284acc2f66425dff3ea0b0e14b36msarett    */
700dca352e2d42cfe698573947b3d11abc1eaade160msarett    void drawRegion(const SkRegion& region, const SkPaint& paint);
70144df651ebefc284acc2f66425dff3ea0b0e14b36msarett
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7070846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawOval(const SkRect& oval, const SkPaint&);
7084ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7094ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7104ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7114ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7124ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7134ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7144ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7154ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7160846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
718ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
719ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
720ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
721ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
722ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
723ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7323661bc997620899695041010a750d11dbe8a972dMike Reed    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
73521af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        specified oval. Sweep angles are not treated as modulo 360 and thus can
73621af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        exceed a full sweep of the oval. Note that this differs slightly from
73721af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty
73821af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        or the sweep angle is zero nothing is drawn. If useCenter is true the oval
73921af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        center is inserted into the implied path before the arc and the path is
74021af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        closed back to the, center forming a wedge. Otherwise, the implied path
74121af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        contains just the arc and is not closed.
742ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param oval The bounds of oval used to define the shape of the arc.
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
744ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param sweepAngle Sweep angle (in degrees) measured clockwise.
74521af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        @param useCenter true means include the center of the oval.
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7583661bc997620899695041010a750d11dbe8a972dMike Reed    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 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.
1161199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param mode Used if both texs and colors are present and paint has a
1162199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    shader. In this case the colors are combined with the texture
1163199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    using mode, 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    }
1181199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    enum VerticesFlags {
1182199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        /** Ignore the vertices' colors and instead use the paint color. */
1183199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        kIgnoreColors_VerticesFlag = 0x1,
1184199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        /** Ignore the vertices' tex coords (and any shader on the paint). */
1185199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        kIgnoreTexCoords_VerticesFlag = 0x2
1186199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    };
1187199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    /** Draw vertices from an immutable SkVertices object.
1188199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon
1189199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param vertices The mesh to draw.
1190199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param mode Used if both texs and colors are present and paint has a
1191199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    shader. In this case the colors are combined with the texture
1192199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    using mode, before being drawn using the paint.
1193199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param paint Specifies the shader/texture if present.
1194199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param flags Allows the caller to ignore colors or texs on vertices.
1195199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     */
1196199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    void drawVertices(sk_sp<SkVertices> vertices, SkBlendMode mode, const SkPaint& paint,
1197199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                      uint32_t flags = 0);
11987d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
1199b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1200b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
12016cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1202b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1203b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1204b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1205b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
12066cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1207b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
12087d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     @param mode specifies how are the colors and the textures combined if both of them are
1209b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1210963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1211963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1212b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
12137d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
12147d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
12157d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], const SkPaint& paint) {
12167d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
12177d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12187d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
12193cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
122071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
122171c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
122271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  into a quad.
122371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
122471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *      xform maps [0, 0, tex.width, tex.height] -> quad
122571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
122671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The color array is optional. When specified, each color modulates the pixels in its
12277d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  corresponding quad (via the specified SkBlendMode).
122871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
122971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The cullRect is optional. When specified, it must be a conservative bounds of all of the
123071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
123171c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  intersect the current clip.
123271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
123371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
12347d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  and blendmode are used to affect each of the quads.
123571c3c760a83123ee0b3127b8c65c6394ce541c50reed     */
123671c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
12377d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect,
123871c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkPaint* paint);
12397d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12407d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
12417d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPaint* paint) {
12427d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
12437d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
124471c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
124571c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkRect* cullRect, const SkPaint* paint) {
12467d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
124771c3c760a83123ee0b3127b8c65c6394ce541c50reed    }
1248f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12497d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   int count, const SkRect* cullRect, const SkPaint* paint) {
12507d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
12517d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                        cullRect, paint);
12527d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12537d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
125471c3c760a83123ee0b3127b8c65c6394ce541c50reed    /**
12553cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
12563cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
12573cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
12583cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
12593cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
12603cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
12613cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
1262a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
1263a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
12646a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1265f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    /**
1266f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
1267f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a null-terminated utf8 string, and the value is a blob of data stored in an SkData
1268f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  (which may be null). The annotation is associated with the specified rectangle.
1269f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1270f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  The caller still retains its ownership of the data (if any).
1271f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1272f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
1273f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a picture or drawing to a PDF document) will pass on this information.
1274f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     */
1275f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    void drawAnnotation(const SkRect&, const char key[], SkData* value);
12760fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
12770fba3b97b5b0e3707b31931ab9325030b81c940fmtklein        this->drawAnnotation(rect, key, value.get());
12780fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    }
1279f70b531daaf47db1ee95c70da9843f1dd1f418d3reed
12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12817765000709dc64eb23be7df47d1f995d1f787115fmalita#ifdef SK_INTERNAL
128253d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
128353d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita    #define SK_SUPPORT_LEGACY_DRAWFILTER
12847765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12857765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12864b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
128753d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1289dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
12908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
12918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12927765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated")
12938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
12944b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
12968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
12978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1298dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1299dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
13008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
13037765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
13057765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1308754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1309754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1310754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1311754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1312754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1313754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1314754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
13158f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1316754de5f65b466f721d952a379194cc94de376f42reed@google.com
13175c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
13185c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
13195c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
13205c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
13215c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
13225c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
13238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
13258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
13268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1327a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1329c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
13305e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
133190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
133290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
133390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
13347d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
133590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
133936736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
13401105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
134136736a2dae94947e075ac9503d5de7799772a5f7robertphillips
134236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
134336736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
134436736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetIgnoreSaveLayerBounds();
134536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
134636736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetTreatSpriteAsBitmap();
134736736a2dae94947e075ac9503d5de7799772a5f7robertphillips
134836736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // TEMP helpers until we switch virtual over to const& for src-rect
134936736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
135036736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              const SkPaint* paint,
135136736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              SrcRectConstraint constraint = kStrict_SrcRectConstraint);
135236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
135336736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               const SkPaint* paint,
135436736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               SrcRectConstraint constraint = kStrict_SrcRectConstraint);
135536736a2dae94947e075ac9503d5de7799772a5f7robertphillips
1356cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    // expose minimum amount of information necessary for transitional refactoring
1357cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    /**
1358cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     * Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates.
1359cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     */
1360cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds);
1361cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson
13623726a4ac68821deea7ef4d5472a42f7d35ec4b4eMike Reed    void temporary_internal_getRgnClip(SkRegion*);
13633726a4ac68821deea7ef4d5472a42f7d35ec4b4eMike Reed
1364da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillipsprotected:
136595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1366e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Returns the current (cumulative) draw depth of the canvas.
1367e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack      */
1368e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    SkScalar getZ() const;
1369e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
137095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> fLights;
137195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
137295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
137376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
1374e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
137576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1376c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1377884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onPeekPixels(SkPixmap*);
1378884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onAccessTopLayerPixels(SkPixmap*);
1379ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual SkImageInfo onImageInfo() const;
1380ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual bool onGetProps(SkSurfaceProps*) const;
1381ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual void onFlush();
1382c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1383e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1384e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // getSaveLayerStrategy()'s return value may suppress full layer allocation.
1386e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1387e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
13884960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kNoLayer_SaveLayerStrategy,
1389e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1390e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
13916ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
13924960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13934960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
13944960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        return kFullLayer_SaveLayerStrategy;
13954960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    }
1396fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
13976cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
1398fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1399fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
1400cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    virtual void didTranslate(SkScalar dx, SkScalar dy) {
1401cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein        this->didConcat(SkMatrix::MakeTrans(dx, dy));
1402cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    }
140395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
140495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1405e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    virtual void didTranslateZ(SkScalar) {}
140695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
140744c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
140842e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    virtual SkRect onGetLocalClipBounds() const;
140942e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    virtual SkIRect onGetDeviceClipBounds() const;
141042e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
141142e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
1412f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
1413ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1414ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1415e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1416e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1417b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1418e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1419e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1420b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1421e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1422e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1423e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1424b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1425e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1426e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1427e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
142845561a0b15fe045ba272c328684c3f7ae290785areed    virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
142945561a0b15fe045ba272c328684c3f7ae290785areed                                   const SkRect* cullRect, const SkPaint& paint);
14306cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
143100d5c2c6523321d25b32905ff4822f083a4173eefmalita    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
143200d5c2c6523321d25b32905ff4822f083a4173eefmalita                                const SkPaint& paint);
143300d5c2c6523321d25b32905ff4822f083a4173eefmalita
1434b3c9d1c33caf325aada244204215eb790c228c12dandov    virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
1435faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                           const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
1436e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1437a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
14386a070dc06af4e9f305f9d08a69e34d18ade473cbreed
143941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPaint(const SkPaint&);
144041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRect(const SkRect&, const SkPaint&);
144144df651ebefc284acc2f66425dff3ea0b0e14b36msarett    virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
144241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawOval(const SkRect&, const SkPaint&);
1443ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon    virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
1444ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon                           const SkPaint&);
144541af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRRect(const SkRRect&, const SkPaint&);
144641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
144741af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
1448faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                                const SkPoint texs[], const SkColor colors[], SkBlendMode,
144941af966ab338e95eee81ab618ab28195075338f7reed                                const uint16_t indices[], int indexCount, const SkPaint&);
1450199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    virtual void onDrawVerticesObject(sk_sp<SkVertices> vertices, SkBlendMode mode,
1451199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                                      const SkPaint& paint, uint32_t flags);
1452199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    // Subclasses can use this put the vertices object call on the regular draw vertices code path.
1453199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    // This is temporary until we teach recording and other SkCanvas classes about SkVertices.
1454199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    void onDrawVerticesObjectFallback(sk_sp<SkVertices> vertices, SkBlendMode mode,
1455199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                                      const SkPaint& paint, uint32_t flags);
14562766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein
145771c3c760a83123ee0b3127b8c65c6394ce541c50reed    virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
1458faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                             int count, SkBlendMode, const SkRect* cull, const SkPaint*);
145941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPath(const SkPath&, const SkPaint&);
146041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
1461562fe4767cc73e08a4e039362bc0336aea66ecfbreed    virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
1462562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                 SrcRectConstraint);
14634c21dc5ddf3b482293ed34eead876d8d61a662c3reed    virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
14644c21dc5ddf3b482293ed34eead876d8d61a662c3reed                                 const SkPaint*);
1465168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
1466168820625c35a8c19f66c661efcbce7a5e334837msarett                                    const SkPaint*);
14674c21dc5ddf3b482293ed34eead876d8d61a662c3reed
146841af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
146941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
1470562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                  SrcRectConstraint);
147141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
147241af966ab338e95eee81ab618ab28195075338f7reed                                  const SkPaint*);
1473168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
1474168820625c35a8c19f66c661efcbce7a5e334837msarett                                     const SkPaint*);
147541af966ab338e95eee81ab618ab28195075338f7reed
14768f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
14778f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
14788f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
14798f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
14808f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
1481c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle);
1482c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle);
1483c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle);
1484c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp);
14858f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
148628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
148728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
1488d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
14899b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
149095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
149195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    virtual void onDrawShadowedPicture(const SkPicture*,
149295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                                       const SkMatrix*,
1493e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkPaint*,
1494e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkShadowParams& params);
149595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
14961356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
1497a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1498a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1499c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1500c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
15014960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection,
1502c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1503a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1504c83a29759a5c2966da5ab973e4fd90763e4c962breedprivate:
15053aafe111b6cc388400092851cc53bbbdfcb8a81creed    /** After calling saveLayer(), there can be any number of devices that make
15063aafe111b6cc388400092851cc53bbbdfcb8a81creed     up the top-most drawing area. LayerIter can be used to iterate through
15073aafe111b6cc388400092851cc53bbbdfcb8a81creed     those devices. Note that the iterator is only valid until the next API
15083aafe111b6cc388400092851cc53bbbdfcb8a81creed     call made on the canvas. Ownership of all pointers in the iterator stays
15093aafe111b6cc388400092851cc53bbbdfcb8a81creed     with the canvas, so none of them should be modified or deleted.
15103aafe111b6cc388400092851cc53bbbdfcb8a81creed     */
15113aafe111b6cc388400092851cc53bbbdfcb8a81creed    class LayerIter /*: SkNoncopyable*/ {
15123aafe111b6cc388400092851cc53bbbdfcb8a81creed    public:
15133aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Initialize iterator with canvas, and set values for 1st device */
15143aafe111b6cc388400092851cc53bbbdfcb8a81creed        LayerIter(SkCanvas*);
15153aafe111b6cc388400092851cc53bbbdfcb8a81creed        ~LayerIter();
15163aafe111b6cc388400092851cc53bbbdfcb8a81creed
15173aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Return true if the iterator is done */
15183aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool done() const { return fDone; }
15193aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Cycle to the next device */
15203aafe111b6cc388400092851cc53bbbdfcb8a81creed        void next();
15213aafe111b6cc388400092851cc53bbbdfcb8a81creed
15223aafe111b6cc388400092851cc53bbbdfcb8a81creed        // These reflect the current device in the iterator
15233aafe111b6cc388400092851cc53bbbdfcb8a81creed
15243aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkBaseDevice*   device() const;
15253aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkMatrix& matrix() const;
15263aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkRasterClip& clip() const;
15273aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkPaint&  paint() const;
15283aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             x() const;
15293aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             y() const;
15303aafe111b6cc388400092851cc53bbbdfcb8a81creed
15313aafe111b6cc388400092851cc53bbbdfcb8a81creed    private:
15323aafe111b6cc388400092851cc53bbbdfcb8a81creed        // used to embed the SkDrawIter object directly in our instance, w/o
15333aafe111b6cc388400092851cc53bbbdfcb8a81creed        // having to expose that class def to the public. There is an assert
15343aafe111b6cc388400092851cc53bbbdfcb8a81creed        // in our constructor to ensure that fStorage is large enough
15353aafe111b6cc388400092851cc53bbbdfcb8a81creed        // (though needs to be a compile-time-assert!). We use intptr_t to work
15363aafe111b6cc388400092851cc53bbbdfcb8a81creed        // safely with 32 and 64 bit machines (to ensure the storage is enough)
15373aafe111b6cc388400092851cc53bbbdfcb8a81creed        intptr_t          fStorage[32];
15383aafe111b6cc388400092851cc53bbbdfcb8a81creed        class SkDrawIter* fImpl;    // this points at fStorage
15393aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkPaint           fDefaultPaint;
15403aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool              fDone;
15413aafe111b6cc388400092851cc53bbbdfcb8a81creed    };
15421356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
15434960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    static bool BoundsAffectsClip(SaveLayerFlags);
1544bada1885da479d948f065182d6dfa85a1140bda5reed    static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
15454960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
1546a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed    static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
1547c42a1cdd1de7a3cf57a9a5fd7363f5fb660e97d0Mike Reed                                     SkBaseDevice* dst, const SkIPoint& dstOrigin,
1548c42a1cdd1de7a3cf57a9a5fd7363f5fb660e97d0Mike Reed                                     const SkMatrix& ctm, const SkClipStack* clipStack);
1549a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed
1550c83a29759a5c2966da5ab973e4fd90763e4c962breed    enum ShaderOverrideOpacity {
1551c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
1552c83a29759a5c2966da5ab973e4fd90763e4c962breed        kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
1553c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
1554c83a29759a5c2966da5ab973e4fd90763e4c962breed    };
1555c83a29759a5c2966da5ab973e4fd90763e4c962breed
155697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
155797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
1558c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(bool willOverwritesEntireSurface = false);
1559c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
1560c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
1561c83a29759a5c2966da5ab973e4fd90763e4c962breed        this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1562c83a29759a5c2966da5ab973e4fd90763e4c962breed                                                                : kNotOpaque_ShaderOverrideOpacity);
1563c83a29759a5c2966da5ab973e4fd90763e4c962breed    }
156497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
15650ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita    SkBaseDevice* getDevice() const;
15660ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita    SkBaseDevice* getTopDevice() const;
15670ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita
15688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15706bd5284415bd983b0628c4941dff5def40018f5abungeman    sk_sp<SkClipStack> fClipStack;
15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
15738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
1575b679ca8926a832274b14fdb512f88f64b61d32eareed    enum {
1576a499f905e9340e4935447f2562fd92e8853382b1reed        kMCRecSize      = 128,  // most recent measurement
157731b80a9dc60ae5411ad6abd10269c4f88c635ec2reed        kMCRecCount     = 32,   // common depth for save/restores
15785f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev        kDeviceCMSize   = 184,  // most recent measurement
1579b679ca8926a832274b14fdb512f88f64b61d32eareed    };
1580b679ca8926a832274b14fdb512f88f64b61d32eareed    intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
1581a499f905e9340e4935447f2562fd92e8853382b1reed    intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
15828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15834a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
15844a8126e7f81384526629b1e21bf89b632ea13cd9reed
15852ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
15868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
1588356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    std::unique_ptr<SkRasterHandleAllocator> fAllocator;
158974bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
159097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
159197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
159297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
159397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
159497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
159597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
159645c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1597fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
15988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
15995f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
16008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
16018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16022ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
16032ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
16048c30a8196dd5903d2d23b4d0a5dc888e802bf698reed    void internalSetMatrix(const SkMatrix&);
16052ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
16069c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
16078926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
16082a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
160952d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1610439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkRecorder;        // resetForNextPicture
1611439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkLiteRecorder;    // resetForNextPicture
1612439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkNoDrawCanvas;    // InitFlags
16132d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1614c83a29759a5c2966da5ab973e4fd90763e4c962breed    friend class SkPictureRecord;   // predrawNotify (why does it need it? <reed>)
16154960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
16161356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby    friend class SkDeferredCanvas;  // For use of resetForNextPicture
161722886c493596655d8fd9512951f9010869b7fbc5Matt Sarett    friend class SkOverdrawCanvas;
1618356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    friend class SkRasterHandleAllocator;
1619b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1620d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1621d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1622d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1623d954498c01ccf0417feacf89e45d0c62a06a813breed    };
162478e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
1625fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips    SkCanvas(SkBaseDevice* device, InitFlags);
1626356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
1627356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed             SkRasterHandleAllocator::Handle);
1628d954498c01ccf0417feacf89e45d0c62a06a813breed
1629feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein    void resetForNextPicture(const SkIRect& bounds);
1630feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein
16318f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1632a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1633b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
16344a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
16354a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
16364a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
16374a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
16384a8126e7f81384526629b1e21bf89b632ea13cd9reed
1639d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1640f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1641403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1642afc7cce5d68663934128d76963cd501f771d71desenorblanco     * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
16434ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
16444ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1645afc7cce5d68663934128d76963cd501f771d71desenorblanco    SkIRect getTopLayerBounds() const;
1646403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
16477112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1648eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1649a5517e2b190a8083b38964972b031c13e99f1012reed                                SrcRectConstraint);
1650fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
16514960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
16527503d60847c4ad22df87458aecd917772b23d293reed    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1653fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
16548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
16552ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
16568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
16574b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1658c83a29759a5c2966da5ab973e4fd90763e4c962breed    /*
1659c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  Returns true if drawing the specified rect (or all if it is null) with the specified
1660c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  paint (or default if null) would overwrite the entire root device of the canvas
1661c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  (i.e. the canvas' surface if it had one).
1662c83a29759a5c2966da5ab973e4fd90763e4c962breed     */
1663c83a29759a5c2966da5ab973e4fd90763e4c962breed    bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
1664c83a29759a5c2966da5ab973e4fd90763e4c962breed
1665262a71b7f95ce98ff3dd8dba845afbd724470903reed    /**
1666262a71b7f95ce98ff3dd8dba845afbd724470903reed     *  Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
1667262a71b7f95ce98ff3dd8dba845afbd724470903reed     */
1668262a71b7f95ce98ff3dd8dba845afbd724470903reed    bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
1669c83a29759a5c2966da5ab973e4fd90763e4c962breed
167046784be70c4712942163bb2ade9e7364bca47157Mike Reed    /** Return the clip stack. The clip stack stores all the individual
167146784be70c4712942163bb2ade9e7364bca47157Mike Reed     *  clips organized by the save/restore frame in which they were
167246784be70c4712942163bb2ade9e7364bca47157Mike Reed     *  added.
167346784be70c4712942163bb2ade9e7364bca47157Mike Reed     *  @return the current clip stack ("list" of individual clip elements)
167446784be70c4712942163bb2ade9e7364bca47157Mike Reed     */
167546784be70c4712942163bb2ade9e7364bca47157Mike Reed    const SkClipStack* getClipStack() const {
167646784be70c4712942163bb2ade9e7364bca47157Mike Reed        return fClipStack.get();
167746784be70c4712942163bb2ade9e7364bca47157Mike Reed    }
1678fbfa25802709139c2f14e304319c9541da65ca27msarett
1679fbfa25802709139c2f14e304319c9541da65ca27msarett    /**
1680fbfa25802709139c2f14e304319c9541da65ca27msarett     *  Keep track of the device clip bounds and if the matrix is scale-translate.  This allows
1681fbfa25802709139c2f14e304319c9541da65ca27msarett     *  us to do a fast quick reject in the common case.
16828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
16839637ea91b88ff8f8e95325bfc41417ffc4d5ee0bmsarett    bool   fIsScaleTranslate;
1684fbfa25802709139c2f14e304319c9541da65ca27msarett    SkRect fDeviceClipBounds;
1685fbfa25802709139c2f14e304319c9541da65ca27msarett
16868f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
168745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
168842b73eb00367c8315974b1c374308d20efa78897reed    const bool fConservativeRasterClip;
16898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16905c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
16915c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
16925c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
16935c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
16945c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
16955c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
16965c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16975c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
16985c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
16995c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
17005c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
17015c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
17025c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
17035c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
17045c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
17055c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
170615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
170715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
17088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
17118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
17128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
17138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
17148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
17158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
17162887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
17172887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
17182887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
17192887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
17202887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
17212887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
17228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
17238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
17248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1725f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1726f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1727f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1728f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1729f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1730f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1731f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1732f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1733f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1734f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1735f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1736f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1737f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1738f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
17398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
17408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
17428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
17438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
17448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1745e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
17468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1747c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1748c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1749c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
1750c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipRect(const SkRect&, SkClipOp, bool antialias) = 0;
1751c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipRRect(const SkRRect&, SkClipOp, bool antialias) = 0;
1752c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    virtual void clipPath(const SkPath&, SkClipOp, bool antialias) = 0;
1753c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
17542a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
17558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1756