2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkCoreBlitters_DEFINED
9 #define SkCoreBlitters_DEFINED
11 #include "SkBitmapProcShader.h"
12 #include "SkBlitter.h"
13 #include "SkBlitRow.h"
15 #include "SkSmallAllocator.h"
17 class SkRasterBlitter : public SkBlitter {
19 SkRasterBlitter(const SkBitmap& device) : fDevice(device) {}
22 const SkBitmap& fDevice;
25 typedef SkBlitter INHERITED;
28 class SkShaderBlitter : public SkRasterBlitter {
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.
35 SkShaderBlitter(const SkBitmap& device, const SkPaint& paint,
36 SkShader::Context* shaderContext);
37 virtual ~SkShaderBlitter();
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).
44 bool resetShaderContext(const SkShader::ContextRec&) SK_OVERRIDE;
46 SkShader::Context* getShaderContext() const SK_OVERRIDE { return fShaderContext; }
49 uint32_t fShaderFlags;
50 const SkShader* fShader;
51 SkShader::Context* fShaderContext;
55 SkShaderBlitter& operator=(const SkShaderBlitter&);
57 typedef SkRasterBlitter INHERITED;
60 ///////////////////////////////////////////////////////////////////////////////
62 class SkA8_Coverage_Blitter : public SkRasterBlitter {
64 SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint);
65 void blitH(int x, int y, int width) SK_OVERRIDE;
66 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) SK_OVERRIDE;
67 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
68 void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
69 void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE;
70 const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE;
73 class SkA8_Blitter : public SkRasterBlitter {
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*);
87 SkA8_Blitter& operator=(const SkA8_Blitter&);
89 typedef SkRasterBlitter INHERITED;
92 class SkA8_Shader_Blitter : public SkShaderBlitter {
94 SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
95 SkShader::Context* shaderContext);
96 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&);
102 SkXfermode* fXfermode;
107 SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&);
109 typedef SkShaderBlitter INHERITED;
112 ////////////////////////////////////////////////////////////////
114 class SkARGB32_Blitter : public SkRasterBlitter {
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*);
127 SkBlitRow::ColorProc fColor32Proc;
130 unsigned fSrcA, fSrcR, fSrcG, fSrcB;
133 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&);
135 typedef SkRasterBlitter INHERITED;
138 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
140 SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
141 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
142 virtual void blitMask(const SkMask&, const SkIRect&);
145 typedef SkARGB32_Blitter INHERITED;
148 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
150 SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
151 : INHERITED(device, paint) {}
152 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
155 typedef SkARGB32_Opaque_Blitter INHERITED;
158 class SkARGB32_Shader_Blitter : public SkShaderBlitter {
160 SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
161 SkShader::Context* shaderContext);
162 virtual ~SkARGB32_Shader_Blitter();
163 void blitH(int x, int y, int width) SK_OVERRIDE;
164 void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
165 void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
166 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) SK_OVERRIDE;
167 void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE;
170 SkXfermode* fXfermode;
172 SkBlitRow::Proc32 fProc32;
173 SkBlitRow::Proc32 fProc32Blend;
174 bool fShadeDirectlyIntoDevice;
178 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&);
180 typedef SkShaderBlitter INHERITED;
183 ///////////////////////////////////////////////////////////////////////////////
185 /* These return the correct subclass of blitter for their device config.
187 Currently, they make the following assumptions about the state of the
190 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
194 These pre-conditions must be handled by the caller, in our case
195 SkBlitter::Choose(...)
198 SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
199 SkShader::Context* shaderContext,
200 SkTBlitterAllocator* allocator);