OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkSweepGradient.h" | 9 #include "SkSweepGradient.h" |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 toggle = next_dither_toggle16(toggle); | 160 toggle = next_dither_toggle16(toggle); |
161 } | 161 } |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 ///////////////////////////////////////////////////////////////////// | 165 ///////////////////////////////////////////////////////////////////// |
166 | 166 |
167 #if SK_SUPPORT_GPU | 167 #if SK_SUPPORT_GPU |
168 | 168 |
169 #include "SkGr.h" | 169 #include "SkGr.h" |
170 #include "effects/GrExtractAlphaFragmentProcessor.h" | |
170 #include "gl/builders/GrGLProgramBuilder.h" | 171 #include "gl/builders/GrGLProgramBuilder.h" |
171 | 172 |
172 class GrGLSweepGradient : public GrGLGradientEffect { | 173 class GrGLSweepGradient : public GrGLGradientEffect { |
173 public: | 174 public: |
174 | 175 |
175 GrGLSweepGradient(const GrProcessor&) {} | 176 GrGLSweepGradient(const GrProcessor&) {} |
176 virtual ~GrGLSweepGradient() { } | 177 virtual ~GrGLSweepGradient() { } |
177 | 178 |
178 virtual void emitCode(EmitArgs&) override; | 179 virtual void emitCode(EmitArgs&) override; |
179 | 180 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 220 |
220 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 221 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
221 | 222 |
222 typedef GrGradientEffect INHERITED; | 223 typedef GrGradientEffect INHERITED; |
223 }; | 224 }; |
224 | 225 |
225 ///////////////////////////////////////////////////////////////////// | 226 ///////////////////////////////////////////////////////////////////// |
226 | 227 |
227 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); | 228 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); |
228 | 229 |
229 GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { | 230 const GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { |
230 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; | 231 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
231 | 232 |
232 SkColor colors[kMaxRandomGradientColors]; | 233 SkColor colors[kMaxRandomGradientColors]; |
233 SkScalar stopsArray[kMaxRandomGradientColors]; | 234 SkScalar stopsArray[kMaxRandomGradientColors]; |
234 SkScalar* stops = stopsArray; | 235 SkScalar* stops = stopsArray; |
235 SkShader::TileMode tmIgnored; | 236 SkShader::TileMode tmIgnored; |
236 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored ); | 237 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored ); |
237 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente r.fY, | 238 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente r.fY, |
238 colors, stops, c olorCount)); | 239 colors, stops, c olorCount)); |
239 SkPaint paint; | 240 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
240 GrFragmentProcessor* fp; | 241 GrTest::TestMatr ix(d->fRandom), |
241 GrColor paintColor; | 242 NULL, kNone_SkFi lterQuality, |
242 SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, | 243 d->fProcDataMana ger); |
243 GrTest::TestMatrix(d->fRandom), n ullptr, | 244 GrAlwaysAssert(fp); |
244 &paintColor, d->fProcDataManager, &fp)); | |
245 return fp; | 245 return fp; |
246 } | 246 } |
247 | 247 |
248 ///////////////////////////////////////////////////////////////////// | 248 ///////////////////////////////////////////////////////////////////// |
249 | 249 |
250 void GrGLSweepGradient::emitCode(EmitArgs& args) { | 250 void GrGLSweepGradient::emitCode(EmitArgs& args) { |
251 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>(); | 251 const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>(); |
252 this->emitUniforms(args.fBuilder, ge); | 252 this->emitUniforms(args.fBuilder, ge); |
253 SkString coords2D = args.fBuilder->getFragmentShaderBuilder() | 253 SkString coords2D = args.fBuilder->getFragmentShaderBuilder() |
254 ->ensureFSCoords2D(args.fCoords, 0); | 254 ->ensureFSCoords2D(args.fCoords, 0); |
255 const GrGLContextInfo& ctxInfo = args.fBuilder->ctxInfo(); | 255 const GrGLContextInfo& ctxInfo = args.fBuilder->ctxInfo(); |
256 SkString t; | 256 SkString t; |
257 // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] | 257 // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] |
258 // On Intel GPU there is an issue where it reads the second arguement to ata n "- %s.x" as an int | 258 // On Intel GPU there is an issue where it reads the second arguement to ata n "- %s.x" as an int |
259 // thus must us -1.0 * %s.x to work correctly | 259 // thus must us -1.0 * %s.x to work correctly |
260 if (kIntel_GrGLVendor != ctxInfo.vendor()){ | 260 if (kIntel_GrGLVendor != ctxInfo.vendor()){ |
261 t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", | 261 t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", |
262 coords2D.c_str(), coords2D.c_str()); | 262 coords2D.c_str(), coords2D.c_str()); |
263 } else { | 263 } else { |
264 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", | 264 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", |
265 coords2D.c_str(), coords2D.c_str()); | 265 coords2D.c_str(), coords2D.c_str()); |
266 } | 266 } |
267 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput Color, | 267 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput Color, |
268 args.fSamplers); | 268 args.fSamplers); |
269 } | 269 } |
270 | 270 |
271 ///////////////////////////////////////////////////////////////////// | 271 ///////////////////////////////////////////////////////////////////// |
272 | 272 |
273 bool SkSweepGradient::asFragmentProcessor(GrContext* context, const SkPaint& pai nt, | 273 const GrFragmentProcessor* SkSweepGradient::asFragmentProcessor(GrContext* conte xt, |
robertphillips
2015/08/28 21:33:06
tabs ?
bsalomon
2015/08/29 01:42:50
Done.
| |
274 const SkMatrix& viewM, | 274 const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality, |
275 const SkMatrix* localMatrix, GrColor* paintColor, | 275 GrProcessorDataManager* procDataManager) const { |
276 GrProcessorDataManager* procDataManage r, | |
277 GrFragmentProcessor** effect) const { | |
278 | 276 |
279 SkMatrix matrix; | 277 SkMatrix matrix; |
280 if (!this->getLocalMatrix().invert(&matrix)) { | 278 if (!this->getLocalMatrix().invert(&matrix)) { |
281 return false; | 279 return nullptr; |
282 } | 280 } |
283 if (localMatrix) { | 281 if (localMatrix) { |
284 SkMatrix inv; | 282 SkMatrix inv; |
285 if (!localMatrix->invert(&inv)) { | 283 if (!localMatrix->invert(&inv)) { |
286 return false; | 284 return nullptr; |
287 } | 285 } |
288 matrix.postConcat(inv); | 286 matrix.postConcat(inv); |
289 } | 287 } |
290 matrix.postConcat(fPtsToUnit); | 288 matrix.postConcat(fPtsToUnit); |
291 | 289 |
292 *effect = GrSweepGradient::Create(context, procDataManager, *this, matrix); | 290 SkAutoTUnref<const GrFragmentProcessor> inner( |
293 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); | 291 GrSweepGradient::Create(context, procDataManager, *this, matrix)); |
294 | 292 return GrExtractAlphaFragmentProcessor::Create(inner); |
295 return true; | |
296 } | |
297 | |
298 #else | |
299 | |
300 bool SkSweepGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&, | |
301 const SkMatrix*, GrColor*, GrProcessor DataManager*, | |
302 GrFragmentProcessor**) const { | |
303 SkDEBUGFAIL("Should not call in GPU-less build"); | |
304 return false; | |
305 } | 293 } |
306 | 294 |
307 #endif | 295 #endif |
308 | 296 |
309 #ifndef SK_IGNORE_TO_STRING | 297 #ifndef SK_IGNORE_TO_STRING |
310 void SkSweepGradient::toString(SkString* str) const { | 298 void SkSweepGradient::toString(SkString* str) const { |
311 str->append("SkSweepGradient: ("); | 299 str->append("SkSweepGradient: ("); |
312 | 300 |
313 str->append("center: ("); | 301 str->append("center: ("); |
314 str->appendScalar(fCenter.fX); | 302 str->appendScalar(fCenter.fX); |
315 str->append(", "); | 303 str->append(", "); |
316 str->appendScalar(fCenter.fY); | 304 str->appendScalar(fCenter.fY); |
317 str->append(") "); | 305 str->append(") "); |
318 | 306 |
319 this->INHERITED::toString(str); | 307 this->INHERITED::toString(str); |
320 | 308 |
321 str->append(")"); | 309 str->append(")"); |
322 } | 310 } |
323 #endif | 311 #endif |
OLD | NEW |