| 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 18 matching lines...) Expand all Loading... |
| 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 = fDst.writable_addr32(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 = fDst.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 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 fProc32 = SkBlitRow::Factory32(flags32); | 82 fProc32 = SkBlitRow::Factory32(flags32); |
| 83 fAlpha = paint.getAlpha(); | 83 fAlpha = paint.getAlpha(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual ~Sprite_D32_XferFilter() { | 86 virtual ~Sprite_D32_XferFilter() { |
| 87 delete[] fBuffer; | 87 delete[] fBuffer; |
| 88 SkSafeUnref(fXfermode); | 88 SkSafeUnref(fXfermode); |
| 89 SkSafeUnref(fColorFilter); | 89 SkSafeUnref(fColorFilter); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void setup(const SkBitmap& device, int left, int top, const SkPaint& paint)
override { | 92 void setup(const SkPixmap& dst, int left, int top, const SkPaint& paint) ove
rride { |
| 93 this->INHERITED::setup(device, left, top, paint); | 93 this->INHERITED::setup(dst, left, top, paint); |
| 94 | 94 |
| 95 int width = device.width(); | 95 int width = dst.width(); |
| 96 if (width > fBufferSize) { | 96 if (width > fBufferSize) { |
| 97 fBufferSize = width; | 97 fBufferSize = width; |
| 98 delete[] fBuffer; | 98 delete[] fBuffer; |
| 99 fBuffer = new SkPMColor[width]; | 99 fBuffer = new SkPMColor[width]; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 SkColorFilter* fColorFilter; | 104 SkColorFilter* fColorFilter; |
| 105 SkXfermode* fXfermode; | 105 SkXfermode* fXfermode; |
| 106 int fBufferSize; | 106 int fBufferSize; |
| 107 SkPMColor* fBuffer; | 107 SkPMColor* fBuffer; |
| 108 SkBlitRow::Proc32 fProc32; | 108 SkBlitRow::Proc32 fProc32; |
| 109 U8CPU fAlpha; | 109 U8CPU fAlpha; |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 typedef SkSpriteBlitter INHERITED; | 112 typedef SkSpriteBlitter INHERITED; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 /////////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////////// |
| 116 | 116 |
| 117 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { | 117 class Sprite_D32_S32A_XferFilter : public Sprite_D32_XferFilter { |
| 118 public: | 118 public: |
| 119 Sprite_D32_S32A_XferFilter(const SkPixmap& source, const SkPaint& paint) | 119 Sprite_D32_S32A_XferFilter(const SkPixmap& source, const SkPaint& paint) |
| 120 : Sprite_D32_XferFilter(source, paint) {} | 120 : Sprite_D32_XferFilter(source, paint) {} |
| 121 | 121 |
| 122 void blitRect(int x, int y, int width, int height) override { | 122 void blitRect(int x, int y, int width, int height) override { |
| 123 SkASSERT(width > 0 && height > 0); | 123 SkASSERT(width > 0 && height > 0); |
| 124 uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 124 uint32_t* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 125 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); |
| 126 size_t dstRB = fDevice->rowBytes(); | 126 size_t dstRB = fDst.rowBytes(); |
| 127 size_t srcRB = fSource.rowBytes(); | 127 size_t srcRB = fSource.rowBytes(); |
| 128 SkColorFilter* colorFilter = fColorFilter; | 128 SkColorFilter* colorFilter = fColorFilter; |
| 129 SkXfermode* xfermode = fXfermode; | 129 SkXfermode* xfermode = fXfermode; |
| 130 | 130 |
| 131 do { | 131 do { |
| 132 const SkPMColor* tmp = src; | 132 const SkPMColor* tmp = src; |
| 133 | 133 |
| 134 if (colorFilter) { | 134 if (colorFilter) { |
| 135 colorFilter->filterSpan(src, width, fBuffer); | 135 colorFilter->filterSpan(src, width, fBuffer); |
| 136 tmp = fBuffer; | 136 tmp = fBuffer; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 160 } while (--count != 0); | 160 } while (--count != 0); |
| 161 } | 161 } |
| 162 | 162 |
| 163 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { | 163 class Sprite_D32_S4444_XferFilter : public Sprite_D32_XferFilter { |
| 164 public: | 164 public: |
| 165 Sprite_D32_S4444_XferFilter(const SkPixmap& source, const SkPaint& paint) | 165 Sprite_D32_S4444_XferFilter(const SkPixmap& source, const SkPaint& paint) |
| 166 : Sprite_D32_XferFilter(source, paint) {} | 166 : Sprite_D32_XferFilter(source, paint) {} |
| 167 | 167 |
| 168 void blitRect(int x, int y, int width, int height) override { | 168 void blitRect(int x, int y, int width, int height) override { |
| 169 SkASSERT(width > 0 && height > 0); | 169 SkASSERT(width > 0 && height > 0); |
| 170 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 170 SkPMColor* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 171 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; | 171 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 172 size_t dstRB = fDevice->rowBytes(); | 172 size_t dstRB = fDst.rowBytes(); |
| 173 size_t srcRB = fSource.rowBytes(); | 173 size_t srcRB = fSource.rowBytes(); |
| 174 SkPMColor* SK_RESTRICT buffer = fBuffer; | 174 SkPMColor* SK_RESTRICT buffer = fBuffer; |
| 175 SkColorFilter* colorFilter = fColorFilter; | 175 SkColorFilter* colorFilter = fColorFilter; |
| 176 SkXfermode* xfermode = fXfermode; | 176 SkXfermode* xfermode = fXfermode; |
| 177 | 177 |
| 178 do { | 178 do { |
| 179 fillbuffer(buffer, src, width); | 179 fillbuffer(buffer, src, width); |
| 180 | 180 |
| 181 if (colorFilter) { | 181 if (colorFilter) { |
| 182 colorFilter->filterSpan(buffer, width, buffer); | 182 colorFilter->filterSpan(buffer, width, buffer); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 206 dst += 1; | 206 dst += 1; |
| 207 } while (--count != 0); | 207 } while (--count != 0); |
| 208 } | 208 } |
| 209 | 209 |
| 210 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { | 210 class Sprite_D32_S4444_Opaque : public SkSpriteBlitter { |
| 211 public: | 211 public: |
| 212 Sprite_D32_S4444_Opaque(const SkPixmap& source) : SkSpriteBlitter(source) {} | 212 Sprite_D32_S4444_Opaque(const SkPixmap& source) : SkSpriteBlitter(source) {} |
| 213 | 213 |
| 214 void blitRect(int x, int y, int width, int height) override { | 214 void blitRect(int x, int y, int width, int height) override { |
| 215 SkASSERT(width > 0 && height > 0); | 215 SkASSERT(width > 0 && height > 0); |
| 216 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 216 SkPMColor* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 217 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; | 217 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 218 size_t dstRB = fDevice->rowBytes(); | 218 size_t dstRB = fDst.rowBytes(); |
| 219 size_t srcRB = fSource.rowBytes(); | 219 size_t srcRB = fSource.rowBytes(); |
| 220 | 220 |
| 221 do { | 221 do { |
| 222 src_row(dst, src, width); | 222 src_row(dst, src, width); |
| 223 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 223 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 224 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 224 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 225 } while (--height != 0); | 225 } while (--height != 0); |
| 226 } | 226 } |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 static void srcover_row(SkPMColor* SK_RESTRICT dst, | 229 static void srcover_row(SkPMColor* SK_RESTRICT dst, |
| 230 const SkPMColor16* SK_RESTRICT src, int count) { | 230 const SkPMColor16* SK_RESTRICT src, int count) { |
| 231 do { | 231 do { |
| 232 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); | 232 *dst = SkPMSrcOver(SkPixel4444ToPixel32(*src), *dst); |
| 233 src += 1; | 233 src += 1; |
| 234 dst += 1; | 234 dst += 1; |
| 235 } while (--count != 0); | 235 } while (--count != 0); |
| 236 } | 236 } |
| 237 | 237 |
| 238 class Sprite_D32_S4444 : public SkSpriteBlitter { | 238 class Sprite_D32_S4444 : public SkSpriteBlitter { |
| 239 public: | 239 public: |
| 240 Sprite_D32_S4444(const SkPixmap& source) : SkSpriteBlitter(source) {} | 240 Sprite_D32_S4444(const SkPixmap& source) : SkSpriteBlitter(source) {} |
| 241 | 241 |
| 242 void blitRect(int x, int y, int width, int height) override { | 242 void blitRect(int x, int y, int width, int height) override { |
| 243 SkASSERT(width > 0 && height > 0); | 243 SkASSERT(width > 0 && height > 0); |
| 244 SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y); | 244 SkPMColor* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 245 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; | 245 const SkPMColor16* SK_RESTRICT src = fSource.addr16(x - fLeft, y - fTop)
; |
| 246 size_t dstRB = fDevice->rowBytes(); | 246 size_t dstRB = fDst.rowBytes(); |
| 247 size_t srcRB = fSource.rowBytes(); | 247 size_t srcRB = fSource.rowBytes(); |
| 248 | 248 |
| 249 do { | 249 do { |
| 250 srcover_row(dst, src, width); | 250 srcover_row(dst, src, width); |
| 251 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); | 251 dst = (SkPMColor* SK_RESTRICT)((char*)dst + dstRB); |
| 252 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); | 252 src = (const SkPMColor16* SK_RESTRICT)((const char*)src + srcRB); |
| 253 } while (--height != 0); | 253 } while (--height != 0); |
| 254 } | 254 } |
| 255 }; | 255 }; |
| 256 | 256 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } else { | 291 } else { |
| 292 // this can handle alpha, but not xfermode or filter | 292 // this can handle alpha, but not xfermode or filter |
| 293 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); | 293 blitter = allocator->createT<Sprite_D32_S32>(source, alpha); |
| 294 } | 294 } |
| 295 break; | 295 break; |
| 296 default: | 296 default: |
| 297 break; | 297 break; |
| 298 } | 298 } |
| 299 return blitter; | 299 return blitter; |
| 300 } | 300 } |
| OLD | NEW |