• 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 "SkShader.h"
15 #include "SkSmallAllocator.h"
16 
17 class SkRasterBlitter : public SkBlitter {
18 public:
SkRasterBlitter(const SkBitmap & device)19     SkRasterBlitter(const SkBitmap& device) : fDevice(device) {}
20 
21 protected:
22     const SkBitmap& 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 SkBitmap& device, const SkPaint& paint,
36                     SkShader::Context* shaderContext);
37     virtual ~SkShaderBlitter();
38 
39     /**
40       *  Create a new shader context and uses it instead of the old one if successful.
41       *  Will create the context at the same location as the old one (this is safe
42       *  because the shader itself is unchanged).
43       */
44     bool resetShaderContext(const SkShader::ContextRec&) override;
45 
getShaderContext()46     SkShader::Context* getShaderContext() const override { return fShaderContext; }
47 
48 protected:
49     uint32_t            fShaderFlags;
50     const SkShader*     fShader;
51     SkShader::Context*  fShaderContext;
52 
53 private:
54     // illegal
55     SkShaderBlitter& operator=(const SkShaderBlitter&);
56 
57     typedef SkRasterBlitter INHERITED;
58 };
59 
60 ///////////////////////////////////////////////////////////////////////////////
61 
62 class SkA8_Coverage_Blitter : public SkRasterBlitter {
63 public:
64     SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint);
65     void blitH(int x, int y, int width) override;
66     void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
67     void blitV(int x, int y, int height, SkAlpha alpha) override;
68     void blitRect(int x, int y, int width, int height) override;
69     void blitMask(const SkMask&, const SkIRect&) override;
70     const SkBitmap* justAnOpaqueColor(uint32_t*) override;
71 };
72 
73 class SkA8_Blitter : public SkRasterBlitter {
74 public:
75     SkA8_Blitter(const SkBitmap& device, const SkPaint& paint);
76     virtual void blitH(int x, int y, int width);
77     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
78     virtual void blitV(int x, int y, int height, SkAlpha alpha);
79     virtual void blitRect(int x, int y, int width, int height);
80     virtual void blitMask(const SkMask&, const SkIRect&);
81     virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
82 
83 private:
84     unsigned fSrcA;
85 
86     // illegal
87     SkA8_Blitter& operator=(const SkA8_Blitter&);
88 
89     typedef SkRasterBlitter INHERITED;
90 };
91 
92 class SkA8_Shader_Blitter : public SkShaderBlitter {
93 public:
94     SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
95                         SkShader::Context* shaderContext);
96     virtual ~SkA8_Shader_Blitter();
97     virtual void blitH(int x, int y, int width);
98     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
99     virtual void blitMask(const SkMask&, const SkIRect&);
100 
101 private:
102     SkXfermode* fXfermode;
103     SkPMColor*  fBuffer;
104     uint8_t*    fAAExpand;
105 
106     // illegal
107     SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&);
108 
109     typedef SkShaderBlitter INHERITED;
110 };
111 
112 ////////////////////////////////////////////////////////////////
113 
114 class SkARGB32_Blitter : public SkRasterBlitter {
115 public:
116     SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint);
117     virtual void blitH(int x, int y, int width);
118     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
119     virtual void blitV(int x, int y, int height, SkAlpha alpha);
120     virtual void blitRect(int x, int y, int width, int height);
121     virtual void blitMask(const SkMask&, const SkIRect&);
122     virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
123     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
124     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
125 
126 protected:
127     SkColor                fColor;
128     SkPMColor              fPMColor;
129 
130 private:
131     unsigned fSrcA, fSrcR, fSrcG, fSrcB;
132 
133     // illegal
134     SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
135 
136     typedef SkRasterBlitter INHERITED;
137 };
138 
139 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
140 public:
SkARGB32_Opaque_Blitter(const SkBitmap & device,const SkPaint & paint)141     SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
142         : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
143     virtual void blitMask(const SkMask&, const SkIRect&);
144     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
145     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
146 
147 private:
148     typedef SkARGB32_Blitter INHERITED;
149 };
150 
151 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
152 public:
SkARGB32_Black_Blitter(const SkBitmap & device,const SkPaint & paint)153     SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
154         : INHERITED(device, paint) {}
155     virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
156     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
157     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
158 
159 private:
160     typedef SkARGB32_Opaque_Blitter INHERITED;
161 };
162 
163 class SkARGB32_Shader_Blitter : public SkShaderBlitter {
164 public:
165     SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
166                             SkShader::Context* shaderContext);
167     virtual ~SkARGB32_Shader_Blitter();
168     void blitH(int x, int y, int width) override;
169     void blitV(int x, int y, int height, SkAlpha alpha) override;
170     void blitRect(int x, int y, int width, int height) override;
171     void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
172     void blitMask(const SkMask&, const SkIRect&) override;
173 
174 private:
175     SkXfermode*         fXfermode;
176     SkPMColor*          fBuffer;
177     SkBlitRow::Proc32   fProc32;
178     SkBlitRow::Proc32   fProc32Blend;
179     bool                fShadeDirectlyIntoDevice;
180     bool                fConstInY;
181 
182     // illegal
183     SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
184 
185     typedef SkShaderBlitter INHERITED;
186 };
187 
188 ///////////////////////////////////////////////////////////////////////////////
189 
190 /*  These return the correct subclass of blitter for their device config.
191 
192     Currently, they make the following assumptions about the state of the
193     paint:
194 
195     1. If there is an xfermode, there will also be a shader
196     2. If there is a colorfilter, there will be a shader that itself handles
197        calling the filter, so the blitter can always ignore the colorfilter obj
198 
199     These pre-conditions must be handled by the caller, in our case
200     SkBlitter::Choose(...)
201  */
202 
203 SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
204                                 SkShader::Context* shaderContext,
205                                 SkTBlitterAllocator* allocator);
206 
207 #endif
208