OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkLerpXfermode.h" | 8 #include "SkLerpXfermode.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 | 13 |
14 SkXfermode* SkLerpXfermode::Create(SkScalar scale) { | 14 SkXfermode* SkLerpXfermode::Create(SkScalar scale) { |
15 int scale256 = SkScalarRoundToInt(scale * 256); | 15 int scale256 = SkScalarRoundToInt(scale * 256); |
16 if (scale256 >= 256) { | 16 if (scale256 >= 256) { |
17 return SkXfermode::Create(SkXfermode::kSrc_Mode); | 17 return SkXfermode::Create(SkXfermode::kSrc_Mode); |
18 } else if (scale256 <= 0) { | 18 } else if (scale256 <= 0) { |
19 return SkXfermode::Create(SkXfermode::kDst_Mode); | 19 return SkXfermode::Create(SkXfermode::kDst_Mode); |
20 } | 20 } |
21 return SkNEW_ARGS(SkLerpXfermode, (scale256)); | 21 return SkNEW_ARGS(SkLerpXfermode, (scale256)); |
22 } | 22 } |
23 | 23 |
24 SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {} | 24 SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {} |
25 | 25 |
26 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
27 SkLerpXfermode::SkLerpXfermode(SkReadBuffer& buffer) : INHERITED(buffer) { | |
28 fScale256 = buffer.readUInt(); | |
29 } | |
30 #endif | |
31 | |
32 void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const { | 26 void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const { |
33 buffer.writeUInt(fScale256); | 27 buffer.writeUInt(fScale256); |
34 } | 28 } |
35 | 29 |
36 SkFlattenable* SkLerpXfermode::CreateProc(SkReadBuffer& buffer) { | 30 SkFlattenable* SkLerpXfermode::CreateProc(SkReadBuffer& buffer) { |
37 return SkNEW_ARGS(SkLerpXfermode, (buffer.readUInt())); | 31 return SkNEW_ARGS(SkLerpXfermode, (buffer.readUInt())); |
38 } | 32 } |
39 | 33 |
40 void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count, | 34 void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
41 const SkAlpha aa[]) const { | 35 const SkAlpha aa[]) const { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale); | 100 dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale); |
107 } | 101 } |
108 } | 102 } |
109 } | 103 } |
110 | 104 |
111 #ifndef SK_IGNORE_TO_STRING | 105 #ifndef SK_IGNORE_TO_STRING |
112 void SkLerpXfermode::toString(SkString* str) const { | 106 void SkLerpXfermode::toString(SkString* str) const { |
113 str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0); | 107 str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0); |
114 } | 108 } |
115 #endif | 109 #endif |
OLD | NEW |