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

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

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 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
OLDNEW
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 "SkArithmeticMode.h" 8 #include "SkArithmeticMode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 typedef SkXfermode INHERITED; 54 typedef SkXfermode INHERITED;
55 }; 55 };
56 56
57 SkFlattenable* SkArithmeticMode_scalar::CreateProc(SkReadBuffer& buffer) { 57 SkFlattenable* SkArithmeticMode_scalar::CreateProc(SkReadBuffer& buffer) {
58 const SkScalar k1 = buffer.readScalar(); 58 const SkScalar k1 = buffer.readScalar();
59 const SkScalar k2 = buffer.readScalar(); 59 const SkScalar k2 = buffer.readScalar();
60 const SkScalar k3 = buffer.readScalar(); 60 const SkScalar k3 = buffer.readScalar();
61 const SkScalar k4 = buffer.readScalar(); 61 const SkScalar k4 = buffer.readScalar();
62 const bool enforcePMColor = buffer.readBool(); 62 const bool enforcePMColor = buffer.readBool();
63 return SkArithmeticMode::Create(k1, k2, k3, k4, enforcePMColor); 63 return SkArithmeticMode::Make(k1, k2, k3, k4, enforcePMColor).release();
64 } 64 }
65 65
66 static int pinToByte(int value) { 66 static int pinToByte(int value) {
67 if (value < 0) { 67 if (value < 0) {
68 value = 0; 68 value = 0;
69 } else if (value > 255) { 69 } else if (value > 255) {
70 value = 255; 70 value = 255;
71 } 71 }
72 return value; 72 return value;
73 } 73 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 for (int i = 0; i < 4; ++i) { 130 for (int i = 0; i < 4; ++i) {
131 str->appendScalar(fK[i]); 131 str->appendScalar(fK[i]);
132 str->append(" "); 132 str->append(" ");
133 } 133 }
134 str->appendS32(fEnforcePMColor ? 1 : 0); 134 str->appendS32(fEnforcePMColor ? 1 : 0);
135 } 135 }
136 #endif 136 #endif
137 137
138 /////////////////////////////////////////////////////////////////////////////// 138 ///////////////////////////////////////////////////////////////////////////////
139 139
140 SkXfermode* SkArithmeticMode::Create(SkScalar k1, SkScalar k2, 140 sk_sp<SkXfermode> SkArithmeticMode::Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
141 SkScalar k3, SkScalar k4, 141 bool enforcePMColor) {
142 bool enforcePMColor) {
143 if (SkScalarNearlyZero(k1) && SkScalarNearlyEqual(k2, SK_Scalar1) && 142 if (SkScalarNearlyZero(k1) && SkScalarNearlyEqual(k2, SK_Scalar1) &&
144 SkScalarNearlyZero(k3) && SkScalarNearlyZero(k4)) { 143 SkScalarNearlyZero(k3) && SkScalarNearlyZero(k4)) {
145 return SkXfermode::Create(SkXfermode::kSrc_Mode); 144 return SkXfermode::Make(SkXfermode::kSrc_Mode);
146 } else if (SkScalarNearlyZero(k1) && SkScalarNearlyZero(k2) && 145 } else if (SkScalarNearlyZero(k1) && SkScalarNearlyZero(k2) &&
147 SkScalarNearlyEqual(k3, SK_Scalar1) && SkScalarNearlyZero(k4)) { 146 SkScalarNearlyEqual(k3, SK_Scalar1) && SkScalarNearlyZero(k4)) {
148 return SkXfermode::Create(SkXfermode::kDst_Mode); 147 return SkXfermode::Make(SkXfermode::kDst_Mode);
149 } 148 }
150 149 return sk_make_sp<SkArithmeticMode_scalar>(k1, k2, k3, k4, enforcePMColor);
151 return new SkArithmeticMode_scalar(k1, k2, k3, k4, enforcePMColor);
152 } 150 }
153 151
154 152
155 ////////////////////////////////////////////////////////////////////////////// 153 //////////////////////////////////////////////////////////////////////////////
156 154
157 #if SK_SUPPORT_GPU 155 #if SK_SUPPORT_GPU
158 const GrFragmentProcessor* SkArithmeticMode_scalar::getFragmentProcessorForImage Filter( 156 const GrFragmentProcessor* SkArithmeticMode_scalar::getFragmentProcessorForImage Filter(
159 const GrFragmentProc essor* dst) const { 157 const GrFragmentProc essor* dst) const {
160 return GrArithmeticFP::Create(SkScalarToFloat(fK[0]), 158 return GrArithmeticFP::Create(SkScalarToFloat(fK[0]),
161 SkScalarToFloat(fK[1]), 159 SkScalarToFloat(fK[1]),
162 SkScalarToFloat(fK[2]), 160 SkScalarToFloat(fK[2]),
163 SkScalarToFloat(fK[3]), 161 SkScalarToFloat(fK[3]),
164 fEnforcePMColor, 162 fEnforcePMColor,
165 dst); 163 dst);
166 } 164 }
167 165
168 GrXPFactory* SkArithmeticMode_scalar::asXPFactory() const { 166 GrXPFactory* SkArithmeticMode_scalar::asXPFactory() const {
169 return GrArithmeticXPFactory::Create(SkScalarToFloat(fK[0]), 167 return GrArithmeticXPFactory::Create(SkScalarToFloat(fK[0]),
170 SkScalarToFloat(fK[1]), 168 SkScalarToFloat(fK[1]),
171 SkScalarToFloat(fK[2]), 169 SkScalarToFloat(fK[2]),
172 SkScalarToFloat(fK[3]), 170 SkScalarToFloat(fK[3]),
173 fEnforcePMColor); 171 fEnforcePMColor);
174 } 172 }
175 173
176 #endif 174 #endif
177 175
178 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) 176 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode)
179 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) 177 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar)
180 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 178 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698