Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: src/effects/SkAvoidXfermode.cpp

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkArithmeticMode.cpp ('k') | src/effects/SkBitmapSource.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkAvoidXfermode.h" 8 #include "SkAvoidXfermode.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 SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode) { 14 SkAvoidXfermode::SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode) {
15 if (tolerance > 255) { 15 if (tolerance > 255) {
16 tolerance = 255; 16 tolerance = 255;
17 } 17 }
18 18 fTolerance = SkToU8(tolerance);
19 fOpColor = opColor; 19 fOpColor = opColor;
20 fDistMul = (256 << 14) / (tolerance + 1); 20 fDistMul = (256 << 14) / (tolerance + 1);
21 fMode = mode; 21 fMode = mode;
22 } 22 }
23 23
24 SkAvoidXfermode::SkAvoidXfermode(SkReadBuffer& buffer) 24 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
25 : INHERITED(buffer) { 25 SkAvoidXfermode::SkAvoidXfermode(SkReadBuffer& buffer) : INHERITED(buffer) {
26 fOpColor = buffer.readColor(); 26 fOpColor = buffer.readColor();
27 fDistMul = buffer.readUInt(); 27 fDistMul = buffer.readUInt();
28 fMode = (Mode)buffer.readUInt(); 28 fMode = (Mode)buffer.readUInt();
29 } 29 }
30 #endif
31
32 SkFlattenable* SkAvoidXfermode::CreateProc(SkReadBuffer& buffer) {
33 const SkColor color = buffer.readColor();
34 const unsigned tolerance = buffer.readUInt();
35 const unsigned mode = buffer.readUInt();
36 return Create(color, tolerance, (Mode)mode);
37 }
30 38
31 void SkAvoidXfermode::flatten(SkWriteBuffer& buffer) const { 39 void SkAvoidXfermode::flatten(SkWriteBuffer& buffer) const {
32 this->INHERITED::flatten(buffer);
33
34 buffer.writeColor(fOpColor); 40 buffer.writeColor(fOpColor);
35 buffer.writeUInt(fDistMul); 41 buffer.writeUInt(fTolerance);
36 buffer.writeUInt(fMode); 42 buffer.writeUInt(fMode);
37 } 43 }
38 44
39 // returns 0..31 45 // returns 0..31
40 static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b) { 46 static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b) {
41 SkASSERT(r <= SK_R16_MASK); 47 SkASSERT(r <= SK_R16_MASK);
42 SkASSERT(g <= SK_G16_MASK); 48 SkASSERT(g <= SK_G16_MASK);
43 SkASSERT(b <= SK_B16_MASK); 49 SkASSERT(b <= SK_B16_MASK);
44 50
45 unsigned dr = SkAbs32(SkGetPackedR16(c) - r); 51 unsigned dr = SkAbs32(SkGetPackedR16(c) - r);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void SkAvoidXfermode::toString(SkString* str) const { 177 void SkAvoidXfermode::toString(SkString* str) const {
172 str->append("SkAvoidXfermode: opColor: "); 178 str->append("SkAvoidXfermode: opColor: ");
173 str->appendHex(fOpColor); 179 str->appendHex(fOpColor);
174 str->appendf("distMul: %d ", fDistMul); 180 str->appendf("distMul: %d ", fDistMul);
175 181
176 static const char* gModeStrings[] = { "Avoid", "Target" }; 182 static const char* gModeStrings[] = { "Avoid", "Target" };
177 183
178 str->appendf("mode: %s", gModeStrings[fMode]); 184 str->appendf("mode: %s", gModeStrings[fMode]);
179 } 185 }
180 #endif 186 #endif
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode.cpp ('k') | src/effects/SkBitmapSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698