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