3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef SkBitmapDevice_DEFINED
10 #define SkBitmapDevice_DEFINED
14 ///////////////////////////////////////////////////////////////////////////////
15 class SK_API SkBitmapDevice : public SkBaseDevice {
17 SK_DECLARE_INST_COUNT(SkBitmapDevice)
20 * Construct a new device with the specified bitmap as its backend. It is
21 * valid for the bitmap to have no pixels associated with it. In that case,
22 * any drawing to this device will have no effect.
24 SkBitmapDevice(const SkBitmap& bitmap);
27 * Construct a new device with the specified bitmap as its backend. It is
28 * valid for the bitmap to have no pixels associated with it. In that case,
29 * any drawing to this device will have no effect.
31 SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties);
32 static SkBitmapDevice* Create(const SkImageInfo&, const SkDeviceProperties*);
34 static SkBitmapDevice* Create(const SkImageInfo& info) {
35 return Create(info, NULL);
38 SkImageInfo imageInfo() const override;
41 bool onShouldDisableLCD(const SkPaint&) const override;
43 /** These are called inside the per-device-layer loop for each draw call.
44 When these are called, we have already applied any saveLayer operations,
45 and are handling any looping from the paint, and any effects from the
48 void drawPaint(const SkDraw&, const SkPaint& paint) override;
49 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
50 const SkPoint[], const SkPaint& paint) override;
51 virtual void drawRect(const SkDraw&, const SkRect& r,
52 const SkPaint& paint) override;
53 virtual void drawOval(const SkDraw&, const SkRect& oval,
54 const SkPaint& paint) override;
55 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
56 const SkPaint& paint) override;
59 * If pathIsMutable, then the implementation is allowed to cast path to a
60 * non-const pointer and modify it in place (as an optimization). Canvas
61 * may do this to implement helpers such as drawOval, by placing a temp
62 * path on the stack to hold the representation of the oval.
64 * If prePathMatrix is not null, it should logically be applied before any
65 * stroking or other effects. If there are no effects on the paint that
66 * affect the geometry/rasterization, then the pre matrix can just be
67 * pre-concated with the current matrix.
69 virtual void drawPath(const SkDraw&, const SkPath& path,
71 const SkMatrix* prePathMatrix = NULL,
72 bool pathIsMutable = false) override;
73 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
74 const SkMatrix& matrix, const SkPaint& paint) override;
75 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
76 int x, int y, const SkPaint& paint) override;
79 * The default impl. will create a bitmap-shader from the bitmap,
80 * and call drawRect with it.
82 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
83 const SkRect* srcOrNull, const SkRect& dst,
85 SkCanvas::DrawBitmapRectFlags flags) override;
88 * Does not handle text decoration.
89 * Decorations (underline and stike-thru) will be handled by SkCanvas.
91 virtual void drawText(const SkDraw&, const void* text, size_t len,
92 SkScalar x, SkScalar y, const SkPaint& paint) override;
93 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
94 const SkScalar pos[], int scalarsPerPos,
95 const SkPoint& offset, const SkPaint& paint) override;
96 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
97 const SkPoint verts[], const SkPoint texs[],
98 const SkColor colors[], SkXfermode* xmode,
99 const uint16_t indices[], int indexCount,
100 const SkPaint& paint) override;
101 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
103 ///////////////////////////////////////////////////////////////////////////
105 /** Update as needed the pixel value in the bitmap, so that the caller can
106 access the pixels directly. Note: only the pixels field should be
107 altered. The config/width/height/rowbytes must remain unchanged.
108 @return the device contents as a bitmap
110 const SkBitmap& onAccessBitmap() override;
112 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
113 // just for subclasses, to assign a custom pixelref
114 SkPixelRef* setPixelRef(SkPixelRef* pr) {
115 fBitmap.setPixelRef(pr);
119 bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
120 bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
121 void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) override;
123 /** Called when this device is installed into a Canvas. Balanced by a call
124 to unlockPixels() when the device is removed from a Canvas.
126 void lockPixels() override;
127 void unlockPixels() override;
130 friend class SkCanvas;
131 friend struct DeviceCM; //for setMatrixClip
133 friend class SkDrawIter;
134 friend class SkDeviceFilteredPaint;
135 friend class SkDeviceImageFilterProxy;
137 friend class SkSurface_Raster;
139 // used to change the backend's pixels (and possibly config/rowbytes)
140 // but cannot change the width/height, so there should be no change to
141 // any clip information.
142 void replaceBitmapBackendForRasterSurface(const SkBitmap&) override;
144 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
146 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override;
147 const void* peekPixels(SkImageInfo*, size_t* rowBytes) override;
149 SkImageFilter::Cache* getImageFilterCache() override;
153 typedef SkBaseDevice INHERITED;
156 #endif // SkBitmapDevice_DEFINED