Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkBitmapDevice.h
1 
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef SkBitmapDevice_DEFINED
10 #define SkBitmapDevice_DEFINED
11 
12 #include "SkBitmap.h"
13 #include "SkCanvas.h"
14 #include "SkColor.h"
15 #include "SkDevice.h"
16 #include "SkImageInfo.h"
17 #include "SkRect.h"
18 #include "SkScalar.h"
19 #include "SkSize.h"
20 #include "SkSurfaceProps.h"
21 #include "SkTypes.h"
22 
23 class SkDraw;
24 class SkImageFilterCache;
25 class SkMatrix;
26 class SkPaint;
27 class SkPath;
28 class SkPixelRef;
29 class SkPixmap;
30 class SkRRect;
31 class SkSurface;
32 class SkXfermode;
33 struct SkPoint;
34 
36 class SK_API SkBitmapDevice : public SkBaseDevice {
37 public:
43  SkBitmapDevice(const SkBitmap& bitmap);
44 
50  static SkBitmapDevice* Create(const SkImageInfo& info);
51 
57  SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps);
58 
59  static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&);
60 
61 protected:
62  bool onShouldDisableLCD(const SkPaint&) const override;
63 
69  void drawPaint(const SkDraw&, const SkPaint& paint) override;
70  virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
71  const SkPoint[], const SkPaint& paint) override;
72  virtual void drawRect(const SkDraw&, const SkRect& r,
73  const SkPaint& paint) override;
74  virtual void drawOval(const SkDraw&, const SkRect& oval,
75  const SkPaint& paint) override;
76  virtual void drawRRect(const SkDraw&, const SkRRect& rr,
77  const SkPaint& paint) override;
78 
90  virtual void drawPath(const SkDraw&, const SkPath& path,
91  const SkPaint& paint,
92  const SkMatrix* prePathMatrix = NULL,
93  bool pathIsMutable = false) override;
94  virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
95  const SkMatrix& matrix, const SkPaint& paint) override;
96  virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
97  int x, int y, const SkPaint& paint) override;
98 
103  void drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect*, const SkRect&,
104  const SkPaint&, SkCanvas::SrcRectConstraint) override;
105 
110  virtual void drawText(const SkDraw&, const void* text, size_t len,
111  SkScalar x, SkScalar y, const SkPaint& paint) override;
112  virtual void drawPosText(const SkDraw&, const void* text, size_t len,
113  const SkScalar pos[], int scalarsPerPos,
114  const SkPoint& offset, const SkPaint& paint) override;
115  virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount,
116  const SkPoint verts[], const SkPoint texs[],
117  const SkColor colors[], SkXfermode* xmode,
118  const uint16_t indices[], int indexCount,
119  const SkPaint& paint) override;
120  virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
121 
123 
124  void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) override;
125  sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
126  sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
127  sk_sp<SkSpecialImage> snapSpecial() override;
128 
130 
136 #ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
137  const SkBitmap& onAccessBitmap() override;
138 #else
139  const SkBitmap& onAccessBitmap();
140 #endif
141 
142  SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
143  // just for subclasses, to assign a custom pixelref
144  SkPixelRef* setPixelRef(SkPixelRef* pr) {
145  fBitmap.setPixelRef(pr);
146  return pr;
147  }
148 
149  bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) override;
150  bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override;
151  bool onPeekPixels(SkPixmap*) override;
152  bool onAccessPixels(SkPixmap*) override;
153 
154 private:
155  friend class SkCanvas;
156  friend struct DeviceCM; //for setMatrixClip
157  friend class SkDraw;
158  friend class SkDrawIter;
159  friend class SkDeviceFilteredPaint;
160 
161  friend class SkSurface_Raster;
162 
163  // used to change the backend's pixels (and possibly config/rowbytes)
164  // but cannot change the width/height, so there should be no change to
165  // any clip information.
166  void replaceBitmapBackendForRasterSurface(const SkBitmap&) override;
167 
168  SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
169 
170  sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
171 
172  SkImageFilterCache* getImageFilterCache() override;
173 
174  SkBitmap fBitmap;
175 
176  void setNewSize(const SkISize&); // Used by SkCanvas for resetForNextPicture().
177 
178  typedef SkBaseDevice INHERITED;
179 };
180 
181 #endif // SkBitmapDevice_DEFINED
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
Describe an image's dimensions and pixel type.
Definition: SkImageInfo.h:181
virtual void drawDevice(const SkDraw &, SkBaseDevice *, int x, int y, const SkPaint &)=0
The SkDevice passed will be an SkDevice which was returned by a call to onCreateDevice on this device...
virtual void drawPath(const SkDraw &, const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix=NULL, bool pathIsMutable=false)=0
If pathIsMutable, then the implementation is allowed to cast path to a non-const pointer and modify i...
PointMode
Definition: SkCanvas.h:620
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
Pairs SkImageInfo with actual pixels and rowbytes.
Definition: SkPixmap.h:23
Definition: SkPoint.h:156
Definition: SkDevice.h:297
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
SkSurface represents the backend/results of drawing to a canvas.
Definition: SkSurface.h:31
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
virtual SkBaseDevice * onCreateDevice(const CreateInfo &, const SkPaint *)
Create a new device based on CreateInfo.
Definition: SkDevice.h:335
virtual void drawPaint(const SkDraw &, const SkPaint &paint)=0
These are called inside the per-device-layer loop for each draw call.
SkXfermode is the base class for objects that are called to implement custom "transfer-modes" in the ...
Definition: SkXfermode.h:34
virtual void drawBitmapRect(const SkDraw &, const SkBitmap &, const SkRect *srcOrNull, const SkRect &dst, const SkPaint &paint, SkCanvas::SrcRectConstraint)=0
The default impl.
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
This class is the smart container for pixel memory, and is used with SkBitmap.
Definition: SkPixelRef.h:38
SrcRectConstraint
Controls the behavior at the edge of the src-rect, when specified in drawImageRect, trading off speed for exactness.
Definition: SkCanvas.h:796
virtual bool onReadPixels(const SkImageInfo &, void *, size_t, int x, int y)
The caller is responsible for "pre-clipping" the dst.
virtual bool onWritePixels(const SkImageInfo &, const void *, size_t, int x, int y)
The caller is responsible for "pre-clipping" the src.
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
Definition: SkDevice.h:28
Definition: SkDraw.h:30
Definition: SkRect.h:390
virtual void drawText(const SkDraw &, const void *text, size_t len, SkScalar x, SkScalar y, const SkPaint &paint)=0
Does not handle text decoration.
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:45
Types and macros for colors.
Definition: SkBitmapDevice.h:36