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"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
18d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass GrContext;
191105224f9701e57ec5ce0354d6a380b664f5c638Brian Osmanclass GrRenderTargetContext;
201f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
21267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkBitmap;
22d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkClipStack;
23f70b531daaf47db1ee95c70da9843f1dd1f418d3reedclass SkData;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
253cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
274204da25aa4c6e0b321314aa32fd9affb4865563Mike Reedstruct SkDrawShadowRec;
28267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkImage;
29d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkImageFilter;
30ab244f045a0740fa6106ed21a4e5824cd09f84f3Florin Malitaclass SkLights;
3174bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
32d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPath;
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
34d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPixmap;
351e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreedclass SkRasterClip;
36267be7fbc38174652c750ec69d8dc1feaa72db0cMike Reedclass SkRegion;
374ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
3871c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform;
3976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
4100d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
42199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomonclass SkVertices;
43fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
5902b7349af7ce61c3f7d301148b54e17877233030Mike Reedclass SK_API SkCanvas : SkNoncopyable {
60bada1885da479d948f065182d6dfa85a1140bda5reed    enum PrivateSaveLayerFlags {
61952538ed50661ad7dff6ec2b7af3f921e1d91b52caryclark        kDontClipToLayer_PrivateSaveLayerFlag   = 1U << 31,
62bada1885da479d948f065182d6dfa85a1140bda5reed    };
6373603f3c52ffd89fe9d035be827b566a0e7d3b79reed
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
65e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
6642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
6742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
6842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
6942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
7142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
7242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
7342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
7444977485bdac75c055c3fa638f118874ccd2d22freed     *      - kUnknown_SkAlphaType
7542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
7642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
7842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
7942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
800418a888d31689f5358b6b90fd09287aeba368dbCary Clark    static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
810418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                                      size_t rowBytes);
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     */
990418a888d31689f5358b6b90fd09287aeba368dbCary Clark    SkCanvas(int width, int height, const SkSurfaceProps* props = 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
11331f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
11431f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett    enum class ColorBehavior {
11531f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett        kLegacy,
11631f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett    };
11731f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett
11831f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett    /**
11931f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett     *  Android framework only constructor.
12031f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett     *  Allows the creation of a legacy SkCanvas even though the |bitmap|
12131f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett     *  and its pixel ref may have an SkColorSpace.
12231f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett     */
123304f9d4e0feb4665d88804c3a4c28b6397c377b0Cary Clark    SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior);
12431f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett#endif
12531f99ce7d2f3c2b61742d07ab92b6dac6a928ef9Matt Sarett
1263d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    /** Construct a canvas with the specified bitmap to draw into.
1273d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1283d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita                        structure are copied to the canvas.
1293d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param props    New canvas surface properties.
1303d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    */
1313d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
1323d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
13674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
137c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
138c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
139c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
140c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
141c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
142c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
143898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    /**
144898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps
145898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  for the canvas to the location supplied by the caller, and returns true. Otherwise,
146898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  return false and leave the supplied props unchanged.
147898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     */
1480418a888d31689f5358b6b90fd09287aeba368dbCary Clark    bool getProps(SkSurfaceProps* props) const;
149898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman
1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
152210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
153e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  Trigger the immediate execution of all pending draw operations. For the GPU
154e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  backend this will resolve all rendering to the GPU surface backing the
155e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  SkSurface that owns this canvas.
156bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
157bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
158bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
159bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1604ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1614ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1624ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
163210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
16468260fa1e913cb1f1f4f07755acd11357a47dc6ftomhudson    virtual SkISize getBaseLayerSize() const;
1654ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
166c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
16776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
168cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
169cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
1704a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
1714a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
1724a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
1734a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
17476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
175304f9d4e0feb4665d88804c3a4c28b6397c377b0Cary Clark    sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr);
176e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
177644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
178644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
179644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
180644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
181d2da87d0b8d127da0530c661618f059eb1cc0f1eBrian Osman    virtual GrContext* getGrContext();
182644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
1834b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
1844b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
185daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
1869c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
1879c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
1889c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
1896b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
1909c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
1919c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
1929c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
1939c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
1946b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
1959c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
1966b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
1979c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
198356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
199356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed
2009c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2019c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
2029c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2036ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  local RAM) return true, and if not null, return in the pixmap parameter information about
2046ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  the pixels. The pixmap's pixel address is only valid
205c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
2066ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  canvas (or its parent surface if any) will invalidate the pixel address
2076ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  (and associated information).
208c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
2096ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  On failure, returns false and the pixmap parameter will be ignored.
210c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
2110418a888d31689f5358b6b90fd09287aeba368dbCary Clark    bool peekPixels(SkPixmap* pixmap);
2126ceeebd37a43d879c120b6ba100ae1febdd67a18reed
213a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
214a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
215a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
216b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
217a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
218b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
219a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
220b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
221a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
222b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
223b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
224b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
225b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
226a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
227a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
228b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
229a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
230a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
231a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
232b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
233b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
2340418a888d31689f5358b6b90fd09287aeba368dbCary Clark    bool readPixels(const SkPixmap& pixmap, int srcX, int srcY);
235304f9d4e0feb4665d88804c3a4c28b6397c377b0Cary Clark    bool readPixels(const SkBitmap& bitmap, int srcX, int srcY);
236a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
2374cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2384cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2394cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2404cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2414cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2424cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2434cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2444cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2454cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2464cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2474cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2484cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2494cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2504cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2514cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2524cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2534cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2544cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2550418a888d31689f5358b6b90fd09287aeba368dbCary Clark    bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y);
2564cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2574cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2584cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2594cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2604cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2614cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
2624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
2648d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
265dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
267dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
268dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
269dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
270dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
271d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
272d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
273d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
274d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
275d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
279dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
280ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
281ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
282ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
283ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
286d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
287d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
288d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
289021f631dc66da06dbe4aed21df2f27daecce9db7reed    int saveLayer(const SkRect& bounds, const SkPaint* paint) {
290021f631dc66da06dbe4aed21df2f27daecce9db7reed        return this->saveLayer(&bounds, paint);
291021f631dc66da06dbe4aed21df2f27daecce9db7reed    }
292d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
29370ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    /**
29470ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Temporary name.
29570ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Will allow any requests for LCD text to be respected, so the caller must be careful to
29670ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  only draw on top of opaque sections of the layer to get good results.
29770ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     */
29870ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
29970ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
303dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
30440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
30540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
30640408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
30740408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
309d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
310d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
311d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
312d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3134960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    enum {
3144960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kIsOpaque_SaveLayerFlag         = 1 << 0,
3154960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kPreserveLCDText_SaveLayerFlag  = 1 << 1,
316bada1885da479d948f065182d6dfa85a1140bda5reed
317c61abeed8958a757c6b49937f28b63066148dd67Mike Reed        /** initialize the new layer with the contents of the previous layer */
318c61abeed8958a757c6b49937f28b63066148dd67Mike Reed        kInitWithPrevious_SaveLayerFlag = 1 << 2,
319c61abeed8958a757c6b49937f28b63066148dd67Mike Reed
320bada1885da479d948f065182d6dfa85a1140bda5reed#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
321bada1885da479d948f065182d6dfa85a1140bda5reed        kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
322bada1885da479d948f065182d6dfa85a1140bda5reed#endif
3234960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3244960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    typedef uint32_t SaveLayerFlags;
3254960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3264960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    struct SaveLayerRec {
32753f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        SaveLayerRec() {}
3284960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
3294960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            : fBounds(bounds)
3304960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fPaint(paint)
331bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fSaveLayerFlags(saveLayerFlags)
332bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
333bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
33425b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita                     SaveLayerFlags saveLayerFlags)
33525b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita            : fBounds(bounds)
33625b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita            , fPaint(paint)
33725b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita            , fBackdrop(backdrop)
33825b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita            , fSaveLayerFlags(saveLayerFlags)
33925b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita        {}
340b34ab04884f6219b93c1f143c83a1fc60fded40cMike Klein
341b34ab04884f6219b93c1f143c83a1fc60fded40cMike Klein        // EXPERIMENTAL: not ready for general use.
34225b37430e606ff268d000b8d1d2c59b4c90679edFlorin Malita        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
343b34ab04884f6219b93c1f143c83a1fc60fded40cMike Klein                     const SkImage* clipMask, const SkMatrix* clipMatrix,
344bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed                     SaveLayerFlags saveLayerFlags)
345bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(bounds)
346bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fPaint(paint)
347bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(backdrop)
348d0e0a8ff416abf9b4736ddac8f6faeb11023ab80Vaclav Brozek            , fClipMask(clipMask)
34953f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita            , fClipMatrix(clipMatrix)
3504960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fSaveLayerFlags(saveLayerFlags)
3514960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        {}
3524960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
35353f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        const SkRect*           fBounds = nullptr;      // optional
35453f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        const SkPaint*          fPaint = nullptr;       // optional
35553f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        const SkImageFilter*    fBackdrop = nullptr;    // optional
356b34ab04884f6219b93c1f143c83a1fc60fded40cMike Klein        const SkImage*          fClipMask = nullptr;    // optional
35753f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        const SkMatrix*         fClipMatrix = nullptr;  // optional -- only used with fClipMask
35853f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        SaveLayerFlags          fSaveLayerFlags = 0;
3594960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3604960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3610418a888d31689f5358b6b90fd09287aeba368dbCary Clark    int saveLayer(const SaveLayerRec& layerRec);
3624960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
364dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
365dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
366dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
368e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
371ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
372ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
374a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
377ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
378ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
379ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
38892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
39492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3967438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about the origin.
3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
39992362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4017438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about a given point.
4027438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param degrees  The amount to rotate, in degrees
4037438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param px  The x coordinate of the point to rotate about.
4047438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param py  The y coordinate of the point to rotate about.
4057438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    */
4067438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    void rotate(SkScalar degrees, SkScalar px, SkScalar py);
4077438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41292362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41792362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4184b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42244c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4234b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4284ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4294ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4304ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4314ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4324ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4334ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
4340418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias);
435c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRect(const SkRect& rect, SkClipOp op) {
436669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRect(rect, op, false);
437669983856d99b9312be3166b7dd1f8483a90c315reed    }
438669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, bool doAntiAlias = false) {
4392dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
440669983856d99b9312be3166b7dd1f8483a90c315reed    }
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4424ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4435f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * Sets the max clip rectangle, which can be set by clipRect, clipRRect and
4445f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * clipPath and intersect the current clip with the specified rect.
4455f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * The max clip affects only future ops (it is not retroactive).
4465f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * We DON'T record the clip restriction in pictures.
4475f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * This is private API to be used only by Android framework.
4485f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     * @param rect   The maximum allowed clip in device coordinates.
4495f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     *               Empty rect means max clip is not enforced.
4505f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev     */
4515f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
4525f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev
4535f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    /**
4544ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4554ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4574ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4584ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
459c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
460c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipRRect(const SkRRect& rrect, SkClipOp op) {
461669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRRect(rrect, op, false);
462669983856d99b9312be3166b7dd1f8483a90c315reed    }
463669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
4642dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
465669983856d99b9312be3166b7dd1f8483a90c315reed    }
4664ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4674ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4684ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path 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 clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
474c1f7774e8d327e3c98b4094c9c01d26e27013f71Mike Reed    void clipPath(const SkPath& path, SkClipOp op) {
475669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipPath(path, op, false);
476669983856d99b9312be3166b7dd1f8483a90c315reed    }
477669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, bool doAntiAlias = false) {
4782dc523722ec27003ced0735618531f9f2aed1f01Mike Reed        this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
479669983856d99b9312be3166b7dd1f8483a90c315reed    }
4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4818f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
48245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
48345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
48445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
48545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
48645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
48745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
4936e998e6137e6b25f047b5c5943f2b02485165e3emtklein        @param op The region op to apply to the current clip
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4952dc523722ec27003ced0735618531f9f2aed1f01Mike Reed    void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5053b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5173b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
519918e144408ba218df919528f8b48c544f4767883Mike Reed    /**
520918e144408ba218df919528f8b48c544f4767883Mike Reed     *  Return the bounds of the current clip in local coordinates. If the clip is empty,
521918e144408ba218df919528f8b48c544f4767883Mike Reed     *  return { 0, 0, 0, 0 }.
522918e144408ba218df919528f8b48c544f4767883Mike Reed     */
52342e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); }
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
525918e144408ba218df919528f8b48c544f4767883Mike Reed    /**
5266f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     *  Returns true if the clip bounds are non-empty.
5276f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     */
5286f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    bool getLocalClipBounds(SkRect* bounds) const {
5296f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        *bounds = this->onGetLocalClipBounds();
5306f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        return !bounds->isEmpty();
5316f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    }
5326f4a9b294868a94e5b1e06a8e855833614355bccMike Reed
5336f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    /**
534918e144408ba218df919528f8b48c544f4767883Mike Reed     *  Return the bounds of the current clip in device coordinates. If the clip is empty,
535918e144408ba218df919528f8b48c544f4767883Mike Reed     *  return { 0, 0, 0, 0 }.
536918e144408ba218df919528f8b48c544f4767883Mike Reed     */
53742e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); }
53842e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
5396f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    /**
5406f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     *  Returns true if the clip bounds are non-empty.
5416f4a9b294868a94e5b1e06a8e855833614355bccMike Reed     */
5426f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    bool getDeviceClipBounds(SkIRect* bounds) const {
5436f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        *bounds = this->onGetDeviceClipBounds();
5446f4a9b294868a94e5b1e06a8e855833614355bccMike Reed        return !bounds->isEmpty();
5456f4a9b294868a94e5b1e06a8e855833614355bccMike Reed    }
5466f4a9b294868a94e5b1e06a8e855833614355bccMike Reed
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
548845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
552374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
554f4e0d9eb2d72fe92c30237de978936113143dc16reed    /**
555f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  Helper method for drawing a color in SRC mode, completely replacing all the pixels
556f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  in the current clip with this color.
557f4e0d9eb2d72fe92c30237de978936113143dc16reed     */
558f4e0d9eb2d72fe92c30237de978936113143dc16reed    void clear(SkColor color) {
559374772bd61951f01bf84fe17bf53d8867681c9aereed        this->drawColor(color, SkBlendMode::kSrc);
5608eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    }
5612a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
5622a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
56328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
56428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
56528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
566a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * dependent and one legal implementation is to do nothing. This method
567a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * ignores the current clip.
56828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
56928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
57028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
57128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
57228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
57328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
57428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
57528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
57628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
577a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     *  Fill the entire canvas (restricted to the current clip) with the
5782a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
5792a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
5802a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
5810846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPaint(const SkPaint& paint);
5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6130846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6153661bc997620899695041010a750d11dbe8a972dMike Reed    /** Helper method for drawing a single point. See drawPoints() for more details.
6163661bc997620899695041010a750d11dbe8a972dMike Reed     */
6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
61823e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    void drawPoint(SkPoint p, const SkPaint& paint) {
61923e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary        this->drawPoint(p.x(), p.y(), paint);
62023e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    }
6214b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6313661bc997620899695041010a750d11dbe8a972dMike Reed    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
63223e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) {
63323e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary        this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
63423e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    }
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6410846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRect(const SkRect& rect, const SkPaint& paint);
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
64887001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6534b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
65444df651ebefc284acc2f66425dff3ea0b0e14b36msarett    /** Draw the outline of the specified region using the specified paint.
65544df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param region   The region to be drawn
65644df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param paint    The paint used to draw the region
65744df651ebefc284acc2f66425dff3ea0b0e14b36msarett    */
658dca352e2d42cfe698573947b3d11abc1eaade160msarett    void drawRegion(const SkRegion& region, const SkPaint& paint);
65944df651ebefc284acc2f66425dff3ea0b0e14b36msarett
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
665304f9d4e0feb4665d88804c3a4c28b6397c377b0Cary Clark    void drawOval(const SkRect& oval, const SkPaint& paint);
6664ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
6674ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
6684ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
6694ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
6704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
6714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
6724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
6734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
6740846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
676ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
677ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
678ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
679ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
680304f9d4e0feb4665d88804c3a4c28b6397c377b0Cary Clark    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
681ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6903661bc997620899695041010a750d11dbe8a972dMike Reed    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
69123e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) {
69223e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary        this->drawCircle(center.x(), center.y(), radius, paint);
69323e474cb7331c5d2389d97dce2d9e5c93c58f39fHal Canary    }
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
69621af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        specified oval. Sweep angles are not treated as modulo 360 and thus can
69721af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        exceed a full sweep of the oval. Note that this differs slightly from
69821af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty
69921af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        or the sweep angle is zero nothing is drawn. If useCenter is true the oval
70021af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        center is inserted into the implied path before the arc and the path is
70121af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        closed back to the, center forming a wedge. Otherwise, the implied path
70221af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        contains just the arc and is not closed.
703ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param oval The bounds of oval used to define the shape of the arc.
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
705ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param sweepAngle Sweep angle (in degrees) measured clockwise.
70621af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        @param useCenter true means include the center of the oval.
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7193661bc997620899695041010a750d11dbe8a972dMike Reed    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint);
7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7260846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPath(const SkPath& path, const SkPaint& paint);
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
728d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with its top/left corner at (x,y), using the
729d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        specified paint, transformed by the current matrix.
730d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr
731d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image    The image to be drawn
732d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param left     The position of the left side of the image being drawn
733d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param top      The position of the top side of the image being drawn
734d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
735d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr     */
7360846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
737f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
738f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkPaint* paint = NULL) {
739f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImage(image.get(), left, top, paint);
740f8053da25981c6b3152b637c1c91f43cff194c25reed    }
741b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
742a5517e2b190a8083b38964972b031c13e99f1012reed    /**
743a5517e2b190a8083b38964972b031c13e99f1012reed     *  Controls the behavior at the edge of the src-rect, when specified in drawImageRect,
744a5517e2b190a8083b38964972b031c13e99f1012reed     *  trading off speed for exactness.
745a5517e2b190a8083b38964972b031c13e99f1012reed     *
746a5517e2b190a8083b38964972b031c13e99f1012reed     *  When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around
747a5517e2b190a8083b38964972b031c13e99f1012reed     *  the pixels in the image. If there is a src-rect specified, it is intended to restrict the
748a5517e2b190a8083b38964972b031c13e99f1012reed     *  pixels that will be read. However, for performance reasons, some implementations may slow
749a5517e2b190a8083b38964972b031c13e99f1012reed     *  down if they cannot read 1-pixel past the src-rect boundary at times.
750a5517e2b190a8083b38964972b031c13e99f1012reed     *
751a5517e2b190a8083b38964972b031c13e99f1012reed     *  This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable.
752a5517e2b190a8083b38964972b031c13e99f1012reed     *  If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect
753a5517e2b190a8083b38964972b031c13e99f1012reed     *  must be strictly respected, the caller should pass kStrict.
754a5517e2b190a8083b38964972b031c13e99f1012reed     */
755a5517e2b190a8083b38964972b031c13e99f1012reed    enum SrcRectConstraint {
756a5517e2b190a8083b38964972b031c13e99f1012reed        /**
757a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kStrict is specified, the implementation must respect the src-rect
758a5517e2b190a8083b38964972b031c13e99f1012reed         *  (if specified) strictly, and will never sample outside of those bounds during sampling
759a5517e2b190a8083b38964972b031c13e99f1012reed         *  even when filtering. This may be slower than kFast.
760a5517e2b190a8083b38964972b031c13e99f1012reed         */
761a5517e2b190a8083b38964972b031c13e99f1012reed        kStrict_SrcRectConstraint,
762a5517e2b190a8083b38964972b031c13e99f1012reed
763a5517e2b190a8083b38964972b031c13e99f1012reed        /**
764a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kFast is specified, the implementation may sample outside of the src-rect
76519e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon         *  (if specified) by half the width of filter. This allows greater flexibility
766a5517e2b190a8083b38964972b031c13e99f1012reed         *  to the implementation and can make the draw much faster.
767a5517e2b190a8083b38964972b031c13e99f1012reed         */
768a5517e2b190a8083b38964972b031c13e99f1012reed        kFast_SrcRectConstraint,
769a5517e2b190a8083b38964972b031c13e99f1012reed    };
770a5517e2b190a8083b38964972b031c13e99f1012reed
771a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified image, scaling and translating so that it fills the specified
772a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the image is transformed
773a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
774a5517e2b190a8083b38964972b031c13e99f1012reed     *
775a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param image      The image to be drawn
776a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the image to be drawn
777a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
778a5517e2b190a8083b38964972b031c13e99f1012reed     *                    image will be drawn
779a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the image, or NULL
780a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
781a5517e2b190a8083b38964972b031c13e99f1012reed     */
782e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
783e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint,
784e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
785e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that takes src SkIRect
786e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
7870418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       const SkPaint* paint,
7880418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
789e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that assumes src == image-bounds
790e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
7910418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
79284984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
793f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
794f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint,
795f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
796f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), src, dst, paint, constraint);
797f8053da25981c6b3152b637c1c91f43cff194c25reed    }
798f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
7990418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       const SkPaint* paint,
8000418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
8010418a888d31689f5358b6b90fd09287aeba368dbCary Clark        this->drawImageRect(image.get(), isrc, dst, paint, constraint);
802f8053da25981c6b3152b637c1c91f43cff194c25reed    }
803f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
8040418a888d31689f5358b6b90fd09287aeba368dbCary Clark                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
8050418a888d31689f5358b6b90fd09287aeba368dbCary Clark        this->drawImageRect(image.get(), dst, paint, constraint);
806f8053da25981c6b3152b637c1c91f43cff194c25reed    }
807f8053da25981c6b3152b637c1c91f43cff194c25reed
8084c21dc5ddf3b482293ed34eead876d8d61a662c3reed    /**
8094c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  Draw the image stretched differentially to fit into dst.
8104c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  center is a rect within the image, and logically divides the image
8114c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
8124c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  image is the "center", then the center-rect should be [2, 2, 3, 3].
8134c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *
8144c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  If the dst is >= the image size, then...
8154c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The 4 corners are not stretched at all.
8164c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides are stretched in only one axis.
8174c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The center is stretched in both axes.
8184c21dc5ddf3b482293ed34eead876d8d61a662c3reed     * Else, for each axis where dst < image,
8194c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The corners shrink proportionally
8204c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides (along the shrink axis) and center are not drawn
8214c21dc5ddf3b482293ed34eead876d8d61a662c3reed     */
8220418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
823f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr);
824f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
825f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr) {
826f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageNine(image.get(), center, dst, paint);
827f8053da25981c6b3152b637c1c91f43cff194c25reed    }
8284c21dc5ddf3b482293ed34eead876d8d61a662c3reed
8298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
8308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
8318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
83591246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
83691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
837f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
83891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
83991246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8450846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
8460846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                    const SkPaint* paint = NULL);
8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
848a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified bitmap, scaling and translating so that it fills the specified
849a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
850a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
851a5517e2b190a8083b38964972b031c13e99f1012reed     *
852a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param bitmap     The bitmap to be drawn
853a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the bitmap to be drawn
854a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
855a5517e2b190a8083b38964972b031c13e99f1012reed     *                    bitmap will be drawn
856a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the bitmap, or NULL
857a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
858a5517e2b190a8083b38964972b031c13e99f1012reed     */
859e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
8600418a888d31689f5358b6b90fd09287aeba368dbCary Clark                        const SkPaint* paint,
8610418a888d31689f5358b6b90fd09287aeba368dbCary Clark                        SrcRectConstraint constraint = kStrict_SrcRectConstraint);
862e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant where src is SkIRect
86384984efeb64787b88c5f8bd6929cfe2d58a3ba06reed    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
8640418a888d31689f5358b6b90fd09287aeba368dbCary Clark                        const SkPaint* paint,
8650418a888d31689f5358b6b90fd09287aeba368dbCary Clark                        SrcRectConstraint constraint = kStrict_SrcRectConstraint);
866e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
8670418a888d31689f5358b6b90fd09287aeba368dbCary Clark                        SrcRectConstraint constraint = kStrict_SrcRectConstraint);
86884984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
869f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
870c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
871f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
872f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
873f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
874f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
875f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
8769bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
8779bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
8789bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
879f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
880f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
881f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
882f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
8830846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
8840846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                        const SkPaint* paint = NULL);
885f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
886c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
887c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
88871df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *
88971df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  If the lattice divs or bounds are invalid, the entire lattice
89071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  struct will be ignored on the draw call.
891c573a40ed5024b463e47088d307e3164a486dba5msarett     */
892c573a40ed5024b463e47088d307e3164a486dba5msarett    struct Lattice {
8930764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        enum Flags : uint8_t {
8940764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            // If set, indicates that we should not draw corresponding rect.
8950764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            kTransparent_Flags = 1 << 0,
8960764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        };
8970764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
898c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of x-coordinates that divide the bitmap vertically.
89971df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight).
900c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
90171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fXDivs;
902c573a40ed5024b463e47088d307e3164a486dba5msarett
903c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of y-coordinates that divide the bitmap horizontally.
90471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom).
905c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
90671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fYDivs;
9070764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9080764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // If non-null, the length of this array must be equal to
9090764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // (fXCount + 1) * (fYCount + 1).  Note that we allow the first rect
91071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft).
91171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // In this case, the caller still must specify a flag (as a placeholder)
91271df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // for these empty rects.
9130764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The flags correspond to the rects in the lattice, first moving
9140764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // left to right and then top to bottom.
91571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const Flags*   fFlags;
9160764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9170764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The number of fXDivs.
91871df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fXCount;
919c573a40ed5024b463e47088d307e3164a486dba5msarett
920c573a40ed5024b463e47088d307e3164a486dba5msarett        // The number of fYDivs.
92171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fYCount;
92271df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett
92371df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // The bound to draw from.  Must be contained by the src that is being drawn,
92471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // non-empty, and non-inverted.
92571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // If nullptr, the bounds are the entire src.
92671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const SkIRect* fBounds;
927c573a40ed5024b463e47088d307e3164a486dba5msarett    };
928c573a40ed5024b463e47088d307e3164a486dba5msarett
929c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
930c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
931c573a40ed5024b463e47088d307e3164a486dba5msarett     *
932c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Moving horizontally across the bitmap, alternating rects will be "scalable"
933c573a40ed5024b463e47088d307e3164a486dba5msarett     *  (in the x-dimension) to fit into dst or must be left "fixed".  The first rect
934c573a40ed5024b463e47088d307e3164a486dba5msarett     *  is treated as "fixed", but it's possible to specify an empty first rect by
935c573a40ed5024b463e47088d307e3164a486dba5msarett     *  making lattice.fXDivs[0] = 0.
936c573a40ed5024b463e47088d307e3164a486dba5msarett     *
937c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The scale factor for all "scalable" rects will be the same, and may be greater
938c573a40ed5024b463e47088d307e3164a486dba5msarett     *  than or less than 1 (meaning we can stretch or shrink).  If the number of
939c573a40ed5024b463e47088d307e3164a486dba5msarett     *  "fixed" pixels is greater than the width of the dst, we will collapse all of
940c573a40ed5024b463e47088d307e3164a486dba5msarett     *  the "scalable" regions and appropriately downscale the "fixed" regions.
941c573a40ed5024b463e47088d307e3164a486dba5msarett     *
942c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The same interpretation also applies to the y-dimension.
943c573a40ed5024b463e47088d307e3164a486dba5msarett     */
944c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
945c573a40ed5024b463e47088d307e3164a486dba5msarett                           const SkPaint* paint = nullptr);
946c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
947c573a40ed5024b463e47088d307e3164a486dba5msarett                          const SkPaint* paint = nullptr);
948c573a40ed5024b463e47088d307e3164a486dba5msarett
9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
957f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
958f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                  const SkPaint& paint);
9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9602a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    /** Draw null-terminated UTF-8 string, with origin at (x,y), using the specified paint.
9612a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        The origin is interpreted based on the Align setting in the paint.
9622a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param string   The null-terminated string to be drawn
9632a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param x        The x-coordinate of the origin of the string being drawn
9642a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param y        The y-coordinate of the origin of the string being drawn
9652a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param paint    The paint used for the string (e.g. color, size, style)
9662a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    */
9672a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint) {
9682a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        if (!string) {
9692a475eae622adc1e8fa29206be1eaf862c23548eCary Clark            return;
9702a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        }
9712a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        this->drawText(string, strlen(string), x, y, paint);
9722a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    }
9732a475eae622adc1e8fa29206be1eaf862c23548eCary Clark
9742a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    /** Draw string, with origin at (x,y), using the specified paint.
9752a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        The origin is interpreted based on the Align setting in the paint.
9762a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param string   The string to be drawn
9772a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param x        The x-coordinate of the origin of the string being drawn
9782a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param y        The y-coordinate of the origin of the string being drawn
9792a475eae622adc1e8fa29206be1eaf862c23548eCary Clark        @param paint    The paint used for the string (e.g. color, size, style)
9802a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    */
9812a475eae622adc1e8fa29206be1eaf862c23548eCary Clark    void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint);
9822a475eae622adc1e8fa29206be1eaf862c23548eCary Clark
9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
9844b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
990f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
991f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                     const SkPaint& paint);
9924b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
9954b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1002f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
1003f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                      const SkPaint& paint);
10044b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
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 path         The path the text should follow for its baseline
10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1017f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1030f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
1031f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                        const SkMatrix* matrix, const SkPaint& paint);
10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
103345561a0b15fe045ba272c328684c3f7ae290785areed    /**
103445561a0b15fe045ba272c328684c3f7ae290785areed     *  Draw the text with each character/glyph individually transformed by its xform.
103545561a0b15fe045ba272c328684c3f7ae290785areed     *  If cullRect is not null, it is a conservative bounds of what will be drawn
103663f30d90498ca1a48868421b528036f3be30e2adreed     *  taking into account the xforms and the paint, and will be used to accelerate culling.
103745561a0b15fe045ba272c328684c3f7ae290785areed     */
10380418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
103945561a0b15fe045ba272c328684c3f7ae290785areed                         const SkRect* cullRect, const SkPaint& paint);
104045561a0b15fe045ba272c328684c3f7ae290785areed
104100d5c2c6523321d25b32905ff4822f083a4173eefmalita    /** Draw the text blob, offset by (x,y), using the specified paint.
104200d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param blob     The text blob to be drawn
104300d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param x        The x-offset of the text being drawn
104400d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param y        The y-offset of the text being drawn
104500d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param paint    The paint used for the text (e.g. color, size, style)
104600d5c2c6523321d25b32905ff4822f083a4173eefmalita    */
104700d5c2c6523321d25b32905ff4822f083a4173eefmalita    void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
10482ab9057b31ee92060b9769ea1adfada51c11c010reed    void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
10492ab9057b31ee92060b9769ea1adfada51c11c010reed        this->drawTextBlob(blob.get(), x, y, paint);
10502ab9057b31ee92060b9769ea1adfada51c11c010reed    }
105100d5c2c6523321d25b32905ff4822f083a4173eefmalita
10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
1054a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10581c2c441fede0ae9573afc098017011e3439624a9reed    void drawPicture(const SkPicture* picture) {
10591c2c441fede0ae9573afc098017011e3439624a9reed        this->drawPicture(picture, NULL, NULL);
10601c2c441fede0ae9573afc098017011e3439624a9reed    }
1061ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture) {
1062f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get());
1063f8053da25981c6b3152b637c1c91f43cff194c25reed    }
10649b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
1065d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    /**
1066d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  Draw the picture into this canvas.
1067d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1068d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
1069d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  logically equivalent to
1070d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      save/concat/drawPicture/restore
1071d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1072d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1073d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1074d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  This is logically equivalent to
1075d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      saveLayer(paint)/drawPicture/restore
1076d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     */
10770418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint);
1078ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
1079f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get(), matrix, paint);
1080f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1081d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed
1082199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon    /** Draw vertices from an immutable SkVertices object.
1083199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon
1084199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param vertices The mesh to draw.
1085199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param mode Used if both texs and colors are present and paint has a
1086199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    shader. In this case the colors are combined with the texture
1087199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon                    using mode, before being drawn using the paint.
1088199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon        @param paint Specifies the shader/texture if present.
1089199fb875c5e63c13233209e89b943c7ac7ab6665Brian Salomon     */
1090e88a1cb20e6b4c9f099070112225a88693a4630bMike Reed    void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
1091e88a1cb20e6b4c9f099070112225a88693a4630bMike Reed    void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
10927d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
1093b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1094b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
10956cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1096b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1097b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1098b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1099b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
11006cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1101b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
11027d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     @param mode specifies how are the colors and the textures combined if both of them are
1103b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1104963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1105963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1106b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
11077d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
11087d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
11097d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], const SkPaint& paint) {
11107d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
11117d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
11127d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
11133cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
111471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
111571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
111671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  into a quad.
111771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
111871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *      xform maps [0, 0, tex.width, tex.height] -> quad
111971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
112071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The color array is optional. When specified, each color modulates the pixels in its
11217d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  corresponding quad (via the specified SkBlendMode).
112271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
112371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The cullRect is optional. When specified, it must be a conservative bounds of all of the
112471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
112571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  intersect the current clip.
112671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
112771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
11287d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  and blendmode are used to affect each of the quads.
112971c3c760a83123ee0b3127b8c65c6394ce541c50reed     */
113071c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
11310418a888d31689f5358b6b90fd09287aeba368dbCary Clark                   const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
113271c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkPaint* paint);
11337d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
11347d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
11357d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPaint* paint) {
11367d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
11377d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
113871c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
113971c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkRect* cullRect, const SkPaint* paint) {
11407d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
114171c3c760a83123ee0b3127b8c65c6394ce541c50reed    }
1142f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
11437d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   int count, const SkRect* cullRect, const SkPaint* paint) {
11447d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
11457d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                        cullRect, paint);
11467d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
11477d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
114871c3c760a83123ee0b3127b8c65c6394ce541c50reed    /**
11493cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
11503cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
11513cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
11523cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
11533cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
11543cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
11553cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
11560418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = NULL);
11570418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y);
11586a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1159f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    /**
1160f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
1161f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a null-terminated utf8 string, and the value is a blob of data stored in an SkData
1162f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  (which may be null). The annotation is associated with the specified rectangle.
1163f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1164f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  The caller still retains its ownership of the data (if any).
1165f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1166f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
1167f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a picture or drawing to a PDF document) will pass on this information.
1168f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     */
11690418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void drawAnnotation(const SkRect& rect, const char key[], SkData* value);
11700fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
11710fba3b97b5b0e3707b31931ab9325030b81c940fmtklein        this->drawAnnotation(rect, key, value.get());
11720fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    }
1173f70b531daaf47db1ee95c70da9843f1dd1f418d3reed
11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
11754b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
117653d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1178dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
11798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
11808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
11824b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
11848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1186dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1187dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
11888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
11908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
11927765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
11938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
11948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1195754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1196754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1197754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1198754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1199754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1200754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1201754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
12028f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1203754de5f65b466f721d952a379194cc94de376f42reed@google.com
12045c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
12055c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
12065c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
12075c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
12085c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
12095c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1214a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
12158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
12178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
121836736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
12191105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
122036736a2dae94947e075ac9503d5de7799772a5f7robertphillips
122136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
122236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
122336736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetIgnoreSaveLayerBounds();
122436736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
122536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetTreatSpriteAsBitmap();
122636736a2dae94947e075ac9503d5de7799772a5f7robertphillips
122736736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // TEMP helpers until we switch virtual over to const& for src-rect
122836736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
122936736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              const SkPaint* paint,
123036736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              SrcRectConstraint constraint = kStrict_SrcRectConstraint);
123136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
123236736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               const SkPaint* paint,
123336736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               SrcRectConstraint constraint = kStrict_SrcRectConstraint);
123436736a2dae94947e075ac9503d5de7799772a5f7robertphillips
1235a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed    /**
1236a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed     *  Returns the global clip as a region. If the clip contains AA, then only the bounds
1237a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed     *  of the clip may be returned.
1238a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed     */
12390418a888d31689f5358b6b90fd09287aeba368dbCary Clark    void temporary_internal_getRgnClip(SkRegion* region);
12403726a4ac68821deea7ef4d5472a42f7d35ec4b4eMike Reed
12414204da25aa4c6e0b321314aa32fd9affb4865563Mike Reed    void private_draw_shadow_rec(const SkPath&, const SkDrawShadowRec&);
12424204da25aa4c6e0b321314aa32fd9affb4865563Mike Reed
1243da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillipsprotected:
124476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
12450418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props);
124676f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1247c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
12480418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual bool onPeekPixels(SkPixmap* pixmap);
12490418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual bool onAccessTopLayerPixels(SkPixmap* pixmap);
1250ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual SkImageInfo onImageInfo() const;
12510418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual bool onGetProps(SkSurfaceProps* props) const;
1252ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual void onFlush();
1253c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1254e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1255e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
12564960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // getSaveLayerStrategy()'s return value may suppress full layer allocation.
1257e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1258e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
12594960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kNoLayer_SaveLayerStrategy,
1260e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1261e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
12626ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
12634960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // Overriders should call the corresponding INHERITED method up the inheritance chain.
12640418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& ) {
12654960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        return kFullLayer_SaveLayerStrategy;
12664960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    }
1267fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
12686cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
12690418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void didConcat(const SkMatrix& ) {}
12700418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void didSetMatrix(const SkMatrix& ) {}
1271cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    virtual void didTranslate(SkScalar dx, SkScalar dy) {
1272cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein        this->didConcat(SkMatrix::MakeTrans(dx, dy));
1273cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    }
127495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
127542e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    virtual SkRect onGetLocalClipBounds() const;
127642e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed    virtual SkIRect onGetDeviceClipBounds() const;
127742e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
127842e8c53b3ef58f887a623b410d9783b4d4ab4921Mike Reed
12790418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value);
12800418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
1281ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1282e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1283e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1284b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1285e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1286e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1287b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1288e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1289e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1290e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1291b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1292e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1293e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1294e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
12950418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
129645561a0b15fe045ba272c328684c3f7ae290785areed                                   const SkRect* cullRect, const SkPaint& paint);
12976cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
129800d5c2c6523321d25b32905ff4822f083a4173eefmalita    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
129900d5c2c6523321d25b32905ff4822f083a4173eefmalita                                const SkPaint& paint);
130000d5c2c6523321d25b32905ff4822f083a4173eefmalita
1301b3c9d1c33caf325aada244204215eb790c228c12dandov    virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
13020418a888d31689f5358b6b90fd09287aeba368dbCary Clark                           const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
1303e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
13040418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix);
13056a070dc06af4e9f305f9d08a69e34d18ade473cbreed
13060418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawPaint(const SkPaint& paint);
13070418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawRect(const SkRect& rect, const SkPaint& paint);
130844df651ebefc284acc2f66425dff3ea0b0e14b36msarett    virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
13090418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawOval(const SkRect& rect, const SkPaint& paint);
13100418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
13110418a888d31689f5358b6b90fd09287aeba368dbCary Clark                           bool useCenter, const SkPaint& paint);
13120418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawRRect(const SkRRect& rrect, const SkPaint& paint);
13130418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
13140418a888d31689f5358b6b90fd09287aeba368dbCary Clark                              const SkPaint& paint);
13150418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
13160418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                      const SkPaint& paint);
13170418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
13180418a888d31689f5358b6b90fd09287aeba368dbCary Clark                             const SkColor colors[], int count, SkBlendMode mode,
13190418a888d31689f5358b6b90fd09287aeba368dbCary Clark                             const SkRect* cull, const SkPaint* paint);
13200418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawPath(const SkPath& path, const SkPaint& paint);
13210418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, const SkPaint* paint);
13220418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
13230418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                 const SkPaint* paint, SrcRectConstraint constraint);
13240418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
13250418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                 const SkPaint* paint);
13260418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
13270418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                    const SkPaint* paint);
13280418a888d31689f5358b6b90fd09287aeba368dbCary Clark
13290418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
13300418a888d31689f5358b6b90fd09287aeba368dbCary Clark                              const SkPaint* paint);
13310418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
13320418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                  const SkPaint* paint, SrcRectConstraint constraint);
13330418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
13340418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                  const SkPaint* paint);
13350418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
13360418a888d31689f5358b6b90fd09287aeba368dbCary Clark                                     const SkRect& dst, const SkPaint* paint);
13374204da25aa4c6e0b321314aa32fd9affb4865563Mike Reed    virtual void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&);
133841af966ab338e95eee81ab618ab28195075338f7reed
13398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
13408f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
13418f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
13428f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
13438f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
13440418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle);
13450418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle);
13460418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle);
13470418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp op);
13488f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
134928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
135028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
13510418a888d31689f5358b6b90fd09287aeba368dbCary Clark    virtual void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
13520418a888d31689f5358b6b90fd09287aeba368dbCary Clark                               const SkPaint* paint);
13539b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
1354a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1355a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1356c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1357c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
13580418a888d31689f5358b6b90fd09287aeba368dbCary Clark    bool clipRectBounds(const SkRect* bounds, SaveLayerFlags flags, SkIRect* intersection,
1359c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1360a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1361c83a29759a5c2966da5ab973e4fd90763e4c962breedprivate:
13623aafe111b6cc388400092851cc53bbbdfcb8a81creed    /** After calling saveLayer(), there can be any number of devices that make
13633aafe111b6cc388400092851cc53bbbdfcb8a81creed     up the top-most drawing area. LayerIter can be used to iterate through
13643aafe111b6cc388400092851cc53bbbdfcb8a81creed     those devices. Note that the iterator is only valid until the next API
13653aafe111b6cc388400092851cc53bbbdfcb8a81creed     call made on the canvas. Ownership of all pointers in the iterator stays
13663aafe111b6cc388400092851cc53bbbdfcb8a81creed     with the canvas, so none of them should be modified or deleted.
13673aafe111b6cc388400092851cc53bbbdfcb8a81creed     */
13683aafe111b6cc388400092851cc53bbbdfcb8a81creed    class LayerIter /*: SkNoncopyable*/ {
13693aafe111b6cc388400092851cc53bbbdfcb8a81creed    public:
13703aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Initialize iterator with canvas, and set values for 1st device */
13713aafe111b6cc388400092851cc53bbbdfcb8a81creed        LayerIter(SkCanvas*);
13723aafe111b6cc388400092851cc53bbbdfcb8a81creed        ~LayerIter();
13733aafe111b6cc388400092851cc53bbbdfcb8a81creed
13743aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Return true if the iterator is done */
13753aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool done() const { return fDone; }
13763aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Cycle to the next device */
13773aafe111b6cc388400092851cc53bbbdfcb8a81creed        void next();
13783aafe111b6cc388400092851cc53bbbdfcb8a81creed
13793aafe111b6cc388400092851cc53bbbdfcb8a81creed        // These reflect the current device in the iterator
13803aafe111b6cc388400092851cc53bbbdfcb8a81creed
13813aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkBaseDevice*   device() const;
13823aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkMatrix& matrix() const;
1383a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed        void clip(SkRegion*) const;
13843aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkPaint&  paint() const;
13853aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             x() const;
13863aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             y() const;
13873aafe111b6cc388400092851cc53bbbdfcb8a81creed
13883aafe111b6cc388400092851cc53bbbdfcb8a81creed    private:
13893aafe111b6cc388400092851cc53bbbdfcb8a81creed        // used to embed the SkDrawIter object directly in our instance, w/o
13903aafe111b6cc388400092851cc53bbbdfcb8a81creed        // having to expose that class def to the public. There is an assert
13913aafe111b6cc388400092851cc53bbbdfcb8a81creed        // in our constructor to ensure that fStorage is large enough
13923aafe111b6cc388400092851cc53bbbdfcb8a81creed        // (though needs to be a compile-time-assert!). We use intptr_t to work
13933aafe111b6cc388400092851cc53bbbdfcb8a81creed        // safely with 32 and 64 bit machines (to ensure the storage is enough)
13943aafe111b6cc388400092851cc53bbbdfcb8a81creed        intptr_t          fStorage[32];
13953aafe111b6cc388400092851cc53bbbdfcb8a81creed        class SkDrawIter* fImpl;    // this points at fStorage
13963aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkPaint           fDefaultPaint;
13973aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool              fDone;
13983aafe111b6cc388400092851cc53bbbdfcb8a81creed    };
13991356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
14004960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    static bool BoundsAffectsClip(SaveLayerFlags);
1401bada1885da479d948f065182d6dfa85a1140bda5reed    static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
14024960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
1403a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed    static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
1404c42a1cdd1de7a3cf57a9a5fd7363f5fb660e97d0Mike Reed                                     SkBaseDevice* dst, const SkIPoint& dstOrigin,
1405a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed                                     const SkMatrix& ctm);
1406a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed
1407c83a29759a5c2966da5ab973e4fd90763e4c962breed    enum ShaderOverrideOpacity {
1408c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
1409c83a29759a5c2966da5ab973e4fd90763e4c962breed        kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
1410c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
1411c83a29759a5c2966da5ab973e4fd90763e4c962breed    };
1412c83a29759a5c2966da5ab973e4fd90763e4c962breed
141397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
141497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
1415c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(bool willOverwritesEntireSurface = false);
1416c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
1417c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
1418c83a29759a5c2966da5ab973e4fd90763e4c962breed        this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1419c83a29759a5c2966da5ab973e4fd90763e4c962breed                                                                : kNotOpaque_ShaderOverrideOpacity);
1420c83a29759a5c2966da5ab973e4fd90763e4c962breed    }
142197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
14220ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita    SkBaseDevice* getDevice() const;
14230ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita    SkBaseDevice* getTopDevice() const;
14240ed3b640c9da71fbbd73c65a4ec1992f85596271Florin Malita
14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
14268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
14298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
14308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
1431b679ca8926a832274b14fdb512f88f64b61d32eareed    enum {
1432a499f905e9340e4935447f2562fd92e8853382b1reed        kMCRecSize      = 128,  // most recent measurement
143331b80a9dc60ae5411ad6abd10269c4f88c635ec2reed        kMCRecCount     = 32,   // common depth for save/restores
143453f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita        kDeviceCMSize   = 224,  // most recent measurement
1435b679ca8926a832274b14fdb512f88f64b61d32eareed    };
1436b679ca8926a832274b14fdb512f88f64b61d32eareed    intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
1437a499f905e9340e4935447f2562fd92e8853382b1reed    intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
14388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14394a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
14404a8126e7f81384526629b1e21bf89b632ea13cd9reed
14412ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
14428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
144374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
1444356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    std::unique_ptr<SkRasterHandleAllocator> fAllocator;
144574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
144697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
144797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
144897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
144997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
145097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
145197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
145245c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1453fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
14545f1bb0a7c5186e797aa0f0d447a68fc3fbf3c2feStan Iliev    SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
14558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14562ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
14572ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
14588c30a8196dd5903d2d23b4d0a5dc888e802bf698reed    void internalSetMatrix(const SkMatrix&);
14592ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
14609c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
14618926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
14622a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
146352d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1464439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkNoDrawCanvas;    // InitFlags
14652d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1466c83a29759a5c2966da5ab973e4fd90763e4c962breed    friend class SkPictureRecord;   // predrawNotify (why does it need it? <reed>)
14674960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
146822886c493596655d8fd9512951f9010869b7fbc5Matt Sarett    friend class SkOverdrawCanvas;
1469356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    friend class SkRasterHandleAllocator;
1470b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1471d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1472d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1473d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1474d954498c01ccf0417feacf89e45d0c62a06a813breed    };
147578e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
1476fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips    SkCanvas(SkBaseDevice* device, InitFlags);
1477356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed    SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
1478356f7c2600ef54237fb8678cf63d5953f065b7daMike Reed             SkRasterHandleAllocator::Handle);
1479d954498c01ccf0417feacf89e45d0c62a06a813breed
1480feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein    void resetForNextPicture(const SkIRect& bounds);
1481feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein
14828f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1483a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1484b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
14854a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
14864a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
14874a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
14884a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
14894a8126e7f81384526629b1e21bf89b632ea13cd9reed
1490d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1491f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1492403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1493afc7cce5d68663934128d76963cd501f771d71desenorblanco     * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
14944ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
14954ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1496afc7cce5d68663934128d76963cd501f771d71desenorblanco    SkIRect getTopLayerBounds() const;
1497403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
14987112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1499eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1500a5517e2b190a8083b38964972b031c13e99f1012reed                                SrcRectConstraint);
1501fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
15024960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
150353f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, SkImage* clipImage,
150453f77bd4fdd76525b66b7f26d1c5c550858120dfFlorin Malita                            const SkMatrix& clipMatrix);
1505fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
15068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
15072ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
15094b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1510c83a29759a5c2966da5ab973e4fd90763e4c962breed    /*
1511c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  Returns true if drawing the specified rect (or all if it is null) with the specified
1512c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  paint (or default if null) would overwrite the entire root device of the canvas
1513c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  (i.e. the canvas' surface if it had one).
1514c83a29759a5c2966da5ab973e4fd90763e4c962breed     */
1515c83a29759a5c2966da5ab973e4fd90763e4c962breed    bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
1516c83a29759a5c2966da5ab973e4fd90763e4c962breed
1517262a71b7f95ce98ff3dd8dba845afbd724470903reed    /**
1518262a71b7f95ce98ff3dd8dba845afbd724470903reed     *  Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
1519262a71b7f95ce98ff3dd8dba845afbd724470903reed     */
1520262a71b7f95ce98ff3dd8dba845afbd724470903reed    bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
1521c83a29759a5c2966da5ab973e4fd90763e4c962breed
1522a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed    /**
1523a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed     *  Returns true if the clip (for any active layer) contains antialiasing.
1524a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed     *  If the clip is empty, this will return false.
152546784be70c4712942163bb2ade9e7364bca47157Mike Reed     */
1526a1361364e64138adda3dc5f71d50d7503838bb6dMike Reed    bool androidFramework_isClipAA() const;
1527fbfa25802709139c2f14e304319c9541da65ca27msarett
1528fbfa25802709139c2f14e304319c9541da65ca27msarett    /**
1529fbfa25802709139c2f14e304319c9541da65ca27msarett     *  Keep track of the device clip bounds and if the matrix is scale-translate.  This allows
1530fbfa25802709139c2f14e304319c9541da65ca27msarett     *  us to do a fast quick reject in the common case.
15318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
15329637ea91b88ff8f8e95325bfc41417ffc4d5ee0bmsarett    bool   fIsScaleTranslate;
1533fbfa25802709139c2f14e304319c9541da65ca27msarett    SkRect fDeviceClipBounds;
1534fbfa25802709139c2f14e304319c9541da65ca27msarett
15358f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
153645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
15378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15385c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
15395c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
15405c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
15415c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
15425c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
15435c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
15445c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
15455c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
15465c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
15475c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
15485c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
15495c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
15505c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
15515c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
15525c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
15535c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
155415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
155515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
15568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
15578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
15608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
15618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
15628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
15642887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
15652887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
15662887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
15672887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
15682887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
15692887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1573f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1574f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1575f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1576f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1577f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1578f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1579f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1580f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1581f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1582f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1583f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1584f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1585f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1586f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
15878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
15888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
15908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
15918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
15928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1593e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
15948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1596