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
21e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL
22e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    #define SK_LEGACY_DRAWTEXT_VIRTUAL  virtual
23e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#else
24e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    #define SK_LEGACY_DRAWTEXT_VIRTUAL
25e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#endif
26e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
27c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor;
281f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
3174bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
334ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
3476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
3597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
36644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext;
379c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comclass GrRenderTarget;
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
547ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt {
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
5615e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    SK_DECLARE_INST_COUNT(SkCanvas)
5715e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
58e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
593107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  Attempt to allocate an offscreen raster canvas, matching the ImageInfo.
603107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  On success, return a new canvas that will draw into that offscreen.
613107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
623107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  The caller can access the pixels after drawing into this canvas by
633107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  calling readPixels() or peekPixels().
643107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
653107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  If the requested ImageInfo is opaque (either the colortype is
663107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  intrinsically opaque like RGB_565, or the info's alphatype is kOpaque)
673107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  then the pixel memory may be uninitialized. Otherwise, the pixel memory
683107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  will be initialized to 0, which is interpreted as transparent.
693107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
703107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
713107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  1. the memory allocation failed (e.g. request is too large)
723107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  2. invalid ImageInfo (e.g. negative dimensions)
733107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  3. unsupported ImageInfo for a canvas
743107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
753107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - kIgnore_SkAlphaType
763107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
773107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *
783107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
793107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     *  dimensions.
803107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org     */
813107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    static SkCanvas* NewRaster(const SkImageInfo&);
823107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org
833107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    static SkCanvas* NewRasterN32(int width, int height) {
843107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org        return NewRaster(SkImageInfo::MakeN32Premul(width, height));
853107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    }
863107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org
873107b6a85eee7914b37382f7145ab658e8c27667commit-bot@chromium.org    /**
8842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
8942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
9042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
9142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
9242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
9342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
9442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
9542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
9642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kIgnore_SkAlphaType
9742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
9842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
9942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
10042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
10142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
10242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
10342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
10442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
10542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org        return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
10642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    }
10742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
10842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
109e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
110e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
111e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
112cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
1138d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
114e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
115e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
116e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
117e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
118e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
119e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    SkCanvas(int width, int height);
120e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
1216dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
122e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1238d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
1248d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
1251f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
1268d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
1274469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
13574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
136c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
137c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
138c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
139c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
140c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
141c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
144210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
145bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     *  Trigger the immediate execution of all pending draw operations.
146bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
147bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
148bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
149bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1504ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1514ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1524ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
153210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
1544ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getBaseLayerSize() const;
1554ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1564ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1574ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1584ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1594ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
160210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
161c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
162c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
163c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
164c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
165c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
166c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
1671f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1699266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1709266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1719266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1729266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1739266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1749266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
1750b53d59a24f667350b4282f88470713902409030reed@google.com     *
1760b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
1770b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
1780b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
1790b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
1800b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1819266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1829c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
1839c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
1849c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
1851f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
1869c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
1879266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
18876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
18976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
190cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
191cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
19276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
19376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    SkSurface* newSurface(const SkImageInfo&);
194e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
195644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
196644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
197644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
198644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
199644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
200644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
2014b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
2024b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
203daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
2049c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
2059c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
2069c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
2076b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
2089c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
2099c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
2109c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
2119c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
2126b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
2139c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
2146b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
2159c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
2169c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2179c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base layer (and is not recording to a picture
2189c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
219c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  local RAM) return the const-address of those pixels, and if not null,
220c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  return the ImageInfo and rowBytes. The returned address is only valid
221c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
222c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  canvas (or its parent surface if any) will invalidate the
223c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  returned address (and associated information).
224c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
225c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  On failure, returns NULL and the info and rowBytes parameters are
226c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  ignored.
227c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
228c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
229c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
230a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
231a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
232a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  starting at the specified (x,y) location in the coordinate system of the base-layer.
234a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
235a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a source rectangle
236a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *      srcR(x, y, info.width(), info.height());
238a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  SrcR is intersected with the bounds of the base-layer. If this intersection is not empty,
240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by base-layer at (x,y)
241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  and the "dst" by info+pixels+rowBytes. Replace the dst pixels with the corresponding src
242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
244a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
246a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
248a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    bool readPixels(const SkImageInfo&, void* pixels, size_t rowBytes, int x, int y);
250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
251a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
252a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
253a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
256a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    bool readPixels(SkBitmap* bitmap, int x, int y);
257c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2584b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
259a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
260a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
261a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
262a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
26351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
26451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
26551df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2664cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2674cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2684cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2694cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2704cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2714cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2724cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2734cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2794cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2804cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2814cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2824cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2834cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2844cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2854cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2864cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2874cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2884cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2894cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
2914b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
2938d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum SaveFlags {
2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the matrix state, restoring it on restore() */
2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrix_SaveFlag            = 0x01,
2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the clip state, restoring it on restore() */
2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClip_SaveFlag              = 0x02,
2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support per-pixel alpha */
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kHasAlphaLayer_SaveFlag     = 0x04,
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support 8-bits per color component */
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kFullColorLayer_SaveFlag    = 0x08,
303b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com        /**
304b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  the layer should clip against the bounds argument
305b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *
306b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on.
307b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         */
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClipToLayer_SaveFlag       = 0x10,
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // helper masks for common choices
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrixClip_SaveFlag        = 0x03,
312b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_NoClipLayer_SaveFlag  = 0x0F,
314b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#endif
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_ClipLayer_SaveFlag    = 0x1F
3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
318dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
320dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
321dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
322dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
323dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
324d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
325d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
326d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
327d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
328d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
329d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    /** DEPRECATED - use save() instead.
330d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
331d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        This behaves the same as save(), but it allows fine-grained control of
332d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        which state bits to be saved (and subsequently restored).
333d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
334d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com        @param flags The flags govern what portion of the Matrix/Clip/drawFilter
335d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     state the save (and matching restore) effect. For example,
336d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     if only kMatrix is specified, then only the matrix state
337d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     will be pushed and popped. Likewise for the clip if kClip
338d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     is specified.  However, the drawFilter is always affected
339d4236574cfe4ec333d20e7a30f37e084168bb050djsollen@google.com                     by calls to save/restore.
3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
342d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
343d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save(SaveFlags flags);
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
348dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
349ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
350ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
351ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
352ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
355d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
356d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
357d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
358d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
359d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead.
360d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
361d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        This behaves the same as saveLayer(const SkRect*, const SkPaint*),
362d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        but it allows fine-grained control of which state bits to be saved
363d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        (and subsequently restored).
364d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
365d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param bounds (may be null) This rect, if non-null, is used as a hint to
366d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      limit the size of the offscreen, and thus drawing may be
367d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      clipped to it, though that clipping is not guaranteed to
368d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      happen. If exact clipping is desired, use clipRect().
369d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param paint (may be null) This is copied, and is applied to the
370d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                     offscreen when restore() is called
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
374d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
375d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags);
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
380dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
38140408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
38240408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
38340408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
38440408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
386d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
387d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
388d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
389d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
390d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead.
391d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
392d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        This behaves the same as saveLayerAlpha(const SkRect*, U8CPU),
393d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        but it allows fine-grained control of which state bits to be saved
394d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        (and subsequently restored).
395d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
396d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param bounds (may be null) This rect, if non-null, is used as a hint to
397d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      limit the size of the offscreen, and thus drawing may be
398d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      clipped to it, though that clipping is not guaranteed to
399d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      happen. If exact clipping is desired, use clipRect().
400d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param alpha  This is applied to the offscreen when restore() is called.
4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
404d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
405d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags);
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
408dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
409dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
410dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
412e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
415ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
416ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
418a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
421ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
422ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
423ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4287c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com    /** Returns true if drawing is currently going to a layer (from saveLayer)
4297c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     *  rather than to the root device.
4307c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     */
4318f9ecbd3466d4330886b4c23b06e75b468c795adjunov@chromium.org    virtual bool isDrawingToLayer() const;
4327c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43792362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified rotation.
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
44892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
45492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
45992362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4604b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
46444c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4654b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4714ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4744ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4754ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
476759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRect(const SkRect& rect,
477759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
478759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4804ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4814ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4824ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4834ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4844ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4854ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
486759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRRect(const SkRRect& rrect,
487759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   SkRegion::Op op = SkRegion::kIntersect_Op,
488759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   bool doAntiAlias = false);
4894ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4904ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4914ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4924ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
4934ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4944ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4954ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
496759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipPath(const SkPath& path,
497759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
498759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5008f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
5018f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        Set to false to force clips to be hard, even if doAntiAlias=true is
5028f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        passed to clipRect or clipPath.
5038f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com     */
5048f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    void setAllowSoftClip(bool allow) {
5058f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        fAllowSoftClip = allow;
5068f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    }
5078f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com
50845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    /** EXPERIMENTAL -- only used for testing
50945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
51045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
51145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
51245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
51345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
51445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
522759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRegion(const SkRegion& deviceRgn,
523759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                    SkRegion::Op op = SkRegion::kIntersect_Op);
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified region. This does not intersect or in any other way account
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for the existing clip region.
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn The region to copy into the current clip.
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    void setClipRegion(const SkRegion& deviceRgn) {
5318f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5423b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5543b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the horizontal band specified by top and bottom is
5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely clipped out. This is a conservative calculation, meaning
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        that it is possible that if the method returns false, the band may still
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in fact be clipped out, but the converse is not true. If this method
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true, then the band is guaranteed to be clipped out.
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top  The top of the horizontal band to compare with the clip
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom The bottom of the horizontal and to compare with the clip
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the horizontal band is completely clipped out (i.e. does
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     not intersect the current clip)
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5663b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickRejectY(SkScalar top, SkScalar bottom) const {
567c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        SkASSERT(top <= bottom);
5689836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
5699836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT
5709836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // TODO: add a hasPerspective method similar to getLocalClipBounds. This
5719836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // would cache the SkMatrix::hasPerspective result. Alternatively, have
5729836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // the MC stack just set a hasPerspective boolean as it is updated.
5739836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        if (this->getTotalMatrix().hasPerspective()) {
574a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com            // TODO: consider implementing some half-plane test between the
5759836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // two Y planes and the device-bounds (i.e., project the top and
5769836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // bottom Y planes and then determine if the clip bounds is completely
5779836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // outside either one).
5789836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            return false;
5799836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        }
5809836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif
5819836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
582c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        const SkRect& clipR = this->getLocalClipBounds();
58392d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // In the case where the clip is empty and we are provided with a
58492d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // negative top and positive bottom parameter then this test will return
58592d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // false even though it will be clipped. We have chosen to exclude that
58692d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // check as it is rare and would result double the comparisons.
587c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return top >= clipR.fBottom || bottom <= clipR.fTop;
58892d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com    }
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5958f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
597bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
598bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
599bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
600bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
6018f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
60274b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
603bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
605845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
613845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
616845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawColor(SkColor color,
621845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                   SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6232a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
6242a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  This erases the entire drawing surface to the specified color,
6252a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  irrespective of the clip. It does not blend with the previous pixels,
6262a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  but always overwrites them.
6272a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *
6282a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  It is roughly equivalent to the following:
6292a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.save();
6302a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.clipRect(hugeRect, kReplace_Op);
6312a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setColor(color);
6322a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setXfermodeMode(kSrc_Mode);
6332a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.drawPaint(paint);
6342a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.restore();
6352a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  though it is almost always much more efficient.
6362a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6372a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    virtual void clear(SkColor);
6382a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
6392a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
64028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
64128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
64228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
64328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * dependent and one legal implementation is to do nothing. Like clear(), this
64428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * ignores the clip.
64528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
64628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
64728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
64828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
64928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
65028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
65128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
65228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
65328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
6542a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  Fill the entire canvas' bitmap (restricted to the current clip) with the
6552a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6562a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6572a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPaint(const SkPaint& paint);
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint& paint);
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6974b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7227ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com    virtual void drawRect(const SkRect& rect, const SkPaint& paint);
7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
72987001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7344b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7514ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    virtual void drawOval(const SkRect& oval, const SkPaint&);
7524ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7534ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7544ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7554ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7564ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7574ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7584ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7594ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7604ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
762ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
763ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
764ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
765ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
766ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
767ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified oval. If the sweep angle is >= 360, then the oval is drawn
7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely. Note that this differs slightly from SkPath::arcTo, which
7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        treats the sweep angle mod 360.
7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the shape of the arc
7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param useCenter true means include the center of the oval. For filling
7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         this will draw a wedge. False means just use the arc.
7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8087ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com    virtual void drawPath(const SkPath& path, const SkPaint& paint);
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
81691246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
81791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
818f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
81991246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
82091246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
8278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
8288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
829eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    enum DrawBitmapRectFlags {
83031acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kNone_DrawBitmapRectFlag            = 0x0,
8317475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com        /**
832eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  When filtering is enabled, allow the color samples outside of
8337475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com         *  the src rect (but still in the src bitmap) to bleed into the
834eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  drawn portion
835eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         */
83631acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kBleed_DrawBitmapRectFlag           = 0x1,
837eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    };
838eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org
8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with the specified matrix applied (before the
8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas' matrix is applied).
8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src      Optional: specify the subset of the bitmap to be drawn
8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The destination rectangle where the scaled/translated
8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        image will be drawn
8458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8477112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
8487112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                                      const SkRect& dst,
849eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                      const SkPaint* paint = NULL,
85031acc11977815402e4ef2681350f8559285bec97robertphillips@google.com                                      DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag);
8517112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com
8527112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst,
853eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkPaint* paint = NULL) {
85431acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag);
8557112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
8568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8577112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc,
858eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkRect& dst, const SkPaint* paint = NULL,
85931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com                        DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) {
8607112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect realSrcStorage;
8617112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect* realSrcPtr = NULL;
8627112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        if (isrc) {
8637112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcStorage.set(*isrc);
8647112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcPtr = &realSrcStorage;
8657112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        }
866eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org        this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags);
8677112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
868c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                  const SkPaint* paint = NULL);
8714b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
872f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
873f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  Draw the bitmap stretched differentially to fit into dst.
874f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
875f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
876f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
877f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
878f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
8799bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
8809bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
8819bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
882f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
883f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
884f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
885f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
886f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
887f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint = NULL);
888f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y),
8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        NOT transformed by the current matrix. Note: if the paint
8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
911e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawText(const void* text, size_t byteLength, SkScalar x,
9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar y, const SkPaint& paint);
9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
9154b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
921e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosText(const void* text, size_t byteLength,
9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkPoint pos[], const SkPaint& paint);
9234b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
9264b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
933e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawPosTextH(const void* text, size_t byteLength,
9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkScalar xpos[], SkScalar constY,
9358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
9364b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
9468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawTextOnPathHV(const void* text, size_t byteLength,
9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          const SkPath& path, SkScalar hOffset,
9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
963e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    SK_LEGACY_DRAWTEXT_VIRTUAL void drawTextOnPath(const void* text, size_t byteLength,
9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPath& path, const SkMatrix* matrix,
9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPaint& paint);
9668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
967145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org    /** PRIVATE / EXPERIMENTAL -- do not call
968145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        Perform back-end analysis/optimization of a picture. This may attach
969145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        optimization data to the picture which can be used by a later
970145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        drawPicture call.
971145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org        @param picture The recorded drawing commands to analyze/optimize
972145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org    */
9739b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips    void EXPERIMENTAL_optimize(const SkPicture* picture);
974145d1c0fdcef63991d7f910cc067a653a8aa2c4ccommit-bot@chromium.org
975c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org    /** PRIVATE / EXPERIMENTAL -- do not call
976c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org        Purge all the discardable optimization information associated with
977c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org        'picture'. If NULL is passed in, purge all discardable information.
978c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org    */
9799b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips    void EXPERIMENTAL_purge(const SkPicture* picture);
980c873329ae9ff00b0c45f7294172ad2e9b1ec44c8commit-bot@chromium.org
9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
983a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9879b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips    void drawPicture(const SkPicture* picture);
9889b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
9944b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
996559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
997559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        If both textures and vertex-colors are NULL, it strokes hairlines with
998559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the paint's color. This behavior is a useful debugging mode to visualize
999559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the mesh.
1000559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
1006631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xmode Used if both texs and colors are present. In this
10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    before being drawn using the paint. If mode is null, then
10128d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com                    kModulate_Mode is used.
10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
10164b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
10178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawVertices(VertexMode vmode, int vertexCount,
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPoint vertices[], const SkPoint texs[],
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkColor colors[], SkXfermode* xmode,
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const uint16_t indices[], int indexCount,
10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1024cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com    /** Send a blob of data to the canvas.
1025cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        For canvases that draw, this call is effectively a no-op, as the data
1026cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        is not parsed, but just ignored. However, this call exists for
1027cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        subclasses like SkPicture's recording canvas, that can store the data
1028cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        and then play it back later (via another call to drawData).
1029cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com     */
10300a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void drawData(const void* data, size_t length) {
10310a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something with the data
10320a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1034a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com    /** Add comments. beginCommentGroup/endCommentGroup open/close a new group.
1035a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com        Each comment added via addComment is notionally attached to its
10360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        enclosing group. Top-level comments simply belong to no group.
10370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com     */
10380a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void beginCommentGroup(const char* description) {
10390a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10400a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void addComment(const char* kywd, const char* value) {
10420a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void endCommentGroup() {
10450a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10460a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10470a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1048210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    /**
1049210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  With this call the client asserts that subsequent draw operations (up to the
1050210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  matching popCull()) are fully contained within the given bounding box. The assertion
1051210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  is not enforced, but the information might be used to quick-reject command blocks,
1052210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  so an incorrect bounding box may result in incomplete rendering.
1053210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     */
1054520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void pushCull(const SkRect& cullRect);
1055cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com
1056210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    /**
1057210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     *  Terminates the current culling block, and restores the previous one (if any).
1058210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org     */
1059520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void popCull();
1060520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org
10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1064dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
10668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
10684b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
10708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1072dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1073dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
10788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1081754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1082754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1083754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1084754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1085754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1086754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1087754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
10888f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1089754de5f65b466f721d952a379194cc94de376f42reed@google.com
10905c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
10915c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
10925c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
10935c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
10945c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
10955c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
10968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
10978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
10988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
10998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1100a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
11018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11025c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
1103bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    enum ClipType {
1104bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kEmpty_ClipType = 0,
1105bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kRect_ClipType,
1106bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kComplex_ClipType
1107bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    };
1108bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Returns a description of the total clip; may be cheaper than
1109bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        getting the clip and querying it directly.
1110bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
11118f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual ClipType getClipType() const;
11125c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif
1113bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
11145c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP
11154469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** DEPRECATED -- need to move this guy to private/friend
11164469938e92d779dff05e745559e67907bbf21e78reed@google.com     *  Return the current device clip (concatenation of all clip calls).
1117a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  This does not account for the translate in any of the devices.
1118a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  @return the current device clip (concatenation of all clip calls).
11195e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com     */
1120a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com    const SkRegion& getTotalClip() const;
11215c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org#endif
11225e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com
112340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
112440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
112540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
112640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
112740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
112840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
112940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com        return &fClipStack;
113040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
113140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1132c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
11335e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
113490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
113590c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
113690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
11377d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
113890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After calling saveLayer(), there can be any number of devices that make
11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        up the top-most drawing area. LayerIter can be used to iterate through
11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        those devices. Note that the iterator is only valid until the next API
11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call made on the canvas. Ownership of all pointers in the iterator stays
11468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with the canvas, so none of them should be modified or deleted.
11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11487ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API LayerIter /*: SkNoncopyable*/ {
11498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
11508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Initialize iterator with canvas, and set values for 1st device */
11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        LayerIter(SkCanvas*, bool skipEmptyClips);
11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~LayerIter();
11534b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return true if the iterator is done */
11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool done() const { return fDone; }
11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Cycle to the next device */
11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void next();
11584b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // These reflect the current device in the iterator
11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11611f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com        SkBaseDevice*   device() const;
11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkMatrix& matrix() const;
11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkRegion& clip() const;
11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPaint&  paint() const;
11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             x() const;
11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             y() const;
11674b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // used to embed the SkDrawIter object directly in our instance, w/o
11708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // having to expose that class def to the public. There is an assert
11718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // in our constructor to ensure that fStorage is large enough
11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // (though needs to be a compile-time-assert!). We use intptr_t to work
11738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // safely with 32 and 64 bit machines (to ensure the storage is enough)
1174f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        intptr_t          fStorage[32];
11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        class SkDrawIter* fImpl;    // this points at fStorage
11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint           fDefaultPaint;
11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool              fDone;
11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11805c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    // don't call
11815c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    const SkRegion& internal_private_getTotalClip() const;
11825c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    // don't call
11835c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    void internal_private_getTotalClipAsPath(SkPath*) const;
11849c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    // don't call
11859c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    GrRenderTarget* internal_private_accessTopLayerRenderTarget();
11865c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
118876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
118976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    virtual SkSurface* onNewSurface(const SkImageInfo&);
119076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1191c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1192c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
11939c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes);
1194c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1195e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1196e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
1197e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // willSaveLayer()'s return value may suppress full layer allocation.
1198e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1199e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
1200e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kNoLayer_SaveLayerStrategy
1201e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1202e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
120307fc662d7ee018bfc9eeddab82cc1768f57a69d2fmalita    // Transitional, pending external clients cleanup.
12046ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave(SaveFlags) { this->willSave(); }
120507fc662d7ee018bfc9eeddab82cc1768f57a69d2fmalita
12066ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
1207fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) {
1208fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org        return kFullLayer_SaveLayerStrategy;
1209fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    }
1210fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
1211fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1212fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
121344c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
1214ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1215ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1216e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1217e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1218b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1219e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1220e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1221b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1222e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1223e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1224e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1225b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1226e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1227e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1228e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
1229e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
12308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
12318f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
12328f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
12338f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
12348f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
12358f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12368f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12378f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12388f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
12398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
124028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
124128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
12429b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips    virtual void onDrawPicture(const SkPicture* picture);
12439b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
124474b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    // Returns the canvas to be used by DrawIter. Default implementation
12454370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // returns this. Subclasses that encapsulate an indirect canvas may
12464370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // need to overload this method. The impl must keep track of this, as it
12474370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // is not released or deleted by the caller.
12484370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    virtual SkCanvas* canvasForDrawIter();
12494370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com
1250a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1251a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1252c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1253c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
1254a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
1255c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        SkIRect* intersection,
1256c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1257a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
1258ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org    // Called by child classes that override clipPath and clipRRect to only
1259ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org    // track fast conservative clip bounds, rather than exact clips.
1260759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op,
1261ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org                                             bool inverseFilled);
1262ed8d6bb2be0ed6a20841573682afaa46dea15175junov@chromium.org
126397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
126497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
126597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void predrawNotify();
126697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
1267210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    virtual void onPushCull(const SkRect& cullRect);
1268210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    virtual void onPopCull();
1269210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org
12708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
12718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12735c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    SkClipStack fClipStack;
12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
12758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint32_t    fMCRecStorage[32];
12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1280b0a7ace7cb2a7559bbc254a7c93698bc71bbd245junov@chromium.org    int         fSaveLayerCount;    // number of successful saveLayer calls
1281210ae2a42613b9048e8e8c4096c5bf4fe2ddf838commit-bot@chromium.org    int         fCullCount;         // number of active culls
12828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
128374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
128474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
128597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
128697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
128797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
128897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
128997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
129097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
129145c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1292fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
12938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
12948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12969c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
12978926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
12989c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
12992a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
13009c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDeferredDevice;  // needs getTopDevice()
13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
130215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org    SkBaseDevice* createLayerDevice(const SkImageInfo&);
1303e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
13041f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* init(SkBaseDevice*);
1305f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1306403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1307403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  DEPRECATED
1308403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *
1309403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  Specify a device for this canvas to draw into. If it is not null, its
1310403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  reference count is incremented. If the canvas was already holding a
1311403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  device, its reference count is decremented. The new device is returned.
1312403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     */
1313403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    SkBaseDevice* setRootDevice(SkBaseDevice* device);
131431acdeabce094e9d42f0d6db8eebcf788aaba11askia.committer@gmail.com
13154ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
13164ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this
13174ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
13184ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
13194ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getTopLayerSize() const;
13204ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkIPoint getTopLayerOrigin() const;
1321403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
1322f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // internal methods are not virtual, so they can safely be called by other
1323f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // canvas apis, without confusing subclasses (like SkPictureRecording)
13249bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com    void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint);
13257112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1326eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1327eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                DrawBitmapRectFlags flags);
1328f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
1329f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint);
1330fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
13318926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    int internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
1332e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org                          SaveFlags, bool justForImageFilter, SaveLayerStrategy strategy);
13331f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1334fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
13358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int internalSave(SaveFlags flags);
13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
133852c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
133952c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
134052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
134152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
134252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
13434b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  These maintain a cache of the clip bounds in local coordinates,
13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (converted to 2s-compliment if floats are slow).
13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
1347c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable SkRect fCachedLocalClipBounds;
1348c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable bool   fCachedLocalClipBoundsDirty;
13498f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
135045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1352c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    const SkRect& getLocalClipBounds() const {
1353c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        if (fCachedLocalClipBoundsDirty) {
1354c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            if (!this->getClipBounds(&fCachedLocalClipBounds)) {
1355c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com                fCachedLocalClipBounds.setEmpty();
1356c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            }
1357c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            fCachedLocalClipBoundsDirty = false;
13588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1359c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return fCachedLocalClipBounds;
13608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
136145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
13625c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
13635c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
13645c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
13655c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
13665c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
13675c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
13685c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13695c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
13705c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
13715c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
13725c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13735c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
1374520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    // The cull stack rects are in device-space
1375520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    SkTDArray<SkIRect> fCullStack;
1376520cf8b33e788268432c6314c52dfcef22e776aecommit-bot@chromium.org    void validateCull(const SkIRect&);
13775c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
13785c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
13795c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
13805c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
138115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
138215e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
13838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
13848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
13898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
13908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
13912887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
13922887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
13932887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
13942887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
13952887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
13962887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
13988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1400f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1401f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1402f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1403f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1404f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1405f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1406f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1407f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1408f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1409f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1410f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1411f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1412f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1413f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
14148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
14158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
14178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
14188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
14198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1420e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
14218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14220a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com/** Stack helper class to automatically open and close a comment block
14230a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */
14240a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comclass SkAutoCommentBlock : SkNoncopyable {
14250a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.compublic:
14260a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkAutoCommentBlock(SkCanvas* canvas, const char* description) {
14270a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        fCanvas = canvas;
14280a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        if (NULL != fCanvas) {
14290a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->beginCommentGroup(description);
14300a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14310a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14320a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    ~SkAutoCommentBlock() {
14340a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        if (NULL != fCanvas) {
14350a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->endCommentGroup();
14360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14380a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14390a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comprivate:
14400a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkCanvas* fCanvas;
14410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com};
1442e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
14430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1444c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/**
1445c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the caller wants read-only access to the pixels in a canvas, it can just
1446c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  call canvas->peekPixels(), since that is the fastest way to "peek" at the
1447c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  pixels on a raster-backed canvas.
1448c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1449c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the canvas has pixels, but they are not readily available to the CPU
1450c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
1451c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  succeed (though be slower, since it will return a copy of the pixels).
1452c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1453c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
1454c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  peekPixels() (for performance), but if that fails, calling readPixels() and
1455c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  storing the copy locally.
1456c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1457c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  The caller must respect the restrictions associated with peekPixels(), since
1458c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  that may have been called: The returned information is invalidated if...
1459c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - any API is called on the canvas (or its parent surface if present)
1460c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - the canvas goes out of scope
1461c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */
1462c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable {
1463c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic:
1464c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkAutoROCanvasPixels(SkCanvas* canvas);
1465c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1466c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // returns NULL on failure
1467c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* addr() const { return fAddr; }
146802d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1469c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1470c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t rowBytes() const { return fRowBytes; }
147102d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1472c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1473c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const SkImageInfo& info() const { return fInfo; }
1474c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1475c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // helper that, if returns true, installs the pixels into the bitmap. Note
1476c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // that the bitmap may reference the address returned by peekPixels(), so
1477c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // the caller must respect the restrictions associated with peekPixels().
1478c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    bool asROBitmap(SkBitmap*) const;
1479c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1480c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate:
1481c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkBitmap    fBitmap;    // used if peekPixels() fails
1482c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* fAddr;      // NULL on failure
1483c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo fInfo;
1484c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t      fRowBytes;
1485c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org};
1486c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
14872a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs,
14882a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org                                            const SkCanvas::SaveFlags rhs) {
148992a8916540b14549213332c5f9f0cd44ec12de75commit-bot@chromium.org    return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast<int>(rhs));
14902a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org}
14912a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
14922a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs,
14932a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org                                              const SkCanvas::SaveFlags rhs) {
14942a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org    lhs = lhs | rhs;
14952a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org    return lhs;
14962a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org}
14972a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
1498c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1499c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1500c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
1501c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1502c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1503c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1504c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
15052a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
15068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1507