blob: 31f33979dbbda902c79de2dfc9ee70dfb2bbcea8 [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:
reed41e010c2015-06-09 12:16:53 -070019 SkRasterBlitter(const SkPixmap& device) : fDevice(device) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000020
21protected:
reed41e010c2015-06-09 12:16:53 -070022 const SkPixmap fDevice;
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
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 */
reed41e010c2015-06-09 12:16:53 -070035 SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000036 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:
reed41e010c2015-06-09 12:16:53 -070064 SkA8_Coverage_Blitter(const SkPixmap& 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;
reed41e010c2015-06-09 12:16:53 -070070 const SkPixmap* 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:
reed41e010c2015-06-09 12:16:53 -070075 SkA8_Blitter(const SkPixmap& device, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 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&);
reed41e010c2015-06-09 12:16:53 -070081 virtual const SkPixmap* justAnOpaqueColor(uint32_t*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000082
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:
reed41e010c2015-06-09 12:16:53 -070094 SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000095 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:
reed41e010c2015-06-09 12:16:53 -0700116 SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000117 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&);
reed41e010c2015-06-09 12:16:53 -0700122 virtual const SkPixmap* justAnOpaqueColor(uint32_t*);
reed6983f662015-04-15 18:23:03 -0700123 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
124 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000125
126protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000127 SkColor fColor;
128 SkPMColor fPMColor;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129
130private:
131 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
132
133 // illegal
134 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
135
136 typedef SkRasterBlitter INHERITED;
137};
138
reed@android.comdafaf7a2009-07-10 03:05:59 +0000139class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000140public:
reed41e010c2015-06-09 12:16:53 -0700141 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000142 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143 virtual void blitMask(const SkMask&, const SkIRect&);
reed6983f662015-04-15 18:23:03 -0700144 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
145 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comdafaf7a2009-07-10 03:05:59 +0000146
reed@android.com8a1c16f2008-12-17 15:59:43 +0000147private:
148 typedef SkARGB32_Blitter INHERITED;
149};
150
reed@android.comdafaf7a2009-07-10 03:05:59 +0000151class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000152public:
reed41e010c2015-06-09 12:16:53 -0700153 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000154 : INHERITED(device, paint) {}
reed@android.comdafaf7a2009-07-10 03:05:59 +0000155 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
reed6983f662015-04-15 18:23:03 -0700156 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
157 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comb602b8e2009-07-10 15:58:53 +0000158
reed@android.com8a1c16f2008-12-17 15:59:43 +0000159private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000160 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000161};
162
163class SkARGB32_Shader_Blitter : public SkShaderBlitter {
164public:
reed41e010c2015-06-09 12:16:53 -0700165 SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000166 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000167 virtual ~SkARGB32_Shader_Blitter();
mtklein36352bf2015-03-25 18:17:31 -0700168 void blitH(int x, int y, int width) override;
169 void blitV(int x, int y, int height, SkAlpha alpha) override;
170 void blitRect(int x, int y, int width, int height) override;
171 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
172 void blitMask(const SkMask&, const SkIRect&) override;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000173
reed@android.com8a1c16f2008-12-17 15:59:43 +0000174private:
reed@android.comc4cae852009-09-23 15:06:10 +0000175 SkXfermode* fXfermode;
176 SkPMColor* fBuffer;
177 SkBlitRow::Proc32 fProc32;
178 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000179 bool fShadeDirectlyIntoDevice;
180 bool fConstInY;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000181
reed@android.com8a1c16f2008-12-17 15:59:43 +0000182 // illegal
183 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000184
reed@android.com8a1c16f2008-12-17 15:59:43 +0000185 typedef SkShaderBlitter INHERITED;
186};
187
reed@android.com1fc4c602009-10-02 16:34:57 +0000188///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000189
reed@android.com1fc4c602009-10-02 16:34:57 +0000190/* These return the correct subclass of blitter for their device config.
191
192 Currently, they make the following assumptions about the state of the
193 paint:
reed@google.com981d4792011-03-09 12:55:47 +0000194
reed@android.com1fc4c602009-10-02 16:34:57 +0000195 1. If there is an xfermode, there will also be a shader
196 2. If there is a colorfilter, there will be a shader that itself handles
197 calling the filter, so the blitter can always ignore the colorfilter obj
198
199 These pre-conditions must be handled by the caller, in our case
200 SkBlitter::Choose(...)
201 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000202
reed41e010c2015-06-09 12:16:53 -0700203SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000204 SkShader::Context* shaderContext,
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000205 SkTBlitterAllocator* allocator);
reed@android.com1fc4c602009-10-02 16:34:57 +0000206
reed@android.com8a1c16f2008-12-17 15:59:43 +0000207#endif