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