| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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->getAddr32(x - fLeft, | 40 const uint32_t* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); |
| 41 y - fTop); | |
| 42 size_t dstRB = fDevice->rowBytes(); | 41 size_t dstRB = fDevice->rowBytes(); |
| 43 size_t srcRB = fSource->rowBytes(); | 42 size_t srcRB = fSource->rowBytes(); |
| 44 SkBlitRow::Proc32 proc = fProc32; | 43 SkBlitRow::Proc32 proc = fProc32; |
| 45 U8CPU alpha = fAlpha; | 44 U8CPU alpha = fAlpha; |
| 46 | 45 |
| 47 do { | 46 do { |
| 48 proc(dst, src, width, alpha); | 47 proc(dst, src, width, alpha); |
| 49 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); | 48 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
| 50 src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); | 49 src = (const uint32_t* SK_RESTRICT)((const char*)src + srcRB); |
| 51 } while (--height != 0); | 50 } while (--height != 0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 fProc32 = SkBlitRow::Factory32(flags32); | 83 fProc32 = SkBlitRow::Factory32(flags32); |
| 85 fAlpha = paint.getAlpha(); | 84 fAlpha = paint.getAlpha(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 virtual ~Sprite_D32_XferFilter() { | 87 virtual ~Sprite_D32_XferFilter() { |
| 89 delete[] fBuffer; | 88 delete[] fBuffer; |
| 90 SkSafeUnref(fXfermode); | 89 SkSafeUnref(fXfermode); |
| 91 SkSafeUnref(fColorFilter); | 90 SkSafeUnref(fColorFilter); |
| 92 } | 91 } |
| 93 | 92 |
| 94 virtual void setup(const SkBitmap& device, int left, int top, | 93 bool setup(const SkBitmap& device, int left, int top, const SkPaint& paint)
override { |
| 95 const SkPaint& paint) override { | 94 if (!this->INHERITED::setup(device, left, top, paint)) { |
| 96 this->INHERITED::setup(device, left, top, paint); | 95 return false; |
| 96 } |
| 97 | 97 |
| 98 int width = device.width(); | 98 int width = device.width(); |
| 99 if (width > fBufferSize) { | 99 if (width > fBufferSize) { |
| 100 fBufferSize = width; | 100 fBufferSize = width; |
| 101 delete[] fBuffer; | 101 delete[] fBuffer; |
| 102 fBuffer = new SkPMColor[width]; | 102 fBuffer = new SkPMColor[width]; |
| 103 } | 103 } |
| 104 return true; |
| 104 } | 105 } |
| 105 | 106 |
| 106 protected: | 107 protected: |
| 107 SkColorFilter* fColorFilter; | 108 SkColorFilter* fColorFilter; |
| 108 SkXfermode* fXfermode; | 109 SkXfermode* fXfermode; |
| 109 int fBufferSize; | 110 int fBufferSize; |
| 110 SkPMColor* fBuffer; | 111 SkPMColor* fBuffer; |
| 111 SkBlitRow::Proc32 fProc32; | 112 SkBlitRow::Proc32 fProc32; |
| 112 U8CPU fAlpha; | 113 U8CPU fAlpha; |
| 113 | 114 |
| 114 private: | 115 private: |
| 115 typedef SkSpriteBlitter INHERITED; | 116 typedef SkSpriteBlitter INHERITED; |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 /////////////////////////////////////////////////////////////////////////////// | 119 /////////////////////////////////////////////////////////////////////////////// |
| 119 | 120 |
| 120 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { | 121 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { |
| 121 public: | 122 public: |
| 122 Sprite_D32_S32A_XferFilter(const SkBitmap& source, const SkPaint& paint) | 123 Sprite_D32_S32A_XferFilter(const SkBitmap& source, const SkPaint& paint) |
| 123 : Sprite_D32_XferFilter(source, paint) {} | 124 : Sprite_D32_XferFilter(source, paint) {} |
| 124 | 125 |
| 125 void blitRect(int x, int y, int width, int height) override { | 126 void blitRect(int x, int y, int width, int height) override { |
| 126 SkASSERT(width > 0 && height > 0); | 127 SkASSERT(width > 0 && height > 0); |
| 127 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 128 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 128 const uint32_t* SK_RESTRICT src = fSource->getAddr32(x - fLeft, | 129 const uint32_t* SK_RESTRICT src = fSource->addr32(x - fLeft, y - fTop); |
| 129 y - fTop); | |
| 130 size_t dstRB = fDevice->rowBytes(); | 130 size_t dstRB = fDevice->rowBytes(); |
| 131 size_t srcRB = fSource->rowBytes(); | 131 size_t srcRB = fSource->rowBytes(); |
| 132 SkColorFilter* colorFilter = fColorFilter; | 132 SkColorFilter* colorFilter = fColorFilter; |
| 133 SkXfermode* xfermode = fXfermode; | 133 SkXfermode* xfermode = fXfermode; |
| 134 | 134 |
| 135 do { | 135 do { |
| 136 const SkPMColor* tmp = src; | 136 const SkPMColor* tmp = src; |
| 137 | 137 |
| 138 if (colorFilter) { | 138 if (colorFilter) { |
| 139 colorFilter->filterSpan(src, width, fBuffer); | 139 colorFilter->filterSpan(src, width, fBuffer); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { | 167 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { |
| 168 public: | 168 public: |
| 169 Sprite_D32_S4444_XferFilter(const SkBitmap& source, const SkPaint& paint) | 169 Sprite_D32_S4444_XferFilter(const SkBitmap& source, const SkPaint& paint) |
| 170 : Sprite_D32_XferFilter(source, paint) {} | 170 : Sprite_D32_XferFilter(source, paint) {} |
| 171 | 171 |
| 172 void blitRect(int x, int y, int width, int height) override { | 172 void blitRect(int x, int y, int width, int height) override { |
| 173 SkASSERT(width > 0 && height > 0); | 173 SkASSERT(width > 0 && height > 0); |
| 174 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 174 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 175 const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, | 175 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); |
| 176 y - fTop); | |
| 177 size_t dstRB = fDevice->rowBytes(); | 176 size_t dstRB = fDevice->rowBytes(); |
| 178 size_t srcRB = fSource->rowBytes(); | 177 size_t srcRB = fSource->rowBytes(); |
| 179 SkPMColor* SK_RESTRICT buffer = fBuffer; | 178 SkPMColor* SK_RESTRICT buffer = fBuffer; |
| 180 SkColorFilter* colorFilter = fColorFilter; | 179 SkColorFilter* colorFilter = fColorFilter; |
| 181 SkXfermode* xfermode = fXfermode; | 180 SkXfermode* xfermode = fXfermode; |
| 182 | 181 |
| 183 do { | 182 do { |
| 184 fillbuffer(buffer, src, width); | 183 fillbuffer(buffer, src, width); |
| 185 | 184 |
| 186 if (colorFilter) { | 185 if (colorFilter) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 212 } while (--count != 0); | 211 } while (--count != 0); |
| 213 } | 212 } |
| 214 | 213 |
| 215 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { | 214 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { |
| 216 public: | 215 public: |
| 217 Sprite_D32_S4444_Opaque(const SkBitmap& source) : SkSpriteBlitter(source) {} | 216 Sprite_D32_S4444_Opaque(const SkBitmap& source) : SkSpriteBlitter(source) {} |
| 218 | 217 |
| 219 void blitRect(int x, int y, int width, int height) override { | 218 void blitRect(int x, int y, int width, int height) override { |
| 220 SkASSERT(width > 0 && height > 0); | 219 SkASSERT(width > 0 && height > 0); |
| 221 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 220 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 222 const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, | 221 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); |
| 223 y - fTop); | |
| 224 size_t dstRB = fDevice->rowBytes(); | 222 size_t dstRB = fDevice->rowBytes(); |
| 225 size_t srcRB = fSource->rowBytes(); | 223 size_t srcRB = fSource->rowBytes(); |
| 226 | 224 |
| 227 do { | 225 do { |
| 228 src_row(dst, src, width); | 226 src_row(dst, src, width); |
| 229 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 227 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 230 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 228 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 231 } while (--height != 0); | 229 } while (--height != 0); |
| 232 } | 230 } |
| 233 }; | 231 }; |
| 234 | 232 |
| 235 static void srcover_row(SkPMColor* SK_RESTRICT dst, | 233 static void srcover_row(SkPMColor* SK_RESTRICT dst, |
| 236 const SkPMColor16* SK_RESTRICT src, int count) { | 234 const SkPMColor16* SK_RESTRICT src, int count) { |
| 237 do { | 235 do { |
| 238 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); | 236 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); |
| 239 src += 1; | 237 src += 1; |
| 240 dst += 1; | 238 dst += 1; |
| 241 } while (--count != 0); | 239 } while (--count != 0); |
| 242 } | 240 } |
| 243 | 241 |
| 244 class Sprite_D32_S4444 : public SkSpriteBlitter { | 242 class Sprite_D32_S4444 : public SkSpriteBlitter { |
| 245 public: | 243 public: |
| 246 Sprite_D32_S4444(const SkBitmap& source) : SkSpriteBlitter(source) {} | 244 Sprite_D32_S4444(const SkBitmap& source) : SkSpriteBlitter(source) {} |
| 247 | 245 |
| 248 void blitRect(int x, int y, int width, int height) override { | 246 void blitRect(int x, int y, int width, int height) override { |
| 249 SkASSERT(width > 0 && height > 0); | 247 SkASSERT(width > 0 && height > 0); |
| 250 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 248 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); |
| 251 const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft, | 249 const SkPMColor16* SK_RESTRICT src = fSource->addr16(x - fLeft, y - fTop
); |
| 252 y - fTop); | |
| 253 size_t dstRB = fDevice->rowBytes(); | 250 size_t dstRB = fDevice->rowBytes(); |
| 254 size_t srcRB = fSource->rowBytes(); | 251 size_t srcRB = fSource->rowBytes(); |
| 255 | 252 |
| 256 do { | 253 do { |
| 257 srcover_row(dst, src, width); | 254 srcover_row(dst, src, width); |
| 258 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 255 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 259 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 256 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 260 } while (--height != 0); | 257 } while (--height != 0); |
| 261 } | 258 } |
| 262 }; | 259 }; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } else { | 295 } else { |
| 299 // this can handle alpha, but not xfermode or filter | 296 // this can handle alpha, but not xfermode or filter |
| 300 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); | 297 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); |
| 301 } | 298 } |
| 302 break; | 299 break; |
| 303 default: | 300 default: |
| 304 break; | 301 break; |
| 305 } | 302 } |
| 306 return blitter; | 303 return blitter; |
| 307 } | 304 } |
| OLD | NEW |