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