Sanitizing source files in Skia_Periodic_House_Keeping

git-svn-id: http://skia.googlecode.com/svn/trunk@7038 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
skia.committer@gmail.com 2013-01-05 02:02:05 +00:00
parent ac0d47ecb8
commit 8ae714b186
8 changed files with 57 additions and 57 deletions

View File

@ -31,11 +31,11 @@ protected:
virtual const char* onGetName() { virtual const char* onGetName() {
return fName.c_str(); return fName.c_str();
} }
SkScalar radius() const { SkScalar radius() const {
return fRadius; return fRadius;
} }
void setName( SkString name ) { void setName( SkString name ) {
fName = name; fName = name;
} }
@ -48,9 +48,9 @@ protected:
int pad = fRadius * 1.5 + 1; int pad = fRadius * 1.5 + 1;
SkRect r = SkRect::MakeWH(2 * pad + 1, 2 * pad + 1); SkRect r = SkRect::MakeWH(2 * pad + 1, 2 * pad + 1);
int loop_count; int loop_count;
if (fRadius > SkIntToScalar(50)) { if (fRadius > SkIntToScalar(50)) {
loop_count = 10; loop_count = 10;
} else if (fRadius > SkIntToScalar(5)) { } else if (fRadius > SkIntToScalar(5)) {
@ -58,14 +58,14 @@ protected:
} else { } else {
loop_count = 10000; loop_count = 10000;
} }
preBenchSetup( r ); preBenchSetup( r );
for (int i = 0; i < SkBENCHLOOP(loop_count); i++) { for (int i = 0; i < SkBENCHLOOP(loop_count); i++) {
makeBlurryRect( r ); makeBlurryRect( r );
} }
} }
virtual void makeBlurryRect( SkRect &r ) = 0; virtual void makeBlurryRect( SkRect &r ) = 0;
virtual void preBenchSetup( SkRect &r ) {} virtual void preBenchSetup( SkRect &r ) {}
private: private:
@ -77,13 +77,13 @@ class BlurRectDirectBench: public BlurRectBench {
public: public:
BlurRectDirectBench( void *param, SkScalar rad ) : BlurRectBench( param, rad ) { BlurRectDirectBench( void *param, SkScalar rad ) : BlurRectBench( param, rad ) {
SkString name; SkString name;
if (SkScalarFraction(rad) != 0) { if (SkScalarFraction(rad) != 0) {
name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad)); name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad));
} else { } else {
name.printf("blurrect_direct_%d", SkScalarRound(rad)); name.printf("blurrect_direct_%d", SkScalarRound(rad));
} }
setName( name ); setName( name );
} }
protected: protected:
@ -103,20 +103,20 @@ public:
} else { } else {
name.printf("blurrect_separable_%d", SkScalarRound(rad)); name.printf("blurrect_separable_%d", SkScalarRound(rad));
} }
setName( name ); setName( name );
} }
protected: protected:
virtual void preBenchSetup( SkRect &r ) { virtual void preBenchSetup( SkRect &r ) {
fSrcMask.fFormat = SkMask::kA8_Format; fSrcMask.fFormat = SkMask::kA8_Format;
fSrcMask.fRowBytes = r.width(); fSrcMask.fRowBytes = r.width();
fSrcMask.fBounds = SkIRect::MakeWH(r.width(), r.height()); fSrcMask.fBounds = SkIRect::MakeWH(r.width(), r.height());
fSrcMask.fImage = SkMask::AllocImage( fSrcMask.computeTotalImageSize() ); fSrcMask.fImage = SkMask::AllocImage( fSrcMask.computeTotalImageSize() );
memset( fSrcMask.fImage, 0xff, fSrcMask.computeTotalImageSize() ); memset( fSrcMask.fImage, 0xff, fSrcMask.computeTotalImageSize() );
} }
virtual void makeBlurryRect( SkRect &r ) { virtual void makeBlurryRect( SkRect &r ) {
SkMask mask; SkMask mask;
SkBlurMask::BlurSeparable( &mask, fSrcMask, radius(), SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality ); SkBlurMask::BlurSeparable( &mask, fSrcMask, radius(), SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality );

View File

@ -3,7 +3,7 @@ http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points
*/ */
/* /*
Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2. Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2.
Then for degree elevation, the equations are: Then for degree elevation, the equations are:
Q0 = P0 Q0 = P0
@ -25,11 +25,11 @@ Cubic defined by: P1/2 - anchor points, C1/C2 control points
|x| is the euclidean norm of x |x| is the euclidean norm of x
mid-point approx of cubic: a quad that shares the same anchors with the cubic and has the mid-point approx of cubic: a quad that shares the same anchors with the cubic and has the
control point at C = (3·C2 - P2 + 3·C1 - P1)/4 control point at C = (3·C2 - P2 + 3·C1 - P1)/4
Algorithm Algorithm
pick an absolute precision (prec) pick an absolute precision (prec)
Compute the Tdiv as the root of (cubic) equation Compute the Tdiv as the root of (cubic) equation
sqrt(3)/18 · |P2 - 3·C2 + 3·C1 - P1|/2 · Tdiv ^ 3 = prec sqrt(3)/18 · |P2 - 3·C2 + 3·C1 - P1|/2 · Tdiv ^ 3 = prec
if Tdiv < 0.5 divide the cubic at Tdiv. First segment [0..Tdiv] can be approximated with by a if Tdiv < 0.5 divide the cubic at Tdiv. First segment [0..Tdiv] can be approximated with by a
quadratic, with a defect less than prec, by the mid-point approximation. quadratic, with a defect less than prec, by the mid-point approximation.

View File

@ -161,7 +161,7 @@ public:
, fRectHeight( rectHeight ) , fRectHeight( rectHeight )
, fRadius( radius ) , fRadius( radius )
{} {}
int width() const { return fRectWidth; } int width() const { return fRectWidth; }
int height() const { return fRectHeight; } int height() const { return fRectHeight; }
int radius() const { return fRadius; } int radius() const { return fRadius; }
@ -174,7 +174,7 @@ protected:
virtual SkISize onISize() { virtual SkISize onISize() {
return SkISize::Make(640, 480); return SkISize::Make(640, 480);
} }
virtual void makeMask( SkMask *m, SkRect r ) = 0; virtual void makeMask( SkMask *m, SkRect r ) = 0;
virtual void onDraw(SkCanvas* canvas) { virtual void onDraw(SkCanvas* canvas) {
@ -221,7 +221,7 @@ protected:
memset( src.fImage, 0xff, src.computeTotalImageSize() ); memset( src.fImage, 0xff, src.computeTotalImageSize() );
SkBlurMask::BlurSeparable( m, src, radius()/2, SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality ); SkBlurMask::BlurSeparable( m, src, radius()/2, SkBlurMask::kNormal_Style, SkBlurMask::kHigh_Quality );
} }
}; };
@ -243,4 +243,4 @@ DEF_GM(return new BlurRectFastGM("blurrect_fast_10_100_10", 10, 100, 10);)
DEF_GM(return new BlurRectSlowGM("blurrect_slow_100_100_10", 100, 100, 10);) DEF_GM(return new BlurRectSlowGM("blurrect_slow_100_100_10", 100, 100, 10);)
DEF_GM(return new BlurRectSlowGM("blurrect_slow_100_100_2", 100, 100, 2);) DEF_GM(return new BlurRectSlowGM("blurrect_slow_100_100_2", 100, 100, 2);)
DEF_GM(return new BlurRectSlowGM("blurrect_slow_10_10_100", 10, 10, 100);) DEF_GM(return new BlurRectSlowGM("blurrect_slow_10_10_100", 10, 10, 100);)
DEF_GM(return new BlurRectSlowGM("blurrect_slow_10_100_10", 10, 100, 10);) DEF_GM(return new BlurRectSlowGM("blurrect_slow_10_100_10", 10, 100, 10);)

View File

@ -12,10 +12,10 @@
#include "SkTemplates.h" #include "SkTemplates.h"
#include "SkEndian.h" #include "SkEndian.h"
// scale factor for the blur radius to match the behavior of the all existing blur // scale factor for the blur radius to match the behavior of the all existing blur
// code (both on the CPU and the GPU). This magic constant is 1/sqrt(3). // code (both on the CPU and the GPU). This magic constant is 1/sqrt(3).
// TODO: get rid of this fudge factor and move any required fudging up into // TODO: get rid of this fudge factor and move any required fudging up into
// the calling library // the calling library
#define kBlurRadiusFudgeFactor SkFloatToScalar( .57735f ) #define kBlurRadiusFudgeFactor SkFloatToScalar( .57735f )
@ -1032,16 +1032,16 @@ bool SkBlurMask::Blur(SkMask* dst, const SkMask& src,
/* Convolving a box with itself three times results in a piecewise /* Convolving a box with itself three times results in a piecewise
quadratic function: quadratic function:
0 x <= -1.5 0 x <= -1.5
9/8 + 3/2 x + 1/2 x^2 -1.5 < x <= 1.5 9/8 + 3/2 x + 1/2 x^2 -1.5 < x <= 1.5
3/4 - x^2 -.5 < x <= .5 3/4 - x^2 -.5 < x <= .5
9/8 - 3/2 x + 1/2 x^2 0.5 < x <= 1.5 9/8 - 3/2 x + 1/2 x^2 0.5 < x <= 1.5
0 1.5 < x 0 1.5 < x
To get the profile curve of the blurred step function at the rectangle To get the profile curve of the blurred step function at the rectangle
edge, we evaluate the indefinite integral, which is piecewise cubic: edge, we evaluate the indefinite integral, which is piecewise cubic:
0 x <= -1.5 0 x <= -1.5
5/8 + 9/8 x + 3/4 x^2 + 1/6 x^3 -1.5 < x <= -0.5 5/8 + 9/8 x + 3/4 x^2 + 1/6 x^3 -1.5 < x <= -0.5
1/2 + 3/4 x - 1/3 x^3 -.5 < x <= .5 1/2 + 3/4 x - 1/3 x^3 -.5 < x <= .5
@ -1069,16 +1069,16 @@ static float gaussian_integral( float x ) {
return 0.4375 + (-x3 / 6 - 3 * x2 / 4 - 1.125 * x); return 0.4375 + (-x3 / 6 - 3 * x2 / 4 - 1.125 * x);
} }
/* /*
compute_profile allocates and fills in an array of floating compute_profile allocates and fills in an array of floating
point values between 0 and 255 for the profile signature of point values between 0 and 255 for the profile signature of
a blurred half-plane with the given blur radius. Since we're a blurred half-plane with the given blur radius. Since we're
going to be doing screened multiplications (i.e., 1 - (1-x)(1-y)) going to be doing screened multiplications (i.e., 1 - (1-x)(1-y))
all the time, we actually fill in the profile pre-inverted all the time, we actually fill in the profile pre-inverted
(already done 255-x). (already done 255-x).
The function returns the size of the array allocated for the The function returns the size of the array allocated for the
profile. It's the responsibility of the caller to delete the profile. It's the responsibility of the caller to delete the
memory returned in profile_out. memory returned in profile_out.
*/ */
@ -1101,7 +1101,7 @@ static int compute_profile( SkScalar radius, unsigned int **profile_out ) {
return size; return size;
} }
// TODO MAYBE: Maintain a profile cache to avoid recomputing this for // TODO MAYBE: Maintain a profile cache to avoid recomputing this for
// commonly used radii. Consider baking some of the most common blur radii // commonly used radii. Consider baking some of the most common blur radii
// directly in as static data? // directly in as static data?
@ -1113,71 +1113,71 @@ bool SkBlurMask::BlurRect(SkMask *dst, const SkRect &src,
SkIPoint *margin) { SkIPoint *margin) {
int profile_size; int profile_size;
unsigned int *profile; unsigned int *profile;
float radius = SkScalarToFloat( SkScalarMul( provided_radius, kBlurRadiusFudgeFactor ) ); float radius = SkScalarToFloat( SkScalarMul( provided_radius, kBlurRadiusFudgeFactor ) );
profile_size = compute_profile( radius, &profile ); profile_size = compute_profile( radius, &profile );
int pad = (int) (radius * 1.5f + 1); int pad = (int) (radius * 1.5f + 1);
if (margin) { if (margin) {
margin->set( pad, pad ); margin->set( pad, pad );
} }
dst->fBounds = SkIRect::MakeWH(src.width(), src.height()); dst->fBounds = SkIRect::MakeWH(src.width(), src.height());
dst->fBounds.outset(pad, pad); dst->fBounds.outset(pad, pad);
dst->fRowBytes = dst->fBounds.width(); dst->fRowBytes = dst->fBounds.width();
dst->fFormat = SkMask::kA8_Format; dst->fFormat = SkMask::kA8_Format;
dst->fImage = NULL; dst->fImage = NULL;
size_t dstSize = dst->computeImageSize(); size_t dstSize = dst->computeImageSize();
if (0 == dstSize) { if (0 == dstSize) {
return false; // too big to allocate, abort return false; // too big to allocate, abort
} }
int sw = src.width(); int sw = src.width();
int sh = src.height(); int sh = src.height();
uint8_t* dp = SkMask::AllocImage(dstSize); uint8_t* dp = SkMask::AllocImage(dstSize);
dst->fImage = dp; dst->fImage = dp;
SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp); SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp);
int dst_height = dst->fBounds.height(); int dst_height = dst->fBounds.height();
int dst_width = dst->fBounds.width(); int dst_width = dst->fBounds.width();
// nearest odd number less than the profile size represents the center // nearest odd number less than the profile size represents the center
// of the (2x scaled) profile // of the (2x scaled) profile
int center = ( profile_size & ~1 ) - 1; int center = ( profile_size & ~1 ) - 1;
int w = sw - center; int w = sw - center;
int h = sh - center; int h = sh - center;
uint8_t *outptr = dp; uint8_t *outptr = dp;
for (int y = 0 ; y < dst_height ; y++) for (int y = 0 ; y < dst_height ; y++)
{ {
// time to fill in a scanline of the blurry rectangle. // time to fill in a scanline of the blurry rectangle.
// to avoid floating point math, everything is multiplied by // to avoid floating point math, everything is multiplied by
// 2 where needed. This keeps things nice and integer-oriented. // 2 where needed. This keeps things nice and integer-oriented.
int dy = abs((y << 1) - dst_height) - h; // how far are we from the original edge? int dy = abs((y << 1) - dst_height) - h; // how far are we from the original edge?
int oy = dy >> 1; int oy = dy >> 1;
if (oy < 0) oy = 0; if (oy < 0) oy = 0;
unsigned int profile_y = profile[oy]; unsigned int profile_y = profile[oy];
for (int x = 0 ; x < (dst_width << 1) ; x += 2) { for (int x = 0 ; x < (dst_width << 1) ; x += 2) {
int dx = abs( x - dst_width ) - w; int dx = abs( x - dst_width ) - w;
int ox = dx >> 1; int ox = dx >> 1;
if (ox < 0) ox = 0; if (ox < 0) ox = 0;
unsigned int maskval = SkMulDiv255Round(profile[ox], profile_y); unsigned int maskval = SkMulDiv255Round(profile[ox], profile_y);
*(outptr++) = maskval; *(outptr++) = maskval;
} }
} }
return true; return true;
} }

