Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / core / SkBitmapDevice.h
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #ifndef SkBitmapDevice_DEFINED
9 #define SkBitmapDevice_DEFINED
10
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"
22
23 class SkImageFilterCache;
24 class SkMatrix;
25 class SkPaint;
26 class SkPath;
27 class SkPixmap;
28 class SkRasterHandleAllocator;
29 class SkRRect;
30 class SkSurface;
31 class SkSurfaceProps;
32 struct SkPoint;
33 #ifdef SK_ENABLE_SKSL
34 class SkMesh;
35 #endif
36 ///////////////////////////////////////////////////////////////////////////////
37 class SkBitmapDevice : public SkBaseDevice {
38 public:
39     /**
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.
43      */
44     SkBitmapDevice(const SkBitmap& bitmap);
45
46     /**
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.
50      */
51     static SkBitmapDevice* Create(const SkImageInfo& info);
52
53     /**
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.
57      */
58     SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps,
59                    void* externalHandle = nullptr);
60
61     static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&,
62                                   SkRasterHandleAllocator* = nullptr);
63
64 protected:
65     void* getRasterHandle() const override { return fRasterHandle; }
66
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.
70      */
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;
77
78     /**
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.
83      */
84     void drawPath(const SkPath&, const SkPaint&, bool pathIsMutable) override;
85
86     void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
87                        const SkSamplingOptions&, const SkPaint&,
88                        SkCanvas::SrcRectConstraint) override;
89
90     void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
91 #ifdef SK_ENABLE_SKSL
92     void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
93 #endif
94
95     void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp<SkBlender>,
96                    const SkPaint&) override;
97
98     ///////////////////////////////////////////////////////////////////////////
99
100     void drawDevice(SkBaseDevice*, const SkSamplingOptions&, const SkPaint&) override;
101     void drawSpecial(SkSpecialImage*, const SkMatrix&, const SkSamplingOptions&,
102                      const SkPaint&) override;
103
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(); }
108
109     ///////////////////////////////////////////////////////////////////////////
110
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;
119
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;
134
135     void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
136                     const SkSamplingOptions&, const SkPaint&);
137
138 private:
139     friend class SkCanvas;
140     friend class SkDraw;
141     friend class SkDrawTiler;
142     friend class SkSurface_Raster;
143
144     class BDDraw;
145
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;
150
151     SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
152
153     sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override;
154
155     SkImageFilterCache* getImageFilterCache() override;
156
157     SkBitmap    fBitmap;
158     void*       fRasterHandle = nullptr;
159     SkRasterClipStack  fRCStack;
160     SkGlyphRunListPainterCPU fGlyphPainter;
161
162
163     using INHERITED = SkBaseDevice;
164 };
165
166 #endif // SkBitmapDevice_DEFINED