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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 private: 140 private:
141 141
142 typedef GrGLGradientEffect INHERITED; 142 typedef GrGLGradientEffect INHERITED;
143 143
144 }; 144 };
145 145
146 ///////////////////////////////////////////////////////////////////// 146 /////////////////////////////////////////////////////////////////////
147 147
148 class GrSweepGradient : public GrGradientEffect { 148 class GrSweepGradient : public GrGradientEffect {
149 public: 149 public:
150 static GrFragmentProcessor* Create(GrContext* ctx, const SkSweepGradient& sh ader, 150 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, const SkSweepGradient & shader,
151 const SkMatrix& m) { 151 const SkMatrix& m) {
152 return new GrSweepGradient(ctx, shader, m); 152 return sk_sp<GrFragmentProcessor>(new GrSweepGradient(ctx, shader, m));
153 } 153 }
154 virtual ~GrSweepGradient() { } 154 virtual ~GrSweepGradient() { }
155 155
156 const char* name() const override { return "Sweep Gradient"; } 156 const char* name() const override { return "Sweep Gradient"; }
157 157
158 private: 158 private:
159 GrSweepGradient(GrContext* ctx, 159 GrSweepGradient(GrContext* ctx,
160 const SkSweepGradient& shader, 160 const SkSweepGradient& shader,
161 const SkMatrix& matrix) 161 const SkMatrix& matrix)
162 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { 162 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) {
(...skipping 11 matching lines...) Expand all
174 174
175 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 175 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
176 176
177 typedef GrGradientEffect INHERITED; 177 typedef GrGradientEffect INHERITED;
178 }; 178 };
179 179
180 ///////////////////////////////////////////////////////////////////// 180 /////////////////////////////////////////////////////////////////////
181 181
182 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); 182 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient);
183 183
184 const 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 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, 194 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext,
195 GrTest::TestMatr ix(d->fRandom), 195 GrTest::TestMatr ix(d->fRandom),
196 NULL, kNone_SkFi lterQuality, 196 NULL, kNone_SkFi lterQuality,
197 SkSourceGammaTre atment::kRespect); 197 SkSourceGammaTre atment::kRespect);
198 GrAlwaysAssert(fp); 198 GrAlwaysAssert(fp);
199 return fp; 199 return fp;
200 } 200 }
201 201
202 ///////////////////////////////////////////////////////////////////// 202 /////////////////////////////////////////////////////////////////////
203 203
204 void GrGLSweepGradient::emitCode(EmitArgs& args) { 204 void GrGLSweepGradient::emitCode(EmitArgs& args) {
(...skipping 15 matching lines...) Expand all
220 args.fUniformHandler, 220 args.fUniformHandler,
221 args.fGLSLCaps, 221 args.fGLSLCaps,
222 ge, t.c_str(), 222 ge, t.c_str(),
223 args.fOutputColor, 223 args.fOutputColor,
224 args.fInputColor, 224 args.fInputColor,
225 args.fTexSamplers); 225 args.fTexSamplers);
226 } 226 }
227 227
228 ///////////////////////////////////////////////////////////////////// 228 /////////////////////////////////////////////////////////////////////
229 229
230 const GrFragmentProcessor* SkSweepGradient::asFragmentProcessor( 230 sk_sp<GrFragmentProcessor> SkSweepGradient::asFragmentProcessor(
231 GrContext* context, 231 GrContext* context,
232 const SkMatrix& viewM, 232 const SkMatrix& viewM,
233 const SkMatrix* localMatrix, 233 const SkMatrix* localMatrix,
234 SkFilterQuality, 234 SkFilterQuality,
235 SkSourceGammaTreatment) cons t { 235 SkSourceGammaTreatment) cons t {
236 236
237 SkMatrix matrix; 237 SkMatrix matrix;
238 if (!this->getLocalMatrix().invert(&matrix)) { 238 if (!this->getLocalMatrix().invert(&matrix)) {
239 return nullptr; 239 return nullptr;
240 } 240 }
241 if (localMatrix) { 241 if (localMatrix) {
242 SkMatrix inv; 242 SkMatrix inv;
243 if (!localMatrix->invert(&inv)) { 243 if (!localMatrix->invert(&inv)) {
244 return nullptr; 244 return nullptr;
245 } 245 }
246 matrix.postConcat(inv); 246 matrix.postConcat(inv);
247 } 247 }
248 matrix.postConcat(fPtsToUnit); 248 matrix.postConcat(fPtsToUnit);
249 249
250 SkAutoTUnref<const GrFragmentProcessor> inner( 250 sk_sp<GrFragmentProcessor> inner(GrSweepGradient::Make(context, *this, matri x));
251 GrSweepGradient::Create(context, *this, matrix)); 251 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
252 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
253 } 252 }
254 253
255 #endif 254 #endif
256 255
257 #ifndef SK_IGNORE_TO_STRING 256 #ifndef SK_IGNORE_TO_STRING
258 void SkSweepGradient::toString(SkString* str) const { 257 void SkSweepGradient::toString(SkString* str) const {
259 str->append("SkSweepGradient: ("); 258 str->append("SkSweepGradient: (");
260 259
261 str->append("center: ("); 260 str->append("center: (");
262 str->appendScalar(fCenter.fX); 261 str->appendScalar(fCenter.fX);
263 str->append(", "); 262 str->append(", ");
264 str->appendScalar(fCenter.fY); 263 str->appendScalar(fCenter.fY);
265 str->append(") "); 264 str->append(") ");
266 265
267 this->INHERITED::toString(str); 266 this->INHERITED::toString(str);
268 267
269 str->append(")"); 268 str->append(")");
270 } 269 }
271 #endif 270 #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