Index: src/gpu/effects/GrGradientEffects.cpp |
=================================================================== |
--- src/gpu/effects/GrGradientEffects.cpp (revision 4740) |
+++ src/gpu/effects/GrGradientEffects.cpp (working copy) |
@@ -9,6 +9,7 @@ |
#include "gl/GrGLProgramStage.h" |
#include "GrProgramStageFactory.h" |
#include "SkGr.h" |
+#include "../core/SkShader.h" |
// Base class for GL gradient custom stages |
class GrGLGradientStage : public GrGLProgramStage { |
@@ -51,7 +52,9 @@ |
SkSafeRef(fTexture); |
} |
-GrGradientEffect::GrGradientEffect(GrContext* ctx, const SkShader& shader) |
+GrGradientEffect::GrGradientEffect(GrContext* ctx, |
+ const SkShader& shader, |
+ GrSamplerState* sampler) |
: fTexture (NULL) |
, fUseTexture (false) { |
// TODO: check for simple cases where we don't need a texture: |
@@ -60,16 +63,10 @@ |
//if (info.fColorCount == 2) { ... |
SkBitmap bitmap; |
- shader.asABitmap(&bitmap, NULL, NULL, NULL); |
+ shader.asABitmap(&bitmap, NULL, NULL); |
- // Note: we just construct a default sampler state here, which isn't great, |
- // however, as long as the bitmap has power-of-two dimensions, which should |
- // be the case for gradient bitmaps, it should be fine |
- GrAssert(SkIsPow2(bitmap.width()) && SkIsPow2(bitmap.height())); |
- GrSamplerState sampler; |
- |
GrContext::TextureCacheEntry entry = GrLockCachedBitmapTexture(ctx, bitmap, |
- &sampler); |
+ sampler); |
fTexture = entry.texture(); |
SkSafeRef(fTexture); |
fUseTexture = true; |
@@ -133,8 +130,10 @@ |
: INHERITED(texture) { |
} |
-GrLinearGradient::GrLinearGradient(GrContext* ctx, const SkShader& shader) |
- : INHERITED(ctx, shader) { |
+GrLinearGradient::GrLinearGradient(GrContext* ctx, |
+ const SkShader& shader, |
+ GrSamplerState* sampler) |
+ : INHERITED(ctx, shader, sampler) { |
} |
GrLinearGradient::~GrLinearGradient() { |
@@ -188,8 +187,9 @@ |
} |
-GrRadialGradient::GrRadialGradient(GrContext* ctx, const SkShader& shader) |
- : INHERITED(ctx, shader) { |
+GrRadialGradient::GrRadialGradient(GrContext* ctx, const SkShader& shader, |
+ GrSamplerState* sampler) |
+ : INHERITED(ctx, shader, sampler) { |
} |
GrRadialGradient::~GrRadialGradient() { |
@@ -445,17 +445,16 @@ |
} |
-GrRadial2Gradient::GrRadial2Gradient(GrContext* ctx, const SkShader& shader) |
- : INHERITED(ctx, shader) { |
- SkShader::GradientInfo info; |
- info.fColorCount = 0; |
- shader.asAGradient(&info); |
- fCenterX1 = SkPoint::Distance(info.fPoint[0], info.fPoint[1]); |
- SkScalar diffRadius = info.fRadius[1] - info.fRadius[0]; |
- fPosRoot = diffRadius < 0; |
- SkScalar inv = 0 == diffRadius ? 0 : SkScalarInvert(diffRadius); |
- fRadius0 = SkScalarMul(info.fRadius[0], inv); |
- fCenterX1 = SkScalarMul(fCenterX1, inv); |
+GrRadial2Gradient::GrRadial2Gradient(GrContext* ctx, |
+ const SkShader& shader, |
+ GrSamplerState* sampler, |
+ SkScalar center, |
+ SkScalar startRadius, |
+ SkScalar diffRadius) |
+ : INHERITED(ctx, shader, sampler) |
bsalomon
2012/07/25 15:21:15
nit: I don't know that we have a rule about how th
|
+ , fCenterX1(center) |
+ , fRadius0(startRadius) |
+ , fPosRoot(diffRadius < 0) { |
} |
GrRadial2Gradient::~GrRadial2Gradient() { |
@@ -776,14 +775,16 @@ |
} |
-GrConical2Gradient::GrConical2Gradient(GrContext* ctx, const SkShader& shader) |
- : INHERITED(ctx, shader) { |
- SkShader::GradientInfo info; |
- info.fColorCount = 0; |
- shader.asAGradient(&info); |
- fCenterX1 = SkPoint::Distance(info.fPoint[0], info.fPoint[1]); |
- fRadius0 = info.fRadius[0]; |
- fDiffRadius = info.fRadius[1] - info.fRadius[0]; |
+GrConical2Gradient::GrConical2Gradient(GrContext* ctx, |
+ const SkShader& shader, |
+ GrSamplerState* sampler, |
+ SkScalar center, |
+ SkScalar startRadius, |
+ SkScalar diffRadius) |
+ : INHERITED(ctx, shader, sampler) |
+ , fCenterX1(center) |
+ , fRadius0(startRadius) |
+ , fDiffRadius(diffRadius) { |
} |
GrConical2Gradient::~GrConical2Gradient() { |
@@ -846,8 +847,9 @@ |
} |
-GrSweepGradient::GrSweepGradient(GrContext* ctx, const SkShader& shader) |
- : INHERITED(ctx, shader) { |
+GrSweepGradient::GrSweepGradient(GrContext* ctx, const SkShader& shader, |
+ GrSamplerState* sampler) |
+ : INHERITED(ctx, shader, sampler) { |
} |
GrSweepGradient::~GrSweepGradient() { |