promote SkMask's rowBytes to 32bits, since its bounds is a 32bit rect

be sure a rect is sorted before using it as the path's bounds cache



git-svn-id: http://skia.googlecode.com/svn/trunk@128 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-03-19 21:52:42 +00:00
parent 79b2cd1be5
commit 49f0ff25a0
9 changed files with 375 additions and 15 deletions

View File

@ -37,13 +37,14 @@ struct SkMask {
uint8_t* fImage;
SkIRect fBounds;
uint16_t fRowBytes;
uint8_t fFormat; // Format
uint32_t fRowBytes;
Format fFormat;
/** Return the byte size of the mask, assuming only 1 plane.
Does not account for k3D_Format. For that, use computeFormatImageSize()
*/
size_t computeImageSize() const;
/** Return the byte size of the mask, taking into account
any extra planes (e.g. k3D_Format).
*/
@ -53,19 +54,18 @@ struct SkMask {
Asserts that the mask is kBW_Format, and that x,y are in range.
x,y are in the same coordiate space as fBounds.
*/
uint8_t* getAddr1(int x, int y) const
{
uint8_t* getAddr1(int x, int y) const {
SkASSERT(fFormat == kBW_Format);
SkASSERT(fBounds.contains(x, y));
SkASSERT(fImage != NULL);
return fImage + ((x - fBounds.fLeft) >> 3) + (y - fBounds.fTop) * fRowBytes;
}
/** Returns the address of the specified byte.
Asserts that the mask is kA8_Format, and that x,y are in range.
x,y are in the same coordiate space as fBounds.
*/
uint8_t* getAddr(int x, int y) const
{
uint8_t* getAddr(int x, int y) const {
SkASSERT(fFormat != kBW_Format);
SkASSERT(fBounds.contains(x, y));
SkASSERT(fImage != NULL);

356
samplecode/SampleFuzz.cpp Normal file
View File

@ -0,0 +1,356 @@
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkBlurMaskFilter.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkPorterDuff.h"
#include "SkXfermode.h"
#include "SkMatrix.h"
#include "SkColor.h"
#include "SkRandom.h"
static void set2x3(SkMatrix* m, float a, float b, float c, float d, float e, float f) {
m->reset();
m->set(0, a);
m->set(1, b);
m->set(2, c);
m->set(3, d);
m->set(4, e);
m->set(5, f);
}
static SkRandom gRand;
static bool return_large;
static bool return_undef;
static bool quick;
static bool scale_large;
static int scval = 1;
static float transval = 0;
static int R(float x) {
return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x);
}
static float make_number() {
float v;
int sel;
if (return_large == true && R(3) == 1) sel = R(6); else sel = R(4);
if (return_undef == false && sel == 0) sel = 1;
if (R(2) == 1) v = R(100); else
switch (sel) {
case 0: break;
case 1: v = 0; break;
case 2: v = 0.000001; break;
case 3: v = 10000; break;
case 4: v = 2000000000; break;
case 5: v = 1e100; break;
}
if (R(4) == 1) v = -v;
return v;
}
static SkColor make_color() {
if (R(2) == 1) return 0xFFC0F0A0; else return 0xFF000090;
}
static SkColor make_fill() {
#if 0
int sel;
if (quick == true) sel = 0; else sel = R(6);
switch (sel) {
case 0:
case 1:
case 2:
return make_color();
break;
case 3:
var r = ctx.createLinearGradient(make_number(),make_number(),make_number(),make_number());
for (i=0;i<4;i++)
r.addColorStop(make_number(),make_color());
return r;
break;
case 4:
var r = ctx.createRadialGradient(make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
for (i=0;i<4;i++)
r.addColorStop(make_number(),make_color());
return r;
break;
case 5:
var r = ctx.createPattern(imgObj,"repeat");
if (R(6) == 0)
r.addColorStop(make_number(),make_color());
return r;
break;
}
#else
return make_color();
#endif
}
static void do_fuzz(SkCanvas* canvas) {
SkPath path;
SkPaint paint;
paint.setAntiAlias(true);
for (int i=0;i<100;i++) {
switch (R(33)) {
case 0:
paint.setColor(make_fill());
break;
case 1:
paint.setAlpha(gRand.nextU() & 0xFF);
break;
case 2: {
SkPorterDuff::Mode mode;
switch (R(3)) {
case 0: mode = SkPorterDuff::kSrc_Mode; break;
case 1: mode = SkPorterDuff::kXor_Mode; break;
case 2: mode = SkPorterDuff::kSrcOver_Mode; break;
}
paint.setXfermode(SkPorterDuff::CreateXfermode(mode))->safeUnref();
}
break;
case 3:
switch (R(2)) {
case 0: paint.setStrokeCap(SkPaint::kRound_Cap); break;
case 1: paint.setStrokeCap(SkPaint::kButt_Cap); break;
}
break;
case 4:
switch (R(2)) {
case 0: paint.setStrokeJoin(SkPaint::kRound_Join); break;
case 1: paint.setStrokeJoin(SkPaint::kMiter_Join); break;
}
break;
case 5:
paint.setStrokeWidth(make_number());
break;
case 6:
paint.setStrokeMiter(make_number());
break;
case 7:
if (quick == true) break;
paint.setMaskFilter(SkBlurMaskFilter::Create(make_number(), SkBlurMaskFilter::kNormal_BlurStyle))->safeUnref();
break;
case 8:
if (quick == true) break;
//ctx.shadowColor = make_fill();
break;
case 9:
if (quick == true) break;
//ctx.shadowOffsetX = make_number();
//ctx.shadowOffsetY = make_number();
break;
case 10:
canvas->restore();
break;
case 11:
canvas->rotate(make_number());
break;
case 12:
canvas->save();
break;
case 13:
canvas->scale(-1,-1);
break;
case 14:
if (quick == true) break;
if (transval == 0) {
transval = make_number();
canvas->translate(transval,0);
} else {
canvas->translate(-transval,0);
transval = 0;
}
break;
case 15: {
SkRect r;
r.set(make_number(),make_number(),make_number(),make_number());
SkPaint::Style s = paint.getStyle();
paint.setStyle(SkPaint::kFill_Style);
canvas->drawRect(r, paint);
paint.setStyle(s);
// clearrect
} break;
case 16:
if (quick == true) break;
// ctx.drawImage(imgObj,make_number(),make_number(),make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
break;
case 17: {
SkRect r;
r.set(make_number(),make_number(),make_number(),make_number());
SkPaint::Style s = paint.getStyle();
paint.setStyle(SkPaint::kFill_Style);
canvas->drawRect(r, paint);
paint.setStyle(s);
} break;
case 18:
path.reset();
break;
case 19:
// ctx.clip() is evil.
break;
case 20:
path.close();
break;
case 21: {
SkPaint::Style s = paint.getStyle();
paint.setStyle(SkPaint::kFill_Style);
canvas->drawPath(path, paint);
paint.setStyle(s);
} break;
case 22: {
SkPaint::Style s = paint.getStyle();
paint.setStyle(SkPaint::kFill_Style);
canvas->drawPath(path, paint);
paint.setStyle(s);
} break;
case 23: {
SkRect r;
r.set(make_number(),make_number(),make_number(),make_number());
SkPaint::Style s = paint.getStyle();
paint.setStyle(SkPaint::kStroke_Style);
canvas->drawRect(r, paint);
paint.setStyle(s);
} break;
case 24:
if (quick == true) break;
//ctx.arc(make_number(),make_number(),make_number(),make_number(),make_number(),true);
break;
case 25:
if (quick == true) break;
//ctx.arcTo(make_number(),make_number(),make_number(),make_number(),make_number());
break;
case 26:
if (quick == true) break;
//ctx.bezierCurveTo(make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
break;
case 27:
path.lineTo(make_number(),make_number());
break;
case 28:
path.moveTo(make_number(),make_number());
break;
case 29:
if (quick == true) break;
path.quadTo(make_number(),make_number(),make_number(),make_number());
break;
case 30: {
if (quick == true) break;
SkMatrix matrix;
set2x3(&matrix, make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
canvas->concat(matrix);
} break;
case 31: {
if (quick == true) break;
SkMatrix matrix;
set2x3(&matrix, make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
canvas->setMatrix(matrix);
} break;
case 32:
if (scale_large == true) {
switch (scval) {
case 0: canvas->scale(-1000000000,1);
canvas->scale(-1000000000,1);
scval = 1; break;
case 1: canvas->scale(-.000000001,1); scval = 2; break;
case 2: canvas->scale(-.000000001,1); scval = 0; break;
}
}
break;
}
}
}
//////////////////////////////////////////////////////////////////////////////
class FuzzView : public SkView {
public:
FuzzView() {}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Fuzzer");
return true;
}
return this->INHERITED::onQuery(evt);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
do_fuzz(canvas);
this->inval(NULL);
}
private:
typedef SkView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new FuzzView; }
static SkViewRegister reg(MyFactory);

View File

@ -893,7 +893,7 @@ void SkBitmap::buildMipMap(bool forceRebuild) {
level[i].fPixels = addr;
level[i].fWidth = SkToU16(width);
level[i].fHeight = SkToU16(height);
level[i].fRowBytes = SkToU16(rowBytes);
level[i].fRowBytes = rowBytes;
dstBM.setConfig(config, width, height, rowBytes);
dstBM.setPixels(addr);

View File

@ -1250,7 +1250,7 @@ static void D1G_NoBounder_RectClip(const SkDraw1Glyph& state,
}
mask.fRowBytes = glyph.rowBytes();
mask.fFormat = glyph.fMaskFormat;
mask.fFormat = (SkMask::Format)glyph.fMaskFormat;
mask.fImage = aa;
state.fBlitter->blitMask(mask, *bounds);
}
@ -1280,7 +1280,7 @@ static void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state,
}
mask.fRowBytes = glyph.rowBytes();
mask.fFormat = glyph.fMaskFormat;
mask.fFormat = (SkMask::Format)glyph.fMaskFormat;
mask.fImage = (uint8_t*)aa;
do {
state.fBlitter->blitMask(mask, cr);
@ -1313,7 +1313,7 @@ static void D1G_Bounder(const SkDraw1Glyph& state,
if (state.fBounder->doIRect(cr)) {
mask.fRowBytes = glyph.rowBytes();
mask.fFormat = glyph.fMaskFormat;
mask.fFormat = (SkMask::Format)glyph.fMaskFormat;
mask.fImage = (uint8_t*)aa;
do {
state.fBlitter->blitMask(mask, cr);

View File

@ -62,6 +62,8 @@ private:
fPath = path;
fDirty = path->fFastBoundsIsDirty;
fEmpty = path->isEmpty();
// can't use fRect for our bounds unless we know is upright and proper
fRect.sort();
}
};

View File

@ -41,7 +41,7 @@ void SkGlyph::toMask(SkMask* mask) const {
mask->fImage = (uint8_t*)fImage;
mask->fBounds.set(fLeft, fTop, fLeft + fWidth, fTop + fHeight);
mask->fRowBytes = this->rowBytes();
mask->fFormat = fMaskFormat;
mask->fFormat = (SkMask::Format)fMaskFormat;
}
size_t SkGlyph::computeImageSize() const {

View File

@ -228,7 +228,7 @@ bool SkBlurMask::Blur(SkMask* dst, const SkMask& src,
dst->fBounds.set(src.fBounds.fLeft - rx, src.fBounds.fTop - ry,
src.fBounds.fRight + rx, src.fBounds.fBottom + ry);
dst->fRowBytes = SkToU16(dst->fBounds.width());
dst->fRowBytes = dst->fBounds.width();
dst->fFormat = SkMask::kA8_Format;
dst->fImage = NULL;
@ -277,7 +277,7 @@ bool SkBlurMask::Blur(SkMask* dst, const SkMask& src,
if (style == kInner_Style)
{
dst->fBounds = src.fBounds; // restore trimmed bounds
dst->fRowBytes = SkToU16(dst->fBounds.width());
dst->fRowBytes = dst->fBounds.width();
}
#if 0

View File

@ -107,7 +107,7 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix,
if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode)
{
mask->fFormat = SkMask::kA8_Format;
mask->fRowBytes = SkToU16(mask->fBounds.width());
mask->fRowBytes = mask->fBounds.width();
mask->fImage = SkMask::AllocImage(mask->computeImageSize());
memset(mask->fImage, 0, mask->computeImageSize());
}

View File

@ -181,6 +181,7 @@
007C785D0F3B4C230004B142 /* SamplePathClip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SamplePathClip.cpp; path = ../../samplecode/SamplePathClip.cpp; sourceTree = SOURCE_ROOT; };
009CC9180F65918A002185BE /* SampleFontScalerTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleFontScalerTest.cpp; path = ../../samplecode/SampleFontScalerTest.cpp; sourceTree = SOURCE_ROOT; };
00A41E4A0EFC312F00C9CBEB /* SampleArc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleArc.cpp; path = ../../samplecode/SampleArc.cpp; sourceTree = SOURCE_ROOT; };
00D6B5CB0F72DC4300C466B9 /* SampleFuzz.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleFuzz.cpp; path = ../../samplecode/SampleFuzz.cpp; sourceTree = SOURCE_ROOT; };
0156F80307C56A3000C6122B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
01FC44D407BD3BB800D228F4 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = /System/Library/Frameworks/Quartz.framework; sourceTree = "<absolute>"; };
0867D6ABFE840B52C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@ -214,6 +215,7 @@
isa = PBXGroup;
children = (
007A7CA40F01658C00A2D6EE /* SamplePicture.cpp */,
00D6B5CB0F72DC4300C466B9 /* SampleFuzz.cpp */,
009CC9180F65918A002185BE /* SampleFontScalerTest.cpp */,
007A7CA50F01658C00A2D6EE /* SamplePoints.cpp */,
007A7CA70F01658C00A2D6EE /* SampleRegion.cpp */,
@ -497,7 +499,6 @@
0041CE480F00A12400695E8C /* SampleOverflow.cpp in Sources */,
0041CE4A0F00A12400695E8C /* SamplePatch.cpp in Sources */,
0041CE470F00A12400695E8C /* SampleNinePatch.cpp in Sources */,
007A7CB30F01658C00A2D6EE /* SamplePicture.cpp in Sources */,
007A7CB40F01658C00A2D6EE /* SamplePoints.cpp in Sources */,
007A7CB70F01658C00A2D6EE /* SampleShaders.cpp in Sources */,
007A7CB80F01658C00A2D6EE /* SampleStrokeText.cpp in Sources */,
@ -513,6 +514,7 @@
007A7CB60F01658C00A2D6EE /* SampleRegion.cpp in Sources */,
007C785E0F3B4C230004B142 /* SamplePathClip.cpp in Sources */,
009CC9190F65918A002185BE /* SampleFontScalerTest.cpp in Sources */,
007A7CB30F01658C00A2D6EE /* SamplePicture.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};