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