Debian Codegraph @

src/core/SkCoreBlitters.h

raw
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 #include <optional>
23
24 class SkArenaAlloc;
25 class SkMatrix;
26 class SkRasterPipeline;
27 class SkShader;
28 class SkSurfaceProps;
29 struct SkIRect;
30 struct SkMask;
31
32 class SkRasterBlitter : public SkBlitter {
33 public:
34 SkRasterBlitter(const SkPixmap& device) : fDevice(device) {}
35
36 protected:
37 const SkPixmap fDevice;
38 };
39
40 class SkShaderBlitter : public SkRasterBlitter {
41 public:
42 /**
43 * The storage for shaderContext is owned by the caller, but the object itself is not.
44 * The blitter only ensures that the storage always holds a live object, but it may
45 * exchange that object.
46 */
47 SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
48 SkShaderBase::Context* shaderContext);
49 ~SkShaderBlitter() override;
50
51 protected:
52 sk_sp<SkShader> fShader;
53 SkShaderBase::Context* fShaderContext;
54 };
55
56 ///////////////////////////////////////////////////////////////////////////////
57
58 class SkARGB32_Blitter : public SkRasterBlitter {
59 public:
60 SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
61 void blitH(int x, int y, int width) override;
62 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
63 void blitV(int x, int y, int height, SkAlpha alpha) override;
64 void blitRect(int x, int y, int width, int height) override;
65 void blitMask(const SkMask&, const SkIRect&) override;
66 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
67 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
68
69 protected:
70 SkColor fColor;
71 SkPMColor fPMColor;
72 SkAlpha fSrcA;
73 };
74
75 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
76 public:
77 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
78 : SkARGB32_Blitter(device, paint) {
79 SkASSERT(paint.getAlpha() == 0xFF);
80 }
81 void blitMask(const SkMask&, const SkIRect&) override;
82 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
83 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
84 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
85 std::optional<DirectBlit> canDirectBlit() override;
86 };
87
88 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
89 public:
90 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
91 : SkARGB32_Opaque_Blitter(device, paint) {
92 SkASSERT(paint.getColor() == SK_ColorBLACK);
93 }
94 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) 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
99 class SkARGB32_Shader_Blitter : public SkShaderBlitter {
100 public:
101 SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
102 SkShaderBase::Context* shaderContext);
103 ~SkARGB32_Shader_Blitter() override;
104 void blitH(int x, int y, int width) override;
105 void blitV(int x, int y, int height, SkAlpha alpha) override;
106 void blitRect(int x, int y, int width, int height) override;
107 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
108 void blitMask(const SkMask&, const SkIRect&) override;
109
110 private:
111 SkPMColor* fBuffer;
112 SkBlitRow::Proc32 fProc32;
113 SkBlitRow::Proc32 fProc32Blend;
114 bool fShadeDirectlyIntoDevice;
115 };
116
117 ///////////////////////////////////////////////////////////////////////////////////////////////////
118
119 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&,
120 const SkPaint&,
121 const SkMatrix& ctm,
122 SkArenaAlloc*,
123 sk_sp<SkShader> clipShader,
124 const SkSurfaceProps& props,
125 const SkRect& devBounds);
126 // Use this if you've pre-baked a shader pipeline, including modulating with paint alpha.
127 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&,
128 const SkRasterPipeline& shaderPipeline,
129 bool shader_is_opaque,
130 SkArenaAlloc*, sk_sp<SkShader> clipShader);
131
132 #endif