blob: f4a5d6f4dbbfab199600411adeb5faa977aec22a [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*);
123
124protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000125 SkColor fColor;
126 SkPMColor fPMColor;
senorblanco@chromium.org29e50542010-12-16 19:07:45 +0000127 SkBlitRow::ColorProc fColor32Proc;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000128
129private:
130 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
131
132 // illegal
133 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
134
135 typedef SkRasterBlitter INHERITED;
136};
137
reed@android.comdafaf7a2009-07-10 03:05:59 +0000138class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000139public:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000140 SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
141 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142 virtual void blitMask(const SkMask&, const SkIRect&);
reed@android.comdafaf7a2009-07-10 03:05:59 +0000143
reed@android.com8a1c16f2008-12-17 15:59:43 +0000144private:
145 typedef SkARGB32_Blitter INHERITED;
146};
147
reed@android.comdafaf7a2009-07-10 03:05:59 +0000148class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000149public:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000150 SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
151 : INHERITED(device, paint) {}
reed@android.comdafaf7a2009-07-10 03:05:59 +0000152 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
reed@android.comb602b8e2009-07-10 15:58:53 +0000153
reed@android.com8a1c16f2008-12-17 15:59:43 +0000154private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000155 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000156};
157
158class SkARGB32_Shader_Blitter : public SkShaderBlitter {
159public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000160 SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
161 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000162 virtual ~SkARGB32_Shader_Blitter();
mtklein36352bf2015-03-25 18:17:31 -0700163 void blitH(int x, int y, int width) override;
164 void blitV(int x, int y, int height, SkAlpha alpha) override;
165 void blitRect(int x, int y, int width, int height) override;
166 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
167 void blitMask(const SkMask&, const SkIRect&) override;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000168
reed@android.com8a1c16f2008-12-17 15:59:43 +0000169private:
reed@android.comc4cae852009-09-23 15:06:10 +0000170 SkXfermode* fXfermode;
171 SkPMColor* fBuffer;
172 SkBlitRow::Proc32 fProc32;
173 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000174 bool fShadeDirectlyIntoDevice;
175 bool fConstInY;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000176
reed@android.com8a1c16f2008-12-17 15:59:43 +0000177 // illegal
178 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000179
reed@android.com8a1c16f2008-12-17 15:59:43 +0000180 typedef SkShaderBlitter INHERITED;
181};
182
reed@android.com1fc4c602009-10-02 16:34:57 +0000183///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000184
reed@android.com1fc4c602009-10-02 16:34:57 +0000185/* These return the correct subclass of blitter for their device config.
186
187 Currently, they make the following assumptions about the state of the
188 paint:
reed@google.com981d4792011-03-09 12:55:47 +0000189
reed@android.com1fc4c602009-10-02 16:34:57 +0000190 1. If there is an xfermode, there will also be a shader
191 2. If there is a colorfilter, there will be a shader that itself handles
192 calling the filter, so the blitter can always ignore the colorfilter obj
193
194 These pre-conditions must be handled by the caller, in our case
195 SkBlitter::Choose(...)
196 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000197
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000198SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000199 SkShader::Context* shaderContext,
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000200 SkTBlitterAllocator* allocator);
reed@android.com1fc4c602009-10-02 16:34:57 +0000201
reed@android.com8a1c16f2008-12-17 15:59:43 +0000202#endif