blob: 2d22d38e782977fe48221a270ad85947836400c2 [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 */
44 virtual bool resetShaderContext(const SkBitmap& device, const SkPaint& paint,
45 const SkMatrix& matrix) SK_OVERRIDE;
46
47 virtual SkShader::Context* getShaderContext() const SK_OVERRIDE { return fShaderContext; }
48
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;
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:
65 SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint);
66 virtual void blitH(int x, int y, int width) SK_OVERRIDE;
67 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) SK_OVERRIDE;
68 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
69 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
70 virtual void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE;
71 virtual const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE;
72};
73
reed@android.com8a1c16f2008-12-17 15:59:43 +000074class SkA8_Blitter : public SkRasterBlitter {
75public:
76 SkA8_Blitter(const SkBitmap& device, const SkPaint& paint);
77 virtual void blitH(int x, int y, int width);
78 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
79 virtual void blitV(int x, int y, int height, SkAlpha alpha);
80 virtual void blitRect(int x, int y, int width, int height);
81 virtual void blitMask(const SkMask&, const SkIRect&);
82 virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
83
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:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +000095 SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
96 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 virtual ~SkA8_Shader_Blitter();
98 virtual void blitH(int x, int y, int width);
99 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
100 virtual void blitMask(const SkMask&, const SkIRect&);
101
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:
117 SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint);
118 virtual void blitH(int x, int y, int width);
119 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
120 virtual void blitV(int x, int y, int height, SkAlpha alpha);
121 virtual void blitRect(int x, int y, int width, int height);
122 virtual void blitMask(const SkMask&, const SkIRect&);
123 virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
124
125protected:
reed@google.comee467ee2011-03-09 13:23:57 +0000126 SkColor fColor;
127 SkPMColor fPMColor;
senorblanco@chromium.org29e50542010-12-16 19:07:45 +0000128 SkBlitRow::ColorProc fColor32Proc;
tomhudson@google.com8dd90a92012-03-19 13:49:50 +0000129 SkBlitRow::ColorRectProc fColorRect32Proc;
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:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000142 SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
143 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000144 virtual void blitMask(const SkMask&, const SkIRect&);
reed@android.comdafaf7a2009-07-10 03:05:59 +0000145
reed@android.com8a1c16f2008-12-17 15:59:43 +0000146private:
147 typedef SkARGB32_Blitter INHERITED;
148};
149
reed@android.comdafaf7a2009-07-10 03:05:59 +0000150class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000151public:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000152 SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
153 : INHERITED(device, paint) {}
reed@android.comdafaf7a2009-07-10 03:05:59 +0000154 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
reed@android.comb602b8e2009-07-10 15:58:53 +0000155
reed@android.com8a1c16f2008-12-17 15:59:43 +0000156private:
reed@android.comdafaf7a2009-07-10 03:05:59 +0000157 typedef SkARGB32_Opaque_Blitter INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000158};
159
160class SkARGB32_Shader_Blitter : public SkShaderBlitter {
161public:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000162 SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
163 SkShader::Context* shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000164 virtual ~SkARGB32_Shader_Blitter();
reed@google.com13201e72012-11-16 13:20:41 +0000165 virtual void blitH(int x, int y, int width) SK_OVERRIDE;
reed@google.com13201e72012-11-16 13:20:41 +0000166 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
reed@google.com3bafe742012-10-12 18:56:18 +0000167 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
reed@google.com13201e72012-11-16 13:20:41 +0000168 virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) SK_OVERRIDE;
169 virtual void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000170
reed@android.com8a1c16f2008-12-17 15:59:43 +0000171private:
reed@android.comc4cae852009-09-23 15:06:10 +0000172 SkXfermode* fXfermode;
173 SkPMColor* fBuffer;
174 SkBlitRow::Proc32 fProc32;
175 SkBlitRow::Proc32 fProc32Blend;
reed@google.com13201e72012-11-16 13:20:41 +0000176 bool fShadeDirectlyIntoDevice;
177 bool fConstInY;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000178
reed@android.com8a1c16f2008-12-17 15:59:43 +0000179 // illegal
180 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000181
reed@android.com8a1c16f2008-12-17 15:59:43 +0000182 typedef SkShaderBlitter INHERITED;
183};
184
reed@android.com1fc4c602009-10-02 16:34:57 +0000185///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000186
reed@android.com1fc4c602009-10-02 16:34:57 +0000187/* These return the correct subclass of blitter for their device config.
188
189 Currently, they make the following assumptions about the state of the
190 paint:
reed@google.com981d4792011-03-09 12:55:47 +0000191
reed@android.com1fc4c602009-10-02 16:34:57 +0000192 1. If there is an xfermode, there will also be a shader
193 2. If there is a colorfilter, there will be a shader that itself handles
194 calling the filter, so the blitter can always ignore the colorfilter obj
195
196 These pre-conditions must be handled by the caller, in our case
197 SkBlitter::Choose(...)
198 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000199
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000200SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000201 SkShader::Context* shaderContext,
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000202 SkTBlitterAllocator* allocator);
reed@android.com1fc4c602009-10-02 16:34:57 +0000203
reed@android.com8a1c16f2008-12-17 15:59:43 +0000204#endif