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 SkPixmap & device)19 SkRasterBlitter(const SkPixmap& device) : fDevice(device) {} 20 21 protected: 22 const SkPixmap 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 SkPixmap& 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 bool resetShaderContext(const SkShader::ContextRec&) override; 45 getShaderContext()46 SkShader::Context* getShaderContext() const override { return fShaderContext; } 47 48 protected: 49 uint32_t fShaderFlags; 50 const SkShader* fShader; 51 SkShader::Context* fShaderContext; 52 bool fConstInY; 53 54 private: 55 // illegal 56 SkShaderBlitter& operator=(const SkShaderBlitter&); 57 58 typedef SkRasterBlitter INHERITED; 59 }; 60 61 /////////////////////////////////////////////////////////////////////////////// 62 63 class SkA8_Coverage_Blitter : public SkRasterBlitter { 64 public: 65 SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint); 66 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; 71 const SkPixmap* justAnOpaqueColor(uint32_t*) override; 72 }; 73 74 class SkA8_Blitter : public SkRasterBlitter { 75 public: 76 SkA8_Blitter(const SkPixmap& device, const SkPaint& paint); 77 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; 83 84 private: 85 unsigned fSrcA; 86 87 // illegal 88 SkA8_Blitter& operator=(const SkA8_Blitter&); 89 90 typedef SkRasterBlitter INHERITED; 91 }; 92 93 class SkA8_Shader_Blitter : public SkShaderBlitter { 94 public: 95 SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, 96 SkShader::Context* shaderContext); 97 virtual ~SkA8_Shader_Blitter(); 98 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; 101 102 private: 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 115 class SkARGB32_Blitter : public SkRasterBlitter { 116 public: 117 SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint); 118 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; 124 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; 125 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; 126 127 protected: 128 SkColor fColor; 129 SkPMColor fPMColor; 130 131 private: 132 unsigned fSrcA, fSrcR, fSrcG, fSrcB; 133 134 // illegal 135 SkARGB32_Blitter& operator=(const SkARGB32_Blitter&); 136 137 typedef SkRasterBlitter INHERITED; 138 }; 139 140 class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { 141 public: SkARGB32_Opaque_Blitter(const SkPixmap & device,const SkPaint & paint)142 SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint) 143 : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); } 144 void blitMask(const SkMask&, const SkIRect&) override; 145 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; 146 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; 147 148 private: 149 typedef SkARGB32_Blitter INHERITED; 150 }; 151 152 class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { 153 public: SkARGB32_Black_Blitter(const SkPixmap & device,const SkPaint & paint)154 SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint) 155 : INHERITED(device, paint) {} 156 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; 157 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; 158 void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; 159 160 private: 161 typedef SkARGB32_Opaque_Blitter INHERITED; 162 }; 163 164 class SkARGB32_Shader_Blitter : public SkShaderBlitter { 165 public: 166 SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, 167 SkShader::Context* shaderContext); 168 virtual ~SkARGB32_Shader_Blitter(); 169 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; 174 175 private: 176 SkXfermode* fXfermode; 177 SkPMColor* fBuffer; 178 SkBlitRow::Proc32 fProc32; 179 SkBlitRow::Proc32 fProc32Blend; 180 bool fShadeDirectlyIntoDevice; 181 182 // illegal 183 SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&); 184 185 typedef SkShaderBlitter INHERITED; 186 }; 187 188 SkBlitter* SkBlitter_ARGB32_Create(const SkPixmap& device, const SkPaint& paint, 189 SkShader::Context* shaderContext, 190 SkTBlitterAllocator* allocator); 191 192 SkBlitter* SkBlitter_ARGB64_Create(const SkPixmap& device, const SkPaint& paint, 193 SkShader::Context* shaderContext, 194 SkTBlitterAllocator* allocator); 195 196 /////////////////////////////////////////////////////////////////////////////// 197 198 /* These return the correct subclass of blitter for their device config. 199 200 Currently, they make the following assumptions about the state of the 201 paint: 202 203 1. If there is an xfermode, there will also be a shader 204 2. If there is a colorfilter, there will be a shader that itself handles 205 calling the filter, so the blitter can always ignore the colorfilter obj 206 207 These pre-conditions must be handled by the caller, in our case 208 SkBlitter::Choose(...) 209 */ 210 211 SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint, 212 SkShader::Context* shaderContext, 213 SkTBlitterAllocator* allocator); 214 215 #endif 216