SkCanvas.h revision e0d9ce890e67d02727ac2811bb456ddb64f827d4
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkCanvas_DEFINED
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkCanvas_DEFINED
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h"
145c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#include "SkClipStack.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
19845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
21b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com// if not defined, we always assume ClipToLayer for saveLayer()
22b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com//#define SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
23b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com
24b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com
255c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org//#define SK_SUPPORT_LEGACY_GETCLIPTYPE
265c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org//#define SK_SUPPORT_LEGACY_GETTOTALCLIP
279c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com//#define SK_SUPPORT_LEGACY_GETTOPDEVICE
284cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
29e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com//#define SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL
30e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL
31e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    #define SK_LEGACY_DRAWTEXT_VIRTUAL  virtual
32e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#else
33e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    #define SK_LEGACY_DRAWTEXT_VIRTUAL
34e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#endif
35e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBounder;
371f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
4074bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
424ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
4376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
4497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
45644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext;
469c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comclass GrRenderTarget;
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
637ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt {
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
6515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    SK_DECLARE_INST_COUNT(SkCanvas)
6615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
67e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
683107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  Attempt to allocate an offscreen raster canvas, matching the ImageInfo.
693107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  On success, return a new canvas that will draw into that offscreen.
703107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
713107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  The caller can access the pixels after drawing into this canvas by
723107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  calling readPixels() or peekPixels().
733107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
743107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  If the requested ImageInfo is opaque (either the colortype is
753107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  intrinsically opaque like RGB_565, or the info's alphatype is kOpaque)
763107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  then the pixel memory may be uninitialized. Otherwise, the pixel memory
773107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  will be initialized to 0, which is interpreted as transparent.
783107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
793107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
803107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  1. the memory allocation failed (e.g. request is too large)
813107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  2. invalid ImageInfo (e.g. negative dimensions)
823107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  3. unsupported ImageInfo for a canvas
833107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
843107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - kIgnore_SkAlphaType
853107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
863107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
873107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
883107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  dimensions.
893107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     */
903107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    static SkCanvas* NewRaster(const SkImageInfo&);
913107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org
923107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    static SkCanvas* NewRasterN32(int width, int height) {
933107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org        return NewRaster(SkImageInfo::MakeN32Premul(width, height));
943107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    }
953107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org
963107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    /**
9742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
9842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
9942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
10042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
10142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
10242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
10342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
10442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
10542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kIgnore_SkAlphaType
10642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
10742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
10842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
10942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
11042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
11142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
11242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
11342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
11442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org        return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
11542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    }
11642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
11742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
118e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
119e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
120e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
121cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
1228d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
123e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
124e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
125e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
126e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
127e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
128e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    SkCanvas(int width, int height);
129e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
1306dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
131e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1328d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
1338d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
1341f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
1358d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
1364469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
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
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
153210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
154bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     *  Trigger the immediate execution of all pending draw operations.
155bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
156bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
157bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
158bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1594ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1604ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1614ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
162210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
1634ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getBaseLayerSize() const;
1644ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1654ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1664ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1674ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1684ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
169210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
170c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
171c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
172c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
173c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
174c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
175c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
1761f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1789266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1799266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1809266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1819266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1829266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1839266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
1840b53d59a24f667350b4282f88470713902409030reed@google.com     *
1850b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
1860b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
1870b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
1880b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
1890b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1909266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1919c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
1929c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
1939c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
1941f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
1959c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
1969266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
19776f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
19876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
199cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
200cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
20176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
20276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    SkSurface* newSurface(const SkImageInfo&);
203e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
204644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
205644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
206644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
207644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
208644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
209644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
2104b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
2114b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
212daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
2139c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
2149c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2159c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
2166b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
2179c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
2189c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
2199c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
2209c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
2216b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
2229c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
2236b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
2249c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
2259c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2269c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
2279c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
228c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  local RAM) return the const-address of those pixels, and if not null,
229c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  return the ImageInfo and rowBytes. The returned address is only valid
230c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
231c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  canvas (or its parent surface if any) will invalidate the
232c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  returned address (and associated information).
233c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
234c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  On failure, returns NULL and the info and rowBytes parameters are
235c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  ignored.
236c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
237c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
238c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  starting at the specified (x,y) location in the coordinate system of the base-layer.
243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
244a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a source rectangle
245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
246a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *      srcR(x, y, info.width(), info.height());
247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
248a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  SrcR is intersected with the bounds of the base-layer. If this intersection is not empty,
249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by base-layer at (x,y)
250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  and the "dst" by info+pixels+rowBytes. Replace the dst pixels with the corresponding src
251a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
252a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
253a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
256a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
257a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
258a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    bool readPixels(const SkImageInfo&, void* pixels, size_t rowBytes, int x, int y);
259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
260a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
261a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
262a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
263a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
264a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
265a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    bool readPixels(SkBitmap* bitmap, int x, int y);
266c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
268a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
269a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
270a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
271a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
27251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
27351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
27451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2914cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2924cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2934cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2944cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2954cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2964cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2974cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2984cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2994cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
3004b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
3028d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum SaveFlags {
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the matrix state, restoring it on restore() */
3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrix_SaveFlag            = 0x01,
3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the clip state, restoring it on restore() */
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClip_SaveFlag              = 0x02,
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support per-pixel alpha */
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kHasAlphaLayer_SaveFlag     = 0x04,
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support 8-bits per color component */
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kFullColorLayer_SaveFlag    = 0x08,
312b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com        /**
313b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  the layer should clip against the bounds argument
314b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *
315b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on.
316b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         */
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClipToLayer_SaveFlag       = 0x10,
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // helper masks for common choices
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrixClip_SaveFlag        = 0x03,
321b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_NoClipLayer_SaveFlag  = 0x0F,
323b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#endif
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_ClipLayer_SaveFlag    = 0x1F
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
327dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
329dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
330dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
331dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
332dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
333d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com        @param flags The flags govern what portion of the Matrix/Clip/drawFilter
334d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     state the save (and matching restore) effect. For example,
335d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     if only kMatrix is specified, then only the matrix state
336d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     will be pushed and popped. Likewise for the clip if kClip
337d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     is specified.  However, the drawFilter is always affected
338d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     by calls to save/restore.
3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
341e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    int save(SaveFlags flags = kMatrixClip_SaveFlag);
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
346dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
347ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
348ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
349ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
350ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
356e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint,
357e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org                  SaveFlags flags = kARGB_ClipLayer_SaveFlag);
3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
362dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
36340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
36440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
36540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
36640408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       SaveFlags flags = kARGB_ClipLayer_SaveFlag);
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
375dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
376dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
377dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
379e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
382ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
383ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
385a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
388ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
389ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
390ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3957c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com    /** Returns true if drawing is currently going to a layer (from saveLayer)
3967c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     *  rather than to the root device.
3977c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     */
3988f9ecbd3466d4330886b4c23b06e75b468c795adjunov@chromium.org    virtual bool isDrawingToLayer() const;
3997c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
40492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41092362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified rotation.
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41592362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42192362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42692362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4274b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43144c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4324b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4374ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4384ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4394ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4404ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4414ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4424ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
443759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRect(const SkRect& rect,
444759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
445759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4474ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4484ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4494ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4504ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4514ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4524ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
453759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRRect(const SkRRect& rrect,
454759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   SkRegion::Op op = SkRegion::kIntersect_Op,
455759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   bool doAntiAlias = false);
4564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4574ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4584ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4594ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
4604ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4614ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4624ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
463759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipPath(const SkPath& path,
464759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
465759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4678f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
4688f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        Set to false to force clips to be hard, even if doAntiAlias=true is
4698f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        passed to clipRect or clipPath.
4708f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com     */
4718f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    void setAllowSoftClip(bool allow) {
4728f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        fAllowSoftClip = allow;
4738f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    }
4748f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com
47545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    /** EXPERIMENTAL -- only used for testing
47645a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
47745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
47845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
47945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
48045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
48145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
489759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRegion(const SkRegion& deviceRgn,
490759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                    SkRegion::Op op = SkRegion::kIntersect_Op);
4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified region. This does not intersect or in any other way account
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for the existing clip region.
4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn The region to copy into the current clip.
4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4978f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    void setClipRegion(const SkRegion& deviceRgn) {
4988f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5093b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5213b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the horizontal band specified by top and bottom is
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely clipped out. This is a conservative calculation, meaning
5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        that it is possible that if the method returns false, the band may still
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in fact be clipped out, but the converse is not true. If this method
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true, then the band is guaranteed to be clipped out.
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top  The top of the horizontal band to compare with the clip
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom The bottom of the horizontal and to compare with the clip
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the horizontal band is completely clipped out (i.e. does
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     not intersect the current clip)
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5333b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickRejectY(SkScalar top, SkScalar bottom) const {
534c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        SkASSERT(top <= bottom);
5359836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
5369836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT
5379836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // TODO: add a hasPerspective method similar to getLocalClipBounds. This
5389836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // would cache the SkMatrix::hasPerspective result. Alternatively, have
5399836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // the MC stack just set a hasPerspective boolean as it is updated.
5409836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        if (this->getTotalMatrix().hasPerspective()) {
541a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com            // TODO: consider implementing some half-plane test between the
5429836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // two Y planes and the device-bounds (i.e., project the top and
5439836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // bottom Y planes and then determine if the clip bounds is completely
5449836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // outside either one).
5459836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            return false;
5469836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        }
5479836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif
5489836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
549c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        const SkRect& clipR = this->getLocalClipBounds();
55092d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // In the case where the clip is empty and we are provided with a
55192d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // negative top and positive bottom parameter then this test will return
55292d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // false even though it will be clipped. We have chosen to exclude that
55392d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // check as it is rare and would result double the comparisons.
554c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return top >= clipR.fBottom || bottom <= clipR.fTop;
55592d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com    }
5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5628f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
564bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
565bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
566bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
567bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
5688f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
56974b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
570bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
572845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
580845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
583845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawColor(SkColor color,
588845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                   SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5902a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
5912a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  This erases the entire drawing surface to the specified color,
5922a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  irrespective of the clip. It does not blend with the previous pixels,
5932a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  but always overwrites them.
5942a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *
5952a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  It is roughly equivalent to the following:
5962a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.save();
5972a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.clipRect(hugeRect, kReplace_Op);
5982a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setColor(color);
5992a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setXfermodeMode(kSrc_Mode);
6002a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.drawPaint(paint);
6012a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.restore();
6022a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  though it is almost always much more efficient.
6032a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6042a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    virtual void clear(SkColor);
6052a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
6062a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
60728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
60828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
60928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
61028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * dependent and one legal implementation is to do nothing. Like clear(), this
61128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * ignores the clip.
61228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
61328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
61428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
61528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
61628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
61728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
61828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
61928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
62028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
6212a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  Fill the entire canvas' bitmap (restricted to the current clip) with the
6222a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6232a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6242a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPaint(const SkPaint& paint);
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint& paint);
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6644b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6897ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com    virtual void drawRect(const SkRect& rect, const SkPaint& paint);
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
69687001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7014b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7184ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    virtual void drawOval(const SkRect& oval, const SkPaint&);
7194ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7204ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7214ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7224ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7234ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7244ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7254ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7264ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7274ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
729ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
730ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
731ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
732ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
733ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
734ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified oval. If the sweep angle is >= 360, then the oval is drawn
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely. Note that this differs slightly from SkPath::arcTo, which
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        treats the sweep angle mod 360.
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the shape of the arc
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param useCenter true means include the center of the oval. For filling
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         this will draw a wedge. False means just use the arc.
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7757ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com    virtual void drawPath(const SkPath& path, const SkPaint& paint);
7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
78391246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
78491246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
785f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
78691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
78791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
796eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    enum DrawBitmapRectFlags {
79731acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kNone_DrawBitmapRectFlag            = 0x0,
7987475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com        /**
799eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  When filtering is enabled, allow the color samples outside of
8007475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com         *  the src rect (but still in the src bitmap) to bleed into the
801eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  drawn portion
802eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         */
80331acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kBleed_DrawBitmapRectFlag           = 0x1,
804eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    };
805eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org
8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with the specified matrix applied (before the
8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas' matrix is applied).
8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src      Optional: specify the subset of the bitmap to be drawn
8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The destination rectangle where the scaled/translated
8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        image will be drawn
8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8147112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
8157112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                                      const SkRect& dst,
816eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                      const SkPaint* paint = NULL,
81731acc11977815402e4ef2681350f8559285bec97robertphillips@google.com                                      DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag);
8187112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com
8197112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst,
820eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkPaint* paint = NULL) {
82131acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag);
8227112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8247112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc,
825eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkRect& dst, const SkPaint* paint = NULL,
82631acc11977815402e4ef2681350f8559285bec97robertphillips@google.com                        DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) {
8277112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect realSrcStorage;
8287112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect* realSrcPtr = NULL;
8297112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        if (isrc) {
8307112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcStorage.set(*isrc);
8317112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcPtr = &realSrcStorage;
8327112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        }
833eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org        this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags);
8347112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
835c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com
8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
8378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                  const SkPaint* paint = NULL);
8384b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
839f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
840f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  Draw the bitmap stretched differentially to fit into dst.
841f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
842f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
843f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
844f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
845f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
8469bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
8479bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
8489bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
849f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
850f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
851f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
852f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
853f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
854f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint = NULL);
855f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
8568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y),
8578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        NOT transformed by the current matrix. Note: if the paint
8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
878e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawText(const void* text, size_t byteLength, SkScalar x,
8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar y, const SkPaint& paint);
8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
8824b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
8878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
888e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosText(const void* text, size_t byteLength,
8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkPoint pos[], const SkPaint& paint);
8904b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
8934b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
8968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
900e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosTextH(const void* text, size_t byteLength,
9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkScalar xpos[], SkScalar constY,
9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
9034b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawTextOnPathHV(const void* text, size_t byteLength,
9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          const SkPath& path, SkScalar hOffset,
9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
930e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawTextOnPath(const void* text, size_t byteLength,
9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPath& path, const SkMatrix* matrix,
9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPaint& paint);
9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
934145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org    /** PRIVATE / EXPERIMENTAL -- do not call
935145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        Perform back-end analysis/optimization of a picture. This may attach
936145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        optimization data to the picture which can be used by a later
937145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        drawPicture call.
938145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        @param picture The recorded drawing commands to analyze/optimize
939145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org    */
940145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org    void EXPERIMENTAL_optimize(SkPicture* picture);
941145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org
942c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org    /** PRIVATE / EXPERIMENTAL -- do not call
943c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org        Purge all the discardable optimization information associated with
944c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org        'picture'. If NULL is passed in, purge all discardable information.
945c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org    */
946c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org    void EXPERIMENTAL_purge(SkPicture* picture);
947c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org
9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
950a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPicture(SkPicture& picture);
9554b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
9588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
9614b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
9668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
968631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xmode Used if both texs and colors are present. In this
9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    before being drawn using the paint. If mode is null, then
9748d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com                    kModulate_Mode is used.
9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
9778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
9784b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawVertices(VertexMode vmode, int vertexCount,
9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPoint vertices[], const SkPoint texs[],
9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkColor colors[], SkXfermode* xmode,
9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const uint16_t indices[], int indexCount,
9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
986cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com    /** Send a blob of data to the canvas.
987cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        For canvases that draw, this call is effectively a no-op, as the data
988cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        is not parsed, but just ignored. However, this call exists for
989cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        subclasses like SkPicture's recording canvas, that can store the data
990cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        and then play it back later (via another call to drawData).
991cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com     */
9920a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void drawData(const void* data, size_t length) {
9930a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something with the data
9940a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
9950a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
996a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com    /** Add comments. beginCommentGroup/endCommentGroup open/close a new group.
997a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com        Each comment added via addComment is notionally attached to its
9980a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        enclosing group. Top-level comments simply belong to no group.
9990a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com     */
10000a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void beginCommentGroup(const char* description) {
10010a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10020a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10030a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void addComment(const char* kywd, const char* value) {
10040a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10050a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10060a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void endCommentGroup() {
10070a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10080a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10090a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1010210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    /**
1011210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  With this call the client asserts that subsequent draw operations (up to the
1012210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  matching popCull()) are fully contained within the given bounding box. The assertion
1013210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  is not enforced, but the information might be used to quick-reject command blocks,
1014210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  so an incorrect bounding box may result in incomplete rendering.
1015210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     */
1016520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void pushCull(const SkRect& cullRect);
1017cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com
1018210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    /**
1019210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  Terminates the current culling block, and restores the previous one (if any).
1020210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     */
1021520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void popCull();
1022520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org
10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10244b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current bounder object.
10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The bounder's reference count is unchaged.
10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canva's bounder (or NULL).
10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBounder*  getBounder() const { return fBounder; }
10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set a new bounder (or NULL).
10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Pass NULL to clear any previous bounder.
10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter passed is also returned.
10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If a previous bounder exists, its reference count is decremented.
10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If bounder is not NULL, its reference count is incremented.
10368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bounder the new bounder (or NULL) to be installed in the canvas
10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the set bounder object
10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkBounder* setBounder(SkBounder* bounder);
10404b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1042dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
10464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1050dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1051dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1059754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1060754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1061754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1062754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1063754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1064754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1065754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
10668f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1067754de5f65b466f721d952a379194cc94de376f42reed@google.com
10685c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
10695c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
10705c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
10715c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
10725c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
10735c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1078a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10805c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
1081bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    enum ClipType {
1082bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kEmpty_ClipType = 0,
1083bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kRect_ClipType,
1084bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kComplex_ClipType
1085bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    };
1086bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Returns a description of the total clip; may be cheaper than
1087bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        getting the clip and querying it directly.
1088bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
10898f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual ClipType getClipType() const;
10905c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif
1091bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
10925c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP
10934469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** DEPRECATED -- need to move this guy to private/friend
10944469938e92d779dff05e745559e67907bbf21e78reed@google.com     *  Return the current device clip (concatenation of all clip calls).
1095a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  This does not account for the translate in any of the devices.
1096a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  @return the current device clip (concatenation of all clip calls).
10975e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com     */
1098a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com    const SkRegion& getTotalClip() const;
10995c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif
11005e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com
110140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
110240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
110340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
110440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
110540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
110640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
110740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com        return &fClipStack;
110840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
110940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
111090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    class ClipVisitor {
111190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    public:
111220a550c6ea947f0ab239da1d4ecba209d76a98fdjustinlin@google.com        virtual ~ClipVisitor();
111390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com        virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1114e5b2af955b7d06815ddd405659ad62a2a8355ca3commit-bot@chromium.org        virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
111590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com        virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
111690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    };
111790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com
11185e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
111990c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
112090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
112190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
11227d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
112390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
11248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
11268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After calling saveLayer(), there can be any number of devices that make
11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        up the top-most drawing area. LayerIter can be used to iterate through
11298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        those devices. Note that the iterator is only valid until the next API
11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call made on the canvas. Ownership of all pointers in the iterator stays
11318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with the canvas, so none of them should be modified or deleted.
11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11337ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API LayerIter /*: SkNoncopyable*/ {
11348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
11358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Initialize iterator with canvas, and set values for 1st device */
11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        LayerIter(SkCanvas*, bool skipEmptyClips);
11378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~LayerIter();
11384b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return true if the iterator is done */
11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool done() const { return fDone; }
11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Cycle to the next device */
11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void next();
11434b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // These reflect the current device in the iterator
11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11461f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com        SkBaseDevice*   device() const;
11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkMatrix& matrix() const;
11488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkRegion& clip() const;
11498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPaint&  paint() const;
11508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             x() const;
11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             y() const;
11524b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // used to embed the SkDrawIter object directly in our instance, w/o
11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // having to expose that class def to the public. There is an assert
11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // in our constructor to ensure that fStorage is large enough
11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // (though needs to be a compile-time-assert!). We use intptr_t to work
11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // safely with 32 and 64 bit machines (to ensure the storage is enough)
1159f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        intptr_t          fStorage[32];
11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        class SkDrawIter* fImpl;    // this points at fStorage
11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint           fDefaultPaint;
11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool              fDone;
11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11655c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    // don't call
11665c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    const SkRegion& internal_private_getTotalClip() const;
11675c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    // don't call
11685c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    void internal_private_getTotalClipAsPath(SkPath*) const;
11699c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    // don't call
11709c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    GrRenderTarget* internal_private_accessTopLayerRenderTarget();
11715c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
117376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
117476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    virtual SkSurface* onNewSurface(const SkImageInfo&);
117576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1176c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1177c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
11789c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes);
1179c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1180e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1181e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
1182e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // willSaveLayer()'s return value may suppress full layer allocation.
1183e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1184e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
1185e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kNoLayer_SaveLayerStrategy
1186e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1187e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    virtual void willSave(SaveFlags);
1188e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags);
1189e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    virtual void willRestore();
1190e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
119144c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    virtual void didConcat(const SkMatrix&);
119244c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&);
119344c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
1194ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1195ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1196e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1197e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1198e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1199e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1200e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1201e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1202e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1203e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1204e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1205e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
1206e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1207e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1208e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
1209e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
12108f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
12118f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
12128f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
12138f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
12148f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
12158f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12168f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12178f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12188f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
12198f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
122028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
122128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
122274b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    // Returns the canvas to be used by DrawIter. Default implementation
12234370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // returns this. Subclasses that encapsulate an indirect canvas may
12244370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // need to overload this method. The impl must keep track of this, as it
12254370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // is not released or deleted by the caller.
12264370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    virtual SkCanvas* canvasForDrawIter();
12274370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com
1228a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1229a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1230c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1231c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
1232a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
1233c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        SkIRect* intersection,
1234c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1235a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1236ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org    // Called by child classes that override clipPath and clipRRect to only
1237ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org    // track fast conservative clip bounds, rather than exact clips.
1238759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op,
1239ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org                                             bool inverseFilled);
1240ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org
124197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
124297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
124397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void predrawNotify();
124497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
1245210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    virtual void onPushCull(const SkRect& cullRect);
1246210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    virtual void onPopCull();
1247210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org
12488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12515c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    SkClipStack fClipStack;
12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
12538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
12548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint32_t    fMCRecStorage[32];
12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBounder*  fBounder;
1259b0a7ace7cb2a7559bbc254a7c93698bc71bbd245junov@chromium.org    int         fSaveLayerCount;    // number of successful saveLayer calls
1260210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    int         fCullCount;         // number of active culls
12618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
126274bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
126374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
126497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
126597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
126697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
126797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
126897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
126997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
127045c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1271fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12759c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
12768926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
12779c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
12789c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDeferredDevice;  // needs getTopDevice()
12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
128015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org    SkBaseDevice* createLayerDevice(const SkImageInfo&);
1281e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
12821f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* init(SkBaseDevice*);
1283f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1284403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1285403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  DEPRECATED
1286403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *
1287403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  Specify a device for this canvas to draw into. If it is not null, its
1288403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  reference count is incremented. If the canvas was already holding a
1289403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  device, its reference count is decremented. The new device is returned.
1290403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     */
1291403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    SkBaseDevice* setRootDevice(SkBaseDevice* device);
129231acdeabce094e9d42f0d6db8eebcf788aaba11askia.committer@gmail.com
12934ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
12944ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this
12954ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
12964ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
12974ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getTopLayerSize() const;
12984ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkIPoint getTopLayerOrigin() const;
1299403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
1300f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // internal methods are not virtual, so they can safely be called by other
1301f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // canvas apis, without confusing subclasses (like SkPictureRecording)
13029bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com    void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint);
13037112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1304eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1305eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                DrawBitmapRectFlags flags);
1306f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
1307f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint);
1308fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
13098926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    int internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
1310e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org                          SaveFlags, bool justForImageFilter, SaveLayerStrategy strategy);
13111f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1312fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
13138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
13148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int internalSave(SaveFlags flags);
13158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
131652c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
131752c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
131852c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
131952c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
132052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
13214b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
13228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  These maintain a cache of the clip bounds in local coordinates,
13238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (converted to 2s-compliment if floats are slow).
13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
1325c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable SkRect fCachedLocalClipBounds;
1326c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable bool   fCachedLocalClipBoundsDirty;
13278f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
132845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1330c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    const SkRect& getLocalClipBounds() const {
1331c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        if (fCachedLocalClipBoundsDirty) {
1332c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            if (!this->getClipBounds(&fCachedLocalClipBounds)) {
1333c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com                fCachedLocalClipBounds.setEmpty();
1334c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            }
1335c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            fCachedLocalClipBoundsDirty = false;
13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1337c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return fCachedLocalClipBounds;
13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
133945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
13405c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
13415c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
13425c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
13435c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
13445c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
13455c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
13465c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13475c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
13485c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
13495c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
13505c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13515c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
1352520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    // The cull stack rects are in device-space
1353520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    SkTDArray<SkIRect> fCullStack;
1354520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void validateCull(const SkIRect&);
13555c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
13565c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
13575c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
13585c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
135915e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
136015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
13618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
13658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
13688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
13692887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
13702887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
13712887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
13722887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
13732887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
13742887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
13758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
13768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
13778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1378f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1379f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1380f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1381f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1382f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1383f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1384f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1385f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1386f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1387f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1388f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1389f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1390f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1391f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
13958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
13968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1398e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14000a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com/** Stack helper class to automatically open and close a comment block
14010a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */
14020a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comclass SkAutoCommentBlock : SkNoncopyable {
14030a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.compublic:
14040a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkAutoCommentBlock(SkCanvas* canvas, const char* description) {
14050a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        fCanvas = canvas;
14060a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        if (NULL != fCanvas) {
14070a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->beginCommentGroup(description);
14080a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14090a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14100a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14110a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    ~SkAutoCommentBlock() {
14120a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        if (NULL != fCanvas) {
14130a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->endCommentGroup();
14140a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14150a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14160a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14170a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comprivate:
14180a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkCanvas* fCanvas;
14190a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com};
1420e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
14210a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1422c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/**
1423c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the caller wants read-only access to the pixels in a canvas, it can just
1424c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  call canvas->peekPixels(), since that is the fastest way to "peek" at the
1425c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  pixels on a raster-backed canvas.
1426c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1427c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the canvas has pixels, but they are not readily available to the CPU
1428c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
1429c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  succeed (though be slower, since it will return a copy of the pixels).
1430c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1431c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
1432c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  peekPixels() (for performance), but if that fails, calling readPixels() and
1433c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  storing the copy locally.
1434c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1435c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  The caller must respect the restrictions associated with peekPixels(), since
1436c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  that may have been called: The returned information is invalidated if...
1437c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - any API is called on the canvas (or its parent surface if present)
1438c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - the canvas goes out of scope
1439c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */
1440c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable {
1441c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic:
1442c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkAutoROCanvasPixels(SkCanvas* canvas);
1443c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1444c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // returns NULL on failure
1445c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* addr() const { return fAddr; }
144602d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1447c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1448c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t rowBytes() const { return fRowBytes; }
144902d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1450c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1451c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const SkImageInfo& info() const { return fInfo; }
1452c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1453c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // helper that, if returns true, installs the pixels into the bitmap. Note
1454c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // that the bitmap may reference the address returned by peekPixels(), so
1455c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // the caller must respect the restrictions associated with peekPixels().
1456c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    bool asROBitmap(SkBitmap*) const;
1457c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1458c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate:
1459c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkBitmap    fBitmap;    // used if peekPixels() fails
1460c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* fAddr;      // NULL on failure
1461c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo fInfo;
1462c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t      fRowBytes;
1463c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org};
1464c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
14658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1466