OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 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 #include "SkSpriteBlitter.h" |
| 9 #include "SkSpanProcs.h" |
| 10 #include "SkTemplates.h" |
| 11 #include "SkXfermode.h" |
| 12 |
| 13 class Sprite_4f : public SkSpriteBlitter { |
| 14 public: |
| 15 Sprite_4f(const SkPixmap& src, const SkPaint& paint) : INHERITED(src) { |
| 16 fLoader = SkLoadSpanProc_Choose(src.info()); |
| 17 fFilter = SkFilterSpanProc_Choose(paint); |
| 18 fBuffer.reset(src.width()); |
| 19 } |
| 20 |
| 21 protected: |
| 22 SkLoadSpanProc fLoader; |
| 23 SkFilterSpanProc fFilter; |
| 24 SkAutoTMalloc<SkPM4f> fBuffer; |
| 25 |
| 26 private: |
| 27 typedef SkSpriteBlitter INHERITED; |
| 28 }; |
| 29 |
| 30 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 31 |
| 32 static SkXfermode::Mode get_mode(const SkXfermode* xfer) { |
| 33 SkXfermode::Mode mode; |
| 34 if (!SkXfermode::AsMode(xfer, &mode)) { |
| 35 mode = SkXfermode::kSrcOver_Mode; |
| 36 } |
| 37 return mode; |
| 38 } |
| 39 |
| 40 class Sprite_F16 : public Sprite_4f { |
| 41 public: |
| 42 Sprite_F16(const SkPixmap& src, const SkPaint& paint) : INHERITED(src, paint
) { |
| 43 fState = { paint.getXfermode(), SkXfermode::kDstIsFloat16_U64Flag }; |
| 44 if (src.isOpaque()) { |
| 45 fState.fFlags |= SkXfermode::kSrcIsOpaque_U64Flag; |
| 46 } |
| 47 fXfer = SkXfermode::GetU64ProcN(get_mode(fState.fXfer), fState.fFlags); |
| 48 } |
| 49 |
| 50 void blitRect(int x, int y, int width, int height) override { |
| 51 SkASSERT(width > 0 && height > 0); |
| 52 uint64_t* SK_RESTRICT dst = fDst.writable_addr64(x, y); |
| 53 size_t dstRB = fDst.rowBytes(); |
| 54 |
| 55 for (int bottom = y + height; y < bottom; ++y) { |
| 56 fLoader(fSource, x - fLeft, y - fTop, fBuffer, width); |
| 57 fFilter(*fPaint, fBuffer, width); |
| 58 fXfer(fState, dst, fBuffer, width, nullptr); |
| 59 dst = (uint64_t* SK_RESTRICT)((char*)dst + dstRB); |
| 60 } |
| 61 } |
| 62 |
| 63 private: |
| 64 SkXfermode::U64State fState; |
| 65 SkXfermode::U64ProcN fXfer; |
| 66 |
| 67 typedef Sprite_4f INHERITED; |
| 68 }; |
| 69 |
| 70 |
| 71 SkSpriteBlitter* SkSpriteBlitter::ChooseF16(const SkPixmap& source, const SkPain
t& paint, |
| 72 SkTBlitterAllocator* allocator) { |
| 73 SkASSERT(allocator != nullptr); |
| 74 |
| 75 if (paint.getMaskFilter() != nullptr) { |
| 76 return nullptr; |
| 77 } |
| 78 |
| 79 switch (source.colorType()) { |
| 80 case kN32_SkColorType: |
| 81 case kRGBA_F16_SkColorType: |
| 82 return allocator->createT<Sprite_F16>(source, paint); |
| 83 default: |
| 84 return nullptr; |
| 85 } |
| 86 } |
| 87 |
| 88 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 89 |
| 90 class Sprite_sRGB : public Sprite_4f { |
| 91 public: |
| 92 Sprite_sRGB(const SkPixmap& src, const SkPaint& paint) : INHERITED(src, pain
t) { |
| 93 fState = { paint.getXfermode(), SkXfermode::kDstIsSRGB_PM4fFlag }; |
| 94 if (src.isOpaque()) { |
| 95 fState.fFlags |= SkXfermode::kSrcIsOpaque_PM4fFlag; |
| 96 } |
| 97 fXfer = SkXfermode::GetPM4fProcN(get_mode(fState.fXfer), fState.fFlags); |
| 98 } |
| 99 |
| 100 void blitRect(int x, int y, int width, int height) override { |
| 101 SkASSERT(width > 0 && height > 0); |
| 102 uint32_t* SK_RESTRICT dst = fDst.writable_addr32(x, y); |
| 103 size_t dstRB = fDst.rowBytes(); |
| 104 |
| 105 for (int bottom = y + height; y < bottom; ++y) { |
| 106 fLoader(fSource, x - fLeft, y - fTop, fBuffer, width); |
| 107 fFilter(*fPaint, fBuffer, width); |
| 108 fXfer(fState, dst, fBuffer, width, nullptr); |
| 109 dst = (uint32_t* SK_RESTRICT)((char*)dst + dstRB); |
| 110 } |
| 111 } |
| 112 |
| 113 protected: |
| 114 SkXfermode::PM4fState fState; |
| 115 SkXfermode::PM4fProcN fXfer; |
| 116 |
| 117 private: |
| 118 typedef Sprite_4f INHERITED; |
| 119 }; |
| 120 |
| 121 |
| 122 SkSpriteBlitter* SkSpriteBlitter::ChooseS32(const SkPixmap& source, const SkPain
t& paint, |
| 123 SkTBlitterAllocator* allocator) { |
| 124 SkASSERT(allocator != nullptr); |
| 125 |
| 126 if (paint.getMaskFilter() != nullptr) { |
| 127 return nullptr; |
| 128 } |
| 129 |
| 130 switch (source.colorType()) { |
| 131 case kN32_SkColorType: |
| 132 case kRGBA_F16_SkColorType: |
| 133 return allocator->createT<Sprite_sRGB>(source, paint); |
| 134 default: |
| 135 return nullptr; |
| 136 } |
| 137 } |
OLD | NEW |