SkCanvas.h revision 260eae59b4edef636685e640ec13d82490d3474f
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkCanvas_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkCanvas_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypes.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDeque.h"
165c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#include "SkClipStack.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalarCompare.h"
22845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com#include "SkXfermode.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkBounder;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDevice;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawFilter;
2874bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.orgclass SkMetaData;
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPicture;
3097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comclass SkSurface_Base;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkCanvas
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    A Canvas encapsulates all of the state about drawing into a device (bitmap).
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This includes a reference to the device itself, and a stack of matrix/clip
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    values. For any given draw call (e.g. drawRect), the geometry of the object
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    being drawn is transformed by the concatenation of all the matrices in the
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    stack. The transformed geometry is clipped by the intersection of all of
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    the clips in the stack.
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    While the Canvas holds the state of the drawing device, the state (style)
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    of the object being drawn is held by the Paint, which is provided as a
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parameter to each of the draw() methods. The Paint holds attributes such as
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    etc.
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
477ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkCanvas : public SkRefCnt {
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
4915e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    SK_DECLARE_INST_COUNT(SkCanvas)
5015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
51cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com    SkCanvas();
528d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
536dc745506e6d6cc0936fed4de24443dc1ecb5a34reed@google.com    /** Construct a canvas with the specified device to draw into.
54e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
558d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org        @param device   Specifies a device for the canvas to draw into.
568d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    */
578d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    explicit SkCanvas(SkDevice* device);
588d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
598d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    /** Deprecated - Construct a canvas with the specified bitmap to draw into.
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   Specifies a bitmap for the canvas to draw into. Its
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        structure are copied to the canvas.
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    explicit SkCanvas(const SkBitmap& bitmap);
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkCanvas();
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData& getMetaData();
6774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
70210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    /**
71bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     *  Trigger the immediate execution of all pending draw operations.
72bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org     */
73bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    void flush();
74bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org
75bf6c1e4aff4d233f6502157fb73459cf69d0ab37junov@chromium.org    /**
76210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     *  Return the width/height of the underlying device. The current drawable
77210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     *  area may be small (due to clipping or saveLayer). For a canvas with
78210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     *  no device, 0,0 will be returned.
79210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com     */
80210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com    SkISize getDeviceSize() const;
81210ce003a5ec039dda80de0569fb47ca4efc4dc7reed@google.com
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the canvas' device object, which may be null. The device holds
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the bitmap of the pixels that the canvas draws into. The reference count
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        of the returned device is not changed by this call.
858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDevice* getDevice() const;
878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
889266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com    /**
899266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  saveLayer() can create another device (which is later drawn onto
909266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  the previous device). getTopDevice() returns the top-most device current
919266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  installed. Note that this can change on other calls like save/restore,
929266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  so do not access this device after subsequent canvas calls.
939266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     *  The reference count of the device is not changed.
940b53d59a24f667350b4282f88470713902409030reed@google.com     *
950b53d59a24f667350b4282f88470713902409030reed@google.com     * @param updateMatrixClip If this is true, then before the device is
960b53d59a24f667350b4282f88470713902409030reed@google.com     *        returned, we ensure that its has been notified about the current
970b53d59a24f667350b4282f88470713902409030reed@google.com     *        matrix and clip. Note: this happens automatically when the device
980b53d59a24f667350b4282f88470713902409030reed@google.com     *        is drawn to, but is optional here, as there is a small perf hit
990b53d59a24f667350b4282f88470713902409030reed@google.com     *        sometimes.
1009266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com     */
1010b53d59a24f667350b4282f88470713902409030reed@google.com    SkDevice* getTopDevice(bool updateMatrixClip = false) const;
1029266fed56a46a4edc710a52c7be8d46fd7c2bc7areed@google.com
103f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /**
104cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com     *  Shortcut for getDevice()->createCompatibleDevice(...).
105cde92111d50a96b6d0f3e166fbac7c9bc6eca349reed@google.com     *  If getDevice() == NULL, this method does nothing, and returns NULL.
106e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com     */
10774b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    SkDevice* createCompatibleDevice(SkBitmap::Config config,
108e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com                                    int width, int height,
109e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com                                    bool isOpaque);
110e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
1114b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    ///////////////////////////////////////////////////////////////////////////
1124b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
113daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com    /**
114d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * This enum can be used with read/writePixels to perform a pixel ops to or
115d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * from an 8888 config other than Skia's native config (SkPMColor). There
116d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * are three byte orders supported: native, BGRA, and RGBA. Each has a
117d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * premultiplied and unpremultiplied variant.
118d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *
119d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * Components of a 8888 pixel can be packed/unpacked from a 32bit word using
120d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * either byte offsets or shift values. Byte offsets are endian-invariant
121d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * while shifts are not. BGRA and RGBA configs are defined by byte
122d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * orderings. The native config is defined by shift values (SK_A32_SHIFT,
123d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     * ..., SK_B32_SHIFT).
1246850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     */
1256850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com    enum Config8888 {
1266850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        /**
1276850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * Skia's native order specified by:
1286850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         *      SK_A32_SHIFT, SK_R32_SHIFT, SK_G32_SHIFT, and SK_B32_SHIFT
1296850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         *
1306850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * kNative_Premul_Config8888 is equivalent to SkPMColor
1316850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * kNative_Unpremul_Config8888 has the same component order as SkPMColor
1326850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * but is not premultiplied.
1336850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         */
1346850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        kNative_Premul_Config8888,
1356850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        kNative_Unpremul_Config8888,
1366850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        /**
1376850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * low byte to high byte: B, G, R, A.
1386850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         */
1396850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        kBGRA_Premul_Config8888,
1406850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        kBGRA_Unpremul_Config8888,
1416850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        /**
1426850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         * low byte to high byte: R, G, B, A.
1436850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com         */
1446850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com        kRGBA_Premul_Config8888,
1451f90287df3129cb267422e482c52ebeca6a8990ftomhudson@google.com        kRGBA_Unpremul_Config8888
1466850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com    };
1476850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com
1486850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com    /**
149daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  On success (returns true), copy the canvas pixels into the bitmap.
150daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  On failure, the bitmap parameter is left unchanged and false is
151daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  returned.
152daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *
1536850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  The canvas' pixels are converted to the bitmap's config. The only
1546850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  supported config is kARGB_8888_Config, though this is likely to be
1556850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  relaxed in  the future. The meaning of config kARGB_8888_Config is
1566850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  modified by the enum param config8888. The default value interprets
1576850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  kARGB_8888_Config as SkPMColor
158daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *
159daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  If the bitmap has pixels already allocated, the canvas pixels will be
16074b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org     *  written there. If not, bitmap->allocPixels() will be called
161daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  automatically. If the bitmap is backed by a texture readPixels will
162daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  fail.
163daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *
164daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  The actual pixels written is the intersection of the canvas' bounds, and
165daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  the rectangle formed by the bitmap's width,height and the specified x,y.
166daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  If bitmap pixels extend outside of that intersection, they will not be
167daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *  modified.
168daba14b7d4fc96b915c45d82713b22729c0d0f37bsalomon@google.com     *
1696850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  Other failure conditions:
1706850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    * If the canvas is backed by a non-raster device (e.g. PDF) then
1716850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *       readPixels will fail.
1726850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    * If bitmap is texture-backed then readPixels will fail. (This may be
1736850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *       relaxed in the future.)
1746850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *
1756850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  Example that reads the entire canvas into a bitmap using the native
1766850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *  SkPMColor:
1776850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    SkISize size = canvas->getDeviceSize();
1786850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
1796850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *                                                   size.fHeight);
1806850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    if (canvas->readPixels(bitmap, 0, 0)) {
1816850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *       // use the pixels
1826850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com     *    }
183c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com     */
1846850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com    bool readPixels(SkBitmap* bitmap,
1856850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com                    int x, int y,
1866850eab42ba4c2a7033a99824b02a2846ce0ef2absalomon@google.com                    Config8888 config8888 = kNative_Premul_Config8888);
187c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com
1884b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com    /**
189c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com     * DEPRECATED: This will be removed as soon as webkit is no longer relying
190c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com     * on it. The bitmap is resized to the intersection of srcRect and the
191c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com     * canvas bounds. New pixels are always allocated on success. Bitmap is
192c69809745e6496564639e42ef998ad39adf7dfb8bsalomon@google.com     * unmodified on failure.
19351df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
19451df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
19551df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com
19651df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com    /**
19751df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     *  Similar to draw sprite, this method will copy the pixels in bitmap onto
198d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  the canvas, with the top/left corner specified by (x, y). The canvas'
199d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  pixel values are completely replaced: there is no blending.
200d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *
201d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  Currently if bitmap is backed by a texture this is a no-op. This may be
202d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  relaxed in the future.
203d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *
204d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  If the bitmap has config kARGB_8888_Config then the config8888 param
205d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  will determines how the pixel valuess are intepreted. If the bitmap is
206d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com     *  not kARGB_8888_Config then this parameter is ignored.
2074f1151ab27485aff393d16559086c4c461f137a4epoger@google.com     *
2084f1151ab27485aff393d16559086c4c461f137a4epoger@google.com     *  Note: If you are recording drawing commands on this canvas to
2094f1151ab27485aff393d16559086c4c461f137a4epoger@google.com     *  SkPicture, writePixels() is ignored!
21051df9e3fe3c1aec370854b2718df16fc02faa1b2reed@google.com     */
211d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com    void writePixels(const SkBitmap& bitmap,
212d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com                     int x, int y,
213d58a1cd00b969a7755c375f55cf80f4d49d3047bbsalomon@google.com                     Config8888 config8888 = kNative_Premul_Config8888);
2144b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
2168d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum SaveFlags {
2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the matrix state, restoring it on restore() */
2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrix_SaveFlag            = 0x01,
2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** save the clip state, restoring it on restore() */
2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClip_SaveFlag              = 0x02,
2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support per-pixel alpha */
2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kHasAlphaLayer_SaveFlag     = 0x04,
2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer needs to support 8-bits per color component */
2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kFullColorLayer_SaveFlag    = 0x08,
2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** the layer should clip against the bounds argument */
2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kClipToLayer_SaveFlag       = 0x10,
2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // helper masks for common choices
2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMatrixClip_SaveFlag        = 0x03,
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_NoClipLayer_SaveFlag  = 0x0F,
2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kARGB_ClipLayer_SaveFlag    = 0x1F
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
235dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com    /** This call saves the current matrix, clip, and drawFilter, and pushes a
2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        copy onto a private stack. Subsequent calls to translate, scale,
237dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
238dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        operate on this copy.
239dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        When the balancing call to restore() is made, the previous matrix, clip,
240dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        and drawFilter are restored.
2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
248dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
249ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
250ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      limit the size of the offscreen, and thus drawing may be
251ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      clipped to it, though that clipping is not guaranteed to
252ad164b2025cba65131ca68221a6ea7640d7b1de8reed@android.com                      happen. If exact clipping is desired, use clipRect().
2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint (may be null) This is copied, and is applied to the
2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     offscreen when restore() is called
2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SaveFlags flags = kARGB_ClipLayer_SaveFlag);
2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This behaves the same as save(), but in addition it allocates an
2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        offscreen bitmap. All drawing calls are directed there, and only when
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the balancing call to restore() is made is that offscreen transfered to
264dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        the canvas (or the previous layer).
26540408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com        @param bounds (may be null) This rect, if non-null, is used as a hint to
26640408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      limit the size of the offscreen, and thus drawing may be
26740408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      clipped to it, though that clipping is not guaranteed to
26840408614655c4057d93842c9b0f09aa6dfff9e02reed@android.com                      happen. If exact clipping is desired, use clipRect().
2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param alpha  This is applied to the offscreen when restore() is called.
2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param flags  LayerFlags
2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The value to pass to restoreToCount() to balance this save()
2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       SaveFlags flags = kARGB_ClipLayer_SaveFlag);
2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** This call balances a previous call to save(), and is used to remove all
277dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        modifications to the matrix/clip/drawFilter state since the last save
278dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        call.
279dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        It is an error to call restore() more times than save() was called.
2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void restore();
2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of matrix/clip states on the SkCanvas' private stack.
2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This will equal # save() calls - # restore() calls.
2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
286a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    int getSaveCount() const;
2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Efficient way to pop any calls to save() that happened after the save
2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        count reached saveCount. It is an error for saveCount to be less than
2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        getSaveCount()
2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param saveCount    The number of save() levels to restore from
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void restoreToCount(int saveCount);
2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2957c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com    /** Returns true if drawing is currently going to a layer (from saveLayer)
2967c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     *  rather than to the root device.
2977c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com     */
2988f9ecbd3466d4330886b4c23b06e75b468c795adjunov@chromium.org    virtual bool isDrawingToLayer() const;
2997c2029367cea5479fa3b74fb0ca2b0297b42b709reed@google.com
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified translation
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The distance to translate in X
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The distance to translate in Y
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true if the operation succeeded (e.g. did not overflow)
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool translate(SkScalar dx, SkScalar dy);
3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified scale.
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to scale in X
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to scale in Y
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true if the operation succeeded (e.g. did not overflow)
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool scale(SkScalar sx, SkScalar sy);
3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified rotation.
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param degrees  The amount to rotate, in degrees
3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true if the operation succeeded (e.g. did not overflow)
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool rotate(SkScalar degrees);
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified skew.
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sx   The amount to skew in X
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sy   The amount to skew in Y
3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true if the operation succeeded (e.g. did not overflow)
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool skew(SkScalar sx, SkScalar sy);
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Preconcat the current matrix with the specified matrix.
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to preconcatenate with the current matrix
3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the operation succeeded (e.g. did not overflow)
3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool concat(const SkMatrix& matrix);
3324b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Replace the current matrix with a copy of the specified matrix.
3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix that will be copied into the current matrix.
3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void setMatrix(const SkMatrix& matrix);
3374b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for setMatrix(identity). Sets the current matrix to identity.
3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resetMatrix();
3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified rectangle.
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect The rect to intersect with the current clip
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the canvas' clip is non-empty
3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool clipRect(const SkRect& rect,
348071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com                          SkRegion::Op op = SkRegion::kIntersect_Op,
349071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com                          bool doAntiAlias = false);
3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified path.
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to apply to the current clip
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the canvas' new clip is non-empty
3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool clipPath(const SkPath& path,
357071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com                          SkRegion::Op op = SkRegion::kIntersect_Op,
358071eef918d70b6ca8334bc1241d1ea6923e828d5reed@google.com                          bool doAntiAlias = false);
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3608f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    /** EXPERIMENTAL -- only used for testing
3618f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        Set to false to force clips to be hard, even if doAntiAlias=true is
3628f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        passed to clipRect or clipPath.
3638f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com     */
3648f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    void setAllowSoftClip(bool allow) {
3658f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com        fAllowSoftClip = allow;
3668f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    }
3678f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com
3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Modify the current clip with the specified region. Note that unlike
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        clipRect() and clipPath() which transform their arguments by the current
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        matrix, clipRegion() assumes its argument is already in device
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinates, and so no transformation is performed.
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn    The region to apply to the current clip
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param op The region op to apply to the current clip
3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the canvas' new clip is non-empty
3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool clipRegion(const SkRegion& deviceRgn,
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            SkRegion::Op op = SkRegion::kIntersect_Op);
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified region. This does not intersect or in any other way account
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for the existing clip region.
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param deviceRgn The region to copy into the current clip.
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the new clip region is non-empty
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool setClipRegion(const SkRegion& deviceRgn) {
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return this->clipRegion(deviceRgn, SkRegion::kReplace_Op);
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle, after being transformed by the
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls).
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect the rect to compare with the current clip
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the rect (transformed by the canvas' matrix) does not
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3973b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkRect& rect) const;
3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified path, after being transformed by the
4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current matrix, would lie completely outside of the current clip. Call
4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this to check if an area you intend to draw into is clipped out (and
4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        therefore you can skip making the draw calls). Note, for speed it may
4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return false even if the path itself might not intersect the clip
4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (i.e. the bounds of the path intersects, but the path does not).
4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path The path to compare with the current clip
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path (transformed by the canvas' matrix) does not
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     intersect with the canvas' clip
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4093b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickReject(const SkPath& path) const;
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the horizontal band specified by top and bottom is
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely clipped out. This is a conservative calculation, meaning
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        that it is possible that if the method returns false, the band may still
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in fact be clipped out, but the converse is not true. If this method
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        returns true, then the band is guaranteed to be clipped out.
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top  The top of the horizontal band to compare with the clip
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom The bottom of the horizontal and to compare with the clip
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the horizontal band is completely clipped out (i.e. does
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     not intersect the current clip)
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4213b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool quickRejectY(SkScalar top, SkScalar bottom) const {
42292d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        SkASSERT(SkScalarToCompareType(top) <= SkScalarToCompareType(bottom));
4233b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com        const SkRectCompareType& clipR = this->getLocalClipBoundsCompareType();
42492d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // In the case where the clip is empty and we are provided with a
42592d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // negative top and positive bottom parameter then this test will return
42692d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // false even though it will be clipped. We have chosen to exclude that
42792d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        // check as it is rare and would result double the comparisons.
42892d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com        return SkScalarToCompareType(top) >= clipR.fBottom
42992d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com            || SkScalarToCompareType(bottom) <= clipR.fTop;
43092d2a299d2738e4369508ea1296981a2f1f8aadbdjsollen@google.com    }
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the current clip (in local coordinates) in the
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bounds parameter, and return true if it is non-empty. This can be useful
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        in a way similar to quickReject, in that it tells you that drawing
4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        outside of these bounds will be clipped out.
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4373b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    bool getClipBounds(SkRect* bounds) const;
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
439bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Return the bounds of the current clip, in device coordinates; returns
440bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        true if non-empty. Maybe faster than getting the clip explicitly and
441bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        then taking its bounds.
442bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
443bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    bool getClipDeviceBounds(SkIRect* bounds) const;
44474b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
445bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
447845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified ARGB color, using the specified mode.
4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param a    the alpha component (0..255) of the color to fill the canvas
4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param r    the red component (0..255) of the color to fill the canvas
4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param g    the green component (0..255) of the color to fill the canvas
4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param b    the blue component (0..255) of the color to fill the canvas
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b,
455845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Fill the entire canvas' bitmap (restricted to the current clip) with the
458845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com        specified color and mode.
4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    the color to draw with
4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode the mode to apply the color in (defaults to SrcOver)
4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawColor(SkColor color,
463845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                   SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode);
4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4652a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
4662a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  This erases the entire drawing surface to the specified color,
4672a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  irrespective of the clip. It does not blend with the previous pixels,
4682a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  but always overwrites them.
4692a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *
4702a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  It is roughly equivalent to the following:
4712a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.save();
4722a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.clipRect(hugeRect, kReplace_Op);
4732a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setColor(color);
4742a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      paint.setXfermodeMode(kSrc_Mode);
4752a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.drawPaint(paint);
4762a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *      canvas.restore();
4772a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  though it is almost always much more efficient.
4782a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
4792a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    virtual void clear(SkColor);
4802a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com
4812a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com    /**
4822a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  Fill the entire canvas' bitmap (restricted to the current clip) with the
4832a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  specified paint.
4842a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     *  @param paint    The paint used to fill the canvas
4852a98181f048c11f21f52fbd99f803f5fd6118261reed@google.com     */
4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPaint(const SkPaint& paint);
4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum PointMode {
4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each point separately */
4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPoints_PointMode,
4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws each pair of points as a line segment */
4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLines_PointMode,
4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** drawPoints draws the array of points as a polygon */
4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kPolygon_PointMode
4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a series of points, interpreted based on the PointMode mode. For
4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        all modes, the count parameter is interpreted as the total number of
4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        points. For kLine mode, count/2 line segments are drawn.
5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPoint mode, each point is drawn centered at its coordinate, and its
5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        size is specified by the paint's stroke-width. It draws as a square,
5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        unless the paint's cap-type is round, in which the points are drawn as
5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        circles.
5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kLine mode, each pair of points is drawn as a line segment,
5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        respecting the paint's settings for cap/join/width.
5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        For kPolygon mode, the entire array is drawn as a series of connected
5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        line segments.
5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Note that, while similar, kLine and kPolygon modes draw slightly
5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        differently than the equivalent path built with a series of moveto,
5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        lineto calls, in that the path will draw all of its contours at once,
5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with no interactions if contours intersect each other (think XOR
5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        xfermode). drawPoints always draws each element one at a time.
5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param mode     PointMode specifying how to draw the array of points.
5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param count    The number of points in the array
5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pts      Array of points to draw
5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the points
5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint& paint);
5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper method for drawing a single point. See drawPoints() for a more
5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        details.
5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
5254b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draws a single pixel in the specified color.
5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The X coordinate of which pixel to draw
5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The Y coordiante of which pixel to draw
5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param color    The color to draw
5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawPoint(SkScalar x, SkScalar y, SkColor color);
5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw a line segment with the specified start and stop x,y coordinates,
5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        using the specified paint. NOTE: since a line is always "framed", the
5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint's Style is ignored.
5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x0    The x-coordinate of the start point of the line
5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y0    The y-coordinate of the start point of the line
5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1    The x-coordinate of the end point of the line
5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1    The y-coordinate of the end point of the line
5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint The paint used to draw the line
5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1,
5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                  const SkPaint& paint);
5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or stroked based on the Style in the paint.
5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawRect(const SkRect& rect, const SkPaint& paint);
5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rect to be drawn
5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawIRect(const SkIRect& rect, const SkPaint& paint)
5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    {
5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkRect r;
5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        r.set(rect);    // promotes the ints to scalars
5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->drawRect(r, paint);
5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
5634b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified rectangle using the specified paint. The rectangle
5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The left side of the rectangle to be drawn
5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The top side of the rectangle to be drawn
5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param right    The right side of the rectangle to be drawn
5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bottom   The bottom side of the rectangle to be drawn
5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the rect
5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRectCoords(SkScalar left, SkScalar top, SkScalar right,
5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        SkScalar bottom, const SkPaint& paint);
5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified oval using the specified paint. The oval will be
5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval     The rectangle bounds of the oval to be drawn
5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the oval
5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawOval(const SkRect& oval, const SkPaint&);
5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified circle using the specified paint. If radius is <= 0,
5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        then nothing will be drawn. The circle will be filled
5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        or framed based on the Style in the paint.
5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cx       The x-coordinate of the center of the cirle to be drawn
5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param cy       The y-coordinate of the center of the cirle to be drawn
5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param radius   The radius of the cirle to be drawn
5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the circle
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius,
5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    const SkPaint& paint);
5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified arc, which will be scaled to fit inside the
5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified oval. If the sweep angle is >= 360, then the oval is drawn
5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        completely. Note that this differs slightly from SkPath::arcTo, which
5968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        treats the sweep angle mod 360.
5978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the shape of the arc
5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param useCenter true means include the center of the oval. For filling
6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                         this will draw a wedge. False means just use the arc.
6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the arc
6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 bool useCenter, const SkPaint& paint);
6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified round-rect using the specified paint. The round-rect
6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will be filled or framed based on the Style in the paint.
6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect     The rectangular bounds of the roundRect to be drawn
6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rx       The x-radius of the oval used to round the corners
6118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ry       The y-radius of the oval used to round the corners
6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the roundRect
6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       const SkPaint& paint);
6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified path using the specified paint. The path will be
6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        filled or framed based on the Style in the paint.
6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path     The path to be drawn
6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the path
6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPath(const SkPath& path, const SkPaint& paint);
6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y), using the
6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specified paint, transformed by the current matrix. Note: if the paint
6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with the specified matrix applied (before the
6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas' matrix is applied).
6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src      Optional: specify the subset of the bitmap to be drawn
6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The destination rectangle where the scaled/translated
6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                        image will be drawn
6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6467112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
6477112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                                      const SkRect& dst,
6487112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                                      const SkPaint* paint);
6497112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com
6507112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst,
6517112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                        const SkPaint* paint) {
6527112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        this->drawBitmapRectToRect(bitmap, NULL, dst, paint);
6537112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6557112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* isrc,
6567112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com                        const SkRect& dst, const SkPaint* paint = NULL) {
6577112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect realSrcStorage;
6587112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        SkRect* realSrcPtr = NULL;
6597112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        if (isrc) {
6607112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcStorage.set(*isrc);
6617112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com            realSrcPtr = &realSrcStorage;
6627112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        }
6637112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com        this->drawBitmapRectToRect(bitmap, realSrcPtr, dst, paint);
6647112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    }
665c1ad0226087e10b1f300b5a45e3d6fdb23b8d1b8skia.committer@gmail.com
6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
6678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                  const SkPaint* paint = NULL);
6684b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
669f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    /**
670f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  Draw the bitmap stretched differentially to fit into dst.
671f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  center is a rect within the bitmap, and logically divides the bitmap
672f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  into 9 sections (3x3). For example, if the middle pixel of a [5x5]
673f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
674f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *
675f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  If the dst is >= the bitmap size, then...
676f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The 4 corners are not stretch at all.
677f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides are stretch in only one axis.
678f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The center is stretch in both axes.
679f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     * Else, for each axis where dst < bitmap,
680f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The corners shrink proportionally
681f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     *  - The sides (along the shrink axis) and center are not drawn
682f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com     */
683f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
684f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint = NULL);
685f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the specified bitmap, with its top/left corner at (x,y),
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        NOT transformed by the current matrix. Note: if the paint
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contains a maskfilter that generates a mask which extends beyond the
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bitmap's original width/height, then the bitmap will be drawn as if it
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        were in a Shader with CLAMP mode. Thus the color outside of the original
6918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width/height will be the edge color replicated.
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   The bitmap to be drawn
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param left     The position of the left side of the bitmap being drawn
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param top      The position of the top side of the bitmap being drawn
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used to draw the bitmap, or NULL
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint* paint = NULL);
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint.
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The origin is interpreted based on the Align setting in the paint.
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x        The x-coordinate of the origin of the text being drawn
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y        The y-coordinate of the origin of the text being drawn
7068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
7078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawText(const void* text, size_t byteLength, SkScalar x,
7098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar y, const SkPaint& paint);
7108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the pos[]
7124b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        array. The origin is interpreted by the Align setting in the paint.
7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param pos      Array of positions, used to position each character
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPosText(const void* text, size_t byteLength,
7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkPoint pos[], const SkPaint& paint);
7204b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with each character/glyph origin specified by the x
7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        coordinate taken from the xpos[] array, and the y from the constY param.
7234b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        The origin is interpreted by the Align setting in the paint.
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xpos     Array of x-positions, used to position each character
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param constY   The shared Y coordinate for all of the positions
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint    The paint used for the text (e.g. color, size, style)
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPosTextH(const void* text, size_t byteLength,
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkScalar xpos[], SkScalar constY,
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
7334b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param hOffset      The distance along the path to add to the text's
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            starting position
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vOffset      The distance above(-) or below(+) the path to
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            position the text
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void drawTextOnPathHV(const void* text, size_t byteLength,
7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          const SkPath& path, SkScalar hOffset,
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar vOffset, const SkPaint& paint);
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the text, with origin at (x,y), using the specified paint, along
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the specified path. The paint's Align setting determins where along the
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to start the text.
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param text The text to be drawn
7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param byteLength   The number of bytes to read from the text parameter
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param path         The path the text should follow for its baseline
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix       (may be null) Applied to the text before it is
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            mapped onto the path
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param paint        The paint used for the text
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawTextOnPath(const void* text, size_t byteLength,
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPath& path, const SkMatrix* matrix,
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPaint& paint);
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
76456c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID
765cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com    /** Draw the text on path, with each character/glyph origin specified by the pos[]
766cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        array. The origin is interpreted by the Align setting in the paint.
767cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param text The text to be drawn
768cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param byteLength   The number of bytes to read from the text parameter
769cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param pos      Array of positions, used to position each character
770cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param paint    The paint used for the text (e.g. color, size, style)
771cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param path The path to draw on
772cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        @param matrix The canvas matrix
773cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com        */
774cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com    void drawPosTextOnPath(const void* text, size_t byteLength,
775cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com                           const SkPoint pos[], const SkPaint& paint,
776cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com                           const SkPath& path, const SkMatrix* matrix);
777cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif
778cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com
7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the picture into this canvas. This method effective brackets the
7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        playback of the picture's draw calls with save/restore, so the state
7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        of this canvas will be unchanged after this call. This contrasts with
7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the more immediate method SkPicture::draw(), which does not bracket
7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the canvas with save/restore, thus the canvas may be left in a changed
7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        state after the call.
7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param picture The recorded drawing commands to playback into this
7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                       canvas.
7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPicture(SkPicture& picture);
7894b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum VertexMode {
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangles_VertexMode,
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleStrip_VertexMode,
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kTriangleFan_VertexMode
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
7954b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Draw the array of vertices, interpreted as triangles (based on mode).
7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vmode How to interpret the array of vertices
7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertexCount The number of points in the vertices array (and
7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    corresponding texs and colors arrays if non-null)
8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param vertices Array of vertices for the mesh
8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param texs May be null. If not null, specifies the coordinate
8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             in texture space for each vertex.
8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param colors May be null. If not null, specifies a color for each
8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      vertex, to be interpolated across the triangle.
8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param xmode Used if both texs and colors are present. In this
8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    case the colors are combined with the texture using mode,
8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    before being drawn using the paint. If mode is null, then
808845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com                    kMultiply_Mode is used.
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indices If not null, array of indices to reference into the
8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    vertex (texs, colors) array.
8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param indexCount number of entries in the indices array (if not null)
8124b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com        @param paint Specifies the shader/texture if present.
8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawVertices(VertexMode vmode, int vertexCount,
8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPoint vertices[], const SkPoint texs[],
8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkColor colors[], SkXfermode* xmode,
8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const uint16_t indices[], int indexCount,
8188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
8198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
820cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com    /** Send a blob of data to the canvas.
821cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        For canvases that draw, this call is effectively a no-op, as the data
822cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        is not parsed, but just ignored. However, this call exists for
823cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        subclasses like SkPicture's recording canvas, that can store the data
824cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com        and then play it back later (via another call to drawData).
825cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com     */
826cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com    virtual void drawData(const void* data, size_t length);
827cb60844b34766aad4151df5e87c144d4a57e9abereed@android.com
8288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
8294b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
8308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current bounder object.
8318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The bounder's reference count is unchaged.
8328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canva's bounder (or NULL).
8338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBounder*  getBounder() const { return fBounder; }
8358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set a new bounder (or NULL).
8378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Pass NULL to clear any previous bounder.
8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter passed is also returned.
8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If a previous bounder exists, its reference count is decremented.
8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If bounder is not NULL, its reference count is incremented.
8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bounder the new bounder (or NULL) to be installed in the canvas
8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the set bounder object
8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkBounder* setBounder(SkBounder* bounder);
8454b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Get the current filter object. The filter's reference count is not
847dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        affected. The filter is saved/restored, just like the matrix and clip.
8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the canvas' filter (or NULL).
8498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawFilter* getDrawFilter() const;
8514b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
8528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the new filter (or NULL). Pass NULL to clear any existing filter.
8538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        As a convenience, the parameter is returned. If an existing filter
8548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        exists, its refcnt is decrement. If the new filter is not null, its
855dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        refcnt is incremented. The filter is saved/restored, just like the
856dc3381fc8194a6192af39539c6ac9787b20209d3reed@android.com        matrix and clip.
8578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param filter the new filter (or NULL)
8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the new filter
8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //////////////////////////////////////////////////////////////////////////
8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current matrix on the canvas.
8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This does not account for the translate in any of the devices.
8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return The current matrix on the canvas.
8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
868a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    const SkMatrix& getTotalMatrix() const;
8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
870bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    enum ClipType {
871bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kEmpty_ClipType = 0,
872bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kRect_ClipType,
873bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        kComplex_ClipType
874bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    };
875bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
876bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    /** Returns a description of the total clip; may be cheaper than
877bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com        getting the clip and querying it directly.
878bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    */
879bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com    ClipType getClipType() const;
880bcb671c82a7341253864cda3a5c46d396402d7fbtomhudson@google.com
8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the current device clip (concatenation of all clip calls).
882a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  This does not account for the translate in any of the devices.
883a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  @return the current device clip (concatenation of all clip calls).
8845e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com     *
885a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com     *  DEPRECATED -- call getClipDeviceBounds() instead.
8865e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com     */
887a707f6087455834fab5525a0c656cc5b6df2ff29reed@google.com    const SkRegion& getTotalClip() const;
8885e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com
88940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    /** Return the clip stack. The clip stack stores all the individual
89040a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  clips organized by the save/restore frame in which they were
89140a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  added.
89240a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     *  @return the current clip stack ("list" of individual clip elements)
89340a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com     */
89440a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* getClipStack() const {
89540a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com        return &fClipStack;
89640a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    }
89740a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
89890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    class ClipVisitor {
89990c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    public:
90020a550c6ea947f0ab239da1d4ecba209d76a98fdjustinlin@google.com        virtual ~ClipVisitor();
90190c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com        virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
90290c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com        virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
90390c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    };
90490c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com
9055e2457ef2eba0c3f2e4c8fc89be7f36659e4f3b1reed@google.com    /**
90690c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  Replays the clip operations, back to front, that have been applied to
90790c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  the canvas, calling the appropriate method on the visitor for each
90890c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com     *  clip. All clips have already been transformed into device space.
9097d7ca79c3e6e6be7b7849b0d9a7fe26effb89c38reed@google.com     */
91090c07ea1d0aa6b7f20252c43fe23ee5ddc1d23cbreed@google.com    void replayClips(ClipVisitor*) const;
9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ///////////////////////////////////////////////////////////////////////////
9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After calling saveLayer(), there can be any number of devices that make
9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        up the top-most drawing area. LayerIter can be used to iterate through
9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        those devices. Note that the iterator is only valid until the next API
9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call made on the canvas. Ownership of all pointers in the iterator stays
9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        with the canvas, so none of them should be modified or deleted.
9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9207ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API LayerIter /*: SkNoncopyable*/ {
9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Initialize iterator with canvas, and set values for 1st device */
9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        LayerIter(SkCanvas*, bool skipEmptyClips);
9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        ~LayerIter();
9254b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return true if the iterator is done */
9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool done() const { return fDone; }
9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Cycle to the next device */
9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void next();
9304b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // These reflect the current device in the iterator
9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkDevice*       device() const;
9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkMatrix& matrix() const;
9358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkRegion& clip() const;
9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPaint&  paint() const;
9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             x() const;
9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        int             y() const;
9394b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // used to embed the SkDrawIter object directly in our instance, w/o
9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // having to expose that class def to the public. There is an assert
9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // in our constructor to ensure that fStorage is large enough
9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // (though needs to be a compile-time-assert!). We use intptr_t to work
9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // safely with 32 and 64 bit machines (to ensure the storage is enough)
946f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        intptr_t          fStorage[32];
9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        class SkDrawIter* fImpl;    // this points at fStorage
9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint           fDefaultPaint;
9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool              fDone;
9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
95374b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    // Returns the canvas to be used by DrawIter. Default implementation
9544370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // returns this. Subclasses that encapsulate an indirect canvas may
9554370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // need to overload this method. The impl must keep track of this, as it
9564370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    // is not released or deleted by the caller.
9574370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com    virtual SkCanvas* canvasForDrawIter();
9584370aedf7f55af74e9ebb4ad1c2e010c08236dfajunov@google.com
9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // all of the drawBitmap variants call this guy
96049794c0cbd934545854a7b4091af5af7dfb46570reed@google.com    void commonDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix&,
96149794c0cbd934545854a7b4091af5af7dfb46570reed@google.com                          const SkPaint& paint);
9624b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
963a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // Clip rectangle bounds. Called internally by saveLayer.
964a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    // returns false if the entire rectangle is entirely clipped out
965a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org    bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
96649794c0cbd934545854a7b4091af5af7dfb46570reed@google.com                        SkIRect* intersection);
967a907ac3e3e3458fbb5d673c3feafb31fd7647b38junov@chromium.org
96897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // notify our surface (if we have one) that we are about to draw, so it
96997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    // can perform copy-on-write or invalidate any cached images
97097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void predrawNotify();
97197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com
972260eae59b4edef636685e640ec13d82490d3474freed@google.com    /** DEPRECATED -- use constructor(device)
973260eae59b4edef636685e640ec13d82490d3474freed@google.com
974260eae59b4edef636685e640ec13d82490d3474freed@google.com     Marked as 'protected' to avoid new clients using this before we can
975260eae59b4edef636685e640ec13d82490d3474freed@google.com     completely remove it.
976260eae59b4edef636685e640ec13d82490d3474freed@google.com
977260eae59b4edef636685e640ec13d82490d3474freed@google.com     Specify a device for this canvas to draw into. If it is not null, its
978260eae59b4edef636685e640ec13d82490d3474freed@google.com     reference count is incremented. If the canvas was already holding a
979260eae59b4edef636685e640ec13d82490d3474freed@google.com     device, its reference count is decremented. The new device is returned.
980260eae59b4edef636685e640ec13d82490d3474freed@google.com     */
981260eae59b4edef636685e640ec13d82490d3474freed@google.com    virtual SkDevice* setDevice(SkDevice* device);
982260eae59b4edef636685e640ec13d82490d3474freed@google.com
9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MCRec;
9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9865c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    SkClipStack fClipStack;
9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDeque     fMCStack;
9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // points to top of stack
9898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    MCRec*      fMCRec;
9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // the first N recs that can fit here mean we won't call malloc
9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint32_t    fMCRecStorage[32];
9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBounder*  fBounder;
994b0a7ace7cb2a7559bbc254a7c93698bc71bbd245junov@chromium.org    int         fSaveLayerCount;    // number of successful saveLayer calls
9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
99674bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org    SkMetaData* fMetaData;
99774bb77ee4c747b8c70c5c613987c9f93df71df06mike@reedtribe.org
99897af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base*  fSurfaceBase;
99997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
100097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    void setSurfaceBase(SkSurface_Base* sb) {
100197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com        fSurfaceBase = sb;
100297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    }
100397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com    friend class SkSurface_Base;
1004fc84359aa920567e72742877a1249f52d076ad35skia.committer@gmail.com
10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void updateDeviceCMCache();
10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkDrawIter;    // needs setupDrawForLayerDevice()
10098926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    friend class AutoDrawLooper;
10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
101174b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org    SkDevice* createLayerDevice(SkBitmap::Config, int width, int height,
1012e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com                                bool isOpaque);
1013e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDevice* init(SkDevice*);
1015f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com
1016f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // internal methods are not virtual, so they can safely be called by other
1017f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    // canvas apis, without confusing subclasses (like SkPictureRecording)
1018f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    void internalDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix& m,
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                  const SkPaint* paint);
10207112173c3c4cd1b1e7da8cdf971d71f01dd91299reed@google.com    void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1021f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint);
1022f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com    void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
1023f0b5e1190af9807a027c0adba2f1380663c8e910reed@google.com                                const SkRect& dst, const SkPaint* paint);
1024fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com    void internalDrawPaint(const SkPaint& paint);
10258926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    int internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
10268926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com                          SaveFlags, bool justForImageFilter);
10278926b169f6a0dfa4c2129a98ec2aee205f0c8527reed@google.com    void internalDrawDevice(SkDevice*, int x, int y, const SkPaint*);
1028fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.com
10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // shared by save() and saveLayer()
10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int internalSave(SaveFlags flags);
10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void internalRestore();
103252c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawRect(const SkDraw& draw, const SkPaint& paint,
103352c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                         const SkRect& r, SkScalar textSize);
103452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com    static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
103552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    const char text[], size_t byteLength,
103652c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com                                    SkScalar x, SkScalar y);
10374b226023832011bc3bcdd1e5092ff0645ad0bdeereed@google.com
10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  These maintain a cache of the clip bounds in local coordinates,
10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (converted to 2s-compliment if floats are slow).
10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    mutable SkRectCompareType fLocalBoundsCompareType;
10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    mutable bool              fLocalBoundsCompareTypeDirty;
10438f0a7b8e7334187a5d7d5ab7fde5a3c3009555f5caryclark@google.com    bool fAllowSoftClip;
10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkRectCompareType& getLocalClipBoundsCompareType() const {
10463b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com        if (fLocalBoundsCompareTypeDirty) {
10473b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com            this->computeLocalClipBoundsCompareType();
10483b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com            fLocalBoundsCompareTypeDirty = false;
10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
10503b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com        return fLocalBoundsCompareType;
10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
10523b3e895df6f8ee0f33010367c215944cd16a8334reed@google.com    void computeLocalClipBoundsCompareType() const;
1053f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
10545c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    class AutoValidateClip : ::SkNoncopyable {
10555c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    public:
10565c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
10575c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com            fCanvas->validateClip();
10585c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        }
10595c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        ~AutoValidateClip() { fCanvas->validateClip(); }
10605c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
10615c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    private:
10625c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com        const SkCanvas* fCanvas;
10635c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    };
10645c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com
10655c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#ifdef SK_DEBUG
10665c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const;
10675c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#else
10685c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com    void validateClip() const {}
10695c3d1471e4908706cd053a5e2ea9ded3a6c2eaebreed@google.com#endif
107015e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com
107115e9d3e66e161ce23df30bc13f8a0c87d196b463robertphillips@google.com    typedef SkRefCnt INHERITED;
10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
10738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** Stack helper class to automatically call restoreToCount() on the canvas
10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    when this object goes out of scope. Use this to guarantee that the canvas
10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    is restored to a known state.
10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
10788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoCanvasRestore : SkNoncopyable {
10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas) {
10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkASSERT(canvas);
10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fSaveCount = canvas->getSaveCount();
10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        if (doSave) {
10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            canvas->save();
10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
10868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
10878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAutoCanvasRestore() {
10888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fCanvas->restoreToCount(fSaveCount);
10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
10928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas*   fCanvas;
10938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fSaveCount;
10948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
10958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1097