View File

@ -28,8 +28,8 @@ public:
kHigh_Quality //!< three pass box blur (similar to gaussian) kHigh_Quality //!< three pass box blur (similar to gaussian)
}; };
static bool BlurRect(SkMask *dst, const SkRect &src, static bool BlurRect(SkMask *dst, const SkRect &src,
SkScalar radius, Style style, Quality quality, SkScalar radius, Style style, Quality quality,
SkIPoint *margin = NULL); SkIPoint *margin = NULL);
static bool Blur(SkMask* dst, const SkMask& src, static bool Blur(SkMask* dst, const SkMask& src,

View File

@ -912,4 +912,4 @@ void GrGLProgram::setData(GrGpuGL* gpu) {
} }
} }
} }
} }

View File

@ -173,7 +173,7 @@ private:
const char* adjustInColor(const SkString& inColor) const; const char* adjustInColor(const SkString& inColor) const;
typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray; typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray;
struct UniformHandles { struct UniformHandles {
UniformHandle fViewMatrixUni; UniformHandle fViewMatrixUni;
UniformHandle fColorUni; UniformHandle fColorUni;
@ -184,7 +184,7 @@ private:
UniformHandle fRTHeightUni; UniformHandle fRTHeightUni;
// An array of sampler uniform handles for each effect. // An array of sampler uniform handles for each effect.
SamplerUniSArray fSamplerUnis[GrDrawState::kNumStages]; SamplerUniSArray fSamplerUnis[GrDrawState::kNumStages];
UniformHandles() { UniformHandles() {
fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle; fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle;
fColorUni = GrGLUniformManager::kInvalidUniformHandle; fColorUni = GrGLUniformManager::kInvalidUniformHandle;

View File

@ -181,7 +181,7 @@ public:
GrBackendEffectFactory::EffectKey key, GrBackendEffectFactory::EffectKey key,
const char* fsInColor, // NULL means no incoming color const char* fsInColor, // NULL means no incoming color
const char* fsOutColor, const char* fsOutColor,
const char* vsInCoord, const char* vsInCoord,
SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles); SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles);
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; } GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
// TODO: Make this do all the compiling, linking, etc. // TODO: Make this do all the compiling, linking, etc.