blob: 81bbf43cb490d6211f74b089be0aee6db7848e55 [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
bungeman@google.com88edf1e2011-08-08 19:41:56 +000026// This is an opaque class, not interpreted by skia
bsalomon@google.comd9f826c2011-07-18 15:25:04 +000027class SkGpuRenderTarget;
28
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000029class SK_API SkDevice : public SkRefCnt {
reed@android.com8a1c16f2008-12-17 15:59:43 +000030public:
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000031 SK_DECLARE_INST_COUNT(SkDevice)
32
reed@google.comaf951c92011-06-16 19:10:39 +000033 /**
34 * Construct a new device with the specified bitmap as its backend. It is
35 * valid for the bitmap to have no pixels associated with it. In that case,
36 * any drawing to this device will have no effect.
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 */
reed@google.comaf951c92011-06-16 19:10:39 +000038 SkDevice(const SkBitmap& bitmap);
39
40 /**
bungeman@google.com532470f2013-01-22 19:25:14 +000041 * Construct a new device with the specified bitmap as its backend. It is
42 * valid for the bitmap to have no pixels associated with it. In that case,
43 * any drawing to this device will have no effect.
44 */
45 SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties);
46
47 /**
reed@google.comaf951c92011-06-16 19:10:39 +000048 * Create a new raster device and have the pixels be automatically
49 * allocated. The rowBytes of the device will be computed automatically
50 * based on the config and the width.
51 *
52 * @param config The desired config for the pixels. If the request cannot
53 * be met, the closest matching support config will be used.
54 * @param width width (in pixels) of the device
55 * @param height height (in pixels) of the device
56 * @param isOpaque Set to true if it is known that all of the pixels will
57 * be drawn to opaquely. Used as an accelerator when drawing
58 * these pixels to another device.
59 */
60 SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false);
61
bungeman@google.com532470f2013-01-22 19:25:14 +000062 /**
63 * Create a new raster device and have the pixels be automatically
64 * allocated. The rowBytes of the device will be computed automatically
65 * based on the config and the width.
66 *
67 * @param config The desired config for the pixels. If the request cannot
68 * be met, the closest matching support config will be used.
69 * @param width width (in pixels) of the device
70 * @param height height (in pixels) of the device
71 * @param isOpaque Set to true if it is known that all of the pixels will
72 * be drawn to opaquely. Used as an accelerator when drawing
73 * these pixels to another device.
74 * @param deviceProperties Properties which affect compositing.
75 */
76 SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
77 const SkDeviceProperties& deviceProperties);
78
reed@google.coma7d94852011-03-30 21:23:07 +000079 virtual ~SkDevice();
reed@android.com8a1c16f2008-12-17 15:59:43 +000080
mike@reedtribe.orgea4ac972011-04-26 11:48:33 +000081 /**
reed@google.com2d54d062011-06-21 12:19:28 +000082 * Creates a device that is of the same type as this device (e.g. SW-raster,
83 * GPU, or PDF). The backing store for this device is created automatically
84 * (e.g. offscreen pixels or FBO or whatever is appropriate).
bsalomon@google.come97f0852011-06-17 13:10:25 +000085 *
reed@google.com2d54d062011-06-21 12:19:28 +000086 * @param width width of the device to create
87 * @param height height of the device to create
88 * @param isOpaque performance hint, set to true if you know that you will
89 * draw into this device such that all of the pixels will
90 * be opaque.
bsalomon@google.come97f0852011-06-17 13:10:25 +000091 */
vandebo@chromium.org74b46192012-01-28 01:45:11 +000092 SkDevice* createCompatibleDevice(SkBitmap::Config config,
bsalomon@google.come97f0852011-06-17 13:10:25 +000093 int width, int height,
94 bool isOpaque);
95
bungeman@google.com88edf1e2011-08-08 19:41:56 +000096 SkMetaData& getMetaData();
97
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +000098 enum Capabilities {
99 kGL_Capability = 0x1, //!< mask indicating GL support
100 kVector_Capability = 0x2, //!< mask indicating a vector representation
101 kAll_Capabilities = 0x3
102 };
tomhudson@google.com8a0b0292011-09-13 14:41:06 +0000103 virtual uint32_t getDeviceCapabilities() { return 0; }
vandebo@chromium.org35fc62b2010-10-26 19:47:30 +0000104
reed@android.com8a1c16f2008-12-17 15:59:43 +0000105 /** Return the width of the device (in pixels).
106 */
tomhudson@google.com8a0b0292011-09-13 14:41:06 +0000107 virtual int width() const { return fBitmap.width(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000108 /** Return the height of the device (in pixels).
109 */
tomhudson@google.com8a0b0292011-09-13 14:41:06 +0000110 virtual int height() const { return fBitmap.height(); }
reed@google.com6f8f2922011-03-04 22:27:10 +0000111
bungeman@google.com532470f2013-01-22 19:25:14 +0000112 /** Return the image properties of the device. */
113 virtual const SkDeviceProperties& getDeviceProperties() const {
114 //Currently, all the properties are leaky.
115 return fLeakyProperties;
116 }
117
reed@google.comd51bfa02011-08-30 15:56:11 +0000118 /**
119 * Return the bounds of the device in the coordinate space of the root
120 * canvas. The root device will have its top-left at 0,0, but other devices
121 * such as those associated with saveLayer may have a non-zero origin.
122 */
123 void getGlobalBounds(SkIRect* bounds) const;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000124
reed@android.com8a1c16f2008-12-17 15:59:43 +0000125 /** Returns true if the device's bitmap's config treats every pixels as
126 implicitly opaque.
127 */
128 bool isOpaque() const { return fBitmap.isOpaque(); }
reed@google.com3dd42b32011-02-07 22:44:43 +0000129
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000130 /** Return the bitmap config of the device's pixels
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131 */
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000132 SkBitmap::Config config() const { return fBitmap.getConfig(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000133
134 /** Return the bitmap associated with this device. Call this each time you need
135 to access the bitmap, as it notifies the subclass to perform any flushing
136 etc. before you examine the pixels.
137 @param changePixels set to true if the caller plans to change the pixels
138 @return the device's bitmap
139 */
140 const SkBitmap& accessBitmap(bool changePixels);
141
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000142 /**
bsalomon@google.comae0fb052011-11-10 22:34:56 +0000143 * DEPRECATED: This will be made protected once WebKit stops using it.
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000144 * Instead use Canvas' writePixels method.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000145 *
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000146 * Similar to draw sprite, this method will copy the pixels in bitmap onto
147 * the device, with the top/left corner specified by (x, y). The pixel
148 * values in the device are completely replaced: there is no blending.
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000149 *
150 * Currently if bitmap is backed by a texture this is a no-op. This may be
151 * relaxed in the future.
152 *
153 * If the bitmap has config kARGB_8888_Config then the config8888 param
154 * will determines how the pixel valuess are intepreted. If the bitmap is
155 * not kARGB_8888_Config then this parameter is ignored.
bsalomon@google.com398109c2011-04-14 18:40:27 +0000156 */
bsalomon@google.comd58a1cd2011-11-10 20:57:43 +0000157 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
bsalomon@google.comae0fb052011-11-10 22:34:56 +0000158 SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000159
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000160 /**
161 * Return the device's associated gpu render target, or NULL.
reed@android.comf2b98d62010-12-20 18:26:13 +0000162 */
bsalomon@google.comd9f826c2011-07-18 15:25:04 +0000163 virtual SkGpuRenderTarget* accessRenderTarget() { return NULL; }
reed@android.comf2b98d62010-12-20 18:26:13 +0000164
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000165
166 /**
167 * Return the device's origin: its offset in device coordinates from
168 * the default origin in its canvas' matrix/clip
169 */
170 const SkIPoint& getOrigin() const { return fOrigin; }
171
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000172 /**
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000173 * onAttachToCanvas is invoked whenever a device is installed in a canvas
174 * (i.e., setDevice, saveLayer (for the new device created by the save),
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000175 * and SkCanvas' SkDevice & SkBitmap -taking ctors). It allows the
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000176 * devices to prepare for drawing (e.g., locking their pixels, etc.)
177 */
178 virtual void onAttachToCanvas(SkCanvas* canvas) {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000179 SkASSERT(!fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000180 this->lockPixels();
181#ifdef SK_DEBUG
182 fAttachedToCanvas = true;
183#endif
184 };
185
186 /**
187 * onDetachFromCanvas notifies a device that it will no longer be drawn to.
188 * It gives the device a chance to clean up (e.g., unlock its pixels). It
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000189 * is invoked from setDevice (for the displaced device), restore and
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000190 * possibly from SkCanvas' dtor.
191 */
192 virtual void onDetachFromCanvas() {
bsalomon@google.com405d0f42012-08-29 21:26:13 +0000193 SkASSERT(fAttachedToCanvas);
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000194 this->unlockPixels();
195#ifdef SK_DEBUG
196 fAttachedToCanvas = false;
197#endif
198 };
199
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000200protected:
201 enum Usage {
202 kGeneral_Usage,
tomhudson@google.com1f902872012-06-01 13:15:47 +0000203 kSaveLayer_Usage // <! internal use only
caryclark@google.comd53f7c22012-01-05 17:05:05 +0000204 };
205
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000206 struct TextFlags {
207 uint32_t fFlags; // SkPaint::getFlags()
208 SkPaint::Hinting fHinting;
209 };
210
211 /**
212 * Device may filter the text flags for drawing text here. If it wants to
213 * make a change to the specified values, it should write them into the
214 * textflags parameter (output) and return true. If the paint is fine as
215 * is, then ignore the textflags parameter and return false.
216 *
217 * The baseclass SkDevice filters based on its depth and blitters.
218 */
219 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
220
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000221 /**
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000222 *
223 * DEPRECATED: This will be removed in a future change. Device subclasses
224 * should use the matrix and clip from the SkDraw passed to draw functions.
225 *
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000226 * Called with the correct matrix and clip before this device is drawn
227 * to using those settings. If your subclass overrides this, be sure to
228 * call through to the base class as well.
229 *
230 * The clipstack is another view of the clip. It records the actual
231 * geometry that went into building the region. It is present for devices
232 * that want to parse it, but is not required: the region is a complete
233 * picture of the current clip. (i.e. if you regionize all of the geometry
234 * in the clipstack, you will arrive at an equivalent region to the one
235 * passed in).
bsalomon@google.coma6926b12012-10-10 15:25:50 +0000236 */
237 virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
skia.committer@gmail.comfc843592012-10-11 02:01:14 +0000238 const SkClipStack&);
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000239
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000240 /** Clears the entire device to the specified color (including alpha).
241 * Ignores the clip.
reed@android.comf2b98d62010-12-20 18:26:13 +0000242 */
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000243 virtual void clear(SkColor color);
reed@android.comf2b98d62010-12-20 18:26:13 +0000244
245 /**
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000246 * Deprecated name for clear.
reed@android.comf2b98d62010-12-20 18:26:13 +0000247 */
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000248 void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000249
250 /** These are called inside the per-device-layer loop for each draw call.
251 When these are called, we have already applied any saveLayer operations,
252 and are handling any looping from the paint, and any effects from the
253 DrawFilter.
254 */
255 virtual void drawPaint(const SkDraw&, const SkPaint& paint);
256 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
257 const SkPoint[], const SkPaint& paint);
258 virtual void drawRect(const SkDraw&, const SkRect& r,
259 const SkPaint& paint);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000260 virtual void drawOval(const SkDraw&, const SkRect& oval,
261 const SkPaint& paint);
reed@google.com7ff8d812011-03-25 15:08:16 +0000262 /**
263 * If pathIsMutable, then the implementation is allowed to cast path to a
264 * non-const pointer and modify it in place (as an optimization). Canvas
265 * may do this to implement helpers such as drawOval, by placing a temp
266 * path on the stack to hold the representation of the oval.
267 *
268 * If prePathMatrix is not null, it should logically be applied before any
269 * stroking or other effects. If there are no effects on the paint that
270 * affect the geometry/rasterization, then the pre matrix can just be
271 * pre-concated with the current matrix.
272 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000273 virtual void drawPath(const SkDraw&, const SkPath& path,
reed@android.comf2b98d62010-12-20 18:26:13 +0000274 const SkPaint& paint,
275 const SkMatrix* prePathMatrix = NULL,
276 bool pathIsMutable = false);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000277 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
reed@android.comf2b98d62010-12-20 18:26:13 +0000278 const SkIRect* srcRectOrNull,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000279 const SkMatrix& matrix, const SkPaint& paint);
280 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
281 int x, int y, const SkPaint& paint);
reed@google.com33535f32012-09-25 15:37:50 +0000282
283 /**
284 * The default impl. will create a bitmap-shader from the bitmap,
285 * and call drawRect with it.
286 */
287 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
288 const SkRect* srcOrNull, const SkRect& dst,
289 const SkPaint& paint);
290
bungeman@google.com52c748b2011-08-22 21:30:43 +0000291 /**
292 * Does not handle text decoration.
293 * Decorations (underline and stike-thru) will be handled by SkCanvas.
294 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000295 virtual void drawText(const SkDraw&, const void* text, size_t len,
296 SkScalar x, SkScalar y, const SkPaint& paint);
297 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
298 const SkScalar pos[], SkScalar constY,
299 int scalarsPerPos, const SkPaint& paint);
300 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
301 const SkPath& path, const SkMatrix* matrix,
302 const SkPaint& paint);
djsollen@google.com56c69772011-11-08 19:00:26 +0000303#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000304 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
305 const SkPoint pos[], const SkPaint& paint,
306 const SkPath& path, const SkMatrix* matrix);
307#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000308 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
309 const SkPoint verts[], const SkPoint texs[],
310 const SkColor colors[], SkXfermode* xmode,
311 const uint16_t indices[], int indexCount,
312 const SkPaint& paint);
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000313 /** The SkDevice passed will be an SkDevice which was returned by a call to
314 onCreateCompatibleDevice on this device with kSaveLayer_Usage.
315 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000316 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
317 const SkPaint&);
318
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000319 /**
320 * On success (returns true), copy the device pixels into the bitmap.
321 * On failure, the bitmap parameter is left unchanged and false is
322 * returned.
323 *
324 * The device's pixels are converted to the bitmap's config. The only
325 * supported config is kARGB_8888_Config, though this is likely to be
326 * relaxed in the future. The meaning of config kARGB_8888_Config is
327 * modified by the enum param config8888. The default value interprets
328 * kARGB_8888_Config as SkPMColor
329 *
330 * If the bitmap has pixels already allocated, the device pixels will be
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000331 * written there. If not, bitmap->allocPixels() will be called
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000332 * automatically. If the bitmap is backed by a texture readPixels will
333 * fail.
334 *
335 * The actual pixels written is the intersection of the device's bounds,
336 * and the rectangle formed by the bitmap's width,height and the specified
337 * x,y. If bitmap pixels extend outside of that intersection, they will not
338 * be modified.
339 *
340 * Other failure conditions:
341 * * If the device is not a raster device (e.g. PDF) then readPixels will
342 * fail.
343 * * If bitmap is texture-backed then readPixels will fail. (This may be
344 * relaxed in the future.)
345 */
346 bool readPixels(SkBitmap* bitmap,
347 int x, int y,
348 SkCanvas::Config8888 config8888);
349
reed@google.com3636ed52011-01-25 23:50:57 +0000350 ///////////////////////////////////////////////////////////////////////////
351
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000352 /** Update as needed the pixel value in the bitmap, so that the caller can
353 access the pixels directly. Note: only the pixels field should be
354 altered. The config/width/height/rowbytes must remain unchanged.
355 @param bitmap The device's bitmap
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000356 @return Echo the bitmap parameter, or an alternate (shadow) bitmap
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000357 maintained by the subclass.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000358 */
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000359 virtual const SkBitmap& onAccessBitmap(SkBitmap*);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000360
reed@android.comf2b98d62010-12-20 18:26:13 +0000361 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
362 // just for subclasses, to assign a custom pixelref
363 SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) {
364 fBitmap.setPixelRef(pr, offset);
365 return pr;
366 }
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000367
bsalomon@google.comc6980972011-11-02 19:57:21 +0000368 /**
369 * Implements readPixels API. The caller will ensure that:
370 * 1. bitmap has pixel config kARGB_8888_Config.
371 * 2. bitmap has pixels.
372 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
373 * contained in the device bounds.
bsalomon@google.comc6980972011-11-02 19:57:21 +0000374 */
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000375 virtual bool onReadPixels(const SkBitmap& bitmap,
376 int x, int y,
377 SkCanvas::Config8888 config8888);
reed@android.comf2b98d62010-12-20 18:26:13 +0000378
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000379 /** Called when this device is installed into a Canvas. Balanaced by a call
380 to unlockPixels() when the device is removed from a Canvas.
381 */
382 virtual void lockPixels();
383 virtual void unlockPixels();
384
reed@google.com76dd2772012-01-05 21:15:07 +0000385 /**
reed@google.comb55deeb2012-01-06 14:43:09 +0000386 * Returns true if the device allows processing of this imagefilter. If
387 * false is returned, then the filter is ignored. This may happen for
388 * some subclasses that do not support pixel manipulations after drawing
389 * has occurred (e.g. printing). The default implementation returns true.
390 */
391 virtual bool allowImageFilter(SkImageFilter*);
392
393 /**
reed@google.com8926b162012-03-23 15:36:36 +0000394 * Override and return true for filters that the device can handle
395 * intrinsically. Doing so means that SkCanvas will pass-through this
396 * filter to drawSprite and drawDevice (and potentially filterImage).
397 * Returning false means the SkCanvas will have apply the filter itself,
398 * and just pass the resulting image to the device.
reed@google.com76dd2772012-01-05 21:15:07 +0000399 */
reed@google.com8926b162012-03-23 15:36:36 +0000400 virtual bool canHandleImageFilter(SkImageFilter*);
401
402 /**
403 * Related (but not required) to canHandleImageFilter, this method returns
404 * true if the device could apply the filter to the src bitmap and return
405 * the result (and updates offset as needed).
406 * If the device does not recognize or support this filter,
407 * it just returns false and leaves result and offset unchanged.
408 */
409 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&,
reed@google.com76dd2772012-01-05 21:15:07 +0000410 SkBitmap* result, SkIPoint* offset);
411
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000412 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
bsalomon@google.com6850eab2011-11-03 20:29:47 +0000413 // either is identical to kNative_Premul_Config8888. Otherwise, -1.
414 static const SkCanvas::Config8888 kPMColorAlias;
415
reed@android.com8a1c16f2008-12-17 15:59:43 +0000416private:
reed@google.com6f8f2922011-03-04 22:27:10 +0000417 friend class SkCanvas;
robertphillips@google.com3fffb2e2012-10-09 22:30:18 +0000418 friend struct DeviceCM; //for setMatrixClip
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000419 friend class SkDraw;
420 friend class SkDrawIter;
421 friend class SkDeviceFilteredPaint;
senorblanco@chromium.org9c397442012-09-27 21:57:45 +0000422 friend class SkDeviceImageFilterProxy;
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000423
reed@google.com97af1a62012-08-28 12:19:02 +0000424 friend class SkSurface_Raster;
425 // used to change the backend's pixels (and possibly config/rowbytes)
426 // but cannot change the width/height, so there should be no change to
427 // any clip information.
428 void replaceBitmapBackendForRasterSurface(const SkBitmap&);
429
vandebo@chromium.org5676b4a2011-10-03 19:03:48 +0000430 // just called by SkCanvas when built as a layer
431 void setOrigin(int x, int y) { fOrigin.set(x, y); }
bsalomon@google.come97f0852011-06-17 13:10:25 +0000432 // just called by SkCanvas for saveLayer
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000433 SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
bsalomon@google.come97f0852011-06-17 13:10:25 +0000434 int width, int height,
435 bool isOpaque);
reed@google.com6f8f2922011-03-04 22:27:10 +0000436
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000437 /**
438 * Subclasses should override this to implement createCompatibleDevice.
439 */
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000440 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
441 int width, int height,
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000442 bool isOpaque,
443 Usage usage);
444
445 /** Causes any deferred drawing to the device to be completed.
446 */
tomhudson@google.com8a0b0292011-09-13 14:41:06 +0000447 virtual void flush() {}
bungeman@google.com88edf1e2011-08-08 19:41:56 +0000448
reed@google.com3636ed52011-01-25 23:50:57 +0000449 SkBitmap fBitmap;
reed@google.com6f8f2922011-03-04 22:27:10 +0000450 SkIPoint fOrigin;
reed@google.coma7d94852011-03-30 21:23:07 +0000451 SkMetaData* fMetaData;
bungeman@google.com532470f2013-01-22 19:25:14 +0000452 /**
453 * Leaky properties are those which the device should be applying but it isn't.
454 * These properties will be applied by the draw, when and as it can.
455 * If the device does handle a property, that property should be set to the identity value
456 * for that property, effectively making it non-leaky.
457 */
458 SkDeviceProperties fLeakyProperties;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000459
robertphillips@google.com40a1ae42012-07-13 15:36:15 +0000460#ifdef SK_DEBUG
461 bool fAttachedToCanvas;
462#endif
463
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000464 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000465};
466
467#endif