blob: 23fca0f402fb0682d459d1f50810f1a37e778582 [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"
Mike Reedd4706732016-11-15 16:44:34 -050016#include "SkXfermodePriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017
18class SkRasterBlitter : public SkBlitter {
19public:
reed41e010c2015-06-09 12:16:53 -070020 SkRasterBlitter(const SkPixmap& device) : fDevice(device) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000021
22protected:
reed41e010c2015-06-09 12:16:53 -070023 const SkPixmap fDevice;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
25private:
26 typedef SkBlitter INHERITED;
27};
28
29class SkShaderBlitter : public SkRasterBlitter {
30public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000031 /**
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 */
reed41e010c2015-06-09 12:16:53 -070036 SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000037 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 virtual ~SkShaderBlitter();
39
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000040 /**
41 * Create a new shader context and uses it instead of the old one if successful.
42 * Will create the context at the same location as the old one (this is safe
43 * because the shader itself is unchanged).
44 */
mtklein36352bf2015-03-25 18:17:31 -070045 bool resetShaderContext(const SkShader::ContextRec&) override;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000046
mtklein36352bf2015-03-25 18:17:31 -070047 SkShader::Context* getShaderContext() const override { return fShaderContext; }
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000048
reed@android.com8a1c16f2008-12-17 15:59:43 +000049protected:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000050 uint32_t fShaderFlags;
51 const SkShader* fShader;
52 SkShader::Context* fShaderContext;
reeda34be682016-02-15 07:48:35 -080053 bool fConstInY;
reed@android.com8a1c16f2008-12-17 15:59:43 +000054
55private:
56 // illegal
57 SkShaderBlitter& operator=(const SkShaderBlitter&);
58
59 typedef SkRasterBlitter INHERITED;
60};
61
62///////////////////////////////////////////////////////////////////////////////
63
reed@google.com126f7f52013-11-07 16:06:53 +000064class SkA8_Coverage_Blitter : public SkRasterBlitter {
65public:
reed41e010c2015-06-09 12:16:53 -070066 SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -070067 void blitH(int x, int y, int width) override;
68 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
69 void blitV(int x, int y, int height, SkAlpha alpha) override;
70 void blitRect(int x, int y, int width, int height) override;
71 void blitMask(const SkMask&, const SkIRect&) override;
reed41e010c2015-06-09 12:16:53 -070072 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed@google.com126f7f52013-11-07 16:06:53 +000073};
74
reed@android.com8a1c16f2008-12-17 15:59:43 +000075class SkA8_Blitter : public SkRasterBlitter {
76public:
reed41e010c2015-06-09 12:16:53 -070077 SkA8_Blitter(const SkPixmap& device, const SkPaint& paint);
reed3dfd1332015-06-25 14:26:11 -070078 void blitH(int x, int y, int width) override;
79 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
80 void blitV(int x, int y, int height, SkAlpha alpha) override;
81 void blitRect(int x, int y, int width, int height) override;
82 void blitMask(const SkMask&, const SkIRect&) override;
83 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000084
85private:
86 unsigned fSrcA;
87
88 // illegal
89 SkA8_Blitter& operator=(const SkA8_Blitter&);
90
91 typedef SkRasterBlitter INHERITED;
92};
93
94class SkA8_Shader_Blitter : public SkShaderBlitter {
95public:
reed41e010c2015-06-09 12:16:53 -070096 SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000097 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +000098 virtual ~SkA8_Shader_Blitter();
reed3dfd1332015-06-25 14:26:11 -070099 void blitH(int x, int y, int width) override;
100 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
101 void blitMask(const SkMask&, const SkIRect&) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102
103private:
104 SkXfermode* fXfermode;
105 SkPMColor* fBuffer;
106 uint8_t* fAAExpand;
107
108 // illegal
109 SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&);
110
111 typedef SkShaderBlitter INHERITED;
112};
113
114////////////////////////////////////////////////////////////////
115
116class SkARGB32_Blitter : public SkRasterBlitter {
117public:
reed41e010c2015-06-09 12:16:53 -0700118 SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
reed3dfd1332015-06-25 14:26:11 -0700119 void blitH(int x, int y, int width) override;
120 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
121 void blitV(int x, int y, int height, SkAlpha alpha) override;
122 void blitRect(int x, int y, int width, int height) override;
123 void blitMask(const SkMask&, const SkIRect&) override;
124 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed6983f662015-04-15 18:23:03 -0700125 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
126 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127
128protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000129 SkColor fColor;
130 SkPMColor fPMColor;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131
132private:
133 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
134
135 // illegal
136 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
137
138 typedef SkRasterBlitter INHERITED;
139};
140
reed@android.comdafaf7a2009-07-10 03:05:59 +0000141class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142public:
reed41e010c2015-06-09 12:16:53 -0700143 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000144 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed3dfd1332015-06-25 14:26:11 -0700145 void blitMask(const SkMask&, const SkIRect&) override;
reed6983f662015-04-15 18:23:03 -0700146 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
147 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comdafaf7a2009-07-10 03:05:59 +0000148
reed@android.com8a1c16f2008-12-17 15:59:43 +0000149private:
150 typedef SkARGB32_Blitter INHERITED;
151};
152
reed@android.comdafaf7a2009-07-10 03:05:59 +0000153class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000154public:
reed41e010c2015-06-09 12:16:53 -0700155 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000156 : INHERITED(device, paint) {}
reed3dfd1332015-06-25 14:26:11 -0700157 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
reed6983f662015-04-15 18:23:03 -0700158 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
159 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comb602b8e2009-07-10 15:58:53 +0000160
reed@android.com8a1c16f2008-12-17 15:59:43 +0000161private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000162 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000163};
164
165class SkARGB32_Shader_Blitter : public SkShaderBlitter {
166public:
reed41e010c2015-06-09 12:16:53 -0700167 SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000168 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000169 virtual ~SkARGB32_Shader_Blitter();
mtklein36352bf2015-03-25 18:17:31 -0700170 void blitH(int x, int y, int width) override;
171 void blitV(int x, int y, int height, SkAlpha alpha) override;
172 void blitRect(int x, int y, int width, int height) override;
173 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
174 void blitMask(const SkMask&, const SkIRect&) override;
halcanary9d524f22016-03-29 09:03:52 -0700175
reed@android.com8a1c16f2008-12-17 15:59:43 +0000176private:
reed@android.comc4cae852009-09-23 15:06:10 +0000177 SkXfermode* fXfermode;
178 SkPMColor* fBuffer;
179 SkBlitRow::Proc32 fProc32;
180 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000181 bool fShadeDirectlyIntoDevice;
halcanary9d524f22016-03-29 09:03:52 -0700182
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183 // illegal
184 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
halcanary9d524f22016-03-29 09:03:52 -0700185
reed@android.com8a1c16f2008-12-17 15:59:43 +0000186 typedef SkShaderBlitter INHERITED;
187};
188
reed3dc6aac2016-04-14 09:02:14 -0700189SkBlitter* SkBlitter_ARGB32_Create(const SkPixmap& device, const SkPaint&, SkShader::Context*,
190 SkTBlitterAllocator*);
reeda34be682016-02-15 07:48:35 -0800191
reed3dc6aac2016-04-14 09:02:14 -0700192SkBlitter* SkBlitter_F16_Create(const SkPixmap& device, const SkPaint&, SkShader::Context*,
193 SkTBlitterAllocator*);
reed395eabe2016-01-30 18:52:31 -0800194
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
reed41e010c2015-06-09 12:16:53 -0700210SkBlitter* SkBlitter_ChooseD565(const SkPixmap& 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
mtklein9a5c47f2016-07-22 11:05:04 -0700214
215// Returns nullptr if no SkRasterPipeline blitter can be constructed for this paint.
Mike Kleinfb191da2016-11-15 13:20:33 -0500216SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm,
217 SkTBlitterAllocator*);
mtklein9a5c47f2016-07-22 11:05:04 -0700218
reed@android.com8a1c16f2008-12-17 15:59:43 +0000219#endif