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

Side by Side Diff: src/effects/gradients/SkSweepGradient.cpp

Issue 2175563003: Bundle SkShader::asFragmentProcessor arguments in a struct (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix indentation to be less arbitrary Created 4 years, 5 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 2012 Google Inc. 2 * Copyright 2012 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 "SkSweepGradient.h" 8 #include "SkSweepGradient.h"
9 9
10 static SkMatrix translate(SkScalar dx, SkScalar dy) { 10 static SkMatrix translate(SkScalar dx, SkScalar dy) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) { 184 sk_sp<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) {
185 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 185 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
186 186
187 SkColor colors[kMaxRandomGradientColors]; 187 SkColor colors[kMaxRandomGradientColors];
188 SkScalar stopsArray[kMaxRandomGradientColors]; 188 SkScalar stopsArray[kMaxRandomGradientColors];
189 SkScalar* stops = stopsArray; 189 SkScalar* stops = stopsArray;
190 SkShader::TileMode tmIgnored; 190 SkShader::TileMode tmIgnored;
191 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored ); 191 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored );
192 sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, co lors, stops, 192 sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, co lors, stops,
193 colorCount)); 193 colorCount));
194 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, 194 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
195 GrTest::TestMatr ix(d->fRandom), 195 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs(
196 NULL, kNone_SkFi lterQuality, 196 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, SkSourceGammaTrea tment::kRespect));
197 SkSourceGammaTre atment::kRespect);
198 GrAlwaysAssert(fp); 197 GrAlwaysAssert(fp);
199 return fp; 198 return fp;
200 } 199 }
201 200
202 ///////////////////////////////////////////////////////////////////// 201 /////////////////////////////////////////////////////////////////////
203 202
204 void GrGLSweepGradient::emitCode(EmitArgs& args) { 203 void GrGLSweepGradient::emitCode(EmitArgs& args) {
205 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>(); 204 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>();
206 this->emitUniforms(args.fUniformHandler, ge); 205 this->emitUniforms(args.fUniformHandler, ge);
207 SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0); 206 SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
(...skipping 12 matching lines...) Expand all
220 args.fUniformHandler, 219 args.fUniformHandler,
221 args.fGLSLCaps, 220 args.fGLSLCaps,
222 ge, t.c_str(), 221 ge, t.c_str(),
223 args.fOutputColor, 222 args.fOutputColor,
224 args.fInputColor, 223 args.fInputColor,
225 args.fTexSamplers); 224 args.fTexSamplers);
226 } 225 }
227 226
228 ///////////////////////////////////////////////////////////////////// 227 /////////////////////////////////////////////////////////////////////
229 228
230 sk_sp<GrFragmentProcessor> SkSweepGradient::asFragmentProcessor( 229 sk_sp<GrFragmentProcessor> SkSweepGradient::asFragmentProcessor(const AsFPArgs& args) const {
231 GrContext* context,
232 const SkMatrix& viewM,
233 const SkMatrix* localMatrix,
234 SkFilterQuality,
235 SkSourceGammaTreatment) cons t {
236 230
237 SkMatrix matrix; 231 SkMatrix matrix;
238 if (!this->getLocalMatrix().invert(&matrix)) { 232 if (!this->getLocalMatrix().invert(&matrix)) {
239 return nullptr; 233 return nullptr;
240 } 234 }
241 if (localMatrix) { 235 if (args.fLocalMatrix) {
242 SkMatrix inv; 236 SkMatrix inv;
243 if (!localMatrix->invert(&inv)) { 237 if (!args.fLocalMatrix->invert(&inv)) {
244 return nullptr; 238 return nullptr;
245 } 239 }
246 matrix.postConcat(inv); 240 matrix.postConcat(inv);
247 } 241 }
248 matrix.postConcat(fPtsToUnit); 242 matrix.postConcat(fPtsToUnit);
249 243
250 sk_sp<GrFragmentProcessor> inner(GrSweepGradient::Make(context, *this, matri x)); 244 sk_sp<GrFragmentProcessor> inner(GrSweepGradient::Make(args.fContext, *this, matrix));
251 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); 245 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
252 } 246 }
253 247
254 #endif 248 #endif
255 249
256 #ifndef SK_IGNORE_TO_STRING 250 #ifndef SK_IGNORE_TO_STRING
257 void SkSweepGradient::toString(SkString* str) const { 251 void SkSweepGradient::toString(SkString* str) const {
258 str->append("SkSweepGradient: ("); 252 str->append("SkSweepGradient: (");
259 253
260 str->append("center: ("); 254 str->append("center: (");
261 str->appendScalar(fCenter.fX); 255 str->appendScalar(fCenter.fX);
262 str->append(", "); 256 str->append(", ");
263 str->appendScalar(fCenter.fY); 257 str->appendScalar(fCenter.fY);
264 str->append(") "); 258 str->append(") ");
265 259
266 this->INHERITED::toString(str); 260 this->INHERITED::toString(str);
267 261
268 str->append(")"); 262 str->append(")");
269 } 263 }
270 #endif 264 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.h ('k') | src/effects/gradients/SkTwoPointConicalGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698