SkCanvas.h revision 3cb3840c9af6f70896cf5565a38d4ee03c02d767
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"
194a8126e7f81384526629b1e21bf89b632ea13cd9reed#include "SkSurfaceProps.h"
20845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SkBaseDevice;
236a070dc06af4e9f305f9d08a69e34d18ade473cbreedclass SkCanvasClipVisitor;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
253cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
27b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixrclass SkImage;
2874bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
304ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
3176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comclass SkSurface;
3297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
3300d5c2c6523321d25b32905ff4822f083a4173eefmalitaclass SkTextBlob;
34644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.orgclass GrContext;
359c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comclass GrRenderTarget;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
37fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereedclass SkCanvasState;
38fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
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    /**
5942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
6042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  specified pixels. To access the pixels after drawing to them, the caller should call
6142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  flush() or call peekPixels(...).
6242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
6342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  On failure, return NULL. This can fail for several reasons:
6442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  1. invalid ImageInfo (e.g. negative dimensions)
6542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  2. unsupported ImageInfo for a canvas
6642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kUnknown_SkColorType, kIndex_8_SkColorType
6742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - kIgnore_SkAlphaType
6842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *      - this list is not complete, so others may also be unsupported
6942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *
7042b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  Note: it is valid to request a supported ImageInfo, but with zero
7142b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     *  dimensions.
7242b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org     */
7342b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirect(const SkImageInfo&, void*, size_t);
7442b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
7542b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    static SkCanvas* NewRasterDirectN32(int width, int height, SkPMColor* pixels, size_t rowBytes) {
7642b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org        return NewRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
7742b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    }
7842b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org
7942b08932e81abd8ebf296bede1994d297811511dcommit-bot@chromium.org    /**
80e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates an empty canvas with no backing device/pixels, and zero
81e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  dimensions.
82e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
83cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
848d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
85e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org    /**
86e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  Creates a canvas of the specified dimensions, but explicitly not backed
87e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  by any device/pixels. Typically this use used by subclasses who handle
88e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     *  the draw calls in some other way.
89e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org     */
9096a857ef5a40b3d0751ec9ebaaa96d9f20b82b21reed    SkCanvas(int width, int height, const SkSurfaceProps* = NULL);
91e254310a55d55a710309714c48f7fbbe7a6126f7commit-bot@chromium.org
926dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
93e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
948d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
958d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
961f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    explicit SkCanvas(SkBaseDevice* device);
978d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
984469938e92d779dff05e745559e67907bbf21e78reed@google.com    /** Construct a canvas with the specified bitmap to draw into.
998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
1033d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1043d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    /** Construct a canvas with the specified bitmap to draw into.
1053d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
1063d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita                        structure are copied to the canvas.
1073d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita        @param props    New canvas surface properties.
1083d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    */
1093d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita    SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
1103d91aad293b0f68886ed48ecfa6aa75826a27da8fmalita
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11374bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
11474bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
115c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
116c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return ImageInfo for this canvas. If the canvas is not backed by pixels
117c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
118c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
119c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo imageInfo() const;
120c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
123210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
124bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     *  Trigger the immediate execution of all pending draw operations.
125bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
126bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
127bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
128bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
1294ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size of the base or root layer in global canvas coordinates. The
1304ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * origin of the base layer is always (0,0). The current drawable area may be
1314ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * smaller (due to clipping or saveLayer).
132210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
1334ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getBaseLayerSize() const;
1344ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com
1354ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
1364ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     *  DEPRECATED: call getBaseLayerSize
1374ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
1384ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getDeviceSize() const { return this->getBaseLayerSize(); }
139210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
140c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    /**
141c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  DEPRECATED.
142c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  Return the canvas' device object, which may be null. The device holds
143c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  the bitmap of the pixels that the canvas draws into. The reference count
144c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  of the returned device is not changed by this call.
145c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
14652d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#ifndef SK_SUPPORT_LEGACY_GETDEVICE
14752d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedprotected:  // Can we make this private?
14852d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed#endif
1491f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getDevice() const;
15052d9ac6c92ddf33b3b05eb77ba9509a7aa441657reedpublic:
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1529266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
1539266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
1549266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
1559266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
1569266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
1579266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
1580b53d59a24f667350b4282f88470713902409030reed@google.com     *
1590b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
1600b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
1610b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
1620b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
1630b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1649266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1659c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#ifndef SK_SUPPORT_LEGACY_GETTOPDEVICE
1669c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comprivate:
1679c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com#endif
1681f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    SkBaseDevice* getTopDevice(bool updateMatrixClip = false) const;
1699c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.compublic:
1709266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
17176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    /**
17276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     *  Create a new surface matching the specified info, one that attempts to
173cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  be maximally compatible when used with this canvas. If there is no matching Surface type,
174cae54f1f211e3c293ef9afb968067d06ca0ea23dcommit-bot@chromium.org     *  NULL is returned.
1754a8126e7f81384526629b1e21bf89b632ea13cd9reed     *
1764a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
1774a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  inherits the properties of the surface that owns this canvas. If this canvas has no parent
1784a8126e7f81384526629b1e21bf89b632ea13cd9reed     *  surface, then the new surface is created with default properties.
17976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com     */
1804a8126e7f81384526629b1e21bf89b632ea13cd9reed    SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps* = NULL);
181e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
182644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    /**
183644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * Return the GPU context of the device that is associated with the canvas.
184644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     * For a canvas with non-GPU device, NULL is returned.
185644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org     */
186644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org    GrContext* getGrContext();
187644629c1c7913a43ced172b98d56e0f471bc348bcommit-bot@chromium.org
1884b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
1894b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
190daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
1919c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has writable pixels in its top layer (and is not recording to a picture
1929c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  or other non-raster target) and has direct access to its pixels (i.e. they are in
1939c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  local RAM) return the address of those pixels, and if not null,
1946b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  return the ImageInfo, rowBytes and origin. The returned address is only valid
1959c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  while the canvas object is in scope and unchanged. Any API calls made on
1969c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  canvas (or its parent surface if any) will invalidate the
1979c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  returned address (and associated information).
1989c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *
1996b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org     *  On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
2009c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     */
2016b4aaa77dcc4f17d0e22986f5f4cca70011d1ee5commit-bot@chromium.org    void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
2029c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
2039c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    /**
2049c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com     *  If the canvas has readable pixels in its base 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
206c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  local RAM) return the const-address of those pixels, and if not null,
207c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  return the ImageInfo and rowBytes. The returned address is only valid
208c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  while the canvas object is in scope and unchanged. Any API calls made on
209c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  canvas (or its parent surface if any) will invalidate the
210c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  returned address (and associated information).
211c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *
212c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  On failure, returns NULL and the info and rowBytes parameters are
213c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     *  ignored.
214c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org     */
215c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* peekPixels(SkImageInfo* info, size_t* rowBytes);
216c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
217a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
218a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
219a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  converting them into the requested format (SkImageInfo). The base-layer pixels are read
220b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
221a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
222b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
223a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
224b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *      srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
225a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
226b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
227b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  then we have two sets of pixels (of equal size). Replace the dst pixels with the
228b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  corresponding src pixels, performing any colortype/alphatype transformations needed
229b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  (in the case where the src and dst have different colortypes or alphatypes).
230a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *
231a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
232b184f7f52b2a94e95aee326a3ca37110d2e43336reed     *  - If srcR does not intersect the base-layer bounds.
233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If the requested colortype/alphatype cannot be converted from the base-layer's types.
234a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
235a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
236b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
237b184f7f52b2a94e95aee326a3ca37110d2e43336reed                    int srcX, int srcY);
238a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org    /**
240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated.
241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  If not, it will attempt to call allocPixels(). If this fails, it will return false. If not,
242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  it calls through to readPixels(info, ...) and returns its result.
243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     */
244b184f7f52b2a94e95aee326a3ca37110d2e43336reed    bool readPixels(SkBitmap* bitmap, int srcX, int srcY);
245c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
2464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized
248a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  to the intersection of srcRect and the base-layer bounds. On success, pixels will be
249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  allocated in bitmap and true returned. On failure, false is returned and bitmap will be
250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org     *  set to empty.
25151df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
25251df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
25351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
2544cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2554cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This method affects the pixels in the base-layer, and operates in pixel coordinates,
2564cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  ignoring the matrix and clip.
2574cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2584cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  The specified ImageInfo and (x,y) offset specifies a rectangle: target.
2594cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2604cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *      target.setXYWH(x, y, info.width(), info.height());
2614cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2624cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Target is intersected with the bounds of the base-layer. If this intersection is not empty,
2634cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
2644cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
2654cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  pixels, performing any colortype/alphatype transformations needed (in the case where the
2664cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  src and dst have different colortypes or alphatypes).
2674cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *
2684cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  This call can fail, returning false, for several reasons:
2694cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If the src colortype/alphatype cannot be converted to the canvas' types
2704cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  - If this canvas is not backed by pixels (e.g. picture or PDF)
2714cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2724cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
2734cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
2744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    /**
2754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
2764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     *  is just wrapping a texture, returns false and does nothing.
2774cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org     */
2784cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    bool writePixels(const SkBitmap& bitmap, int x, int y);
2794b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
2818d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum SaveFlags {
2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the matrix state, restoring it on restore() */
2845f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita        // [deprecated] kMatrix_SaveFlag            = 0x01,
285696d3611760b0465caaebf6243824960034c3592fmalita        kMatrix_SaveFlag            = 0x01,
2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the clip state, restoring it on restore() */
2875f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita        // [deprecated] kClip_SaveFlag              = 0x02,
288696d3611760b0465caaebf6243824960034c3592fmalita        kClip_SaveFlag              = 0x02,
2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support per-pixel alpha */
2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kHasAlphaLayer_SaveFlag     = 0x04,
2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support 8-bits per color component */
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kFullColorLayer_SaveFlag    = 0x08,
293b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com        /**
294b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  the layer should clip against the bounds argument
295b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *
296b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         *  if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated as always on.
297b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com         */
2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClipToLayer_SaveFlag       = 0x10,
2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // helper masks for common choices
3015f6102d07982043542343ff0a6c67b1319ac9fc7Florin Malita        // [deprecated] kMatrixClip_SaveFlag        = 0x03,
302696d3611760b0465caaebf6243824960034c3592fmalita        kMatrixClip_SaveFlag        = 0x03,
303b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_NoClipLayer_SaveFlag  = 0x0F,
305b93ba45b58ad24e0e2cb75b842e24ff711c368b0reed@google.com#endif
3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_ClipLayer_SaveFlag    = 0x1F
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
309dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
311dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
312dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
313dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
314dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
315d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
316d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
317d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
318d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int save();
319d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
323dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
324ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
325ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
326ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
327ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
330d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
331d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
332d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint);
333d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
334d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead.
335d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
336d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        This behaves the same as saveLayer(const SkRect*, const SkPaint*),
337d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        but it allows fine-grained control of which state bits to be saved
338d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        (and subsequently restored).
339d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
340d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param bounds (may be null) This rect, if non-null, is used as a hint to
341d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      limit the size of the offscreen, and thus drawing may be
342d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      clipped to it, though that clipping is not guaranteed to
343d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      happen. If exact clipping is desired, use clipRect().
344d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param paint (may be null) This is copied, and is applied to the
345d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                     offscreen when restore() is called
3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
349d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
350d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags);
3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
355dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
35640408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
35740408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
35840408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
35940408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
361d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @return The value to pass to restoreToCount() to balance this save()
362d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    */
363d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
364d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
365d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead.
366d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
367d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        This behaves the same as saveLayerAlpha(const SkRect*, U8CPU),
368d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        but it allows fine-grained control of which state bits to be saved
369d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        (and subsequently restored).
370d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org
371d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param bounds (may be null) This rect, if non-null, is used as a hint to
372d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      limit the size of the offscreen, and thus drawing may be
373d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      clipped to it, though that clipping is not guaranteed to
374d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org                      happen. If exact clipping is desired, use clipRect().
375d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org        @param alpha  This is applied to the offscreen when restore() is called.
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
379d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
380d70fa2013adccaa52d1f3e6ca501a4d4ab1520f3commit-bot@chromium.org    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags);
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
383dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
384dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
385dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
387e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    void restore();
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
390ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        This will equal # save() calls - # restore() calls + 1. The save count on
391ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        a new canvas is 1.
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
393a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
396ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        count reached saveCount. It is an error for saveCount to be greater than
397ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        getSaveCount(). To pop all the way back to the initial matrix/clip context
398ea7d08e3bbc45a0a573c1ac06afa4452f8d7000acommit-bot@chromium.org        pass saveCount == 1.
3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
40792362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void translate(SkScalar dx, SkScalar dy);
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41392362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void scale(SkScalar sx, SkScalar sy);
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified rotation.
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
41892362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void rotate(SkScalar degrees);
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42492362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void skew(SkScalar sx, SkScalar sy);
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
42992362383a4de7b0d819c88fa8b74242bb2507602commit-bot@chromium.org    void concat(const SkMatrix& matrix);
4304b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
43444c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org    void setMatrix(const SkMatrix& matrix);
4354b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4404ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4414ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified rectangle.
4424ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rect The rect to combine with the current clip
4434ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4444ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4454ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
446759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRect(const SkRect& rect,
447759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
448759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4504ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4514ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified SkRRect.
4524ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect The rrect to combine with the current clip
4534ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4544ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4554ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
456759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRRect(const SkRRect& rrect,
457759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   SkRegion::Op op = SkRegion::kIntersect_Op,
458759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                   bool doAntiAlias = false);
4594ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
4604ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
4614ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Modify the current clip with the specified path.
4624ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param path The path to combine with the current clip
4634ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param op The region op to apply to the current clip
4644ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param doAntiAlias true if the clip should be antialiased
4654ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
466759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipPath(const SkPath& path,
467759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  SkRegion::Op op = SkRegion::kIntersect_Op,
468759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                  bool doAntiAlias = false);
4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4708f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
4718f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        Set to false to force clips to be hard, even if doAntiAlias=true is
4728f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        passed to clipRect or clipPath.
4738f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com     */
4748f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    void setAllowSoftClip(bool allow) {
4758f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        fAllowSoftClip = allow;
4768f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    }
4778f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com
47845a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    /** EXPERIMENTAL -- only used for testing
47945a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        Set to simplify clip stack using path ops.
48045a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com     */
48145a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    void setAllowSimplifyClip(bool allow) {
48245a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com        fAllowSimplifyClip = allow;
48345a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    }
48445a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
492759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org    void clipRegion(const SkRegion& deviceRgn,
493759cf4846804be137229393e04925752423de2d0commit-bot@chromium.org                    SkRegion::Op op = SkRegion::kIntersect_Op);
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified region. This does not intersect or in any other way account
4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for the existing clip region.
4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn The region to copy into the current clip.
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5008f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    void setClipRegion(const SkRegion& deviceRgn) {
5018f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5123b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5243b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the horizontal band specified by top and bottom is
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely clipped out. This is a conservative calculation, meaning
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        that it is possible that if the method returns false, the band may still
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in fact be clipped out, but the converse is not true. If this method
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true, then the band is guaranteed to be clipped out.
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top  The top of the horizontal band to compare with the clip
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom The bottom of the horizontal and to compare with the clip
5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the horizontal band is completely clipped out (i.e. does
5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     not intersect the current clip)
5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5363b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickRejectY(SkScalar top, SkScalar bottom) const {
537c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        SkASSERT(top <= bottom);
5389836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
5399836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#ifndef SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT
5409836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // TODO: add a hasPerspective method similar to getLocalClipBounds. This
5419836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // would cache the SkMatrix::hasPerspective result. Alternatively, have
5429836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        // the MC stack just set a hasPerspective boolean as it is updated.
5439836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        if (this->getTotalMatrix().hasPerspective()) {
544a3b532743dbb1d54a4c17a2574083ef93c949d50skia.committer@gmail.com            // TODO: consider implementing some half-plane test between the
5459836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // two Y planes and the device-bounds (i.e., project the top and
5469836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // bottom Y planes and then determine if the clip bounds is completely
5479836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            // outside either one).
5489836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org            return false;
5499836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org        }
5509836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org#endif
5519836bc3fdddd51ed050102d03916cc5c7928dcc6commit-bot@chromium.org
552c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        const SkRect& clipR = this->getLocalClipBounds();
55392d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // In the case where the clip is empty and we are provided with a
55492d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // negative top and positive bottom parameter then this test will return
55592d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // false even though it will be clipped. We have chosen to exclude that
55692d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // check as it is rare and would result double the comparisons.
557c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return top >= clipR.fBottom || bottom <= clipR.fTop;
55892d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com    }
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5658f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipBounds(SkRect* bounds) const;
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
567bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
568bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
569bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
570bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
5718f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool getClipDeviceBounds(SkIRect* bounds) const;
57274b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
573bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
575845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
583845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
586845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5908eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    void drawColor(SkColor color, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
592f4e0d9eb2d72fe92c30237de978936113143dc16reed    /**
593f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  Helper method for drawing a color in SRC mode, completely replacing all the pixels
594f4e0d9eb2d72fe92c30237de978936113143dc16reed     *  in the current clip with this color.
595f4e0d9eb2d72fe92c30237de978936113143dc16reed     */
596f4e0d9eb2d72fe92c30237de978936113143dc16reed    void clear(SkColor color) {
5978eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed        this->drawColor(color, SkXfermode::kSrc_Mode);
5988eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed    }
5992a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
6002a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
60128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This makes the contents of the canvas undefined. Subsequent calls that
60228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * require reading the canvas contents will produce undefined results. Examples
60328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * include blending and readPixels. The actual implementation is backend-
60428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * dependent and one legal implementation is to do nothing. Like clear(), this
60528361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * ignores the clip.
60628361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     *
60728361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * This function should only be called if the caller intends to subsequently
60828361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * draw to the canvas. The canvas may do real work at discard() time in order
60928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * to optimize performance on subsequent draws. Thus, if you call this and then
61028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     * never draw to the canvas subsequently you may pay a perfomance penalty.
61128361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org     */
61228361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    void discard() { this->onDiscard(); }
61328361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
61428361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    /**
6152a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  Fill the entire canvas' bitmap (restricted to the current clip) with the
6162a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
6172a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
6182a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
6190846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPaint(const SkPaint& paint);
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6510846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
6574b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
6688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
6698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
6708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
6718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
6728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
6738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6820846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRect(const SkRect& rect, const SkPaint& paint);
6838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
68987001ed1f6f1d498874f7f4ba39abcf608ae8bf5reed@google.com    void drawIRect(const SkIRect& rect, const SkPaint& paint) {
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
6944b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7110846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawOval(const SkRect& oval, const SkPaint&);
7124ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
7134ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
7144ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  Draw the specified RRect using the specified paint The rrect will be filled or stroked
7154ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  based on the Style in the paint.
7164ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *
7174ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param rrect    The round-rect to draw
7184ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     *  @param paint    The paint used to draw the round-rect
7194ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
7200846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawRRect(const SkRRect& rrect, const SkPaint& paint);
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
722ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    /**
723ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  Draw the annulus formed by the outer and inner rrects. The results
724ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     *  are undefined if the outer does not contain the inner.
725ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org     */
726ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
727ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified oval. If the sweep angle is >= 360, then the oval is drawn
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely. Note that this differs slightly from SkPath::arcTo, which
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        treats the sweep angle mod 360.
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the shape of the arc
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param useCenter true means include the center of the oval. For filling
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         this will draw a wedge. False means just use the arc.
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7680846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawPath(const SkPath& path, const SkPaint& paint);
7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
770d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with its top/left corner at (x,y), using the
771d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        specified paint, transformed by the current matrix.
772d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr
773d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image    The image to be drawn
774d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param left     The position of the left side of the image being drawn
775d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param top      The position of the top side of the image being drawn
776d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
777d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr     */
7780846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
779d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    /** Draw the specified image, with the specified matrix applied (before the
780d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        canvas' matrix is applied).
781b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
782d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param image   The image to be drawn
783d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param src      Optional: specify the subset of the image to be drawn
784d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param dst      The destination rectangle where the scaled/translated
785d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr                        image will be drawn
786d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr        @param paint    The paint used to draw the image, or NULL
787d52893cfc8c3fb1187c04c66f6beda66e1bb0b2cpiotaixr    */
7880846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
7890846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                       const SkPaint* paint = NULL);
790b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
79791246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
79891246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        If a shader is present on the paint it will be ignored, except in the
799f20fc24a7def23093a1abd2fc8de4a1302aeb9f8reed@google.com        case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
80091246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org        generated by the shader.
80191246b9fc7740547d4b1b3f144684483c8e968cdcommit-bot@chromium.org
8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8070846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
8080846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                    const SkPaint* paint = NULL);
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
810eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    enum DrawBitmapRectFlags {
81131acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kNone_DrawBitmapRectFlag            = 0x0,
8127475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com        /**
813eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  When filtering is enabled, allow the color samples outside of
8147475811143e190e172bf83d13c4bdba85704b604skia.committer@gmail.com         *  the src rect (but still in the src bitmap) to bleed into the
815eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         *  drawn portion
816eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org         */
81731acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        kBleed_DrawBitmapRectFlag           = 0x1,
818eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org    };
819eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org
8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with the specified matrix applied (before the
8218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas' matrix is applied).
8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src      Optional: specify the subset of the bitmap to be drawn
8248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The destination rectangle where the scaled/translated
8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        image will be drawn
8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8280846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
8290846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                              const SkPaint* paint = NULL,
8300846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                              DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag);
8317112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com
8327112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst,
833eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkPaint* paint = NULL) {
83431acc11977815402e4ef2681350f8559285bec97robertphillips@google.com        this->drawBitmapRectToRect(bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag);
8357112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8377112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc,
838eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                        const SkRect& dst, const SkPaint* paint = NULL,
83931acc11977815402e4ef2681350f8559285bec97robertphillips@google.com                        DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) {
8407112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect realSrcStorage;
8417112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect* realSrcPtr = NULL;
8427112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        if (isrc) {
8437112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcStorage.set(*isrc);
8447112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcPtr = &realSrcStorage;
8457112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        }
846eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org        this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint, flags);
8477112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
848c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com
849f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
850f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  Draw the bitmap stretched differentially to fit into dst.
851f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
852f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
853f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
854f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
855f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
8569bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The 4 corners are not stretched at all.
8579bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The sides are stretched in only one axis.
8589bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com     *  - The center is stretched in both axes.
859f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
860f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
861f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
862f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
8630846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
8640846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                        const SkPaint* paint = NULL);
865f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y),
8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        NOT transformed by the current matrix. Note: if the paint
8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8770846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint = NULL);
8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
887f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
888f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                  const SkPaint& paint);
8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
8914b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
8968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
897f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
898f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                     const SkPaint& paint);
8994b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
9024b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
909f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
910f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                      const SkPaint& paint);
9114b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
924f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
9268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
9358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
937f7430ccfc0e7b445a44b840c1453c9ef5988a656reed    void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
938f7430ccfc0e7b445a44b840c1453c9ef5988a656reed                        const SkMatrix* matrix, const SkPaint& paint);
9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
94000d5c2c6523321d25b32905ff4822f083a4173eefmalita    /** Draw the text blob, offset by (x,y), using the specified paint.
94100d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param blob     The text blob to be drawn
94200d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param x        The x-offset of the text being drawn
94300d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param y        The y-offset of the text being drawn
94400d5c2c6523321d25b32905ff4822f083a4173eefmalita        @param paint    The paint used for the text (e.g. color, size, style)
94500d5c2c6523321d25b32905ff4822f083a4173eefmalita    */
94600d5c2c6523321d25b32905ff4822f083a4173eefmalita    void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
94700d5c2c6523321d25b32905ff4822f083a4173eefmalita
9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
950a44de9617a0a51014bacc4151287995ededcdf62djsollen@google.com        of this canvas will be unchanged after this call.
9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9549b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips    void drawPicture(const SkPicture* picture);
9559b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
956d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    /**
957d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  Draw the picture into this canvas.
958d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
959d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
960d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  logically equivalent to
961d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      save/concat/drawPicture/restore
962d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *
963d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
964d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
965d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *  This is logically equivalent to
966d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     *      saveLayer(paint)/drawPicture/restore
967d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed     */
968d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
969d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed
9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
9754b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
977559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
978559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        If both textures and vertex-colors are NULL, it strokes hairlines with
979559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the paint's color. This behavior is a useful debugging mode to visualize
980559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org        the mesh.
981559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
987631a59b9393208ed3546e81ca843f2f7da06ca64robertphillips@google.com                    in _texture_ space (not uv space) for each vertex.
9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xmode Used if both texs and colors are present. In this
9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    before being drawn using the paint. If mode is null, then
9938d3cd7a170c810e3816bf00220cbef51e7b16795reed@google.com                    kModulate_Mode is used.
9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
9974b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9990846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed    void drawVertices(VertexMode vmode, int vertexCount,
10000846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPoint vertices[], const SkPoint texs[],
10010846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkColor colors[], SkXfermode* xmode,
10020846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const uint16_t indices[], int indexCount,
10030846f1b1c43f5edebc2d87a19c7bca6574ff41dfreed                      const SkPaint& paint);
10046cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1005b3c9d1c33caf325aada244204215eb790c228c12dandov    /**
1006b3c9d1c33caf325aada244204215eb790c228c12dandov     Draw a cubic coons patch
10076cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
1008b3c9d1c33caf325aada244204215eb790c228c12dandov     @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
1009b3c9d1c33caf325aada244204215eb790c228c12dandov                    starting at the top left corner.
1010b3c9d1c33caf325aada244204215eb790c228c12dandov     @param colors specifies the colors for the corners which will be bilerp across the patch,
1011b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is clockwise starting at the top left corner.
10126cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param texCoords specifies the texture coordinates that will be bilerp across the patch,
1013b3c9d1c33caf325aada244204215eb790c228c12dandov                    their order is the same as the colors.
10146cfa73a29a26edf1d03bca224ad6860396308ffcmtklein     @param xmode specifies how are the colors and the textures combined if both of them are
1015b3c9d1c33caf325aada244204215eb790c228c12dandov                    present.
1016963137b75c0a1fe91f35e9826742f36309f5e65ddandov     @param paint Specifies the shader/texture if present.
1017963137b75c0a1fe91f35e9826742f36309f5e65ddandov     */
1018b3c9d1c33caf325aada244204215eb790c228c12dandov    void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
1019b3c9d1c33caf325aada244204215eb790c228c12dandov                   const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10213cb3840c9af6f70896cf5565a38d4ee03c02d767reed    /**
10223cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  Draw the contents of this drawable into the canvas. If the canvas is async
10233cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  (e.g. it is recording into a picture) then the drawable will be referenced instead,
10243cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  to have its draw() method called when the picture is finalized.
10253cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *
10263cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  If the intent is to force the contents of the drawable into this canvas immediately,
10273cb3840c9af6f70896cf5565a38d4ee03c02d767reed     *  then drawable->draw(canvas) may be called.
10283cb3840c9af6f70896cf5565a38d4ee03c02d767reed     */
10293cb3840c9af6f70896cf5565a38d4ee03c02d767reed    void drawDrawable(SkDrawable* drawable);
10306a070dc06af4e9f305f9d08a69e34d18ade473cbreed
1031a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com    /** Add comments. beginCommentGroup/endCommentGroup open/close a new group.
1032a5d3e77420621c912383c3b22e542d9413d68278skia.committer@gmail.com        Each comment added via addComment is notionally attached to its
10330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        enclosing group. Top-level comments simply belong to no group.
10340a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com     */
1035c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen    virtual void beginCommentGroup(const char* /*description*/) {
10360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10370a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
1038c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen    virtual void addComment(const char* /*kywd*/, const char* /*value*/) {
10390a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10400a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    virtual void endCommentGroup() {
10420a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        // do nothing. Subclasses may do something
10430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
10440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10464b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
1048dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
10508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
10524b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
1056dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
1057dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
10598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
10608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1065754de5f65b466f721d952a379194cc94de376f42reed@google.com    /**
1066754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Return true if the current clip is empty (i.e. nothing will draw).
1067754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  Note: this is not always a free call, so it should not be used
1068754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  more often than necessary. However, once the canvas has computed this
1069754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  result, subsequent calls will be cheap (until the clip state changes,
1070754de5f65b466f721d952a379194cc94de376f42reed@google.com     *  which can happen on any clip..() or restore() call.
1071754de5f65b466f721d952a379194cc94de376f42reed@google.com     */
10728f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual bool isClipEmpty() const;
1073754de5f65b466f721d952a379194cc94de376f42reed@google.com
10745c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    /**
10755c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns true if the current clip is just a (non-empty) rectangle.
10765c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     *  Returns false if the clip is empty, or if it is complex.
10775c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org     */
10785c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    virtual bool isClipRect() const;
10795c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1084a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
108640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
108740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
108840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
108940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
109040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
109140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
1092de358a9946fb6cffa905c7aa0e5f29cf6960b927joshualitt        return fClipStack;
109340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
109440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1095c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    typedef SkCanvasClipVisitor ClipVisitor;
10965e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
109790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
109890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
109990c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
11007d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
110190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
11028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After calling saveLayer(), there can be any number of devices that make
11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        up the top-most drawing area. LayerIter can be used to iterate through
11078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        those devices. Note that the iterator is only valid until the next API
11088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call made on the canvas. Ownership of all pointers in the iterator stays
11098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with the canvas, so none of them should be modified or deleted.
11108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
11117ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API LayerIter /*: SkNoncopyable*/ {
11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
11138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Initialize iterator with canvas, and set values for 1st device */
11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        LayerIter(SkCanvas*, bool skipEmptyClips);
11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~LayerIter();
11164b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return true if the iterator is done */
11188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool done() const { return fDone; }
11198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Cycle to the next device */
11208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void next();
11214b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // These reflect the current device in the iterator
11238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com        SkBaseDevice*   device() const;
11258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkMatrix& matrix() const;
11268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkRegion& clip() const;
11278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPaint&  paint() const;
11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             x() const;
11298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             y() const;
11304b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
11318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // used to embed the SkDrawIter object directly in our instance, w/o
11338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // having to expose that class def to the public. There is an assert
11348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // in our constructor to ensure that fStorage is large enough
11358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // (though needs to be a compile-time-assert!). We use intptr_t to work
11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // safely with 32 and 64 bit machines (to ensure the storage is enough)
1137f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        intptr_t          fStorage[32];
11388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        class SkDrawIter* fImpl;    // this points at fStorage
11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint           fDefaultPaint;
11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool              fDone;
11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
11435c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org    // don't call
11449c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    GrRenderTarget* internal_private_accessTopLayerRenderTarget();
11455c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org
1146d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed    // don't call
1147d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed    static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
1148d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed    static bool Internal_Private_GetIgnoreSaveLayerBounds();
11490acf1b4b3645772d220c720313821bac389751b5reed    static void Internal_Private_SetTreatSpriteAsBitmap(bool);
11500acf1b4b3645772d220c720313821bac389751b5reed    static bool Internal_Private_GetTreatSpriteAsBitmap();
1151d990e2f14f14c36c3d0beb303dd0953c7aa1fcfareed
11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
115376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    // default impl defers to getDevice()->newSurface(info)
11544a8126e7f81384526629b1e21bf89b632ea13cd9reed    virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
115576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
1156c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // default impl defers to its device
1157c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    virtual const void* onPeekPixels(SkImageInfo*, size_t* rowBytes);
11589c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    virtual void* onAccessTopLayerPixels(SkImageInfo*, size_t* rowBytes);
1159c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1160e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Subclass save/restore notifiers.
1161e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // Overriders should call the corresponding INHERITED method up the inheritance chain.
1162e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    // willSaveLayer()'s return value may suppress full layer allocation.
1163e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    enum SaveLayerStrategy {
1164e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kFullLayer_SaveLayerStrategy,
1165e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org        kNoLayer_SaveLayerStrategy
1166e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org    };
1167e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org
11686ca763f362f25500ffeee0cc0b5dd2b58e9f2a79fmalita    virtual void willSave() {}
1169fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) {
1170fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org        return kFullLayer_SaveLayerStrategy;
1171fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    }
1172fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void willRestore() {}
11736cfa73a29a26edf1d03bca224ad6860396308ffcmtklein    virtual void didRestore() {}
1174fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didConcat(const SkMatrix&) {}
1175fc6dfbab7565bb02db50f38f21b2c7d6c8f61c5ccommit-bot@chromium.org    virtual void didSetMatrix(const SkMatrix&) {}
117644c48d062f7996b5b46917e1b312a32ad101f326commit-bot@chromium.org
1177ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
1178ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
1179e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
1180e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                            SkScalar y, const SkPaint& paint);
1181b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1182e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosText(const void* text, size_t byteLength,
1183e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                               const SkPoint pos[], const SkPaint& paint);
1184b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1185e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawPosTextH(const void* text, size_t byteLength,
1186e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkScalar xpos[], SkScalar constY,
1187e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                const SkPaint& paint);
1188b0430d024572b1a5e5d7b80e406c668e975e3030skia.committer@gmail.com
1189e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
1190e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPath& path, const SkMatrix* matrix,
1191e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com                                  const SkPaint& paint);
11926cfa73a29a26edf1d03bca224ad6860396308ffcmtklein
119300d5c2c6523321d25b32905ff4822f083a4173eefmalita    virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
119400d5c2c6523321d25b32905ff4822f083a4173eefmalita                                const SkPaint& paint);
119500d5c2c6523321d25b32905ff4822f083a4173eefmalita
1196b3c9d1c33caf325aada244204215eb790c228c12dandov    virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
1197b3c9d1c33caf325aada244204215eb790c228c12dandov                           const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
1198e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com
11993cb3840c9af6f70896cf5565a38d4ee03c02d767reed    virtual void onDrawDrawable(SkDrawable*);
12006a070dc06af4e9f305f9d08a69e34d18ade473cbreed
120141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPaint(const SkPaint&);
120241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRect(const SkRect&, const SkPaint&);
120341af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawOval(const SkRect&, const SkPaint&);
120441af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawRRect(const SkRRect&, const SkPaint&);
120541af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
120641af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[],
120741af966ab338e95eee81ab618ab28195075338f7reed                                const SkPoint texs[], const SkColor colors[], SkXfermode*,
120841af966ab338e95eee81ab618ab28195075338f7reed                                const uint16_t indices[], int indexCount, const SkPaint&);
120941af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawPath(const SkPath&, const SkPaint&);
121041af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
121141af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*);
121241af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
121341af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
121441af966ab338e95eee81ab618ab28195075338f7reed                                  DrawBitmapRectFlags);
121541af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
121641af966ab338e95eee81ab618ab28195075338f7reed                                  const SkPaint*);
121741af966ab338e95eee81ab618ab28195075338f7reed    virtual void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*);
121841af966ab338e95eee81ab618ab28195075338f7reed
12198f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    enum ClipEdgeStyle {
12208f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kHard_ClipEdgeStyle,
12218f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com        kSoft_ClipEdgeStyle
12228f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    };
12238f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
12248f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12258f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12268f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle);
12278f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com    virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
12288f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com
122928361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org    virtual void onDiscard();
123028361fad1054d59ed4e6a320c7a8b8782a1487c7commit-bot@chromium.org
1231d5fa1a455aad61f3e99081fe7a9b065cb3b115c6reed    virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
12329b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips
123374b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    // Returns the canvas to be used by DrawIter. Default implementation
12344370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // returns this. Subclasses that encapsulate an indirect canvas may
12354370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // need to overload this method. The impl must keep track of this, as it
12364370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // is not released or deleted by the caller.
12374370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    virtual SkCanvas* canvasForDrawIter();
12384370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com
1239a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
1240a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
1241c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // If non-NULL, The imageFilter parameter will be used to expand the clip
1242c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org    // and offscreen bounds for any margin required by the filter DAG.
1243a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
1244c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        SkIRect* intersection,
1245c4b12f19a46946e1c02f3525e0ea4902b09feac5senorblanco@chromium.org                        const SkImageFilter* imageFilter = NULL);
1246a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
124797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
124897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
124997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void predrawNotify();
125097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
12518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
12538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1254de358a9946fb6cffa905c7aa0e5f29cf6960b927joshualitt    SkAutoTUnref<SkClipStack> fClipStack;
12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
12588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
12598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint32_t    fMCRecStorage[32];
12608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12614a8126e7f81384526629b1e21bf89b632ea13cd9reed    const SkSurfaceProps fProps;
12624a8126e7f81384526629b1e21bf89b632ea13cd9reed
12632ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    int         fSaveCount;         // value returned by getSaveCount()
12648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
126574bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
126674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
126797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
126897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
126997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
127097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
127197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
127297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
127345c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.org    friend class SkSurface_Gpu;
1274fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
12758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12782ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void doSave();
12792ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void checkForDeferredSave();
12802ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed
12819c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDrawIter;        // needs setupDrawForLayerDevice()
12828926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
12839c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkLua;             // needs top layer size and offset
12842a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    friend class SkDebugCanvas;     // needs experimental fAllowSimplifyClip
12859c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    friend class SkDeferredDevice;  // needs getTopDevice()
128652d9ac6c92ddf33b3b05eb77ba9509a7aa441657reed    friend class SkSurface_Raster;  // needs getDevice()
1287d954498c01ccf0417feacf89e45d0c62a06a813breed    friend class SkRecorder;        // InitFlags
1288d954498c01ccf0417feacf89e45d0c62a06a813breed    friend class SkNoSaveLayerCanvas;   // InitFlags
12892d97bc139a7de5813468bd3dbfd0037351ae5606fmalita    friend class SkPictureImageFilter;  // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
1290b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
1291d954498c01ccf0417feacf89e45d0c62a06a813breed    enum InitFlags {
1292d954498c01ccf0417feacf89e45d0c62a06a813breed        kDefault_InitFlags                  = 0,
1293d954498c01ccf0417feacf89e45d0c62a06a813breed        kConservativeRasterClip_InitFlag    = 1 << 0,
1294d954498c01ccf0417feacf89e45d0c62a06a813breed    };
129578e276889795454891cbba48ab11927968114953reed    SkCanvas(const SkIRect& bounds, InitFlags);
12964a8126e7f81384526629b1e21bf89b632ea13cd9reed    SkCanvas(SkBaseDevice*, const SkSurfaceProps*, InitFlags);
1297d954498c01ccf0417feacf89e45d0c62a06a813breed
12988f2e791baa1287bd321217c88756695c41699a7ereed    // needs gettotalclip()
1299a5414c4a8efc3119ee20fcee96c0bf68a04909c7tfarina    friend class SkCanvasStateUtils;
1300b5fae93d72c7b6480f83fd8a7b534cd1fdfcd49apiotaixr
13014a8126e7f81384526629b1e21bf89b632ea13cd9reed    // call this each time we attach ourselves to a device
13024a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - constructor
13034a8126e7f81384526629b1e21bf89b632ea13cd9reed    //  - internalSaveLayer
13044a8126e7f81384526629b1e21bf89b632ea13cd9reed    void setupDevice(SkBaseDevice*);
13054a8126e7f81384526629b1e21bf89b632ea13cd9reed
1306d954498c01ccf0417feacf89e45d0c62a06a813breed    SkBaseDevice* init(SkBaseDevice*, InitFlags);
1307f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1308403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    /**
1309403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  DEPRECATED
1310403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *
1311403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  Specify a device for this canvas to draw into. If it is not null, its
1312403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  reference count is incremented. If the canvas was already holding a
1313403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     *  device, its reference count is decremented. The new device is returned.
1314403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org     */
1315403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org    SkBaseDevice* setRootDevice(SkBaseDevice* device);
131631acdeabce094e9d42f0d6db8eebcf788aaba11askia.committer@gmail.com
13174ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    /**
13184ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this
13194ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     * to be public because it exposes decisions about layer sizes that are internal to the canvas.
13204ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com     */
13214ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkISize getTopLayerSize() const;
13224ebe3821888d550d8a8b89341ec251ba942f0225bsalomon@google.com    SkIPoint getTopLayerOrigin() const;
1323403f8d7a052269583175e945689824838e5e0ef4commit-bot@chromium.org
1324f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // internal methods are not virtual, so they can safely be called by other
1325f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // canvas apis, without confusing subclasses (like SkPictureRecording)
13269bf380ce7f848dfb5886dd52b82746521454b739robertphillips@google.com    void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint);
13277112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1328eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                const SkRect& dst, const SkPaint* paint,
1329eed779d866e1e239bfb9ebc6a225b7345a41adf9commit-bot@chromium.org                                DrawBitmapRectFlags flags);
1330f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
1331f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint);
1332fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
13332ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
13342ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed                           SaveFlags, bool justForImageFilter, SaveLayerStrategy strategy);
13351f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com    void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*);
1336fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
13382ff1fcede1e9525285c5de1f35fb2dcb0fab32bdreed    void internalSave();
13398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
134052c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
134152c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
134252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
134352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
134452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
13454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
1346fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    // only for canvasutils
1347fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed    const SkRegion& internal_private_getTotalClip() const;
1348fa35f8e6ebc9d98d57d2edc35e4a83556eb75caereed
13498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  These maintain a cache of the clip bounds in local coordinates,
13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (converted to 2s-compliment if floats are slow).
13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
1352c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable SkRect fCachedLocalClipBounds;
1353c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    mutable bool   fCachedLocalClipBoundsDirty;
13548f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
135545a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com    bool fAllowSimplifyClip;
1356d954498c01ccf0417feacf89e45d0c62a06a813breed    bool fConservativeRasterClip;
13578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1358c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com    const SkRect& getLocalClipBounds() const {
1359c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        if (fCachedLocalClipBoundsDirty) {
1360c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            if (!this->getClipBounds(&fCachedLocalClipBounds)) {
1361c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com                fCachedLocalClipBounds.setEmpty();
1362c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            }
1363c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com            fCachedLocalClipBoundsDirty = false;
13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
1365c0784dbd408596aff13a5d97448f7a9e5d3cf7d9reed@google.com        return fCachedLocalClipBounds;
13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
136745a75fb4d0ca5daa0ac5e634238970306e3b5838caryclark@google.com
13685c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
13695c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
13705c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
13715c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
13725c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
13735c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
13745c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13755c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
13765c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
13775c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
13785c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
13795c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
13805c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
13815c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
13825c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
13835c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
138415e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
138515e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
13898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
13908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
13918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
13942887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
13952887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org        if (fCanvas) {
13962887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            fSaveCount = canvas->getSaveCount();
13972887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            if (doSave) {
13982887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org                canvas->save();
13992887119a63e314704673b971e9bc9a3461313a2ccommit-bot@chromium.org            }
14008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
14018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
14028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
1403f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1404f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1405f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
1406f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    }
1407f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com
1408f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    /**
1409f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  Perform the restore now, instead of waiting for the destructor. Will
1410f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     *  only do this once.
1411f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com     */
1412f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com    void restore() {
1413f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        if (fCanvas) {
1414f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas->restoreToCount(fSaveCount);
1415f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com            fCanvas = NULL;
1416f6c9a5ba5cded8d4f663b13e71e6e1e572322b41reed@google.com        }
14178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
14188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
14208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
14218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
14228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1423e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
14250a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com/** Stack helper class to automatically open and close a comment block
14260a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com */
14270a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comclass SkAutoCommentBlock : SkNoncopyable {
14280a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.compublic:
14290a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkAutoCommentBlock(SkCanvas* canvas, const char* description) {
14300a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        fCanvas = canvas;
143149f085dddff10473b6ebf832a974288300224e60bsalomon        if (fCanvas) {
14320a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->beginCommentGroup(description);
14330a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14340a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14350a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14360a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    ~SkAutoCommentBlock() {
143749f085dddff10473b6ebf832a974288300224e60bsalomon        if (fCanvas) {
14380a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com            fCanvas->endCommentGroup();
14390a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com        }
14400a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    }
14410a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
14420a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.comprivate:
14430a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com    SkCanvas* fCanvas;
14440a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com};
1445e61a86cfa00ea393ecc4a71fca94e1d476a37ecccommit-bot@chromium.org#define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock)
14460a4805e33f8ddb445a2fd061462e715e1707f049robertphillips@google.com
1447c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org/**
1448c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the caller wants read-only access to the pixels in a canvas, it can just
1449c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  call canvas->peekPixels(), since that is the fastest way to "peek" at the
1450c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  pixels on a raster-backed canvas.
1451c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1452c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  If the canvas has pixels, but they are not readily available to the CPU
1453c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  (e.g. gpu-backed), then peekPixels() will fail, but readPixels() will
1454c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  succeed (though be slower, since it will return a copy of the pixels).
1455c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1456c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  SkAutoROCanvasPixels encapsulates these two techniques, trying first to call
1457c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  peekPixels() (for performance), but if that fails, calling readPixels() and
1458c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  storing the copy locally.
1459c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *
1460c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  The caller must respect the restrictions associated with peekPixels(), since
1461c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *  that may have been called: The returned information is invalidated if...
1462c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - any API is called on the canvas (or its parent surface if present)
1463c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *      - the canvas goes out of scope
1464c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org */
1465c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgclass SkAutoROCanvasPixels : SkNoncopyable {
1466c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgpublic:
1467c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkAutoROCanvasPixels(SkCanvas* canvas);
1468c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1469c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // returns NULL on failure
1470c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* addr() const { return fAddr; }
147102d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1472c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1473c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t rowBytes() const { return fRowBytes; }
147402d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com
1475c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // undefined if addr() == NULL
1476c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const SkImageInfo& info() const { return fInfo; }
1477c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1478c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // helper that, if returns true, installs the pixels into the bitmap. Note
1479c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // that the bitmap may reference the address returned by peekPixels(), so
1480c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    // the caller must respect the restrictions associated with peekPixels().
1481c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    bool asROBitmap(SkBitmap*) const;
1482c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
1483c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgprivate:
1484c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkBitmap    fBitmap;    // used if peekPixels() fails
1485c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    const void* fAddr;      // NULL on failure
1486c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    SkImageInfo fInfo;
1487c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    size_t      fRowBytes;
1488c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org};
1489c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
14902a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs,
14912a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org                                            const SkCanvas::SaveFlags rhs) {
149292a8916540b14549213332c5f9f0cd44ec12de75commit-bot@chromium.org    return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast<int>(rhs));
14932a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org}
14942a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
14952a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.orgstatic inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs,
14962a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org                                              const SkCanvas::SaveFlags rhs) {
14972a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org    lhs = lhs | rhs;
14982a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org    return lhs;
14992a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org}
15002a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
1501c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitaclass SkCanvasClipVisitor {
1502c3b589a24eb4d567a906189f882c259ecf5c2f58fmalitapublic:
1503c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual ~SkCanvasClipVisitor();
1504c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1505c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1506c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita    virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1507c3b589a24eb4d567a906189f882c259ecf5c2f58fmalita};
15082a5cd60bfff32c92cf44a8cfc3e8c017b9aee456commit-bot@chromium.org
15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1510