blob: 1f104247003b124a57a087c345a06afec8c1c5b0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkDevice_DEFINED
11#define SkDevice_DEFINED
12
13#include "SkRefCnt.h"
14#include "SkBitmap.h"
15#include "SkCanvas.h"
16#include "SkColor.h"
bungeman@google.com532470f2013-01-22 19:25:14 +000017#include "SkDeviceProperties.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018
reed@google.com46799cd2011-02-22 20:56:26 +000019class SkClipStack;
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkDraw;
21struct SkIRect;
22class SkMatrix;
reed@google.coma7d94852011-03-30 21:23:07 +000023class SkMetaData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024class SkRegion;
25
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +000026class GrRenderTarget;
bsalomon@google.comd9f826c2011-07-18 15:25:04 +000027
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000028class SK_API SkBaseDevice : public SkRefCnt {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029public:
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000030 SK_DECLARE_INST_COUNT(SkBaseDevice)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000031
reed@google.comaf951c92011-06-16 19:10:39 +000032 /**
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000033 * Construct a new device.
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000035 SkBaseDevice();
reed@google.comaf951c92011-06-16 19:10:39 +000036
37 /**
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000038 * Construct a new device.
bungeman@google.com532470f2013-01-22 19:25:14 +000039 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000040 SkBaseDevice(const SkDeviceProperties& deviceProperties);
bungeman@google.com532470f2013-01-22 19:25:14 +000041
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000042 virtual ~SkBaseDevice();
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
mike@reedtribe.orgea4ac972011-04-26 11:48:33 +000044 /**
reed@google.com2d54d062011-06-21 12:19:28 +000045 * Creates a device that is of the same type as this device (e.g. SW-raster,
46 * GPU, or PDF). The backing store for this device is created automatically
47 * (e.g. offscreen pixels or FBO or whatever is appropriate).
bsalomon@google.come97f0852011-06-17 13:10:25 +000048 *
reed@google.com2d54d062011-06-21 12:19:28 +000049 * @param width width of the device to create
50 * @param height height of the device to create
51 * @param isOpaque performance hint, set to true if you know that you will
52 * draw into this device such that all of the pixels will
53 * be opaque.
bsalomon@google.come97f0852011-06-17 13:10:25 +000054 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000055 SkBaseDevice* createCompatibleDevice(SkBitmap::Config config,
56 int width, int height,
57 bool isOpaque);
bsalomon@google.come97f0852011-06-17 13:10:25 +000058
bungeman@google.com88edf1e2011-08-08 19:41:56 +000059 SkMetaData& getMetaData();
60
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000061 enum Capabilities {
62 kGL_Capability = 0x1, //!< mask indicating GL support
63 kVector_Capability = 0x2, //!< mask indicating a vector representation
64 kAll_Capabilities = 0x3
65 };
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000066 virtual uint32_t getDeviceCapabilities() = 0;
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 /** Return the width of the device (in pixels).
69 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000070 virtual int width() const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 /** Return the height of the device (in pixels).
72 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000073 virtual int height() const = 0;
reed@google.com6f8f2922011-03-04 22:27:10 +000074
bungeman@google.com532470f2013-01-22 19:25:14 +000075 /** Return the image properties of the device. */
76 virtual const SkDeviceProperties& getDeviceProperties() const {
77 //Currently, all the properties are leaky.
78 return fLeakyProperties;
79 }
80
reed@google.comd51bfa02011-08-30 15:56:11 +000081 /**
82 * Return the bounds of the device in the coordinate space of the root
83 * canvas. The root device will have its top-left at 0,0, but other devices
84 * such as those associated with saveLayer may have a non-zero origin.
85 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000086 virtual void getGlobalBounds(SkIRect* bounds) const = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +000087
reed@android.com8a1c16f2008-12-17 15:59:43 +000088 /** Returns true if the device's bitmap's config treats every pixels as
89 implicitly opaque.
90 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000091 virtual bool isOpaque() const = 0;
92
93 /** DEPRECATED - Return the bitmap config of the device's pixels
94 */
95 virtual SkBitmap::Config config() const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +000096
97 /** Return the bitmap associated with this device. Call this each time you need
98 to access the bitmap, as it notifies the subclass to perform any flushing
99 etc. before you examine the pixels.
100 @param changePixels set to true if the caller plans to change the pixels
101 @return the device's bitmap
102 */
103 const SkBitmap& accessBitmap(bool changePixels);
104
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000105 /**
bsalomon@google.comae0fb052011-11-10 22:34:56 +0000106 * DEPRECATED: This will be made protected once WebKit stops using it.
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000107 * Instead use Canvas' writePixels method.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000108 *
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000109 * Similar to draw sprite, this method will copy the pixels in bitmap onto
110 * the device, with the top/left corner specified by (x, y). The pixel
111 * values in the device are completely replaced: there is no blending.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000112 *
113 * Currently if bitmap is backed by a texture this is a no-op. This may be
114 * relaxed in the future.
115 *
116 * If the bitmap has config kARGB_8888_Config then the config8888 param
117 * will determines how the pixel valuess are intepreted. If the bitmap is
118 * not kARGB_8888_Config then this parameter is ignored.
bsalomon@google.com398109c2011-04-14 18:40:27 +0000119 */
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000120 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000121 SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000122
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000123 /**
124 * Return the device's associated gpu render target, or NULL.
reed@android.comf2b98d62010-12-20 18:26:13 +0000125 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000126 virtual GrRenderTarget* accessRenderTarget() = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000127
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000128
129 /**
130 * Return the device's origin: its offset in device coordinates from
131 * the default origin in its canvas' matrix/clip
132 */
133 const SkIPoint& getOrigin() const { return fOrigin; }
134
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000135 /**
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000136 * onAttachToCanvas is invoked whenever a device is installed in a canvas
137 * (i.e., setDevice, saveLayer (for the new device created by the save),
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000138 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000139 * devices to prepare for drawing (e.g., locking their pixels, etc.)
140 */
sugoi@google.come0e385c2013-03-11 18:50:03 +0000141 virtual void onAttachToCanvas(SkCanvas*) {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000142 SkASSERT(!fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000143 this->lockPixels();
144#ifdef SK_DEBUG
145 fAttachedToCanvas = true;
146#endif
147 };
148
149 /**
150 * onDetachFromCanvas notifies a device that it will no longer be drawn to.
151 * It gives the device a chance to clean up (e.g., unlock its pixels). It
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000152 * is invoked from setDevice (for the displaced device), restore and
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000153 * possibly from SkCanvas' dtor.
154 */
155 virtual void onDetachFromCanvas() {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000156 SkASSERT(fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000157 this->unlockPixels();
158#ifdef SK_DEBUG
159 fAttachedToCanvas = false;
160#endif
161 };
162
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000163protected:
164 enum Usage {
165 kGeneral_Usage,
tomhudson@google.com1f902872012-06-01 13:15:47 +0000166 kSaveLayer_Usage // <! internal use only
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000167 };
168
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000169 struct TextFlags {
170 uint32_t fFlags; // SkPaint::getFlags()
171 SkPaint::Hinting fHinting;
172 };
173
174 /**
175 * Device may filter the text flags for drawing text here. If it wants to
176 * make a change to the specified values, it should write them into the
177 * textflags parameter (output) and return true. If the paint is fine as
178 * is, then ignore the textflags parameter and return false.
179 *
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000180 * The baseclass SkBaseDevice filters based on its depth and blitters.
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000181 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000182 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000183
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000184 /**
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000185 *
186 * DEPRECATED: This will be removed in a future change. Device subclasses
187 * should use the matrix and clip from the SkDraw passed to draw functions.
188 *
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000189 * Called with the correct matrix and clip before this device is drawn
190 * to using those settings. If your subclass overrides this, be sure to
191 * call through to the base class as well.
192 *
193 * The clipstack is another view of the clip. It records the actual
194 * geometry that went into building the region. It is present for devices
195 * that want to parse it, but is not required: the region is a complete
196 * picture of the current clip. (i.e. if you regionize all of the geometry
197 * in the clipstack, you will arrive at an equivalent region to the one
198 * passed in).
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000199 */
200 virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000201 const SkClipStack&) {};
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000202
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000203 /** Clears the entire device to the specified color (including alpha).
204 * Ignores the clip.
reed@android.comf2b98d62010-12-20 18:26:13 +0000205 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000206 virtual void clear(SkColor color) = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000207
208 /**
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000209 * Deprecated name for clear.
reed@android.comf2b98d62010-12-20 18:26:13 +0000210 */
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000211 void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000212
213 /** These are called inside the per-device-layer loop for each draw call.
214 When these are called, we have already applied any saveLayer operations,
215 and are handling any looping from the paint, and any effects from the
216 DrawFilter.
217 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000218 virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000219 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000220 const SkPoint[], const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000221 virtual void drawRect(const SkDraw&, const SkRect& r,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000222 const SkPaint& paint) = 0;
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000223 virtual void drawOval(const SkDraw&, const SkRect& oval,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000224 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000225 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000226 const SkPaint& paint) = 0;
commit-bot@chromium.orgf2bfd542013-04-25 15:27:00 +0000227
reed@google.com7ff8d812011-03-25 15:08:16 +0000228 /**
229 * If pathIsMutable, then the implementation is allowed to cast path to a
230 * non-const pointer and modify it in place (as an optimization). Canvas
231 * may do this to implement helpers such as drawOval, by placing a temp
232 * path on the stack to hold the representation of the oval.
233 *
234 * If prePathMatrix is not null, it should logically be applied before any
235 * stroking or other effects. If there are no effects on the paint that
236 * affect the geometry/rasterization, then the pre matrix can just be
237 * pre-concated with the current matrix.
238 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239 virtual void drawPath(const SkDraw&, const SkPath& path,
reed@android.comf2b98d62010-12-20 18:26:13 +0000240 const SkPaint& paint,
241 const SkMatrix* prePathMatrix = NULL,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000242 bool pathIsMutable = false) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000243 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000244 const SkMatrix& matrix, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000245 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000246 int x, int y, const SkPaint& paint) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000247
248 /**
249 * The default impl. will create a bitmap-shader from the bitmap,
250 * and call drawRect with it.
251 */
252 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
253 const SkRect* srcOrNull, const SkRect& dst,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +0000254 const SkPaint& paint,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000255 SkCanvas::DrawBitmapRectFlags flags) = 0;
reed@google.com33535f32012-09-25 15:37:50 +0000256
bungeman@google.com52c748b2011-08-22 21:30:43 +0000257 /**
258 * Does not handle text decoration.
259 * Decorations (underline and stike-thru) will be handled by SkCanvas.
260 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000261 virtual void drawText(const SkDraw&, const void* text, size_t len,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000262 SkScalar x, SkScalar y, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000263 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
264 const SkScalar pos[], SkScalar constY,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000265 int scalarsPerPos, const SkPaint& paint) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000266 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
267 const SkPath& path, const SkMatrix* matrix,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000268 const SkPaint& paint) = 0;
djsollen@google.com56c69772011-11-08 19:00:26 +0000269#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000270 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
271 const SkPoint pos[], const SkPaint& paint,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000272 const SkPath& path, const SkMatrix* matrix) = 0;
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000273#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000274 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
275 const SkPoint verts[], const SkPoint texs[],
276 const SkColor colors[], SkXfermode* xmode,
277 const uint16_t indices[], int indexCount,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000278 const SkPaint& paint) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000279 /** The SkDevice passed will be an SkDevice which was returned by a call to
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000280 onCreateCompatibleDevice on this device with kSaveLayer_Usage.
281 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000282 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
283 const SkPaint&) = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000284
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000285 /**
286 * On success (returns true), copy the device pixels into the bitmap.
287 * On failure, the bitmap parameter is left unchanged and false is
288 * returned.
289 *
290 * The device's pixels are converted to the bitmap's config. The only
291 * supported config is kARGB_8888_Config, though this is likely to be
292 * relaxed in the future. The meaning of config kARGB_8888_Config is
293 * modified by the enum param config8888. The default value interprets
294 * kARGB_8888_Config as SkPMColor
295 *
296 * If the bitmap has pixels already allocated, the device pixels will be
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000297 * written there. If not, bitmap->allocPixels() will be called
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000298 * automatically. If the bitmap is backed by a texture readPixels will
299 * fail.
300 *
301 * The actual pixels written is the intersection of the device's bounds,
302 * and the rectangle formed by the bitmap's width,height and the specified
303 * x,y. If bitmap pixels extend outside of that intersection, they will not
304 * be modified.
305 *
306 * Other failure conditions:
307 * * If the device is not a raster device (e.g. PDF) then readPixels will
308 * fail.
309 * * If bitmap is texture-backed then readPixels will fail. (This may be
310 * relaxed in the future.)
311 */
312 bool readPixels(SkBitmap* bitmap,
313 int x, int y,
314 SkCanvas::Config8888 config8888);
315
reed@google.com3636ed52011-01-25 23:50:57 +0000316 ///////////////////////////////////////////////////////////////////////////
317
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000318 /** Update as needed the pixel value in the bitmap, so that the caller can
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000319 access the pixels directly.
320 @return The device contents as a bitmap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000321 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000322 virtual const SkBitmap& onAccessBitmap() = 0;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000323
bsalomon@google.comc6980972011-11-02 19:57:21 +0000324 /**
325 * Implements readPixels API. The caller will ensure that:
326 * 1. bitmap has pixel config kARGB_8888_Config.
327 * 2. bitmap has pixels.
328 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
329 * contained in the device bounds.
bsalomon@google.comc6980972011-11-02 19:57:21 +0000330 */
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000331 virtual bool onReadPixels(const SkBitmap& bitmap,
332 int x, int y,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000333 SkCanvas::Config8888 config8888) = 0;
reed@android.comf2b98d62010-12-20 18:26:13 +0000334
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000335 /** Called when this device is installed into a Canvas. Balanaced by a call
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000336 to unlockPixels() when the device is removed from a Canvas.
337 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000338 virtual void lockPixels() = 0;
339 virtual void unlockPixels() = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000340
reed@google.com76dd2772012-01-05 21:15:07 +0000341 /**
reed@google.comb55deeb2012-01-06 14:43:09 +0000342 * Returns true if the device allows processing of this imagefilter. If
343 * false is returned, then the filter is ignored. This may happen for
344 * some subclasses that do not support pixel manipulations after drawing
345 * has occurred (e.g. printing). The default implementation returns true.
346 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000347 virtual bool allowImageFilter(SkImageFilter*) = 0;
reed@google.comb55deeb2012-01-06 14:43:09 +0000348
349 /**
reed@google.com8926b162012-03-23 15:36:36 +0000350 * Override and return true for filters that the device can handle
351 * intrinsically. Doing so means that SkCanvas will pass-through this
352 * filter to drawSprite and drawDevice (and potentially filterImage).
353 * Returning false means the SkCanvas will have apply the filter itself,
354 * and just pass the resulting image to the device.
reed@google.com76dd2772012-01-05 21:15:07 +0000355 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000356 virtual bool canHandleImageFilter(SkImageFilter*) = 0;
reed@google.com8926b162012-03-23 15:36:36 +0000357
358 /**
359 * Related (but not required) to canHandleImageFilter, this method returns
360 * true if the device could apply the filter to the src bitmap and return
361 * the result (and updates offset as needed).
362 * If the device does not recognize or support this filter,
363 * it just returns false and leaves result and offset unchanged.
364 */
365 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&,
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000366 SkBitmap* result, SkIPoint* offset) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000367
368 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
369 // either is identical to kNative_Premul_Config8888. Otherwise, -1.
370 static const SkCanvas::Config8888 kPMColorAlias;
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000371
reed@android.com8a1c16f2008-12-17 15:59:43 +0000372private:
reed@google.com6f8f2922011-03-04 22:27:10 +0000373 friend class SkCanvas;
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000374 friend struct DeviceCM; //for setMatrixClip
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000375 friend class SkDraw;
376 friend class SkDrawIter;
377 friend class SkDeviceFilteredPaint;
senorblanco@chromium.org9c397442012-09-27 21:57:45 +0000378 friend class SkDeviceImageFilterProxy;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000379
reed@google.com97af1a62012-08-28 12:19:02 +0000380 friend class SkSurface_Raster;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000381
reed@google.com97af1a62012-08-28 12:19:02 +0000382 // used to change the backend's pixels (and possibly config/rowbytes)
383 // but cannot change the width/height, so there should be no change to
384 // any clip information.
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000385 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0;
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000386
387 // just called by SkCanvas when built as a layer
388 void setOrigin(int x, int y) { fOrigin.set(x, y); }
389 // just called by SkCanvas for saveLayer
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000390 SkBaseDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
391 int width, int height,
392 bool isOpaque);
reed@google.com6f8f2922011-03-04 22:27:10 +0000393
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000394 /**
395 * Subclasses should override this to implement createCompatibleDevice.
396 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000397 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
398 int width, int height,
399 bool isOpaque,
400 Usage usage) = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000401
402 /** Causes any deferred drawing to the device to be completed.
403 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000404 virtual void flush() = 0;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000405
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000406 SkIPoint fOrigin;
407 SkMetaData* fMetaData;
408 /**
409 * Leaky properties are those which the device should be applying but it isn't.
410 * These properties will be applied by the draw, when and as it can.
411 * If the device does handle a property, that property should be set to the identity value
412 * for that property, effectively making it non-leaky.
413 */
414 SkDeviceProperties fLeakyProperties;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000415
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000416#ifdef SK_DEBUG
417 bool fAttachedToCanvas;
418#endif
419
420 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000421};
422
reed@android.com8a1c16f2008-12-17 15:59:43 +0000423#endif