blob: acc18febede6e44ac3cbd6c0ab2ff592b370ccd4 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkCoreBlitters_DEFINED
9#define SkCoreBlitters_DEFINED
10
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000011#include "SkBitmapProcShader.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkBlitter.h"
13#include "SkBlitRow.h"
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000014#include "SkShader.h"
15#include "SkSmallAllocator.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016
17class SkRasterBlitter : public SkBlitter {
18public:
19 SkRasterBlitter(const SkBitmap& device) : fDevice(device) {}
20
21protected:
22 const SkBitmap& fDevice;
23
24private:
25 typedef SkBlitter INHERITED;
26};
27
28class SkShaderBlitter : public SkRasterBlitter {
29public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000030 /**
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);
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 virtual ~SkShaderBlitter();
38
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000039 /**
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 */
mtklein36352bf2015-03-25 18:17:31 -070044 bool resetShaderContext(const SkShader::ContextRec&) override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000045
mtklein36352bf2015-03-25 18:17:31 -070046 SkShader::Context* getShaderContext() const override { return fShaderContext; }
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000047
reed@android.com8a1c16f2008-12-17 15:59:43 +000048protected:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000049 uint32_t fShaderFlags;
50 const SkShader* fShader;
51 SkShader::Context* fShaderContext;
reed@android.com8a1c16f2008-12-17 15:59:43 +000052
53private:
54 // illegal
55 SkShaderBlitter& operator=(const SkShaderBlitter&);
56
57 typedef SkRasterBlitter INHERITED;
58};
59
60///////////////////////////////////////////////////////////////////////////////
61
reed@google.com126f7f52013-11-07 16:06:53 +000062class SkA8_Coverage_Blitter : public SkRasterBlitter {
63public:
64 SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -070065 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;
reed@google.com126f7f52013-11-07 16:06:53 +000071};
72
reed@android.com8a1c16f2008-12-17 15:59:43 +000073class SkA8_Blitter : public SkRasterBlitter {
74public:
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
83private:
84 unsigned fSrcA;
85
86 // illegal
87 SkA8_Blitter& operator=(const SkA8_Blitter&);
88
89 typedef SkRasterBlitter INHERITED;
90};
91
92class SkA8_Shader_Blitter : public SkShaderBlitter {
93public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000094 SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
95 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +000096 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
101private:
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
114class SkARGB32_Blitter : public SkRasterBlitter {
115public:
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*);
reed6983f662015-04-15 18:23:03 -0700123#ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2
124 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
125 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
126#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127
128protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000129 SkColor fColor;
130 SkPMColor fPMColor;
senorblanco@chromium.org29e50542010-12-16 19:07:45 +0000131 SkBlitRow::ColorProc fColor32Proc;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000132
133private:
134 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
135
136 // illegal
137 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
138
139 typedef SkRasterBlitter INHERITED;
140};
141
reed@android.comdafaf7a2009-07-10 03:05:59 +0000142class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143public:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000144 SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
145 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000146 virtual void blitMask(const SkMask&, const SkIRect&);
reed6983f662015-04-15 18:23:03 -0700147#ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2
148 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
149 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
150#endif
reed@android.comdafaf7a2009-07-10 03:05:59 +0000151
reed@android.com8a1c16f2008-12-17 15:59:43 +0000152private:
153 typedef SkARGB32_Blitter INHERITED;
154};
155
reed@android.comdafaf7a2009-07-10 03:05:59 +0000156class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000157public:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000158 SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
159 : INHERITED(device, paint) {}
reed@android.comdafaf7a2009-07-10 03:05:59 +0000160 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
reed6983f662015-04-15 18:23:03 -0700161#ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2
162 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
163 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
164#endif
reed@android.comb602b8e2009-07-10 15:58:53 +0000165
reed@android.com8a1c16f2008-12-17 15:59:43 +0000166private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000167 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000168};
169
170class SkARGB32_Shader_Blitter : public SkShaderBlitter {
171public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000172 SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
173 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000174 virtual ~SkARGB32_Shader_Blitter();
mtklein36352bf2015-03-25 18:17:31 -0700175 void blitH(int x, int y, int width) override;
176 void blitV(int x, int y, int height, SkAlpha alpha) override;
177 void blitRect(int x, int y, int width, int height) override;
178 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
179 void blitMask(const SkMask&, const SkIRect&) override;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000180
reed@android.com8a1c16f2008-12-17 15:59:43 +0000181private:
reed@android.comc4cae852009-09-23 15:06:10 +0000182 SkXfermode* fXfermode;
183 SkPMColor* fBuffer;
184 SkBlitRow::Proc32 fProc32;
185 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000186 bool fShadeDirectlyIntoDevice;
187 bool fConstInY;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000188
reed@android.com8a1c16f2008-12-17 15:59:43 +0000189 // illegal
190 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000191
reed@android.com8a1c16f2008-12-17 15:59:43 +0000192 typedef SkShaderBlitter INHERITED;
193};
194
reed@android.com1fc4c602009-10-02 16:34:57 +0000195///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000196
reed@android.com1fc4c602009-10-02 16:34:57 +0000197/* These return the correct subclass of blitter for their device config.
198
199 Currently, they make the following assumptions about the state of the
200 paint:
reed@google.com981d4792011-03-09 12:55:47 +0000201
reed@android.com1fc4c602009-10-02 16:34:57 +0000202 1. If there is an xfermode, there will also be a shader
203 2. If there is a colorfilter, there will be a shader that itself handles
204 calling the filter, so the blitter can always ignore the colorfilter obj
205
206 These pre-conditions must be handled by the caller, in our case
207 SkBlitter::Choose(...)
208 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000209
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000210SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000211 SkShader::Context* shaderContext,
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000212 SkTBlitterAllocator* allocator);
reed@android.com1fc4c602009-10-02 16:34:57 +0000213
reed@android.com8a1c16f2008-12-17 15:59:43 +0000214#endif