blob: 8fcfde6f762acf035dac8e1b5af9135d3bd8f225 [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;
reeda34be682016-02-15 07:48:35 -080052 bool fConstInY;
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
54private:
55 // illegal
56 SkShaderBlitter& operator=(const SkShaderBlitter&);
57
58 typedef SkRasterBlitter INHERITED;
59};
60
61///////////////////////////////////////////////////////////////////////////////
62
reed@google.com126f7f52013-11-07 16:06:53 +000063class SkA8_Coverage_Blitter : public SkRasterBlitter {
64public:
reed41e010c2015-06-09 12:16:53 -070065 SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint);
mtklein36352bf2015-03-25 18:17:31 -070066 void blitH(int x, int y, int width) override;
67 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
68 void blitV(int x, int y, int height, SkAlpha alpha) override;
69 void blitRect(int x, int y, int width, int height) override;
70 void blitMask(const SkMask&, const SkIRect&) override;
reed41e010c2015-06-09 12:16:53 -070071 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed@google.com126f7f52013-11-07 16:06:53 +000072};
73
reed@android.com8a1c16f2008-12-17 15:59:43 +000074class SkA8_Blitter : public SkRasterBlitter {
75public:
reed41e010c2015-06-09 12:16:53 -070076 SkA8_Blitter(const SkPixmap& device, const SkPaint& paint);
reed3dfd1332015-06-25 14:26:11 -070077 void blitH(int x, int y, int width) override;
78 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
79 void blitV(int x, int y, int height, SkAlpha alpha) override;
80 void blitRect(int x, int y, int width, int height) override;
81 void blitMask(const SkMask&, const SkIRect&) override;
82 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000083
84private:
85 unsigned fSrcA;
86
87 // illegal
88 SkA8_Blitter& operator=(const SkA8_Blitter&);
89
90 typedef SkRasterBlitter INHERITED;
91};
92
93class SkA8_Shader_Blitter : public SkShaderBlitter {
94public:
reed41e010c2015-06-09 12:16:53 -070095 SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000096 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 virtual ~SkA8_Shader_Blitter();
reed3dfd1332015-06-25 14:26:11 -070098 void blitH(int x, int y, int width) override;
99 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
100 void blitMask(const SkMask&, const SkIRect&) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101
102private:
103 SkXfermode* fXfermode;
104 SkPMColor* fBuffer;
105 uint8_t* fAAExpand;
106
107 // illegal
108 SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&);
109
110 typedef SkShaderBlitter INHERITED;
111};
112
113////////////////////////////////////////////////////////////////
114
115class SkARGB32_Blitter : public SkRasterBlitter {
116public:
reed41e010c2015-06-09 12:16:53 -0700117 SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint);
reed3dfd1332015-06-25 14:26:11 -0700118 void blitH(int x, int y, int width) override;
119 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
120 void blitV(int x, int y, int height, SkAlpha alpha) override;
121 void blitRect(int x, int y, int width, int height) override;
122 void blitMask(const SkMask&, const SkIRect&) override;
123 const SkPixmap* justAnOpaqueColor(uint32_t*) override;
reed6983f662015-04-15 18:23:03 -0700124 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
125 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000126
127protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000128 SkColor fColor;
129 SkPMColor fPMColor;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000130
131private:
132 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
133
134 // illegal
135 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
136
137 typedef SkRasterBlitter INHERITED;
138};
139
reed@android.comdafaf7a2009-07-10 03:05:59 +0000140class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141public:
reed41e010c2015-06-09 12:16:53 -0700142 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000143 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed3dfd1332015-06-25 14:26:11 -0700144 void blitMask(const SkMask&, const SkIRect&) override;
reed6983f662015-04-15 18:23:03 -0700145 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
146 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comdafaf7a2009-07-10 03:05:59 +0000147
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148private:
149 typedef SkARGB32_Blitter INHERITED;
150};
151
reed@android.comdafaf7a2009-07-10 03:05:59 +0000152class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000153public:
reed41e010c2015-06-09 12:16:53 -0700154 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
reed@android.comdafaf7a2009-07-10 03:05:59 +0000155 : INHERITED(device, paint) {}
reed3dfd1332015-06-25 14:26:11 -0700156 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
reed6983f662015-04-15 18:23:03 -0700157 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
158 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
reed@android.comb602b8e2009-07-10 15:58:53 +0000159
reed@android.com8a1c16f2008-12-17 15:59:43 +0000160private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000161 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000162};
163
164class SkARGB32_Shader_Blitter : public SkShaderBlitter {
165public:
reed41e010c2015-06-09 12:16:53 -0700166 SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000167 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000168 virtual ~SkARGB32_Shader_Blitter();
mtklein36352bf2015-03-25 18:17:31 -0700169 void blitH(int x, int y, int width) override;
170 void blitV(int x, int y, int height, SkAlpha alpha) override;
171 void blitRect(int x, int y, int width, int height) override;
172 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
173 void blitMask(const SkMask&, const SkIRect&) override;
halcanary9d524f22016-03-29 09:03:52 -0700174
reed@android.com8a1c16f2008-12-17 15:59:43 +0000175private:
reed@android.comc4cae852009-09-23 15:06:10 +0000176 SkXfermode* fXfermode;
177 SkPMColor* fBuffer;
178 SkBlitRow::Proc32 fProc32;
179 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000180 bool fShadeDirectlyIntoDevice;
halcanary9d524f22016-03-29 09:03:52 -0700181
reed@android.com8a1c16f2008-12-17 15:59:43 +0000182 // illegal
183 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
halcanary9d524f22016-03-29 09:03:52 -0700184
reed@android.com8a1c16f2008-12-17 15:59:43 +0000185 typedef SkShaderBlitter INHERITED;
186};
187
reed3dc6aac2016-04-14 09:02:14 -0700188SkBlitter* SkBlitter_ARGB32_Create(const SkPixmap& device, const SkPaint&, SkShader::Context*,
189 SkTBlitterAllocator*);
reeda34be682016-02-15 07:48:35 -0800190
reed3dc6aac2016-04-14 09:02:14 -0700191SkBlitter* SkBlitter_F16_Create(const SkPixmap& device, const SkPaint&, SkShader::Context*,
192 SkTBlitterAllocator*);
reed395eabe2016-01-30 18:52:31 -0800193
reed@android.com1fc4c602009-10-02 16:34:57 +0000194///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000195
reed@android.com1fc4c602009-10-02 16:34:57 +0000196/* These return the correct subclass of blitter for their device config.
197
198 Currently, they make the following assumptions about the state of the
199 paint:
reed@google.com981d4792011-03-09 12:55:47 +0000200
reed@android.com1fc4c602009-10-02 16:34:57 +0000201 1. If there is an xfermode, there will also be a shader
202 2. If there is a colorfilter, there will be a shader that itself handles
203 calling the filter, so the blitter can always ignore the colorfilter obj
204
205 These pre-conditions must be handled by the caller, in our case
206 SkBlitter::Choose(...)
207 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000208
reed41e010c2015-06-09 12:16:53 -0700209SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000210 SkShader::Context* shaderContext,
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000211 SkTBlitterAllocator* allocator);
reed@android.com1fc4c602009-10-02 16:34:57 +0000212
reed@android.com8a1c16f2008-12-17 15:59:43 +0000213#endif