• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
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 SkCoreBlitters_DEFINED
9 #define SkCoreBlitters_DEFINED
10 
11 #include "include/core/SkPaint.h"
12 #include "src/core/SkBlitRow.h"
13 #include "src/core/SkBlitter.h"
14 #include "src/core/SkXfermodePriv.h"
15 #include "src/shaders/SkBitmapProcShader.h"
16 #include "src/shaders/SkShaderBase.h"
17 
18 class SkRasterBlitter : public SkBlitter {
19 public:
SkRasterBlitter(const SkPixmap & device)20     SkRasterBlitter(const SkPixmap& device) : fDevice(device) {}
21 
22 protected:
23     const SkPixmap fDevice;
24 
25 private:
26     typedef SkBlitter INHERITED;
27 };
28 
29 class SkShaderBlitter : public SkRasterBlitter {
30 public:
31     /**
32       *  The storage for shaderContext is owned by the caller, but the object itself is not.
33       *  The blitter only ensures that the storage always holds a live object, but it may
34       *  exchange that object.
35       */
36     SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
37                     SkShaderBase::Context* shaderContext);
38     virtual ~SkShaderBlitter();
39 
40 protected:
41     uint32_t                fShaderFlags;
42     const SkShader*         fShader;
43     SkShaderBase::Context*  fShaderContext;
44     bool                    fConstInY;
45 
46 private:
47     // illegal
48     SkShaderBlitter& operator=(const SkShaderBlitter&);
49 
50     typedef SkRasterBlitter INHERITED;
51 };
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 class SkA8_Coverage_Blitter : public SkRasterBlitter {
56 public:
57     SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint);
58     void blitH(int x, int y, int width) override;
59     void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
60     void blitV(int x, int y, int height, SkAlpha alpha) override;
61     void blitRect(int x, int y, int width, int height) override;
62     void blitMask(const SkMask&, const SkIRect&) override;
63     const SkPixmap* justAnOpaqueColor(uint32_t*) override;
64 
65 private:
66     typedef SkRasterBlitter INHERITED;
67 };
68 
69 ////////////////////////////////////////////////////////////////
70 
71 class SkARGB32_Blitter : public SkRasterBlitter {
72 public:
73     SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
74     void blitH(int x, int y, int width) override;
75     void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
76     void blitV(int x, int y, int height, SkAlpha alpha) override;
77     void blitRect(int x, int y, int width, int height) override;
78     void blitMask(const SkMask&, const SkIRect&) override;
79     const SkPixmap* justAnOpaqueColor(uint32_t*) override;
80     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
81     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
82 
83 protected:
84     SkColor                fColor;
85     SkPMColor              fPMColor;
86 
87 private:
88     unsigned fSrcA, fSrcR, fSrcG, fSrcB;
89 
90     // illegal
91     SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
92 
93     typedef SkRasterBlitter INHERITED;
94 };
95 
96 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
97 public:
SkARGB32_Opaque_Blitter(const SkPixmap & device,const SkPaint & paint)98     SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
99         : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
100     void blitMask(const SkMask&, const SkIRect&) override;
101     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
102     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
103 
104 private:
105     typedef SkARGB32_Blitter INHERITED;
106 };
107 
108 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
109 public:
SkARGB32_Black_Blitter(const SkPixmap & device,const SkPaint & paint)110     SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
111         : INHERITED(device, paint) {}
112     void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
113     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
114     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
115 
116 private:
117     typedef SkARGB32_Opaque_Blitter INHERITED;
118 };
119 
120 class SkARGB32_Shader_Blitter : public SkShaderBlitter {
121 public:
122     SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
123                             SkShaderBase::Context* shaderContext);
124     ~SkARGB32_Shader_Blitter() override;
125     void blitH(int x, int y, int width) override;
126     void blitV(int x, int y, int height, SkAlpha alpha) override;
127     void blitRect(int x, int y, int width, int height) override;
128     void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
129     void blitMask(const SkMask&, const SkIRect&) override;
130 
131 private:
132     SkXfermode*         fXfermode;
133     SkPMColor*          fBuffer;
134     SkBlitRow::Proc32   fProc32;
135     SkBlitRow::Proc32   fProc32Blend;
136     bool                fShadeDirectlyIntoDevice;
137 
138     // illegal
139     SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
140 
141     typedef SkShaderBlitter INHERITED;
142 };
143 
144 ///////////////////////////////////////////////////////////////////////////////////////////////////
145 
146 typedef void (*SkS32D16BlendProc)(uint16_t*, const SkPMColor*, int, uint8_t);
147 
148 class SkRGB565_Shader_Blitter : public SkShaderBlitter {
149 public:
150     SkRGB565_Shader_Blitter(const SkPixmap& device, const SkPaint&, SkShaderBase::Context*);
151     ~SkRGB565_Shader_Blitter() override;
152     void blitH(int x, int y, int width) override;
153     void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
154 
155     static bool Supports(const SkPixmap& device, const SkPaint&);
156 
157 private:
158     SkPMColor*          fBuffer;
159     SkS32D16BlendProc   fBlend;
160     SkS32D16BlendProc   fBlendCoverage;
161 
162     typedef SkShaderBlitter INHERITED;
163 };
164 
165 ///////////////////////////////////////////////////////////////////////////////
166 
167 // Neither of these ever returns nullptr, but this first factory may return a SkNullBlitter.
168 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm,
169                                          SkArenaAlloc*);
170 // Use this if you've pre-baked a shader pipeline, including modulating with paint alpha.
171 // This factory never returns an SkNullBlitter.
172 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&,
173                                          const SkRasterPipeline& shaderPipeline,
174                                          bool shader_is_opaque,
175                                          SkArenaAlloc*);
176 
177 SkBlitter* SkCreateSkVMBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm, SkArenaAlloc*);
178 
179 #endif
180