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