| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkSpriteBlitter.h" | 10 #include "SkSpriteBlitter.h" |
| 11 #include "SkBlitRow.h" | 11 #include "SkBlitRow.h" |
| 12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
| 13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
| 15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
| 16 #include "SkXfermode.h" | 16 #include "SkXfermode.h" |
| 17 | 17 |
| 18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
| 20 class Sprite_D32_S32 : public SkSpriteBlitter { | 20 class Sprite_D32_S32 : public SkSpriteBlitter { |
| 21 public: | 21 public: |
| 22 Sprite_D32_S32(const SkBitmap& src, U8CPU alpha) : INHERITED(src) { | 22 Sprite_D32_S32(const SkPixmap& src, U8CPU alpha) : INHERITED(src) { |
| 23 SkASSERT(src.colorType() == kN32_SkColorType); | 23 SkASSERT(src.colorType() == kN32_SkColorType); |
| 24 | 24 |
| 25 unsigned flags32 = 0; | 25 unsigned flags32 = 0; |
| 26 if (255 != alpha) { | 26 if (255 != alpha) { |
| 27 flags32 |= SkBlitRow::kGlobalAlpha_Flag32; | 27 flags32 |= SkBlitRow::kGlobalAlpha_Flag32; |
| 28 } | 28 } |
| 29 if (!src.isOpaque()) { | 29 if (!src.isOpaque()) { |
| 30 flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; | 30 flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; |
| 31 } | 31 } |
| 32 | 32 |
| 33 fProc32 = SkBlitRow::Factory32(flags32); | 33 fProc32 = SkBlitRow::Factory32(flags32); |
| 34 fAlpha = alpha; | 34 fAlpha = alpha; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void blitRect(int x, int y, int width, int height) override { | 37 void blitRect(int x, int y, int width, int height) override { |
| 38 SkASSERT(width > 0 && height > 0); | 38 SkASSERT(width > 0 && height > 0); |
| 39 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 39 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 40 const uint32_t* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); | 40 const uint32_t* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop); |
| 41 size_t dstRB = fDevice->rowBytes(); | 41 size_t dstRB = fDevice->rowBytes(); |
| 42 size_t srcRB = fSource->rowBytes(); | 42 size_t srcRB = fSource.rowBytes(); |
| 43 SkBlitRow::Proc32 proc = fProc32; | 43 SkBlitRow::Proc32 proc = fProc32; |
| 44 U8CPU alpha = fAlpha; | 44 U8CPU alpha = fAlpha; |
| 45 | 45 |
| 46 do { | 46 do { |
| 47 proc(dst, src, width, alpha); | 47 proc(dst, src, width, alpha); |
| 48 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); | 48 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
| 49 src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); | 49 src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); |
| 50 } while (--height != 0); | 50 } while (--height != 0); |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 SkBlitRow::Proc32 fProc32; | 54 SkBlitRow::Proc32 fProc32; |
| 55 U8CPU fAlpha; | 55 U8CPU fAlpha; |
| 56 | 56 |
| 57 typedef SkSpriteBlitter INHERITED; | 57 typedef SkSpriteBlitter INHERITED; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
| 61 | 61 |
| 62 class Sprite_D32_XferFilter : public SkSpriteBlitter { | 62 class Sprite_D32_XferFilter : public SkSpriteBlitter { |
| 63 public: | 63 public: |
| 64 Sprite_D32_XferFilter(const SkBitmap& source, const SkPaint& paint) | 64 Sprite_D32_XferFilter(const SkPixmap& source, const SkPaint& paint) : SkSpri
teBlitter(source) { |
| 65 : SkSpriteBlitter(source) { | |
| 66 fColorFilter = paint.getColorFilter(); | 65 fColorFilter = paint.getColorFilter(); |
| 67 SkSafeRef(fColorFilter); | 66 SkSafeRef(fColorFilter); |
| 68 | 67 |
| 69 fXfermode = paint.getXfermode(); | 68 fXfermode = paint.getXfermode(); |
| 70 SkSafeRef(fXfermode); | 69 SkSafeRef(fXfermode); |
| 71 | 70 |
| 72 fBufferSize = 0; | 71 fBufferSize = 0; |
| 73 fBuffer = NULL; | 72 fBuffer = NULL; |
| 74 | 73 |
| 75 unsigned flags32 = 0; | 74 unsigned flags32 = 0; |
| 76 if (255 != paint.getAlpha()) { | 75 if (255 != paint.getAlpha()) { |
| 77 flags32 |= SkBlitRow::kGlobalAlpha_Flag32; | 76 flags32 |= SkBlitRow::kGlobalAlpha_Flag32; |
| 78 } | 77 } |
| 79 if (!source.isOpaque()) { | 78 if (!source.isOpaque()) { |
| 80 flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; | 79 flags32 |= SkBlitRow::kSrcPixelAlpha_Flag32; |
| 81 } | 80 } |
| 82 | 81 |
| 83 fProc32 = SkBlitRow::Factory32(flags32); | 82 fProc32 = SkBlitRow::Factory32(flags32); |
| 84 fAlpha = paint.getAlpha(); | 83 fAlpha = paint.getAlpha(); |
| 85 } | 84 } |
| 86 | 85 |
| 87 virtual ~Sprite_D32_XferFilter() { | 86 virtual ~Sprite_D32_XferFilter() { |
| 88 delete[] fBuffer; | 87 delete[] fBuffer; |
| 89 SkSafeUnref(fXfermode); | 88 SkSafeUnref(fXfermode); |
| 90 SkSafeUnref(fColorFilter); | 89 SkSafeUnref(fColorFilter); |
| 91 } | 90 } |
| 92 | 91 |
| 93 bool setup(const SkBitmap& device, int left, int top, const SkPaint& paint)
override { | 92 void setup(const SkBitmap& device, int left, int top, const SkPaint& paint)
override { |
| 94 if (!this->INHERITED::setup(device, left, top, paint)) { | 93 this->INHERITED::setup(device, left, top, paint); |
| 95 return false; | |
| 96 } | |
| 97 | 94 |
| 98 int width = device.width(); | 95 int width = device.width(); |
| 99 if (width > fBufferSize) { | 96 if (width > fBufferSize) { |
| 100 fBufferSize = width; | 97 fBufferSize = width; |
| 101 delete[] fBuffer; | 98 delete[] fBuffer; |
| 102 fBuffer = new SkPMColor[width]; | 99 fBuffer = new SkPMColor[width]; |
| 103 } | 100 } |
| 104 return true; | |
| 105 } | 101 } |
| 106 | 102 |
| 107 protected: | 103 protected: |
| 108 SkColorFilter* fColorFilter; | 104 SkColorFilter* fColorFilter; |
| 109 SkXfermode* fXfermode; | 105 SkXfermode* fXfermode; |
| 110 int fBufferSize; | 106 int fBufferSize; |
| 111 SkPMColor* fBuffer; | 107 SkPMColor* fBuffer; |
| 112 SkBlitRow::Proc32 fProc32; | 108 SkBlitRow::Proc32 fProc32; |
| 113 U8CPU fAlpha; | 109 U8CPU fAlpha; |
| 114 | 110 |
| 115 private: | 111 private: |
| 116 typedef SkSpriteBlitter INHERITED; | 112 typedef SkSpriteBlitter INHERITED; |
| 117 }; | 113 }; |
| 118 | 114 |
| 119 /////////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////////// |
| 120 | 116 |
| 121 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { | 117 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { |
| 122 public: | 118 public: |
| 123 Sprite_D32_S32A_XferFilter(const SkBitmap& source, const SkPaint& paint) | 119 Sprite_D32_S32A_XferFilter(const SkPixmap& source, const SkPaint& paint) |
| 124 : Sprite_D32_XferFilter(source, paint) {} | 120 : Sprite_D32_XferFilter(source, paint) {} |
| 125 | 121 |
| 126 void blitRect(int x, int y, int width, int height) override { | 122 void blitRect(int x, int y, int width, int height) override { |
| 127 SkASSERT(width > 0 && height > 0); | 123 SkASSERT(width > 0 && height > 0); |
| 128 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 124 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 129 const uint32_t* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); | 125 const uint32_t* SK_RESTRICT src = fSource.addr32(x - fLeft, y - fTop); |
| 130 size_t dstRB = fDevice->rowBytes(); | 126 size_t dstRB = fDevice->rowBytes(); |
| 131 size_t srcRB = fSource->rowBytes(); | 127 size_t srcRB = fSource.rowBytes(); |
| 132 SkColorFilter* colorFilter = fColorFilter; | 128 SkColorFilter* colorFilter = fColorFilter; |
| 133 SkXfermode* xfermode = fXfermode; | 129 SkXfermode* xfermode = fXfermode; |
| 134 | 130 |
| 135 do { | 131 do { |
| 136 const SkPMColor* tmp = src; | 132 const SkPMColor* tmp = src; |
| 137 | 133 |
| 138 if (colorFilter) { | 134 if (colorFilter) { |
| 139 colorFilter->filterSpan(src, width, fBuffer); | 135 colorFilter->filterSpan(src, width, fBuffer); |
| 140 tmp = fBuffer; | 136 tmp = fBuffer; |
| 141 } | 137 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 159 const SkPMColor16* SK_RESTRICT src, int count) { | 155 const SkPMColor16* SK_RESTRICT src, int count) { |
| 160 SkASSERT(count > 0); | 156 SkASSERT(count > 0); |
| 161 | 157 |
| 162 do { | 158 do { |
| 163 *dst++ = SkPixel4444ToPixel32(*src++); | 159 *dst++ = SkPixel4444ToPixel32(*src++); |
| 164 } while (--count != 0); | 160 } while (--count != 0); |
| 165 } | 161 } |
| 166 | 162 |
| 167 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { | 163 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { |
| 168 public: | 164 public: |
| 169 Sprite_D32_S4444_XferFilter(const SkBitmap& source, const SkPaint& paint) | 165 Sprite_D32_S4444_XferFilter(const SkPixmap& source, const SkPaint& paint) |
| 170 : Sprite_D32_XferFilter(source, paint) {} | 166 : Sprite_D32_XferFilter(source, paint) {} |
| 171 | 167 |
| 172 void blitRect(int x, int y, int width, int height) override { | 168 void blitRect(int x, int y, int width, int height) override { |
| 173 SkASSERT(width > 0 && height > 0); | 169 SkASSERT(width > 0 && height > 0); |
| 174 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 170 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 175 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); | 171 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 176 size_t dstRB = fDevice->rowBytes(); | 172 size_t dstRB = fDevice->rowBytes(); |
| 177 size_t srcRB = fSource->rowBytes(); | 173 size_t srcRB = fSource.rowBytes(); |
| 178 SkPMColor* SK_RESTRICT buffer = fBuffer; | 174 SkPMColor* SK_RESTRICT buffer = fBuffer; |
| 179 SkColorFilter* colorFilter = fColorFilter; | 175 SkColorFilter* colorFilter = fColorFilter; |
| 180 SkXfermode* xfermode = fXfermode; | 176 SkXfermode* xfermode = fXfermode; |
| 181 | 177 |
| 182 do { | 178 do { |
| 183 fillbuffer(buffer, src, width); | 179 fillbuffer(buffer, src, width); |
| 184 | 180 |
| 185 if (colorFilter) { | 181 if (colorFilter) { |
| 186 colorFilter->filterSpan(buffer, width, buffer); | 182 colorFilter->filterSpan(buffer, width, buffer); |
| 187 } | 183 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 206 const SkPMColor16* SK_RESTRICT src, int count) { | 202 const SkPMColor16* SK_RESTRICT src, int count) { |
| 207 do { | 203 do { |
| 208 *dst = SkPixel4444ToPixel32(*src); | 204 *dst = SkPixel4444ToPixel32(*src); |
| 209 src += 1; | 205 src += 1; |
| 210 dst += 1; | 206 dst += 1; |
| 211 } while (--count != 0); | 207 } while (--count != 0); |
| 212 } | 208 } |
| 213 | 209 |
| 214 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { | 210 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { |
| 215 public: | 211 public: |
| 216 Sprite_D32_S4444_Opaque(const SkBitmap& source) : SkSpriteBlitter(source) {} | 212 Sprite_D32_S4444_Opaque(const SkPixmap& source) : SkSpriteBlitter(source) {} |
| 217 | 213 |
| 218 void blitRect(int x, int y, int width, int height) override { | 214 void blitRect(int x, int y, int width, int height) override { |
| 219 SkASSERT(width > 0 && height > 0); | 215 SkASSERT(width > 0 && height > 0); |
| 220 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 216 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 221 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); | 217 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 222 size_t dstRB = fDevice->rowBytes(); | 218 size_t dstRB = fDevice->rowBytes(); |
| 223 size_t srcRB = fSource->rowBytes(); | 219 size_t srcRB = fSource.rowBytes(); |
| 224 | 220 |
| 225 do { | 221 do { |
| 226 src_row(dst, src, width); | 222 src_row(dst, src, width); |
| 227 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 223 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 228 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 224 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 229 } while (--height != 0); | 225 } while (--height != 0); |
| 230 } | 226 } |
| 231 }; | 227 }; |
| 232 | 228 |
| 233 static void srcover_row(SkPMColor* SK_RESTRICT dst, | 229 static void srcover_row(SkPMColor* SK_RESTRICT dst, |
| 234 const SkPMColor16* SK_RESTRICT src, int count) { | 230 const SkPMColor16* SK_RESTRICT src, int count) { |
| 235 do { | 231 do { |
| 236 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); | 232 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); |
| 237 src += 1; | 233 src += 1; |
| 238 dst += 1; | 234 dst += 1; |
| 239 } while (--count != 0); | 235 } while (--count != 0); |
| 240 } | 236 } |
| 241 | 237 |
| 242 class Sprite_D32_S4444 : public SkSpriteBlitter { | 238 class Sprite_D32_S4444 : public SkSpriteBlitter { |
| 243 public: | 239 public: |
| 244 Sprite_D32_S4444(const SkBitmap& source) : SkSpriteBlitter(source) {} | 240 Sprite_D32_S4444(const SkPixmap& source) : SkSpriteBlitter(source) {} |
| 245 | 241 |
| 246 void blitRect(int x, int y, int width, int height) override { | 242 void blitRect(int x, int y, int width, int height) override { |
| 247 SkASSERT(width > 0 && height > 0); | 243 SkASSERT(width > 0 && height > 0); |
| 248 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 244 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 249 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); | 245 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 250 size_t dstRB = fDevice->rowBytes(); | 246 size_t dstRB = fDevice->rowBytes(); |
| 251 size_t srcRB = fSource->rowBytes(); | 247 size_t srcRB = fSource.rowBytes(); |
| 252 | 248 |
| 253 do { | 249 do { |
| 254 srcover_row(dst, src, width); | 250 srcover_row(dst, src, width); |
| 255 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 251 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 256 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 252 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 257 } while (--height != 0); | 253 } while (--height != 0); |
| 258 } | 254 } |
| 259 }; | 255 }; |
| 260 | 256 |
| 261 /////////////////////////////////////////////////////////////////////////////// | 257 /////////////////////////////////////////////////////////////////////////////// |
| 262 | 258 |
| 263 SkSpriteBlitter* SkSpriteBlitter::ChooseD32(const SkBitmap& source, const SkPain
t& paint, | 259 SkSpriteBlitter* SkSpriteBlitter::ChooseD32(const SkPixmap& source, const SkPain
t& paint, |
| 264 SkTBlitterAllocator* allocator) { | 260 SkTBlitterAllocator* allocator) { |
| 265 SkASSERT(allocator != NULL); | 261 SkASSERT(allocator != NULL); |
| 266 | 262 |
| 267 if (paint.getMaskFilter() != NULL) { | 263 if (paint.getMaskFilter() != NULL) { |
| 268 return NULL; | 264 return NULL; |
| 269 } | 265 } |
| 270 | 266 |
| 271 U8CPU alpha = paint.getAlpha(); | 267 U8CPU alpha = paint.getAlpha(); |
| 272 SkXfermode* xfermode = paint.getXfermode(); | 268 SkXfermode* xfermode = paint.getXfermode(); |
| 273 SkColorFilter* filter = paint.getColorFilter(); | 269 SkColorFilter* filter = paint.getColorFilter(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 295 } else { | 291 } else { |
| 296 // this can handle alpha, but not xfermode or filter | 292 // this can handle alpha, but not xfermode or filter |
| 297 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); | 293 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); |
| 298 } | 294 } |
| 299 break; | 295 break; |
| 300 default: | 296 default: |
| 301 break; | 297 break; |
| 302 } | 298 } |
| 303 return blitter; | 299 return blitter; |
| 304 } | 300 } |
| OLD | NEW |