1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrGradientEffects.h"
#include "gl/GrGLProgramStage.h"
#include "GrProgramStageFactory.h"
/////////////////////////////////////////////////////////////////////
class GrGLRadialGradient : public GrGLProgramStage {
public:
GrGLRadialGradient(const GrProgramStageFactory& factory,
const GrCustomStage&) : INHERITED (factory) { }
virtual ~GrGLRadialGradient() { }
virtual void emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) SK_OVERRIDE { }
virtual void emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s) { return 0; }
private:
typedef GrGLProgramStage INHERITED;
};
void GrGLRadialGradient::emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) {
state->fSampleCoords.printf("vec2(length(%s.xy), 0.5)",
state->fSampleCoords.c_str());
state->fComplexCoord = true;
state->emitDefaultFetch(outputColor, samplerName);
}
/////////////////////////////////////////////////////////////////////
GrRadialGradient::GrRadialGradient(GrTexture* texture)
: GrSingleTextureEffect(texture) {
}
GrRadialGradient::~GrRadialGradient() {
}
const GrProgramStageFactory& GrRadialGradient::getFactory() const {
return GrTProgramStageFactory<GrRadialGradient>::getInstance();
}
bool GrRadialGradient::isEqual(const GrCustomStage& sBase) const {
return INHERITED::isEqual(sBase);
}
/////////////////////////////////////////////////////////////////////
class GrGLRadial2Gradient : public GrGLProgramStage {
public:
GrGLRadial2Gradient(const GrProgramStageFactory& factory,
const GrCustomStage&);
virtual ~GrGLRadial2Gradient() { }
virtual void setupVariables(GrGLShaderBuilder* state,
int stage) SK_OVERRIDE;
virtual void emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) SK_OVERRIDE;
virtual void emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE;
virtual void setData(const GrGLInterface*,
const GrCustomStage&,
int stageNum) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s) {
return (static_cast<const GrRadial2Gradient&>(s).isDegenerate());
}
protected:
const GrGLShaderVar* fVSParamVar;
GrGLint fVSParamLocation;
const GrGLShaderVar* fFSParamVar;
GrGLint fFSParamLocation;
const char* fVSVaryingName;
const char* fFSVaryingName;
bool fIsDegenerate;
// @{
/// Values last uploaded as uniforms
GrScalar fCachedCenter;
GrScalar fCachedRadius;
bool fCachedPosRoot;
// @}
private:
typedef GrGLProgramStage INHERITED;
};
GrGLRadial2Gradient::GrGLRadial2Gradient(
const GrProgramStageFactory& factory,
const GrCustomStage& baseData)
: INHERITED(factory)
, fVSParamVar(NULL)
, fFSParamVar(NULL)
, fVSVaryingName(NULL)
, fFSVaryingName(NULL)
, fCachedCenter(GR_ScalarMax)
, fCachedRadius(-GR_ScalarMax)
, fCachedPosRoot(0) {
const GrRadial2Gradient& data =
static_cast<const GrRadial2Gradient&>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* state, int stage) {
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
fVSParamVar = &state->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
kFloat_GrSLType, "uRadial2VSParams", stage, 6);
fFSParamVar = &state->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "uRadial2FSParams", stage, 6);
fVSParamLocation = GrGLProgramStage::kUseUniform;
fFSParamLocation = GrGLProgramStage::kUseUniform;
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
if (state->fVaryingDims == state->fCoordDims) {
state->addVarying(kFloat_GrSLType, "Radial2BCoeff", stage,
&fVSVaryingName, &fFSVaryingName);
}
}
void GrGLRadial2Gradient::emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) {
SkString* code = &state->fVSCode;
SkString p2;
SkString p3;
fVSParamVar->appendArrayAccess(2, &p2);
fVSParamVar->appendArrayAccess(3, &p3);
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
if (state->fVaryingDims == state->fCoordDims) {
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
fVSVaryingName, p2.c_str(),
vertexCoords, p3.c_str());
}
}
void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) {
SkString* code = &state->fFSCode;
SkString cName("c");
SkString ac4Name("ac4");
SkString rootName("root");
SkString p0;
SkString p1;
SkString p2;
SkString p3;
SkString p4;
SkString p5;
fFSParamVar->appendArrayAccess(0, &p0);
fFSParamVar->appendArrayAccess(1, &p1);
fFSParamVar->appendArrayAccess(2, &p2);
fFSParamVar->appendArrayAccess(3, &p3);
fFSParamVar->appendArrayAccess(4, &p4);
fFSParamVar->appendArrayAccess(5, &p5);
// If we we're able to interpolate the linear component,
// bVar is the varying; otherwise compute it
SkString bVar;
if (state->fCoordDims == state->fVaryingDims) {
bVar = fFSVaryingName;
GrAssert(2 == state->fVaryingDims);
} else {
GrAssert(3 == state->fVaryingDims);
bVar = "b";
//bVar.appendS32(stageNum);
code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
bVar.c_str(), p2.c_str(),
state->fSampleCoords.c_str(), p3.c_str());
}
// c = (x^2)+(y^2) - params[4]
code->appendf("\tfloat %s = dot(%s, %s) - %s;\n",
cName.c_str(), state->fSampleCoords.c_str(),
state->fSampleCoords.c_str(),
p4.c_str());
// If we aren't degenerate, emit some extra code, and accept a slightly
// more complex coord.
if (!fIsDegenerate) {
// ac4 = 4.0 * params[0] * c
code->appendf("\tfloat %s = %s * 4.0 * %s;\n",
ac4Name.c_str(), p0.c_str(),
cName.c_str());
// root = sqrt(b^2-4ac)
// (abs to avoid exception due to fp precision)
code->appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
rootName.c_str(), bVar.c_str(), bVar.c_str(),
ac4Name.c_str());
// x coord is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
// y coord is 0.5 (texture is effectively 1D)
state->fSampleCoords.printf("vec2((-%s + %s * %s) * %s, 0.5)",
bVar.c_str(), p5.c_str(),
rootName.c_str(), p1.c_str());
} else {
// x coord is: -c/b
// y coord is 0.5 (texture is effectively 1D)
state->fSampleCoords.printf("vec2((-%s / %s), 0.5)",
cName.c_str(), bVar.c_str());
}
state->fComplexCoord = true;
state->emitDefaultFetch(outputColor, samplerName);
}
void GrGLRadial2Gradient::initUniforms(const GrGLInterface* gl, int programID) {
GR_GL_CALL_RET(gl, fVSParamLocation,
GetUniformLocation(programID, fVSParamVar->getName().c_str()));
GR_GL_CALL_RET(gl, fFSParamLocation,
GetUniformLocation(programID, fFSParamVar->getName().c_str()));
}
void GrGLRadial2Gradient::setData(const GrGLInterface* gl,
const GrCustomStage& baseData,
int stageNum) {
const GrRadial2Gradient& data =
static_cast<const GrRadial2Gradient&>(baseData);
GrAssert(data.isDegenerate() == fIsDegenerate);
GrScalar centerX1 = data.center();
GrScalar radius0 = data.radius();
if (fCachedCenter != centerX1 ||
fCachedRadius != radius0 ||
fCachedPosRoot != data.isPosRoot()) {
GrScalar a = GrMul(centerX1, centerX1) - GR_Scalar1;
// When we're in the degenerate (linear) case, the second
// value will be INF but the program doesn't read it. (We
// use the same 6 uniforms even though we don't need them
// all in the linear case just to keep the code complexity
// down).
float values[6] = {
GrScalarToFloat(a),
1 / (2.f * GrScalarToFloat(a)),
GrScalarToFloat(centerX1),
GrScalarToFloat(radius0),
GrScalarToFloat(GrMul(radius0, radius0)),
data.isPosRoot() ? 1.f : -1.f
};
GR_GL_CALL(gl, Uniform1fv(fVSParamLocation, 6, values));
GR_GL_CALL(gl, Uniform1fv(fFSParamLocation, 6, values));
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedPosRoot = data.isPosRoot();
}
}
/////////////////////////////////////////////////////////////////////
GrRadial2Gradient::GrRadial2Gradient(GrTexture* texture,
GrScalar center,
GrScalar radius,
bool posRoot)
: GrSingleTextureEffect(texture)
, fCenterX1 (center)
, fRadius0 (radius)
, fPosRoot (posRoot) {
}
GrRadial2Gradient::~GrRadial2Gradient() {
}
const GrProgramStageFactory& GrRadial2Gradient::getFactory() const {
return GrTProgramStageFactory<GrRadial2Gradient>::getInstance();
}
bool GrRadial2Gradient::isEqual(const GrCustomStage& sBase) const {
const GrRadial2Gradient& s = static_cast<const GrRadial2Gradient&>(sBase);
return (INHERITED::isEqual(sBase) &&
this->fCenterX1 == s.fCenterX1 &&
this->fRadius0 == s.fRadius0 &&
this->fPosRoot == s.fPosRoot);
}
/////////////////////////////////////////////////////////////////////
class GrGLConical2Gradient : public GrGLProgramStage {
public:
GrGLConical2Gradient(const GrProgramStageFactory& factory,
const GrCustomStage&);
virtual ~GrGLConical2Gradient() { }
virtual void setupVariables(GrGLShaderBuilder* state,
int stage) SK_OVERRIDE;
virtual void emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) SK_OVERRIDE;
virtual void emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
virtual void initUniforms(const GrGLInterface*, int programID) SK_OVERRIDE;
virtual void setData(const GrGLInterface*,
const GrCustomStage&,
int stageNum) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s) {
return (static_cast<const GrConical2Gradient&>(s).isDegenerate());
}
protected:
const GrGLShaderVar* fVSParamVar;
GrGLint fVSParamLocation;
const GrGLShaderVar* fFSParamVar;
GrGLint fFSParamLocation;
const char* fVSVaryingName;
const char* fFSVaryingName;
bool fIsDegenerate;
// @{
/// Values last uploaded as uniforms
GrScalar fCachedCenter;
GrScalar fCachedRadius;
GrScalar fCachedDiffRadius;
// @}
private:
typedef GrGLProgramStage INHERITED;
};
GrGLConical2Gradient::GrGLConical2Gradient(
const GrProgramStageFactory& factory,
const GrCustomStage& baseData)
: INHERITED(factory)
, fVSParamVar(NULL)
, fFSParamVar(NULL)
, fVSVaryingName(NULL)
, fFSVaryingName(NULL)
, fCachedCenter(GR_ScalarMax)
, fCachedRadius(-GR_ScalarMax)
, fCachedDiffRadius(-GR_ScalarMax) {
const GrConical2Gradient& data =
static_cast<const GrConical2Gradient&>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* state, int stage) {
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
fVSParamVar = &state->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
kFloat_GrSLType, "uConical2VSParams", stage, 6);
fFSParamVar = &state->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "uConical2FSParams", stage, 6);
fVSParamLocation = GrGLProgramStage::kUseUniform;
fFSParamLocation = GrGLProgramStage::kUseUniform;
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
if (state->fVaryingDims == state->fCoordDims) {
state->addVarying(kFloat_GrSLType, "Conical2BCoeff", stage,
&fVSVaryingName, &fFSVaryingName);
}
}
void GrGLConical2Gradient::emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) {
SkString* code = &state->fVSCode;
SkString p2; // distance between centers
SkString p3; // start radius
SkString p5; // difference in radii (r1 - r0)
fVSParamVar->appendArrayAccess(2, &p2);
fVSParamVar->appendArrayAccess(3, &p3);
fVSParamVar->appendArrayAccess(5, &p5);
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
if (state->fVaryingDims == state->fCoordDims) {
// r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
code->appendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
fVSVaryingName, p2.c_str(),
vertexCoords, p3.c_str(), p5.c_str());
}
}
void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) {
SkString* code = &state->fFSCode;
SkString cName("c");
SkString ac4Name("ac4");
SkString dName("d");
SkString qName("q");
SkString r0Name("r0");
SkString r1Name("r1");
SkString tName("t");
SkString p0; // 4a
SkString p1; // 1/a
SkString p2; // distance between centers
SkString p3; // start radius
SkString p4; // start radius squared
SkString p5; // difference in radii (r1 - r0)
fFSParamVar->appendArrayAccess(0, &p0);
fFSParamVar->appendArrayAccess(1, &p1);
fFSParamVar->appendArrayAccess(2, &p2);
fFSParamVar->appendArrayAccess(3, &p3);
fFSParamVar->appendArrayAccess(4, &p4);
fFSParamVar->appendArrayAccess(5, &p5);
// If we we're able to interpolate the linear component,
// bVar is the varying; otherwise compute it
SkString bVar;
if (state->fCoordDims == state->fVaryingDims) {
bVar = fFSVaryingName;
GrAssert(2 == state->fVaryingDims);
} else {
GrAssert(3 == state->fVaryingDims);
bVar = "b";
code->appendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
bVar.c_str(), p2.c_str(), state->fSampleCoords.c_str(),
p3.c_str(), p5.c_str());
}
// output will default to transparent black (we simply won't write anything
// else to it if invalid, instead of discarding or returning prematurely)
code->appendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor);
// c = (x^2)+(y^2) - params[4]
code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
state->fSampleCoords.c_str(), state->fSampleCoords.c_str(),
p4.c_str());
// Non-degenerate case (quadratic)
if (!fIsDegenerate) {
// ac4 = params[0] * c
code->appendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p0.c_str(),
cName.c_str());
// d = b^2 - ac4
code->appendf("\tfloat %s = %s * %s - %s;\n", dName.c_str(),
bVar.c_str(), bVar.c_str(), ac4Name.c_str());
// only proceed if discriminant is >= 0
code->appendf("\tif (%s >= 0.0) {\n", dName.c_str());
// intermediate value we'll use to compute the roots
// q = -0.5 * (b +/- sqrt(d))
code->appendf("\t\tfloat %s = -0.5 * (%s + (%s < 0.0 ? -1.0 : 1.0)"
" * sqrt(%s));\n", qName.c_str(), bVar.c_str(),
bVar.c_str(), dName.c_str());
// compute both roots
// r0 = q * params[1]
code->appendf("\t\tfloat %s = %s * %s;\n", r0Name.c_str(),
qName.c_str(), p1.c_str());
// r1 = c / q
code->appendf("\t\tfloat %s = %s / %s;\n", r1Name.c_str(),
cName.c_str(), qName.c_str());
// Note: If there are two roots that both generate radius(t) > 0, the
// Canvas spec says to choose the larger t.
// so we'll look at the larger one first:
code->appendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str(),
r0Name.c_str(), r1Name.c_str());
// if r(t) > 0, then we're done; t will be our x coordinate
code->appendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
p5.c_str(), p3.c_str());
// y coord is 0.5 (texture is effectively 1D)
code->appendf("\t\t");
state->fSampleCoords.printf("vec2(%s, 0.5)", tName.c_str());
state->emitDefaultFetch(outputColor, samplerName);
// otherwise, if r(t) for the larger root was <= 0, try the other root
code->appendf("\t\t} else {\n");
code->appendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(),
r0Name.c_str(), r1Name.c_str());
// if r(t) > 0 for the smaller root, then t will be our x coordinate
code->appendf("\t\t\tif (%s * %s + %s > 0.0) {\n",
tName.c_str(), p5.c_str(), p3.c_str());
// y coord is 0.5 (texture is effectively 1D)
code->appendf("\t\t\t");
state->fSampleCoords.printf("vec2(%s, 0.5)", tName.c_str());
state->emitDefaultFetch(outputColor, samplerName);
// end if (r(t) > 0) for smaller root
code->appendf("\t\t\t}\n");
// end if (r(t) > 0), else, for larger root
code->appendf("\t\t}\n");
// end if (discriminant >= 0)
code->appendf("\t}\n");
} else {
// linear case: t = -c/b
code->appendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
cName.c_str(), bVar.c_str());
// if r(t) > 0, then t will be the x coordinate
code->appendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
p5.c_str(), p3.c_str());
code->appendf("\t");
state->fSampleCoords.printf("vec2(%s, 0.5)", tName.c_str());
state->emitDefaultFetch(outputColor, samplerName);
code->appendf("\t}\n");
}
state->fComplexCoord = true;
}
void GrGLConical2Gradient::initUniforms(const GrGLInterface* gl, int programID) {
GR_GL_CALL_RET(gl, fVSParamLocation,
GetUniformLocation(programID, fVSParamVar->getName().c_str()));
GR_GL_CALL_RET(gl, fFSParamLocation,
GetUniformLocation(programID, fFSParamVar->getName().c_str()));
}
void GrGLConical2Gradient::setData(const GrGLInterface* gl,
const GrCustomStage& baseData,
int stageNum) {
const GrConical2Gradient& data =
static_cast<const GrConical2Gradient&>(baseData);
GrAssert(data.isDegenerate() == fIsDegenerate);
GrScalar centerX1 = data.center();
GrScalar radius0 = data.radius();
GrScalar diffRadius = data.diffRadius();
if (fCachedCenter != centerX1 ||
fCachedRadius != radius0 ||
fCachedDiffRadius != diffRadius) {
GrScalar a = GrMul(centerX1, centerX1) - diffRadius * diffRadius;
// When we're in the degenerate (linear) case, the second
// value will be INF but the program doesn't read it. (We
// use the same 6 uniforms even though we don't need them
// all in the linear case just to keep the code complexity
// down).
float values[6] = {
GrScalarToFloat(a * 4),
1.f / (GrScalarToFloat(a)),
GrScalarToFloat(centerX1),
GrScalarToFloat(radius0),
GrScalarToFloat(SkScalarMul(radius0, radius0)),
GrScalarToFloat(diffRadius)
};
GR_GL_CALL(gl, Uniform1fv(fVSParamLocation, 6, values));
GR_GL_CALL(gl, Uniform1fv(fFSParamLocation, 6, values));
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedDiffRadius = diffRadius;
}
}
/////////////////////////////////////////////////////////////////////
GrConical2Gradient::GrConical2Gradient(GrTexture* texture,
GrScalar center,
GrScalar radius,
GrScalar diffRadius)
: GrSingleTextureEffect (texture)
, fCenterX1 (center)
, fRadius0 (radius)
, fDiffRadius (diffRadius) {
}
GrConical2Gradient::~GrConical2Gradient() {
}
const GrProgramStageFactory& GrConical2Gradient::getFactory() const {
return GrTProgramStageFactory<GrConical2Gradient>::getInstance();
}
bool GrConical2Gradient::isEqual(const GrCustomStage& sBase) const {
const GrConical2Gradient& s = static_cast<const GrConical2Gradient&>(sBase);
return (INHERITED::isEqual(sBase) &&
this->fCenterX1 == s.fCenterX1 &&
this->fRadius0 == s.fRadius0 &&
this->fDiffRadius == s.fDiffRadius);
}
/////////////////////////////////////////////////////////////////////
class GrGLSweepGradient : public GrGLProgramStage {
public:
GrGLSweepGradient(const GrProgramStageFactory& factory,
const GrCustomStage&) : INHERITED (factory) { }
virtual ~GrGLSweepGradient() { }
virtual void emitVS(GrGLShaderBuilder* state,
const char* vertexCoords) SK_OVERRIDE { }
virtual void emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s) { return 0; }
private:
typedef GrGLProgramStage INHERITED;
};
void GrGLSweepGradient::emitFS(GrGLShaderBuilder* state,
const char* outputColor,
const char* inputColor,
const char* samplerName) {
state->fSampleCoords.printf(
"vec2(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5, 0.5)",
state->fSampleCoords.c_str(), state->fSampleCoords.c_str());
state->fComplexCoord = true;
state->emitDefaultFetch(outputColor, samplerName);
}
/////////////////////////////////////////////////////////////////////
GrSweepGradient::GrSweepGradient(GrTexture* texture)
: GrSingleTextureEffect(texture) {
}
GrSweepGradient::~GrSweepGradient() {
}
const GrProgramStageFactory& GrSweepGradient::getFactory() const {
return GrTProgramStageFactory<GrSweepGradient>::getInstance();
}
bool GrSweepGradient::isEqual(const GrCustomStage& sBase) const {
return INHERITED::isEqual(sBase);
}
|