1 /* 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 8 #ifndef SkCoreBlitters_DEFINED 9 #define SkCoreBlitters_DEFINED 10 11 #include "SkBitmapProcShader.h" 12 #include "SkBlitter.h" 13 #include "SkBlitRow.h" 14 #include "SkShader.h" 15 #include "SkSmallAllocator.h" 16 17 class SkRasterBlitter : public SkBlitter { 18 public: SkRasterBlitter(const SkBitmap & device)19 SkRasterBlitter(const SkBitmap& device) : fDevice(device) {} 20 21 protected: 22 const SkBitmap& fDevice; 23 24 private: 25 typedef SkBlitter INHERITED; 26 }; 27 28 class SkShaderBlitter : public SkRasterBlitter { 29 public: 30 /** 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); 37 virtual ~SkShaderBlitter(); 38 39 /** 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 SkShader::ContextRec&) SK_OVERRIDE; 45 getShaderContext()46 virtual SkShader::Context* getShaderContext() const SK_OVERRIDE { return fShaderContext; } 47 48 protected: 49 uint32_t fShaderFlags; 50 const SkShader* fShader; 51 SkShader::Context* fShaderContext; 52 53 private: 54 // illegal 55 SkShaderBlitter& operator=(const SkShaderBlitter&); 56 57 typedef SkRasterBlitter INHERITED; 58 }; 59 60 /////////////////////////////////////////////////////////////////////////////// 61 62 class SkA8_Coverage_Blitter : public SkRasterBlitter { 63 public: 64 SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint); 65 virtual void blitH(int x, int y, int width) SK_OVERRIDE; 66 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) SK_OVERRIDE; 67 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; 68 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; 69 virtual void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE; 70 virtual const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE; 71 }; 72 73 class SkA8_Blitter : public SkRasterBlitter { 74 public: 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 83 private: 84 unsigned fSrcA; 85 86 // illegal 87 SkA8_Blitter& operator=(const SkA8_Blitter&); 88 89 typedef SkRasterBlitter INHERITED; 90 }; 91 92 class SkA8_Shader_Blitter : public SkShaderBlitter { 93 public: 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&); 100 101 private: 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 114 class SkARGB32_Blitter : public SkRasterBlitter { 115 public: 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 124 protected: 125 SkColor fColor; 126 SkPMColor fPMColor; 127 SkBlitRow::ColorProc fColor32Proc; 128 SkBlitRow::ColorRectProc fColorRect32Proc; 129 130 private: 131 unsigned fSrcA, fSrcR, fSrcG, fSrcB; 132 133 // illegal 134 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&); 135 136 typedef SkRasterBlitter INHERITED; 137 }; 138 139 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { 140 public: SkARGB32_Opaque_Blitter(const SkBitmap & device,const SkPaint & paint)141 SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint) 142 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); } 143 virtual void blitMask(const SkMask&, const SkIRect&); 144 145 private: 146 typedef SkARGB32_Blitter INHERITED; 147 }; 148 149 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { 150 public: SkARGB32_Black_Blitter(const SkBitmap & device,const SkPaint & paint)151 SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint) 152 : INHERITED(device, paint) {} 153 virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); 154 155 private: 156 typedef SkARGB32_Opaque_Blitter INHERITED; 157 }; 158 159 class SkARGB32_Shader_Blitter : public SkShaderBlitter { 160 public: 161 SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, 162 SkShader::Context* shaderContext); 163 virtual ~SkARGB32_Shader_Blitter(); 164 virtual void blitH(int x, int y, int width) SK_OVERRIDE; 165 virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; 166 virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; 167 virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) SK_OVERRIDE; 168 virtual void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE; 169 170 private: 171 SkXfermode* fXfermode; 172 SkPMColor* fBuffer; 173 SkBlitRow::Proc32 fProc32; 174 SkBlitRow::Proc32 fProc32Blend; 175 bool fShadeDirectlyIntoDevice; 176 bool fConstInY; 177 178 // illegal 179 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&); 180 181 typedef SkShaderBlitter INHERITED; 182 }; 183 184 /////////////////////////////////////////////////////////////////////////////// 185 186 /* These return the correct subclass of blitter for their device config. 187 188 Currently, they make the following assumptions about the state of the 189 paint: 190 191 1. If there is an xfermode, there will also be a shader 192 2. If there is a colorfilter, there will be a shader that itself handles 193 calling the filter, so the blitter can always ignore the colorfilter obj 194 195 These pre-conditions must be handled by the caller, in our case 196 SkBlitter::Choose(...) 197 */ 198 199 SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, 200 SkShader::Context* shaderContext, 201 SkTBlitterAllocator* allocator); 202 203 #endif 204