SkCanvas.h revision 02b7349af7ce61c3f7d301148b54e17877233030
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkCanvas_DEFINED
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkCanvas_DEFINED
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h"
12374772bd61951f01bf84fe17bf53d8867681c9aereed#include "SkBlendMode.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
1473603f3c52ffd89fe9d035be827b566a0e7d3b79reed#include "SkClipOp.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h"
16e8597a4dd07d78eb0e7a45d6502896c1b9a8bfebmsarett#include "SkImage.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
204a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h"
2195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#include "SkLights.h"
22e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack#include "../private/SkShadowParams.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
24d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass GrContext;
251105224f9701e57ec5ce0354d6a380b664f5c638Brian Osmanclass GrRenderTargetContext;
261f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
276a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor;
28d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkClipStack;
29f70b531daaf47db1ee95c70da9843f1dd1f418d3reedclass SkData;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
313cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
33d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkImageFilter;
3474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
35d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPath;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
37d3ebb48320cf1b7e969974673e4bd7743816985ebungemanclass SkPixmap;
381e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cbreedclass SkRasterClip;
394ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
4071c3c760a83123ee0b3127b8c65c6394ce541c50reedstruct SkRSXform;
4176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
4300d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
44fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
4573603f3c52ffd89fe9d035be827b566a0e7d3b79reed//#define SK_SUPPORT_LEGACY_CLIP_REGIONOPS
4673603f3c52ffd89fe9d035be827b566a0e7d3b79reed
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
6202b7349af7ce61c3f7d301148b54e17877233030Mike Reedclass SK_API SkCanvas : SkNoncopyable {
63bada1885da479d948f065182d6dfa85a1140bda5reed    enum PrivateSaveLayerFlags {
64952538ed50661ad7dff6ec2b7af3f921e1d91b52caryclark        kDontClipToLayer_PrivateSaveLayerFlag   = 1U << 31,
65bada1885da479d948f065182d6dfa85a1140bda5reed    };
6673603f3c52ffd89fe9d035be827b566a0e7d3b79reed
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
6873603f3c52ffd89fe9d035be827b566a0e7d3b79reed#ifdef SK_SUPPORT_LEGACY_CLIP_REGIONOPS
6973603f3c52ffd89fe9d035be827b566a0e7d3b79reed    typedef SkRegion::Op ClipOp;
7073603f3c52ffd89fe9d035be827b566a0e7d3b79reed
7173603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kDifference_Op         = SkRegion::kDifference_Op;
7273603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kIntersect_Op          = SkRegion::kIntersect_Op;
7373603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kUnion_Op              = SkRegion::kUnion_Op;
7473603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kXOR_Op                = SkRegion::kXOR_Op;
7573603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kReverseDifference_Op  = SkRegion::kReverseDifference_Op;
7673603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kReplace_Op            = SkRegion::kReplace_Op;
7773603f3c52ffd89fe9d035be827b566a0e7d3b79reed#else
7873603f3c52ffd89fe9d035be827b566a0e7d3b79reed    typedef SkClipOp ClipOp;
7973603f3c52ffd89fe9d035be827b566a0e7d3b79reed
8073603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kDifference_Op         = kDifference_SkClipOp;
8173603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kIntersect_Op          = kIntersect_SkClipOp;
8273603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kUnion_Op              = kUnion_SkClipOp;
8373603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kXOR_Op                = kXOR_SkClipOp;
8473603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kReverseDifference_Op  = kReverseDifference_SkClipOp;
8573603f3c52ffd89fe9d035be827b566a0e7d3b79reed    static const ClipOp kReplace_Op            = kReplace_SkClipOp;
8673603f3c52ffd89fe9d035be827b566a0e7d3b79reed#endif
87e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
8842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
8942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
9042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
9142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
9242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
9342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
9442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
9542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
9644977485bdac75c055c3fa638f118874ccd2d22freed     *      - kUnknown_SkAlphaType
9742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
9842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
9942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
10042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
10142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
1025df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
1035df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed
1045df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
1055df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed                                                         size_t rowBytes) {
1065df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed        return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
1075df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed    }
1085df4934b3e40cdc378e225d1dda39f015cae9baeMike Reed
10942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
110e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
111e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
112e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
113cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
1148d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
115e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
116e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
117e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
118e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
119e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
12096a857ef5a40b3d0751ec9ebaaa96d9f20b82b21reed    SkCanvas(int width, int height, const SkSurfaceProps* = NULL);
121e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
1226dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
123e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1248d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
1258d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
1261f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
1278d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
1284469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
1333d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1343d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    /** Construct a canvas with the specified bitmap to draw into.
1353d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1363d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita                        structure are copied to the canvas.
1373d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param props    New canvas surface properties.
1383d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    */
1393d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
1403d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
14474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
145c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
146c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
147c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
148c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
149c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
150c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
151898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    /**
152898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps
153898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  for the canvas to the location supplied by the caller, and returns true. Otherwise,
154898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     *  return false and leave the supplied props unchanged.
155898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman     */
156898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman    bool getProps(SkSurfaceProps*) const;
157898235c4864df66aa7f6d32bc2a8b8551040ce1ebrianosman
1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
160210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
161e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  Trigger the immediate execution of all pending draw operations. For the GPU
162e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  backend this will resolve all rendering to the GPU surface backing the
163e63ffef6248bd103b5f7827f1e4bc75e47ca9e20bsalomon     *  SkSurface that owns this canvas.
164bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
165bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
166bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
167bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1684ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1694ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1704ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
171210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
17268260fa1e913cb1f1f4f07755acd11357a47dc6ftomhudson    virtual SkISize getBaseLayerSize() const;
1734ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1744ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1754ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1764ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1774ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
178210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
179c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
180c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
181c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
182c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
183c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
184c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
18552d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#ifndef SK_SUPPORT_LEGACY_GETDEVICE
18652d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedprotected:  // Can we make this private?
18752d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#endif
1881f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
18952d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedpublic:
19041e010cb901c0da9066c4df562030808c9ccd7f8reed    SkBaseDevice* getDevice_just_for_deprecated_compatibility_testing() const {
19141e010cb901c0da9066c4df562030808c9ccd7f8reed        return this->getDevice();
19241e010cb901c0da9066c4df562030808c9ccd7f8reed    }
1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1949266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1959266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1969266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1979266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1989266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1999266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
2000b53d59a24f667350b4282f88470713902409030reed@google.com     *
2010b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
2020b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
2030b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
2040b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
2050b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
2069266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
2079c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
2089c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
2099c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
2101f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
2119c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
2129266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
21376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
21476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
215cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
216cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
2174a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
2184a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
2194a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
2204a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
22176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
222e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
223e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
224644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
225644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
226644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
227644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
228644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
229644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
2304b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
2314b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
232daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
2339c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
2349c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2359c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
2366b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
2379c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
2389c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
2399c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
2409c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
2416b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
2429c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
2436b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
2449c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
2459c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2469c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
2479c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2486ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  local RAM) return true, and if not null, return in the pixmap parameter information about
2496ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  the pixels. The pixmap's pixel address is only valid
250c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
2516ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  canvas (or its parent surface if any) will invalidate the pixel address
2526ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  (and associated information).
253c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
2546ceeebd37a43d879c120b6ba100ae1febdd67a18reed     *  On failure, returns false and the pixmap parameter will be ignored.
255c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
2566ceeebd37a43d879c120b6ba100ae1febdd67a18reed    bool peekPixels(SkPixmap*);
2576ceeebd37a43d879c120b6ba100ae1febdd67a18reed
258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
260a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
261b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
262a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
263b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
264a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
265b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
266a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
267b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
268b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
269b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
270b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
271a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
272a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
273b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
274a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
275a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
276a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
277b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
278b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
279a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
280a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
281a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
282a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
283a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
284a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
285b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(SkBitmap* bitmap, int srcX, int srcY);
286c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2874b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
288a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
289a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
290a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
291a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
29251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
29351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
29451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2954cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2964cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2974cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2984cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2994cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
3004cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
3014cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
3024cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
3034cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
3044cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
3054cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
3064cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
3074cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
3084cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
3094cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
3104cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
3114cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
3124cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
3134cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
3144cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
3154cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
3164cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
3174cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
3184cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
3194cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
3204b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
3228d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
323dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
325dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
326dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
327dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
328dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
329d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
330d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
331d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
332d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
333d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
337dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
338ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
339ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
340ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
341ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
344d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
345d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
346d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
347021f631dc66da06dbe4aed21df2f27daecce9db7reed    int saveLayer(const SkRect& bounds, const SkPaint* paint) {
348021f631dc66da06dbe4aed21df2f27daecce9db7reed        return this->saveLayer(&bounds, paint);
349021f631dc66da06dbe4aed21df2f27daecce9db7reed    }
350d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
35170ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    /**
35270ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Temporary name.
35370ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  Will allow any requests for LCD text to be respected, so the caller must be careful to
35470ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     *  only draw on top of opaque sections of the layer to get good results.
35570ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed     */
35670ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed    int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
35770ee31b2fa127eee6c0cea61cf05508e9d3ca7b1reed
3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
361dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
36240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
36340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
36440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
36540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
367d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
368d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
369d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
370d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3714960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    enum {
3724960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kIsOpaque_SaveLayerFlag         = 1 << 0,
3734960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kPreserveLCDText_SaveLayerFlag  = 1 << 1,
374bada1885da479d948f065182d6dfa85a1140bda5reed
375bada1885da479d948f065182d6dfa85a1140bda5reed#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
376bada1885da479d948f065182d6dfa85a1140bda5reed        kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
377bada1885da479d948f065182d6dfa85a1140bda5reed#endif
3784960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
3794960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    typedef uint32_t SaveLayerFlags;
3804960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
3814960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    struct SaveLayerRec {
382bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec()
383bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(nullptr), fPaint(nullptr), fBackdrop(nullptr), fSaveLayerFlags(0)
384bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
3854960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
3864960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            : fBounds(bounds)
3874960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fPaint(paint)
388bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(nullptr)
389bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fSaveLayerFlags(saveLayerFlags)
390bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        {}
391bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
392bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed                     SaveLayerFlags saveLayerFlags)
393bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            : fBounds(bounds)
394bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fPaint(paint)
395bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed            , fBackdrop(backdrop)
3964960eeec4a1f2a772654883d7f3615d47bcd5dc3reed            , fSaveLayerFlags(saveLayerFlags)
3974960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        {}
3984960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
399bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkRect*           fBounds;    // optional
400bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkPaint*          fPaint;     // optional
401bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        const SkImageFilter*    fBackdrop;  // optional
402bfd5f171e6a3eccd7c4bede652a85fd76bcbce2areed        SaveLayerFlags          fSaveLayerFlags;
4034960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    };
4044960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
4054960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    int saveLayer(const SaveLayerRec&);
4064960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
408dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
409dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
410dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
412e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
415ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
416ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
418a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
421ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
422ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
423ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43292362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4407438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about the origin.
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4457438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    /** Preconcat the current matrix with the specified rotation about a given point.
4467438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param degrees  The amount to rotate, in degrees
4477438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param px  The x coordinate of the point to rotate about.
4487438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman        @param py  The y coordinate of the point to rotate about.
4497438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    */
4507438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman    void rotate(SkScalar degrees, SkScalar px, SkScalar py);
4517438bfc0804d021aa92cdd5ea644994a4248f3dbbungeman
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
45692362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
46192362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
46644c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
47295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
473e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Add the specified translation to the current draw depth of the canvas.
474e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack        @param z    The distance to translate in Z.
475e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Negative into screen, positive out of screen.
476e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack                    Without translation, the draw depth defaults to 0.
477e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    */
478e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    void translateZ(SkScalar z);
479e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
48095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Set the current set of lights in the canvas.
48195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack        @param lights   The lights that we want the canvas to have.
48295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    */
48395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void setLights(sk_sp<SkLights> lights);
48495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
48595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /** Returns the current set of lights the canvas uses
48695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack      */
48795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> getLights() const;
48895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
48995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
4904ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4914ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4924ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4934ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4944ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4954ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
496669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, ClipOp, bool doAntiAlias);
497669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, ClipOp op) {
498669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRect(rect, op, false);
499669983856d99b9312be3166b7dd1f8483a90c315reed    }
500669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRect(const SkRect& rect, bool doAntiAlias = false) {
501669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRect(rect, kIntersect_Op, doAntiAlias);
502669983856d99b9312be3166b7dd1f8483a90c315reed    }
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5044ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
5054ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
5064ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
5074ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
5084ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
5094ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
510669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, ClipOp op, bool doAntiAlias);
511669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, ClipOp op) {
512669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRRect(rrect, op, false);
513669983856d99b9312be3166b7dd1f8483a90c315reed    }
514669983856d99b9312be3166b7dd1f8483a90c315reed    void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
515669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipRRect(rrect, kIntersect_Op, doAntiAlias);
516669983856d99b9312be3166b7dd1f8483a90c315reed    }
5174ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
5184ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
5194ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
5204ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
5214ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
5224ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
5234ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
524669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, ClipOp op, bool doAntiAlias);
525669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, ClipOp op) {
526669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipPath(path, op, false);
527669983856d99b9312be3166b7dd1f8483a90c315reed    }
528669983856d99b9312be3166b7dd1f8483a90c315reed    void clipPath(const SkPath& path, bool doAntiAlias = false) {
529669983856d99b9312be3166b7dd1f8483a90c315reed        this->clipPath(path, kIntersect_Op, doAntiAlias);
530669983856d99b9312be3166b7dd1f8483a90c315reed    }
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5328f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
53345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
53445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
53545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
53645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
53745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
53845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
5446e998e6137e6b25f047b5c5943f2b02485165e3emtklein        @param op The region op to apply to the current clip
5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
54673603f3c52ffd89fe9d035be827b566a0e7d3b79reed    void clipRegion(const SkRegion& deviceRgn, ClipOp op = kIntersect_Op);
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5563b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5683b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5758f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
577bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
578bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
579bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
580bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
5818f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
58274b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
583bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
585845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
592374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, SkBlendMode mode = SkBlendMode::kSrcOver);
5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
595845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
599374772bd61951f01bf84fe17bf53d8867681c9aereed    void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
601f4e0d9eb2d72fe92c30237de978936113143dc16reed    /**
602f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  Helper method for drawing a color in SRC mode, completely replacing all the pixels
603f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  in the current clip with this color.
604f4e0d9eb2d72fe92c30237de978936113143dc16reed     */
605f4e0d9eb2d72fe92c30237de978936113143dc16reed    void clear(SkColor color) {
606374772bd61951f01bf84fe17bf53d8867681c9aereed        this->drawColor(color, SkBlendMode::kSrc);
6078eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    }
6082a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
6092a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
61028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
61128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
61228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
613a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * dependent and one legal implementation is to do nothing. This method
614a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     * ignores the current clip.
61528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
61628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
61728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
61828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
61928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
62028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
62128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
62228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
62328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
624a1bb8e02fe7956b2f85a0afadbca5f607a804403benjaminwagner     *  Fill the entire canvas (restricted to the current clip) with the
6252a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6262a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6272a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6280846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPaint(const SkPaint& paint);
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6600846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6664b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6910846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRect(const SkRect& rect, const SkPaint& paint);
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
69887001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7034b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
71544df651ebefc284acc2f66425dff3ea0b0e14b36msarett    /** Draw the outline of the specified region using the specified paint.
71644df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param region   The region to be drawn
71744df651ebefc284acc2f66425dff3ea0b0e14b36msarett        @param paint    The paint used to draw the region
71844df651ebefc284acc2f66425dff3ea0b0e14b36msarett    */
719dca352e2d42cfe698573947b3d11abc1eaade160msarett    void drawRegion(const SkRegion& region, const SkPaint& paint);
72044df651ebefc284acc2f66425dff3ea0b0e14b36msarett
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7260846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawOval(const SkRect& oval, const SkPaint&);
7274ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7284ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7294ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7304ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7314ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7324ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7334ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7344ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7350846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
737ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
738ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
739ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
740ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
741ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
742ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
75521af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        specified oval. Sweep angles are not treated as modulo 360 and thus can
75621af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        exceed a full sweep of the oval. Note that this differs slightly from
75721af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty
75821af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        or the sweep angle is zero nothing is drawn. If useCenter is true the oval
75921af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        center is inserted into the implied path before the arc and the path is
76021af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        closed back to the, center forming a wedge. Otherwise, the implied path
76121af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        contains just the arc and is not closed.
762ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param oval The bounds of oval used to define the shape of the arc.
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
764ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon        @param sweepAngle Sweep angle (in degrees) measured clockwise.
76521af9ca1b1f54d9ba1de055aa8475928d5c8ecdfbsalomon        @param useCenter true means include the center of the oval.
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7860846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPath(const SkPath& path, const SkPaint& paint);
7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
788d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with its top/left corner at (x,y), using the
789d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        specified paint, transformed by the current matrix.
790d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr
791d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image    The image to be drawn
792d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param left     The position of the left side of the image being drawn
793d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param top      The position of the top side of the image being drawn
794d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
795d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr     */
7960846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
797f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
798f8053da25981c6b3152b637c1c91f43cff194c25reed                   const SkPaint* paint = NULL) {
799f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImage(image.get(), left, top, paint);
800f8053da25981c6b3152b637c1c91f43cff194c25reed    }
801b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
802a5517e2b190a8083b38964972b031c13e99f1012reed    /**
803a5517e2b190a8083b38964972b031c13e99f1012reed     *  Controls the behavior at the edge of the src-rect, when specified in drawImageRect,
804a5517e2b190a8083b38964972b031c13e99f1012reed     *  trading off speed for exactness.
805a5517e2b190a8083b38964972b031c13e99f1012reed     *
806a5517e2b190a8083b38964972b031c13e99f1012reed     *  When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around
807a5517e2b190a8083b38964972b031c13e99f1012reed     *  the pixels in the image. If there is a src-rect specified, it is intended to restrict the
808a5517e2b190a8083b38964972b031c13e99f1012reed     *  pixels that will be read. However, for performance reasons, some implementations may slow
809a5517e2b190a8083b38964972b031c13e99f1012reed     *  down if they cannot read 1-pixel past the src-rect boundary at times.
810a5517e2b190a8083b38964972b031c13e99f1012reed     *
811a5517e2b190a8083b38964972b031c13e99f1012reed     *  This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable.
812a5517e2b190a8083b38964972b031c13e99f1012reed     *  If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect
813a5517e2b190a8083b38964972b031c13e99f1012reed     *  must be strictly respected, the caller should pass kStrict.
814a5517e2b190a8083b38964972b031c13e99f1012reed     */
815a5517e2b190a8083b38964972b031c13e99f1012reed    enum SrcRectConstraint {
816a5517e2b190a8083b38964972b031c13e99f1012reed        /**
817a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kStrict is specified, the implementation must respect the src-rect
818a5517e2b190a8083b38964972b031c13e99f1012reed         *  (if specified) strictly, and will never sample outside of those bounds during sampling
819a5517e2b190a8083b38964972b031c13e99f1012reed         *  even when filtering. This may be slower than kFast.
820a5517e2b190a8083b38964972b031c13e99f1012reed         */
821a5517e2b190a8083b38964972b031c13e99f1012reed        kStrict_SrcRectConstraint,
822a5517e2b190a8083b38964972b031c13e99f1012reed
823a5517e2b190a8083b38964972b031c13e99f1012reed        /**
824a5517e2b190a8083b38964972b031c13e99f1012reed         *  If kFast is specified, the implementation may sample outside of the src-rect
82519e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon         *  (if specified) by half the width of filter. This allows greater flexibility
826a5517e2b190a8083b38964972b031c13e99f1012reed         *  to the implementation and can make the draw much faster.
827a5517e2b190a8083b38964972b031c13e99f1012reed         */
828a5517e2b190a8083b38964972b031c13e99f1012reed        kFast_SrcRectConstraint,
829a5517e2b190a8083b38964972b031c13e99f1012reed    };
830a5517e2b190a8083b38964972b031c13e99f1012reed
831a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified image, scaling and translating so that it fills the specified
832a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the image is transformed
833a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
834a5517e2b190a8083b38964972b031c13e99f1012reed     *
835a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param image      The image to be drawn
836a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the image to be drawn
837a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
838a5517e2b190a8083b38964972b031c13e99f1012reed     *                    image will be drawn
839a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the image, or NULL
840a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
841a5517e2b190a8083b38964972b031c13e99f1012reed     */
842e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
843e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint,
844e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint);
845e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that takes src SkIRect
846e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
847e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
848e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant that assumes src == image-bounds
849e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
850e47829b6b1eeb6b0c97ccb3df3016d197046824creed                       SrcRectConstraint = kStrict_SrcRectConstraint);
85184984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
852f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
853f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint,
854f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
855f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), src, dst, paint, constraint);
856f8053da25981c6b3152b637c1c91f43cff194c25reed    }
857f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
858f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) {
859f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), isrc, dst, paint, cons);
860f8053da25981c6b3152b637c1c91f43cff194c25reed    }
861f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
862f8053da25981c6b3152b637c1c91f43cff194c25reed                       SrcRectConstraint cons = kStrict_SrcRectConstraint) {
863f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageRect(image.get(), dst, paint, cons);
864f8053da25981c6b3152b637c1c91f43cff194c25reed    }
865f8053da25981c6b3152b637c1c91f43cff194c25reed
8664c21dc5ddf3b482293ed34eead876d8d61a662c3reed    /**
8674c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  Draw the image stretched differentially to fit into dst.
8684c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  center is a rect within the image, and logically divides the image
8694c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
8704c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  image is the "center", then the center-rect should be [2, 2, 3, 3].
8714c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *
8724c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  If the dst is >= the image size, then...
8734c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The 4 corners are not stretched at all.
8744c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides are stretched in only one axis.
8754c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The center is stretched in both axes.
8764c21dc5ddf3b482293ed34eead876d8d61a662c3reed     * Else, for each axis where dst < image,
8774c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The corners shrink proportionally
8784c21dc5ddf3b482293ed34eead876d8d61a662c3reed     *  - The sides (along the shrink axis) and center are not drawn
8794c21dc5ddf3b482293ed34eead876d8d61a662c3reed     */
8804c21dc5ddf3b482293ed34eead876d8d61a662c3reed    void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
881f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr);
882f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
883f8053da25981c6b3152b637c1c91f43cff194c25reed                       const SkPaint* paint = nullptr) {
884f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawImageNine(image.get(), center, dst, paint);
885f8053da25981c6b3152b637c1c91f43cff194c25reed    }
8864c21dc5ddf3b482293ed34eead876d8d61a662c3reed
8878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
8888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
89391246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
89491246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
895f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
89691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
89791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9030846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
9040846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                    const SkPaint* paint = NULL);
9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
906a5517e2b190a8083b38964972b031c13e99f1012reed    /** Draw the specified bitmap, scaling and translating so that it fills the specified
907a5517e2b190a8083b38964972b031c13e99f1012reed     *  dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
908a5517e2b190a8083b38964972b031c13e99f1012reed     *  and drawn.
909a5517e2b190a8083b38964972b031c13e99f1012reed     *
910a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param bitmap     The bitmap to be drawn
911a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param src        Optional: specify the subset of the bitmap to be drawn
912a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param dst        The destination rectangle where the scaled/translated
913a5517e2b190a8083b38964972b031c13e99f1012reed     *                    bitmap will be drawn
914a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param paint      The paint used to draw the bitmap, or NULL
915a5517e2b190a8083b38964972b031c13e99f1012reed     *  @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
916a5517e2b190a8083b38964972b031c13e99f1012reed     */
917e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
91884984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
919e47829b6b1eeb6b0c97ccb3df3016d197046824creed    // variant where src is SkIRect
92084984efeb64787b88c5f8bd6929cfe2d58a3ba06reed    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
92184984efeb64787b88c5f8bd6929cfe2d58a3ba06reed                        const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
922e47829b6b1eeb6b0c97ccb3df3016d197046824creed    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
92319e82e3b9f6fb5a02fc033121f2047b4d886112ebsalomon                        SrcRectConstraint = kStrict_SrcRectConstraint);
92484984efeb64787b88c5f8bd6929cfe2d58a3ba06reed
925f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
926c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
927f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
928f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
929f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
930f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
931f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
9329bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
9339bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
9349bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
935f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
936f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
937f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
938f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
9390846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
9400846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                        const SkPaint* paint = NULL);
941f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
942c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
943c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
94471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *
94571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  If the lattice divs or bounds are invalid, the entire lattice
94671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett     *  struct will be ignored on the draw call.
947c573a40ed5024b463e47088d307e3164a486dba5msarett     */
948c573a40ed5024b463e47088d307e3164a486dba5msarett    struct Lattice {
9490764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        enum Flags : uint8_t {
9500764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            // If set, indicates that we should not draw corresponding rect.
9510764efe6a9ae65ad83992f614f57ca9db5b1f191msarett            kTransparent_Flags = 1 << 0,
9520764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        };
9530764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
954c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of x-coordinates that divide the bitmap vertically.
95571df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight).
956c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
95771df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fXDivs;
958c573a40ed5024b463e47088d307e3164a486dba5msarett
959c573a40ed5024b463e47088d307e3164a486dba5msarett        // An array of y-coordinates that divide the bitmap horizontally.
96071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom).
961c573a40ed5024b463e47088d307e3164a486dba5msarett        // Does not have ownership.
96271df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const int*     fYDivs;
9630764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9640764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // If non-null, the length of this array must be equal to
9650764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // (fXCount + 1) * (fYCount + 1).  Note that we allow the first rect
96671df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft).
96771df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // In this case, the caller still must specify a flag (as a placeholder)
96871df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // for these empty rects.
9690764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The flags correspond to the rects in the lattice, first moving
9700764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // left to right and then top to bottom.
97171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const Flags*   fFlags;
9720764efe6a9ae65ad83992f614f57ca9db5b1f191msarett
9730764efe6a9ae65ad83992f614f57ca9db5b1f191msarett        // The number of fXDivs.
97471df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fXCount;
975c573a40ed5024b463e47088d307e3164a486dba5msarett
976c573a40ed5024b463e47088d307e3164a486dba5msarett        // The number of fYDivs.
97771df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        int            fYCount;
97871df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett
97971df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // The bound to draw from.  Must be contained by the src that is being drawn,
98071df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // non-empty, and non-inverted.
98171df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        // If nullptr, the bounds are the entire src.
98271df2d7bc1bbc83ad4cf005f9027df4cb3b88a9bmsarett        const SkIRect* fBounds;
983c573a40ed5024b463e47088d307e3164a486dba5msarett    };
984c573a40ed5024b463e47088d307e3164a486dba5msarett
985c573a40ed5024b463e47088d307e3164a486dba5msarett    /**
986c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Draw the bitmap stretched or shrunk differentially to fit into dst.
987c573a40ed5024b463e47088d307e3164a486dba5msarett     *
988c573a40ed5024b463e47088d307e3164a486dba5msarett     *  Moving horizontally across the bitmap, alternating rects will be "scalable"
989c573a40ed5024b463e47088d307e3164a486dba5msarett     *  (in the x-dimension) to fit into dst or must be left "fixed".  The first rect
990c573a40ed5024b463e47088d307e3164a486dba5msarett     *  is treated as "fixed", but it's possible to specify an empty first rect by
991c573a40ed5024b463e47088d307e3164a486dba5msarett     *  making lattice.fXDivs[0] = 0.
992c573a40ed5024b463e47088d307e3164a486dba5msarett     *
993c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The scale factor for all "scalable" rects will be the same, and may be greater
994c573a40ed5024b463e47088d307e3164a486dba5msarett     *  than or less than 1 (meaning we can stretch or shrink).  If the number of
995c573a40ed5024b463e47088d307e3164a486dba5msarett     *  "fixed" pixels is greater than the width of the dst, we will collapse all of
996c573a40ed5024b463e47088d307e3164a486dba5msarett     *  the "scalable" regions and appropriately downscale the "fixed" regions.
997c573a40ed5024b463e47088d307e3164a486dba5msarett     *
998c573a40ed5024b463e47088d307e3164a486dba5msarett     *  The same interpretation also applies to the y-dimension.
999c573a40ed5024b463e47088d307e3164a486dba5msarett     */
1000c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
1001c573a40ed5024b463e47088d307e3164a486dba5msarett                           const SkPaint* paint = nullptr);
1002c573a40ed5024b463e47088d307e3164a486dba5msarett    void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
1003c573a40ed5024b463e47088d307e3164a486dba5msarett                          const SkPaint* paint = nullptr);
1004c573a40ed5024b463e47088d307e3164a486dba5msarett
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1013f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
1014f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                  const SkPaint& paint);
10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
10174b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1023f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
1024f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                     const SkPaint& paint);
10254b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
10284b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1035f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
1036f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                      const SkPaint& paint);
10374b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
10468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1050f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
10598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
10608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
1063f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
1064f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                        const SkMatrix* matrix, const SkPaint& paint);
10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
106645561a0b15fe045ba272c328684c3f7ae290785areed    /**
106745561a0b15fe045ba272c328684c3f7ae290785areed     *  Draw the text with each character/glyph individually transformed by its xform.
106845561a0b15fe045ba272c328684c3f7ae290785areed     *  If cullRect is not null, it is a conservative bounds of what will be drawn
106963f30d90498ca1a48868421b528036f3be30e2adreed     *  taking into account the xforms and the paint, and will be used to accelerate culling.
107045561a0b15fe045ba272c328684c3f7ae290785areed     */
107145561a0b15fe045ba272c328684c3f7ae290785areed    void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
107245561a0b15fe045ba272c328684c3f7ae290785areed                         const SkRect* cullRect, const SkPaint& paint);
107345561a0b15fe045ba272c328684c3f7ae290785areed
107400d5c2c6523321d25b32905ff4822f083a4173eefmalita    /** Draw the text blob, offset by (x,y), using the specified paint.
107500d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param blob     The text blob to be drawn
107600d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param x        The x-offset of the text being drawn
107700d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param y        The y-offset of the text being drawn
107800d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param paint    The paint used for the text (e.g. color, size, style)
107900d5c2c6523321d25b32905ff4822f083a4173eefmalita    */
108000d5c2c6523321d25b32905ff4822f083a4173eefmalita    void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
10812ab9057b31ee92060b9769ea1adfada51c11c010reed    void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
10822ab9057b31ee92060b9769ea1adfada51c11c010reed        this->drawTextBlob(blob.get(), x, y, paint);
10832ab9057b31ee92060b9769ea1adfada51c11c010reed    }
108400d5c2c6523321d25b32905ff4822f083a4173eefmalita
10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
10868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
1087a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
10888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10911c2c441fede0ae9573afc098017011e3439624a9reed    void drawPicture(const SkPicture* picture) {
10921c2c441fede0ae9573afc098017011e3439624a9reed        this->drawPicture(picture, NULL, NULL);
10931c2c441fede0ae9573afc098017011e3439624a9reed    }
1094ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture) {
1095f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get());
1096f8053da25981c6b3152b637c1c91f43cff194c25reed    }
10979b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
1098d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    /**
1099d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  Draw the picture into this canvas.
1100d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1101d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
1102d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  logically equivalent to
1103d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      save/concat/drawPicture/restore
1104d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
1105d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1106d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1107d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  This is logically equivalent to
1108d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      saveLayer(paint)/drawPicture/restore
1109d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     */
1110d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
1111ca2622ba051829fed5f30facd74c5b41cd4b931creed    void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
1112f8053da25981c6b3152b637c1c91f43cff194c25reed        this->drawPicture(picture.get(), matrix, paint);
1113f8053da25981c6b3152b637c1c91f43cff194c25reed    }
1114d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed
111595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
111695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    /**
1117e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  Draw the picture into this canvas, with shadows!
111895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
111995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  We will use the canvas's lights along with the picture information (draw depths of
112095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
112195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  then use that set of shadowmaps to render the scene with shadows.
112295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
112395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
112495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  logically equivalent to
112595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      save/concat/drawPicture/restore
112695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
112795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
112895302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
112995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *  This is logically equivalent to
113095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *      saveLayer(paint)/drawPicture/restore
113195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     *
1132e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  We also support using variance shadow maps for blurred shadows; the user can specify
1133e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *  what shadow mapping algorithm to use with params.
1134e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1135e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - Then, the shadow map can be blurred, and when reading from it, the fragment shader
1136e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      can calculate the variance of the depth at a position by doing E(x^2) - E(x)^2.
1137e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1138e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      of the probability that the current surface is shadowed by using Chebyshev's
1139e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      inequality, and then use that to shade the fragment.
1140e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *
1141e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *    - There are a few problems with VSM.
1142e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1143e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                         will cause their shadow penumbras to overwrite otherwise solid
1144e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                         shadows.
1145e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *      * Shape Distortion | We can combat Light Bleeding by biasing the shadow (setting
1146e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           mostly shaded fragments to completely shaded) and increasing
1147e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           the minimum allowed variance. However, this warps and rounds
1148e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack     *                           out the shape of the shadow.
114995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack     */
115095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const SkPicture*,
115195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
1152e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkPaint* paint,
1153e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkShadowParams& params);
115495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    void drawShadowedPicture(const sk_sp<SkPicture>& picture,
115595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                             const SkMatrix* matrix,
1156e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkPaint* paint,
1157e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                             const SkShadowParams& params) {
1158e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack        this->drawShadowedPicture(picture.get(), matrix, paint, params);
115995302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    }
116095302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
116195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
1169559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
1170559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        If both textures and vertex-colors are NULL, it strokes hairlines with
1171559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the paint's color. This behavior is a useful debugging mode to visualize
1172559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the mesh.
1173559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
1179631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
11808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
11818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
11827d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        @param mode Used if both texs and colors are present. In this
11838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
11847d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                    before being drawn using the paint.
11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
11868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
11884b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11900846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawVertices(VertexMode vmode, int vertexCount,
11910846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPoint vertices[], const SkPoint texs[],
11927d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkColor colors[], SkBlendMode mode,
11930846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const uint16_t indices[], int indexCount,
11940846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPaint& paint);
1195cfb6bdf767796c950f89985445738d2d8e7f12b0reed    void drawVertices(VertexMode vmode, int vertexCount,
1196cfb6bdf767796c950f89985445738d2d8e7f12b0reed                      const SkPoint vertices[], const SkPoint texs[],
11977d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkColor colors[], const uint16_t indices[], int indexCount,
11987d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                      const SkPaint& paint) {
11997d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawVertices(vmode, vertexCount, vertices, texs, colors, SkBlendMode::kModulate,
12007d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                           indices, indexCount, paint);
12017d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12027d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
1203b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1204b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
12056cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1206b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1207b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1208b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1209b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
12106cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1211b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
12127d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     @param mode specifies how are the colors and the textures combined if both of them are
1213b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1214963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1215963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1216b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
12177d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
12187d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
12197d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPoint texCoords[4], const SkPaint& paint) {
12207d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
12217d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12227d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
12233cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
122471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
122571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
122671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  into a quad.
122771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
122871c3c760a83123ee0b3127b8c65c6394ce541c50reed     *      xform maps [0, 0, tex.width, tex.height] -> quad
122971c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
123071c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The color array is optional. When specified, each color modulates the pixels in its
12317d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  corresponding quad (via the specified SkBlendMode).
123271c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
123371c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The cullRect is optional. When specified, it must be a conservative bounds of all of the
123471c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
123571c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  intersect the current clip.
123671c3c760a83123ee0b3127b8c65c6394ce541c50reed     *
123771c3c760a83123ee0b3127b8c65c6394ce541c50reed     *  The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
12387d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed     *  and blendmode are used to affect each of the quads.
123971c3c760a83123ee0b3127b8c65c6394ce541c50reed     */
124071c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
12417d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect,
124271c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkPaint* paint);
12437d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12447d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
12457d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   const SkPaint* paint) {
12467d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
12477d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
124871c3c760a83123ee0b3127b8c65c6394ce541c50reed    void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
124971c3c760a83123ee0b3127b8c65c6394ce541c50reed                   const SkRect* cullRect, const SkPaint* paint) {
12507d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
125171c3c760a83123ee0b3127b8c65c6394ce541c50reed    }
1252f8053da25981c6b3152b637c1c91f43cff194c25reed    void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
12537d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                   int count, const SkRect* cullRect, const SkPaint* paint) {
12547d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed        this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
12557d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed                        cullRect, paint);
12567d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    }
12577d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed
125871c3c760a83123ee0b3127b8c65c6394ce541c50reed    /**
12593cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
12603cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
12613cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
12623cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
12633cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
12643cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
12653cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
1266a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
1267a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
12686a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1269f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    /**
1270f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
1271f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a null-terminated utf8 string, and the value is a blob of data stored in an SkData
1272f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  (which may be null). The annotation is associated with the specified rectangle.
1273f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1274f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  The caller still retains its ownership of the data (if any).
1275f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *
1276f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
1277f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     *  a picture or drawing to a PDF document) will pass on this information.
1278f70b531daaf47db1ee95c70da9843f1dd1f418d3reed     */
1279f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    void drawAnnotation(const SkRect&, const char key[], SkData* value);
12800fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
12810fba3b97b5b0e3707b31931ab9325030b81c940fmtklein        this->drawAnnotation(rect, key, value.get());
12820fba3b97b5b0e3707b31931ab9325030b81c940fmtklein    }
1283f70b531daaf47db1ee95c70da9843f1dd1f418d3reed
12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
12857765000709dc64eb23be7df47d1f995d1f787115fmalita#ifdef SK_INTERNAL
128653d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
128753d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita    #define SK_SUPPORT_LEGACY_DRAWFILTER
12887765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12897765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
12904b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
129153d9f1cfbd5ddbf57c2f22b9e613ce48e5b2896cfmalita#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
12928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1293dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
12948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
12967765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated")
12978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
12984b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
12998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
13008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1302dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1303dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
13058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
13077765000709dc64eb23be7df47d1f995d1f787115fmalita    SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
13088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
13097765000709dc64eb23be7df47d1f995d1f787115fmalita#endif
13108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
13118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1312754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1313754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1314754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1315754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1316754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1317754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1318754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
13198f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1320754de5f65b466f721d952a379194cc94de376f42reed@google.com
13215c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
13225c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
13235c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
13245c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
13255c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
13265c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
13278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1331a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
13328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
133340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
133440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
133540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
133640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
133740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
133840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
13396bd5284415bd983b0628c4941dff5def40018f5abungeman        return fClipStack.get();
134040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
134140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1342c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
13435e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
134490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
134590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
134690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
13477d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
134890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
13498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
135236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
13531105224f9701e57ec5ce0354d6a380b664f5c638Brian Osman    GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
135436736a2dae94947e075ac9503d5de7799772a5f7robertphillips
135536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // don't call
135636736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
135736736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetIgnoreSaveLayerBounds();
135836736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
135936736a2dae94947e075ac9503d5de7799772a5f7robertphillips    static bool Internal_Private_GetTreatSpriteAsBitmap();
136036736a2dae94947e075ac9503d5de7799772a5f7robertphillips
136136736a2dae94947e075ac9503d5de7799772a5f7robertphillips    // TEMP helpers until we switch virtual over to const& for src-rect
136236736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
136336736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              const SkPaint* paint,
136436736a2dae94947e075ac9503d5de7799772a5f7robertphillips                              SrcRectConstraint constraint = kStrict_SrcRectConstraint);
136536736a2dae94947e075ac9503d5de7799772a5f7robertphillips    void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
136636736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               const SkPaint* paint,
136736736a2dae94947e075ac9503d5de7799772a5f7robertphillips                               SrcRectConstraint constraint = kStrict_SrcRectConstraint);
136836736a2dae94947e075ac9503d5de7799772a5f7robertphillips
1369cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    // expose minimum amount of information necessary for transitional refactoring
1370cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    /**
1371cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     * Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates.
1372cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson     */
1373cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson    void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds);
1374cb3bd18a4b787f6281930dbe49e1c430f28a367ctomhudson
1375da2cd8b1d9b9307cb3fbfb28af4139b6dbe31c94robertphillipsprotected:
137695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1377e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    /** Returns the current (cumulative) draw depth of the canvas.
1378e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack      */
1379e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    SkScalar getZ() const;
1380e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack
138195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    sk_sp<SkLights> fLights;
138295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
138395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
138476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
1385e8f3062a36d3682f4019309a32b5b84dc9eddf8creed    virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
138676f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1387c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1388884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onPeekPixels(SkPixmap*);
1389884e97cb04db7ed053a866567ee9c6e4c01f993areed    virtual bool onAccessTopLayerPixels(SkPixmap*);
1390ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual SkImageInfo onImageInfo() const;
1391ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual bool onGetProps(SkSurfaceProps*) const;
1392ea5a6513c05e3d7261b68c3ef7d42645ee5bfe17reed    virtual void onFlush();
1393c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1394e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1395e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
13964960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // getSaveLayerStrategy()'s return value may suppress full layer allocation.
1397e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1398e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
13994960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        kNoLayer_SaveLayerStrategy,
1400e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1401e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
14026ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
14034960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    // Overriders should call the corresponding INHERITED method up the inheritance chain.
14044960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
14054960eeec4a1f2a772654883d7f3615d47bcd5dc3reed        return kFullLayer_SaveLayerStrategy;
14064960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    }
1407fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
14086cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
1409fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1410fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
1411cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    virtual void didTranslate(SkScalar dx, SkScalar dy) {
1412cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein        this->didConcat(SkMatrix::MakeTrans(dx, dy));
1413cbdf007bc2eb85056a1a5c75c088202becba2d16mtklein    }
141495302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack
141595302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
1416e5de130788c8637d2f7df9ddb0241b78e04d5882vjiaoblack    virtual void didTranslateZ(SkScalar) {}
141795302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
141844c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
1419f70b531daaf47db1ee95c70da9843f1dd1f418d3reed    virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
1420ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1421ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1422e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1423e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1424b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1425e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1426e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1427b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1428e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1429e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1430e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1431b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1432e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1433e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1434e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
143545561a0b15fe045ba272c328684c3f7ae290785areed    virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
143645561a0b15fe045ba272c328684c3f7ae290785areed                                   const SkRect* cullRect, const SkPaint& paint);
14376cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
143800d5c2c6523321d25b32905ff4822f083a4173eefmalita    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
143900d5c2c6523321d25b32905ff4822f083a4173eefmalita                                const SkPaint& paint);
144000d5c2c6523321d25b32905ff4822f083a4173eefmalita
1441b3c9d1c33caf325aada244204215eb790c228c12dandov    virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
1442faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                           const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
1443e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1444a8db72864a43ad1fbba3c2892cf5cd88060a43efreed    virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
14456a070dc06af4e9f305f9d08a69e34d18ade473cbreed
144641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPaint(const SkPaint&);
144741af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRect(const SkRect&, const SkPaint&);
144844df651ebefc284acc2f66425dff3ea0b0e14b36msarett    virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
144941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawOval(const SkRect&, const SkPaint&);
1450ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon    virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
1451ac3aa245acc7b469aa2f0d0078e53401d78ac8b9bsalomon                           const SkPaint&);
145241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRRect(const SkRRect&, const SkPaint&);
145341af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
145441af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
1455faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                                const SkPoint texs[], const SkColor colors[], SkBlendMode,
145641af966ab338e95eee81ab618ab28195075338f7reed                                const uint16_t indices[], int indexCount, const SkPaint&);
14572766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein
145871c3c760a83123ee0b3127b8c65c6394ce541c50reed    virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
1459faba3715b8ddfaa0ce4df79bc8006e9bc7694e5bMike Reed                             int count, SkBlendMode, const SkRect* cull, const SkPaint*);
146041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPath(const SkPath&, const SkPaint&);
146141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
1462562fe4767cc73e08a4e039362bc0336aea66ecfbreed    virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
1463562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                 SrcRectConstraint);
14644c21dc5ddf3b482293ed34eead876d8d61a662c3reed    virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
14654c21dc5ddf3b482293ed34eead876d8d61a662c3reed                                 const SkPaint*);
1466168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
1467168820625c35a8c19f66c661efcbce7a5e334837msarett                                    const SkPaint*);
14684c21dc5ddf3b482293ed34eead876d8d61a662c3reed
146941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
147041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
1471562fe4767cc73e08a4e039362bc0336aea66ecfbreed                                  SrcRectConstraint);
147241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
147341af966ab338e95eee81ab618ab28195075338f7reed                                  const SkPaint*);
1474168820625c35a8c19f66c661efcbce7a5e334837msarett    virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
1475168820625c35a8c19f66c661efcbce7a5e334837msarett                                     const SkPaint*);
147641af966ab338e95eee81ab618ab28195075338f7reed
14778f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
14788f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
14798f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
14808f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
14818f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
148273603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void onClipRect(const SkRect& rect, ClipOp, ClipEdgeStyle);
148373603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void onClipRRect(const SkRRect& rrect, ClipOp, ClipEdgeStyle);
148473603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void onClipPath(const SkPath& path, ClipOp, ClipEdgeStyle);
148573603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void onClipRegion(const SkRegion& deviceRgn, ClipOp);
14868f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
148728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
148828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
1489d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
14909b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
149195302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#ifdef SK_EXPERIMENTAL_SHADOWING
149295302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack    virtual void onDrawShadowedPicture(const SkPicture*,
149395302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack                                       const SkMatrix*,
1494e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkPaint*,
1495e6f5d5623160a69e1585f5121a3695092327dfe0vjiaoblack                                       const SkShadowParams& params);
149695302da19d8b0a3bcd9d9be0e79f486760787f09vjiaoblack#endif
14971356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
1498a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1499a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1500c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1501c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
15024960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection,
1503c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1504a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1505c83a29759a5c2966da5ab973e4fd90763e4c962breedprivate:
15063aafe111b6cc388400092851cc53bbbdfcb8a81creed    /** After calling saveLayer(), there can be any number of devices that make
15073aafe111b6cc388400092851cc53bbbdfcb8a81creed     up the top-most drawing area. LayerIter can be used to iterate through
15083aafe111b6cc388400092851cc53bbbdfcb8a81creed     those devices. Note that the iterator is only valid until the next API
15093aafe111b6cc388400092851cc53bbbdfcb8a81creed     call made on the canvas. Ownership of all pointers in the iterator stays
15103aafe111b6cc388400092851cc53bbbdfcb8a81creed     with the canvas, so none of them should be modified or deleted.
15113aafe111b6cc388400092851cc53bbbdfcb8a81creed     */
15123aafe111b6cc388400092851cc53bbbdfcb8a81creed    class LayerIter /*: SkNoncopyable*/ {
15133aafe111b6cc388400092851cc53bbbdfcb8a81creed    public:
15143aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Initialize iterator with canvas, and set values for 1st device */
15153aafe111b6cc388400092851cc53bbbdfcb8a81creed        LayerIter(SkCanvas*);
15163aafe111b6cc388400092851cc53bbbdfcb8a81creed        ~LayerIter();
15173aafe111b6cc388400092851cc53bbbdfcb8a81creed
15183aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Return true if the iterator is done */
15193aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool done() const { return fDone; }
15203aafe111b6cc388400092851cc53bbbdfcb8a81creed        /** Cycle to the next device */
15213aafe111b6cc388400092851cc53bbbdfcb8a81creed        void next();
15223aafe111b6cc388400092851cc53bbbdfcb8a81creed
15233aafe111b6cc388400092851cc53bbbdfcb8a81creed        // These reflect the current device in the iterator
15243aafe111b6cc388400092851cc53bbbdfcb8a81creed
15253aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkBaseDevice*   device() const;
15263aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkMatrix& matrix() const;
15273aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkRasterClip& clip() const;
15283aafe111b6cc388400092851cc53bbbdfcb8a81creed        const SkPaint&  paint() const;
15293aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             x() const;
15303aafe111b6cc388400092851cc53bbbdfcb8a81creed        int             y() const;
15313aafe111b6cc388400092851cc53bbbdfcb8a81creed
15323aafe111b6cc388400092851cc53bbbdfcb8a81creed    private:
15333aafe111b6cc388400092851cc53bbbdfcb8a81creed        // used to embed the SkDrawIter object directly in our instance, w/o
15343aafe111b6cc388400092851cc53bbbdfcb8a81creed        // having to expose that class def to the public. There is an assert
15353aafe111b6cc388400092851cc53bbbdfcb8a81creed        // in our constructor to ensure that fStorage is large enough
15363aafe111b6cc388400092851cc53bbbdfcb8a81creed        // (though needs to be a compile-time-assert!). We use intptr_t to work
15373aafe111b6cc388400092851cc53bbbdfcb8a81creed        // safely with 32 and 64 bit machines (to ensure the storage is enough)
15383aafe111b6cc388400092851cc53bbbdfcb8a81creed        intptr_t          fStorage[32];
15393aafe111b6cc388400092851cc53bbbdfcb8a81creed        class SkDrawIter* fImpl;    // this points at fStorage
15403aafe111b6cc388400092851cc53bbbdfcb8a81creed        SkPaint           fDefaultPaint;
15413aafe111b6cc388400092851cc53bbbdfcb8a81creed        bool              fDone;
15423aafe111b6cc388400092851cc53bbbdfcb8a81creed    };
15431356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby
15444960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    static bool BoundsAffectsClip(SaveLayerFlags);
1545bada1885da479d948f065182d6dfa85a1140bda5reed    static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
15464960eeec4a1f2a772654883d7f3615d47bcd5dc3reed
1547a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed    static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
1548a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     SkBaseDevice* dst, const SkMatrix& ctm,
1549a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed                                     const SkClipStack* clipStack);
1550a2217ef965e57fdbbf989989e7ec1f2c04f62d39reed
1551c83a29759a5c2966da5ab973e4fd90763e4c962breed    enum ShaderOverrideOpacity {
1552c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
1553c83a29759a5c2966da5ab973e4fd90763e4c962breed        kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
1554c83a29759a5c2966da5ab973e4fd90763e4c962breed        kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
1555c83a29759a5c2966da5ab973e4fd90763e4c962breed    };
1556c83a29759a5c2966da5ab973e4fd90763e4c962breed
155797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
155897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
1559c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(bool willOverwritesEntireSurface = false);
1560c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
1561c83a29759a5c2966da5ab973e4fd90763e4c962breed    void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
1562c83a29759a5c2966da5ab973e4fd90763e4c962breed        this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
1563c83a29759a5c2966da5ab973e4fd90763e4c962breed                                                                : kNotOpaque_ShaderOverrideOpacity);
1564c83a29759a5c2966da5ab973e4fd90763e4c962breed    }
156597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
15668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
15678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15686bd5284415bd983b0628c4941dff5def40018f5abungeman    sk_sp<SkClipStack> fClipStack;
15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
1573b679ca8926a832274b14fdb512f88f64b61d32eareed    enum {
1574a499f905e9340e4935447f2562fd92e8853382b1reed        kMCRecSize      = 128,  // most recent measurement
157531b80a9dc60ae5411ad6abd10269c4f88c635ec2reed        kMCRecCount     = 32,   // common depth for save/restores
15768c30a8196dd5903d2d23b4d0a5dc888e802bf698reed        kDeviceCMSize   = 176,  // most recent measurement
1577b679ca8926a832274b14fdb512f88f64b61d32eareed    };
1578b679ca8926a832274b14fdb512f88f64b61d32eareed    intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
1579a499f905e9340e4935447f2562fd92e8853382b1reed    intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
15808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15814a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
15824a8126e7f81384526629b1e21bf89b632ea13cd9reed
15832ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
15848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
158674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
158797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
158897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
158997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
159097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
159197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
159297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
159345c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1594fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
15958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
15968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
15978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
15982ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
15992ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
16008c30a8196dd5903d2d23b4d0a5dc888e802bf698reed    void internalSetMatrix(const SkMatrix&);
16012ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
16029c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
16038926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
16049c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
16052a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
160652d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1607439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkRecorder;        // resetForNextPicture
1608439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkLiteRecorder;    // resetForNextPicture
1609439ace939b6aaa58408ece0e9e89b633353571aeFlorin Malita    friend class SkNoDrawCanvas;    // InitFlags
16102d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1611c83a29759a5c2966da5ab973e4fd90763e4c962breed    friend class SkPictureRecord;   // predrawNotify (why does it need it? <reed>)
16124960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
16131356978f15a4dc36928353a6fca4cbd6c40abce5Herb Derby    friend class SkDeferredCanvas;  // For use of resetForNextPicture
161422886c493596655d8fd9512951f9010869b7fbc5Matt Sarett    friend class SkOverdrawCanvas;
1615b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1616d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1617d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1618d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1619d954498c01ccf0417feacf89e45d0c62a06a813breed    };
162078e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
1621fcf7829b67b798aff4c41c4688daa9c7381991e6robertphillips    SkCanvas(SkBaseDevice* device, InitFlags);
1622d954498c01ccf0417feacf89e45d0c62a06a813breed
1623feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein    void resetForNextPicture(const SkIRect& bounds);
1624feaadee1c38e1d4e1ec0069a3509ef6fbc5fbeffmtklein
16258f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1626a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1627b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
16284a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
16294a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
16304a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
16314a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
16324a8126e7f81384526629b1e21bf89b632ea13cd9reed
1633d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1634f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1635403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1636afc7cce5d68663934128d76963cd501f771d71desenorblanco     * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
16374ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
16384ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1639afc7cce5d68663934128d76963cd501f771d71desenorblanco    SkIRect getTopLayerBounds() const;
1640403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
16417112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1642eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1643a5517e2b190a8083b38964972b031c13e99f1012reed                                SrcRectConstraint);
1644fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
16454960eeec4a1f2a772654883d7f3615d47bcd5dc3reed    void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
16467503d60847c4ad22df87458aecd917772b23d293reed    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1647fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
16492ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
16508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
165152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
165252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
165352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
165452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
165552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
16564b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1657fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    // only for canvasutils
1658fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    const SkRegion& internal_private_getTotalClip() const;
1659fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
1660c83a29759a5c2966da5ab973e4fd90763e4c962breed    /*
1661c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  Returns true if drawing the specified rect (or all if it is null) with the specified
1662c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  paint (or default if null) would overwrite the entire root device of the canvas
1663c83a29759a5c2966da5ab973e4fd90763e4c962breed     *  (i.e. the canvas' surface if it had one).
1664c83a29759a5c2966da5ab973e4fd90763e4c962breed     */
1665c83a29759a5c2966da5ab973e4fd90763e4c962breed    bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
1666c83a29759a5c2966da5ab973e4fd90763e4c962breed
1667262a71b7f95ce98ff3dd8dba845afbd724470903reed    /**
1668262a71b7f95ce98ff3dd8dba845afbd724470903reed     *  Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
1669262a71b7f95ce98ff3dd8dba845afbd724470903reed     */
1670262a71b7f95ce98ff3dd8dba845afbd724470903reed    bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
1671c83a29759a5c2966da5ab973e4fd90763e4c962breed
1672fbfa25802709139c2f14e304319c9541da65ca27msarett
1673fbfa25802709139c2f14e304319c9541da65ca27msarett    /**
1674fbfa25802709139c2f14e304319c9541da65ca27msarett     *  Keep track of the device clip bounds and if the matrix is scale-translate.  This allows
1675fbfa25802709139c2f14e304319c9541da65ca27msarett     *  us to do a fast quick reject in the common case.
16768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
16779637ea91b88ff8f8e95325bfc41417ffc4d5ee0bmsarett    bool   fIsScaleTranslate;
1678fbfa25802709139c2f14e304319c9541da65ca27msarett    SkRect fDeviceClipBounds;
1679fbfa25802709139c2f14e304319c9541da65ca27msarett
16808f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
168145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
168242b73eb00367c8315974b1c374308d20efa78897reed    const bool fConservativeRasterClip;
16838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16845c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
16855c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
16865c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
16875c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
16885c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
16895c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
16905c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16915c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
16925c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
16935c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
16945c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
16955c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
16965c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
16975c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
16985c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
16995c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
170015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
170115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
17028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
17038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
17058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
17068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
17078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
17088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
17102887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
17112887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
17122887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
17132887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
17142887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
17152887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
17168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
17178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
17188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1719f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1720f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1721f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1722f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1723f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1724f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1725f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1726f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1727f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1728f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1729f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1730f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1731f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1732f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
17338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
17348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
17358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
17368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
17378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
17388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1739e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
17408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1741c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1742c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1743c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
174473603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void clipRect(const SkRect&, SkCanvas::ClipOp, bool antialias) = 0;
174573603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void clipRRect(const SkRRect&, SkCanvas::ClipOp, bool antialias) = 0;
174673603f3c52ffd89fe9d035be827b566a0e7d3b79reed    virtual void clipPath(const SkPath&, SkCanvas::ClipOp, bool antialias) = 0;
1747c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
17482a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
17498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1750