SkDevice.h revision ea4ac97dec2eb291139bd906939e0d2e05cdd7ef
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
28c1d88dcfb978835779b6b5c5e7d1cbb78b6ca4dvandebo@chromium.org * Copyright (C) 2010 The Android Open Source Project
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License");
58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License.
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *      http://www.apache.org/licenses/LICENSE-2.0
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS,
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License.
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDevice_DEFINED
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDevice_DEFINED
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColor.h"
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2546799cd9f0bded51a189d77731b25af159ab4609reed@google.comclass SkClipStack;
268d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.orgclass SkDevice;
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDraw;
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkIRect;
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkMatrix;
30a7d948523dce6044fc02db90726e5f971a93628breed@google.comclass SkMetaData;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkRegion;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
338d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org/** \class SkDeviceFactory
348d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
358d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    Devices that extend SkDevice should also provide a SkDeviceFactory class
368d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    to pass into SkCanvas.  Doing so will eliminate the need to extend
378d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org    SkCanvas as well.
388d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org*/
39ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.orgclass SK_API SkDeviceFactory : public SkRefCnt {
408d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.orgpublic:
41ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    SkDeviceFactory();
428c1d88dcfb978835779b6b5c5e7d1cbb78b6ca4dvandebo@chromium.org    virtual ~SkDeviceFactory();
43f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
44f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                                int height, bool isOpaque, bool isLayer) = 0;
458d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org};
468d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
478d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.orgclass SkRasterDeviceFactory : public SkDeviceFactory {
488d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.orgpublic:
49f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
50f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                                int height, bool isOpaque, bool isLayer);
518d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org};
528d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
537ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDevice : public SkRefCnt {
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
55f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkDevice(SkCanvas*);
56f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /** Construct a new device, extracting the width/height/config/isOpaque values from
57f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        the bitmap. If transferPixelOwnership is true, and the bitmap claims to own its
58f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        own pixels (getOwnsPixels() == true), then transfer this responsibility to the
59f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        device, and call setOwnsPixels(false) on the bitmap.
603dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com
61f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        Subclasses may override the destructor, which is virtual, even though this class
62f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        doesn't have one. SkRefCnt does.
633dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param bitmap   A copy of this bitmap is made and stored in the device
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
66f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkDevice(SkCanvas*, const SkBitmap& bitmap, bool forOffscreen);
67a7d948523dce6044fc02db90726e5f971a93628breed@google.com    virtual ~SkDevice();
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
69ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    /**
70ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  Return the factory that will create this subclass of SkDevice.
71ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  The returned factory is cached by the device, and so its reference count
72ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  is not changed by this call.
73ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     */
74ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    SkDeviceFactory* getDeviceFactory();
758d84fac294682647694b0d2d8a87ac2bd19b6aabvandebo@chromium.org
7635fc62b960db6739b19c59576085663796951e47vandebo@chromium.org    enum Capabilities {
7735fc62b960db6739b19c59576085663796951e47vandebo@chromium.org        kGL_Capability     = 0x1,  //!< mask indicating GL support
7835fc62b960db6739b19c59576085663796951e47vandebo@chromium.org        kVector_Capability = 0x2,  //!< mask indicating a vector representation
7935fc62b960db6739b19c59576085663796951e47vandebo@chromium.org        kAll_Capabilities  = 0x3
8035fc62b960db6739b19c59576085663796951e47vandebo@chromium.org    };
8135fc62b960db6739b19c59576085663796951e47vandebo@chromium.org    virtual uint32_t getDeviceCapabilities() { return 0; }
8235fc62b960db6739b19c59576085663796951e47vandebo@chromium.org
838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the width of the device (in pixels).
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
859b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    virtual int width() const { return fBitmap.width(); }
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the height of the device (in pixels).
878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
889b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    virtual int height() const { return fBitmap.height(); }
896f8f292aa768869a9e85c314b124875f57504f2creed@google.com
906f8f292aa768869a9e85c314b124875f57504f2creed@google.com    /**
916f8f292aa768869a9e85c314b124875f57504f2creed@google.com     *  Return the device's origin: its offset in device coordinates from
926f8f292aa768869a9e85c314b124875f57504f2creed@google.com     *  the default origin in its canvas' matrix/clip
936f8f292aa768869a9e85c314b124875f57504f2creed@google.com     */
946f8f292aa768869a9e85c314b124875f57504f2creed@google.com    const SkIPoint& getOrigin() const { return fOrigin; }
956f8f292aa768869a9e85c314b124875f57504f2creed@google.com
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bitmap config of the device's pixels
978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBitmap::Config config() const { return fBitmap.getConfig(); }
998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the device's bitmap's config treats every pixels as
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        implicitly opaque.
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isOpaque() const { return fBitmap.isOpaque(); }
1033dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com
1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bounds of the device
1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void getBounds(SkIRect* bounds) const;
1073dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return true if the specified rectangle intersects the bounds of the
1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        device. If sect is not NULL and there is an intersection, sect returns
1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the intersection.
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool intersects(const SkIRect& r, SkIRect* sect = NULL) const;
1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the bitmap associated with this device. Call this each time you need
1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        to access the bitmap, as it notifies the subclass to perform any flushing
1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        etc. before you examine the pixels.
1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param changePixels set to true if the caller plans to change the pixels
1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the device's bitmap
1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkBitmap& accessBitmap(bool changePixels);
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
122398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com    /** Clears the entire device to the specified color (including alpha).
123398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com     *  Ignores the clip.
124398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com     */
125398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com    virtual void clear(SkColor color);
126398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com
127398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com    /**
128398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com     * Deprecated name for clear.
129398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com     */
130398109cc3e56b8122ad21c4d43a74a83be5b42a8bsalomon@google.com    void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Called when this device is installed into a Canvas. Balanaced by a call
1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        to unlockPixels() when the device is removed from a Canvas.
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void lockPixels();
1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void unlockPixels();
1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /** Return the device's associated texture, or NULL. If returned, it may be
139f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        drawn into another device
140f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     */
141f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual SkGpuTexture* accessTexture() { return NULL; }
142f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
14346799cd9f0bded51a189d77731b25af159ab4609reed@google.com    /**
14446799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  Called with the correct matrix and clip before this device is drawn
14546799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  to using those settings. If your subclass overrides this, be sure to
14646799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  call through to the base class as well.
14746799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *
14846799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  The clipstack is another view of the clip. It records the actual
14946799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  geometry that went into building the region. It is present for devices
15046799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  that want to parse it, but is not required: the region is a complete
15146799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  picture of the current clip. (i.e. if you regionize all of the geometry
15246799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  in the clipstack, you will arrive at an equivalent region to the one
15346799cd9f0bded51a189d77731b25af159ab4609reed@google.com     *  passed in).
1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
15546799cd9f0bded51a189d77731b25af159ab4609reed@google.com    virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
15646799cd9f0bded51a189d77731b25af159ab4609reed@google.com                               const SkClipStack&);
1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Called when this device gains focus (i.e becomes the current device
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        for drawing).
1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
161d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com    virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&,
162d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com                           const SkClipStack&) {}
1633dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com
164f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /** Causes any deferred drawing to the device to be completed.
165f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     */
166f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual void flush() {}
167f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
168f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /**
169f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     *  Copy the pixels from the device into bitmap. Returns true on success.
170f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     *  If false is returned, then the bitmap parameter is left unchanged.
1713dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com     *  The bitmap parameter is treated as output-only, and will be completely
1723dd42b3c87299ad17b4df93fe251f6f9362495dcreed@google.com     *  overwritten (if the method returns true).
173f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     */
174f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
175f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
176f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    /**
177f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     *  Similar to draw sprite, this method will copy the pixels in bitmap onto
178f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     *  the device, with the top/left corner specified by (x, y). The pixel
179f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     *  values in the device are completely replaced: there is no blending.
180f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com     */
181f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual void writePixels(const SkBitmap& bitmap, int x, int y);
1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** These are called inside the per-device-layer loop for each draw call.
1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     When these are called, we have already applied any saveLayer operations,
1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     and are handling any looping from the paint, and any effects from the
1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     DrawFilter.
1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPaint(const SkDraw&, const SkPaint& paint);
1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPoint[], const SkPaint& paint);
1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawRect(const SkDraw&, const SkRect& r,
1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          const SkPaint& paint);
1937ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com    /**
1947ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  If pathIsMutable, then the implementation is allowed to cast path to a
1957ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  non-const pointer and modify it in place (as an optimization). Canvas
1967ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  may do this to implement helpers such as drawOval, by placing a temp
1977ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  path on the stack to hold the representation of the oval.
1987ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *
1997ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  If prePathMatrix is not null, it should logically be applied before any
2007ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  stroking or other effects. If there are no effects on the paint that
2017ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  affect the geometry/rasterization, then the pre matrix can just be
2027ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     *  pre-concated with the current matrix.
2037ff8d81290c3d9d461f2e304f4fd7846275f956dreed@google.com     */
2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPath(const SkDraw&, const SkPath& path,
205f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                          const SkPaint& paint,
206f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                          const SkMatrix* prePathMatrix = NULL,
207f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                          bool pathIsMutable = false);
2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
209f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com                            const SkIRect* srcRectOrNull,
2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkMatrix& matrix, const SkPaint& paint);
2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            int x, int y, const SkPaint& paint);
2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawText(const SkDraw&, const void* text, size_t len,
2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          SkScalar x, SkScalar y, const SkPaint& paint);
2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawPosText(const SkDraw&, const void* text, size_t len,
2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             const SkScalar pos[], SkScalar constY,
2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                             int scalarsPerPos, const SkPaint& paint);
2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPath& path, const SkMatrix* matrix,
2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                const SkPaint& paint);
221cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#ifdef ANDROID
222cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com    virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
223cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com                                   const SkPoint pos[], const SkPaint& paint,
224cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com                                   const SkPath& path, const SkMatrix* matrix);
225cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif
2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPoint verts[], const SkPoint texs[],
2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkColor colors[], SkXfermode* xmode,
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const uint16_t indices[], int indexCount,
2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                              const SkPaint& paint);
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            const SkPaint&);
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2343636ed558fb2af5a48a9634efec55fd8a87c88d7reed@google.com    ///////////////////////////////////////////////////////////////////////////
2353636ed558fb2af5a48a9634efec55fd8a87c88d7reed@google.com
236a7d948523dce6044fc02db90726e5f971a93628breed@google.com    SkMetaData& getMetaData();
2373636ed558fb2af5a48a9634efec55fd8a87c88d7reed@google.com
238f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com    struct TextFlags {
239f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com        uint32_t            fFlags;     // SkPaint::getFlags()
240f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com        SkPaint::Hinting    fHinting;
241f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com    };
242f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com
243f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com    /**
244f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *  Device may filter the text flags for drawing text here. If it wants to
245f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *  make a change to the specified values, it should write them into the
246f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *  textflags parameter (output) and return true. If the paint is fine as
247f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *  is, then ignore the textflags parameter and return false.
248f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *
249f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     *  The baseclass SkDevice filters based on its depth and blitters.
250f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com     */
251f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com    virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
252f67e4cf4c18cd228738a11372859ee0280bce1d7reed@google.com
2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
254ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    /**
255ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  subclasses must override this to return a new (or ref'd) instance of
256ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  a device factory that will create this subclass of device. This value
257ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     *  is cached, so it should get called at most once for a given instance.
258ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org     */
259ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    virtual SkDeviceFactory* onNewDeviceFactory();
260ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Update as needed the pixel value in the bitmap, so that the caller can access
2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        must remain unchanged.
2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void onAccessBitmap(SkBitmap*);
2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
267f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
268f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    // just for subclasses, to assign a custom pixelref
269f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) {
270f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        fBitmap.setPixelRef(pr, offset);
271f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com        return pr;
272f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    }
273f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com
2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
2756f8f292aa768869a9e85c314b124875f57504f2creed@google.com    friend class SkCanvas;
2766f8f292aa768869a9e85c314b124875f57504f2creed@google.com    // just called by SkCanvas when built as a layer
2776f8f292aa768869a9e85c314b124875f57504f2creed@google.com    void setOrigin(int x, int y) { fOrigin.set(x, y); }
2786f8f292aa768869a9e85c314b124875f57504f2creed@google.com
2793636ed558fb2af5a48a9634efec55fd8a87c88d7reed@google.com    SkCanvas*   fCanvas;
2803636ed558fb2af5a48a9634efec55fd8a87c88d7reed@google.com    SkBitmap    fBitmap;
2816f8f292aa768869a9e85c314b124875f57504f2creed@google.com    SkIPoint    fOrigin;
282a7d948523dce6044fc02db90726e5f971a93628breed@google.com    SkMetaData* fMetaData;
283ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org
284ea4ac97dec2eb291139bd906939e0d2e05cdd7efmike@reedtribe.org    SkDeviceFactory* fCachedDeviceFactory;
2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
288