2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkBitmapDevice_DEFINED
9 #define SkBitmapDevice_DEFINED
11 #include "include/core/SkBitmap.h"
12 #include "include/core/SkCanvas.h"
13 #include "include/core/SkColor.h"
14 #include "include/core/SkImageInfo.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkSize.h"
18 #include "src/core/SkDevice.h"
19 #include "src/core/SkGlyphRunPainter.h"
20 #include "src/core/SkRasterClip.h"
21 #include "src/core/SkRasterClipStack.h"
23 class SkImageFilterCache;
28 class SkRasterHandleAllocator;
36 ///////////////////////////////////////////////////////////////////////////////
37 class SkBitmapDevice : public SkBaseDevice {
40 * Construct a new device with the specified bitmap as its backend. It is
41 * valid for the bitmap to have no pixels associated with it. In that case,
42 * any drawing to this device will have no effect.
44 SkBitmapDevice(const SkBitmap& bitmap);
47 * Create a new device along with its requisite pixel memory using
48 * default SkSurfaceProps (i.e., kLegacyFontHost_InitType-style).
49 * Note: this entry point is slated for removal - no one should call it.
51 static SkBitmapDevice* Create(const SkImageInfo& info);
54 * Construct a new device with the specified bitmap as its backend. It is
55 * valid for the bitmap to have no pixels associated with it. In that case,
56 * any drawing to this device will have no effect.
58 SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps,
59 void* externalHandle = nullptr);
61 static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&,
62 SkRasterHandleAllocator* = nullptr);
65 void* getRasterHandle() const override { return fRasterHandle; }
67 /** These are called inside the per-device-layer loop for each draw call.
68 When these are called, we have already applied any saveLayer operations,
69 and are handling any looping from the paint.
71 void drawPaint(const SkPaint& paint) override;
72 void drawPoints(SkCanvas::PointMode mode, size_t count,
73 const SkPoint[], const SkPaint& paint) override;
74 void drawRect(const SkRect& r, const SkPaint& paint) override;
75 void drawOval(const SkRect& oval, const SkPaint& paint) override;
76 void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
79 * If pathIsMutable, then the implementation is allowed to cast path to a
80 * non-const pointer and modify it in place (as an optimization). Canvas
81 * may do this to implement helpers such as drawOval, by placing a temp
82 * path on the stack to hold the representation of the oval.
84 void drawPath(const SkPath&, const SkPaint&, bool pathIsMutable) override;
86 void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
87 const SkSamplingOptions&, const SkPaint&,
88 SkCanvas::SrcRectConstraint) override;
90 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
92 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
95 void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp<SkBlender>,
96 const SkPaint&) override;
98 ///////////////////////////////////////////////////////////////////////////
100 void drawDevice(SkBaseDevice*, const SkSamplingOptions&, const SkPaint&) override;
101 void drawSpecial(SkSpecialImage*, const SkMatrix&, const SkSamplingOptions&,
102 const SkPaint&) override;
104 sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
105 sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
106 sk_sp<SkSpecialImage> snapSpecial(const SkIRect&, bool = false) override;
107 void setImmutable() override { fBitmap.setImmutable(); }
109 ///////////////////////////////////////////////////////////////////////////
111 void onDrawGlyphRunList(SkCanvas*,
112 const SkGlyphRunList&,
113 const SkPaint& initialPaint,
114 const SkPaint& drawingPaint) override;
115 bool onReadPixels(const SkPixmap&, int x, int y) override;
116 bool onWritePixels(const SkPixmap&, int, int) override;
117 bool onPeekPixels(SkPixmap*) override;
118 bool onAccessPixels(SkPixmap*) override;
120 void onSave() override;
121 void onRestore() override;
122 void onClipRect(const SkRect& rect, SkClipOp, bool aa) override;
123 void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override;
124 void onClipPath(const SkPath& path, SkClipOp, bool aa) override;
125 void onClipShader(sk_sp<SkShader>) override;
126 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
127 void onReplaceClip(const SkIRect& rect) override;
128 bool onClipIsAA() const override;
129 bool onClipIsWideOpen() const override;
130 void onAsRgnClip(SkRegion*) const override;
131 void validateDevBounds(const SkIRect& r) override;
132 ClipType onGetClipType() const override;
133 SkIRect onDevClipBounds() const override;
135 void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
136 const SkSamplingOptions&, const SkPaint&);
139 friend class SkCanvas;
141 friend class SkDrawTiler;
142 friend class SkSurface_Raster;
146 // used to change the backend's pixels (and possibly config/rowbytes)
147 // but cannot change the width/height, so there should be no change to
148 // any clip information.
149 void replaceBitmapBackendForRasterSurface(const SkBitmap&) override;
151 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
153 sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
155 SkImageFilterCache* getImageFilterCache() override;
158 void* fRasterHandle = nullptr;
159 SkRasterClipStack fRCStack;
160 SkGlyphRunListPainterCPU fGlyphPainter;
163 using INHERITED = SkBaseDevice;
166 #endif // SkBitmapDevice_DEFINED