| 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 new SkLerpXfermode(scale256); |
| 22 } | 22 } |
| 23 | 23 |
| 24 SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {} | 24 SkLerpXfermode::SkLerpXfermode(unsigned scale256) : fScale256(scale256) {} |
| 25 | 25 |
| 26 void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const { | 26 void SkLerpXfermode::flatten(SkWriteBuffer& buffer) const { |
| 27 buffer.writeUInt(fScale256); | 27 buffer.writeUInt(fScale256); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SkFlattenable* SkLerpXfermode::CreateProc(SkReadBuffer& buffer) { | 30 SkFlattenable* SkLerpXfermode::CreateProc(SkReadBuffer& buffer) { |
| 31 return SkNEW_ARGS(SkLerpXfermode, (buffer.readUInt())); | 31 return new SkLerpXfermode(buffer.readUInt()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count, | 34 void SkLerpXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
| 35 const SkAlpha aa[]) const { | 35 const SkAlpha aa[]) const { |
| 36 const int scale = fScale256; | 36 const int scale = fScale256; |
| 37 | 37 |
| 38 if (aa) { | 38 if (aa) { |
| 39 for (int i = 0; i < count; ++i) { | 39 for (int i = 0; i < count; ++i) { |
| 40 unsigned a = aa[i]; | 40 unsigned a = aa[i]; |
| 41 if (a) { | 41 if (a) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale); | 100 dst[i] = SkAlphaBlend(SkGetPackedA32(src[i]), dst[i], scale); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 #ifndef SK_IGNORE_TO_STRING | 105 #ifndef SK_IGNORE_TO_STRING |
| 106 void SkLerpXfermode::toString(SkString* str) const { | 106 void SkLerpXfermode::toString(SkString* str) const { |
| 107 str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0); | 107 str->printf("SkLerpXfermode: scale: %g", fScale256 / 256.0); |
| 108 } | 108 } |
| 109 #endif | 109 #endif |
| OLD | NEW |