2011-10-26 15:03:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkAAClip.h"
|
2011-11-23 03:12:58 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkMask.h"
|
2011-10-26 15:03:48 +00:00
|
|
|
#include "SkPath.h"
|
2011-10-26 18:01:25 +00:00
|
|
|
#include "SkRandom.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2011-10-26 18:01:25 +00:00
|
|
|
|
2011-11-23 03:12:58 +00:00
|
|
|
static bool operator==(const SkMask& a, const SkMask& b) {
|
|
|
|
if (a.fFormat != b.fFormat || a.fBounds != b.fBounds) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!a.fImage && !b.fImage) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!a.fImage || !b.fImage) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t wbytes = a.fBounds.width();
|
|
|
|
switch (a.fFormat) {
|
|
|
|
case SkMask::kBW_Format:
|
|
|
|
wbytes = (wbytes + 7) >> 3;
|
|
|
|
break;
|
|
|
|
case SkMask::kA8_Format:
|
|
|
|
case SkMask::k3D_Format:
|
|
|
|
break;
|
|
|
|
case SkMask::kLCD16_Format:
|
|
|
|
wbytes <<= 1;
|
|
|
|
break;
|
|
|
|
case SkMask::kLCD32_Format:
|
|
|
|
case SkMask::kARGB32_Format:
|
|
|
|
wbytes <<= 2;
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-22 15:37:26 +00:00
|
|
|
SkDEBUGFAIL("unknown mask format");
|
2011-11-23 03:12:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int h = a.fBounds.height();
|
|
|
|
const char* aptr = (const char*)a.fImage;
|
|
|
|
const char* bptr = (const char*)b.fImage;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
if (memcmp(aptr, bptr, wbytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aptr += wbytes;
|
|
|
|
bptr += wbytes;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copyToMask(const SkRegion& rgn, SkMask* mask) {
|
2011-11-23 19:43:46 +00:00
|
|
|
mask->fFormat = SkMask::kA8_Format;
|
|
|
|
|
2011-11-23 03:12:58 +00:00
|
|
|
if (rgn.isEmpty()) {
|
|
|
|
mask->fBounds.setEmpty();
|
|
|
|
mask->fRowBytes = 0;
|
2011-11-23 19:43:46 +00:00
|
|
|
mask->fImage = NULL;
|
2011-11-23 03:12:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask->fBounds = rgn.getBounds();
|
|
|
|
mask->fRowBytes = mask->fBounds.width();
|
|
|
|
mask->fImage = SkMask::AllocImage(mask->computeImageSize());
|
|
|
|
sk_bzero(mask->fImage, mask->computeImageSize());
|
|
|
|
|
2014-02-13 22:00:04 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(mask->fBounds.width(),
|
|
|
|
mask->fBounds.height(),
|
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2011-11-23 03:12:58 +00:00
|
|
|
SkBitmap bitmap;
|
2014-05-29 15:57:20 +00:00
|
|
|
bitmap.installPixels(info, mask->fImage, mask->fRowBytes);
|
2011-11-23 03:12:58 +00:00
|
|
|
|
|
|
|
// canvas expects its coordinate system to always be 0,0 in the top/left
|
|
|
|
// so we translate the rgn to match that before drawing into the mask.
|
|
|
|
//
|
|
|
|
SkRegion tmpRgn(rgn);
|
|
|
|
tmpRgn.translate(-rgn.getBounds().fLeft, -rgn.getBounds().fTop);
|
|
|
|
|
|
|
|
SkCanvas canvas(bitmap);
|
|
|
|
canvas.clipRegion(tmpRgn);
|
|
|
|
canvas.drawColor(SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static SkIRect rand_rect(SkRandom& rand, int n) {
|
2011-11-23 03:12:58 +00:00
|
|
|
int x = rand.nextS() % n;
|
|
|
|
int y = rand.nextS() % n;
|
|
|
|
int w = rand.nextU() % n;
|
|
|
|
int h = rand.nextU() % n;
|
|
|
|
return SkIRect::MakeXYWH(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void make_rand_rgn(SkRegion* rgn, SkRandom& rand) {
|
2011-11-23 03:12:58 +00:00
|
|
|
int count = rand.nextU() % 20;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
rgn->op(rand_rect(rand, 100), SkRegion::kXOR_Op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-23 19:43:46 +00:00
|
|
|
static bool operator==(const SkRegion& rgn, const SkAAClip& aaclip) {
|
|
|
|
SkMask mask0, mask1;
|
|
|
|
|
|
|
|
copyToMask(rgn, &mask0);
|
|
|
|
aaclip.copyToMask(&mask1);
|
|
|
|
bool eq = (mask0 == mask1);
|
|
|
|
|
|
|
|
SkMask::FreeImage(mask0.fImage);
|
|
|
|
SkMask::FreeImage(mask1.fImage);
|
|
|
|
return eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool equalsAAClip(const SkRegion& rgn) {
|
|
|
|
SkAAClip aaclip;
|
|
|
|
aaclip.setRegion(rgn);
|
|
|
|
return rgn == aaclip;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setRgnToPath(SkRegion* rgn, const SkPath& path) {
|
|
|
|
SkIRect ir;
|
|
|
|
path.getBounds().round(&ir);
|
|
|
|
rgn->setPath(path, SkRegion(ir));
|
|
|
|
}
|
|
|
|
|
2011-11-23 03:12:58 +00:00
|
|
|
// aaclip.setRegion should create idential masks to the region
|
|
|
|
static void test_rgn(skiatest::Reporter* reporter) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-11-23 03:12:58 +00:00
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
SkRegion rgn;
|
|
|
|
make_rand_rgn(&rgn, rand);
|
2011-11-23 19:43:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, equalsAAClip(rgn));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkRegion rgn;
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(30));
|
|
|
|
setRgnToPath(&rgn, path);
|
|
|
|
REPORTER_ASSERT(reporter, equalsAAClip(rgn));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(SkIntToScalar(100), 0);
|
|
|
|
path.lineTo(SkIntToScalar(100 - 20), SkIntToScalar(20));
|
|
|
|
path.lineTo(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
setRgnToPath(&rgn, path);
|
|
|
|
REPORTER_ASSERT(reporter, equalsAAClip(rgn));
|
2011-11-23 03:12:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-26 18:01:25 +00:00
|
|
|
static const SkRegion::Op gRgnOps[] = {
|
2011-10-27 16:58:46 +00:00
|
|
|
SkRegion::kDifference_Op,
|
2011-10-26 18:01:25 +00:00
|
|
|
SkRegion::kIntersect_Op,
|
|
|
|
SkRegion::kUnion_Op,
|
|
|
|
SkRegion::kXOR_Op,
|
2011-10-27 16:58:46 +00:00
|
|
|
SkRegion::kReverseDifference_Op,
|
2011-10-26 18:01:25 +00:00
|
|
|
SkRegion::kReplace_Op
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* gRgnOpNames[] = {
|
2011-10-27 16:58:46 +00:00
|
|
|
"DIFF", "INTERSECT", "UNION", "XOR", "REVERSE_DIFF", "REPLACE"
|
2011-10-26 18:01:25 +00:00
|
|
|
};
|
2011-10-26 15:03:48 +00:00
|
|
|
|
2011-10-26 15:19:36 +00:00
|
|
|
static void imoveTo(SkPath& path, int x, int y) {
|
|
|
|
path.moveTo(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void icubicTo(SkPath& path, int x0, int y0, int x1, int y1, int x2, int y2) {
|
|
|
|
path.cubicTo(SkIntToScalar(x0), SkIntToScalar(y0),
|
|
|
|
SkIntToScalar(x1), SkIntToScalar(y1),
|
|
|
|
SkIntToScalar(x2), SkIntToScalar(y2));
|
|
|
|
}
|
|
|
|
|
2011-10-26 18:01:25 +00:00
|
|
|
static void test_path_bounds(skiatest::Reporter* reporter) {
|
2011-10-26 15:03:48 +00:00
|
|
|
SkPath path;
|
|
|
|
SkAAClip clip;
|
|
|
|
const int height = 40;
|
|
|
|
const SkScalar sheight = SkIntToScalar(height);
|
|
|
|
|
|
|
|
path.addOval(SkRect::MakeWH(sheight, sheight));
|
|
|
|
REPORTER_ASSERT(reporter, sheight == path.getBounds().height());
|
|
|
|
clip.setPath(path, NULL, true);
|
|
|
|
REPORTER_ASSERT(reporter, height == clip.getBounds().height());
|
|
|
|
|
|
|
|
// this is the trimmed height of this cubic (with aa). The critical thing
|
|
|
|
// for this test is that it is less than height, which represents just
|
|
|
|
// the bounds of the path's control-points.
|
|
|
|
//
|
|
|
|
// This used to fail until we tracked the MinY in the BuilderBlitter.
|
|
|
|
//
|
|
|
|
const int teardrop_height = 12;
|
|
|
|
path.reset();
|
2011-10-26 15:19:36 +00:00
|
|
|
imoveTo(path, 0, 20);
|
|
|
|
icubicTo(path, 40, 40, 40, 0, 0, 20);
|
2011-10-26 15:03:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, sheight == path.getBounds().height());
|
|
|
|
clip.setPath(path, NULL, true);
|
|
|
|
REPORTER_ASSERT(reporter, teardrop_height == clip.getBounds().height());
|
|
|
|
}
|
|
|
|
|
2011-10-26 18:01:25 +00:00
|
|
|
static void test_empty(skiatest::Reporter* reporter) {
|
|
|
|
SkAAClip clip0, clip1;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, clip0.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip1 == clip0);
|
|
|
|
|
|
|
|
clip0.translate(10, 10); // should have no effect on empty
|
|
|
|
REPORTER_ASSERT(reporter, clip0.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip1 == clip0);
|
|
|
|
|
|
|
|
SkIRect r = { 10, 10, 40, 50 };
|
|
|
|
clip0.setRect(r);
|
|
|
|
REPORTER_ASSERT(reporter, !clip0.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, !clip0.getBounds().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip0 != clip1);
|
|
|
|
REPORTER_ASSERT(reporter, clip0.getBounds() == r);
|
|
|
|
|
|
|
|
clip0.setEmpty();
|
|
|
|
REPORTER_ASSERT(reporter, clip0.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip0.getBounds().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, clip1 == clip0);
|
|
|
|
|
|
|
|
SkMask mask;
|
|
|
|
mask.fImage = NULL;
|
|
|
|
clip0.copyToMask(&mask);
|
|
|
|
REPORTER_ASSERT(reporter, NULL == mask.fImage);
|
|
|
|
REPORTER_ASSERT(reporter, mask.fBounds.isEmpty());
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void rand_irect(SkIRect* r, int N, SkRandom& rand) {
|
2011-10-26 18:01:25 +00:00
|
|
|
r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N);
|
|
|
|
int dx = rand.nextU() % (2*N);
|
|
|
|
int dy = rand.nextU() % (2*N);
|
|
|
|
// use int dx,dy to make the subtract be signed
|
|
|
|
r->offset(N - dx, N - dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_irect(skiatest::Reporter* reporter) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-10-26 18:01:25 +00:00
|
|
|
|
2011-10-27 16:58:46 +00:00
|
|
|
for (int i = 0; i < 10000; i++) {
|
2011-10-26 18:01:25 +00:00
|
|
|
SkAAClip clip0, clip1;
|
|
|
|
SkRegion rgn0, rgn1;
|
|
|
|
SkIRect r0, r1;
|
|
|
|
|
|
|
|
rand_irect(&r0, 10, rand);
|
|
|
|
rand_irect(&r1, 10, rand);
|
|
|
|
clip0.setRect(r0);
|
|
|
|
clip1.setRect(r1);
|
|
|
|
rgn0.setRect(r0);
|
|
|
|
rgn1.setRect(r1);
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gRgnOps); ++j) {
|
|
|
|
SkRegion::Op op = gRgnOps[j];
|
|
|
|
SkAAClip clip2;
|
|
|
|
SkRegion rgn2;
|
|
|
|
bool nonEmptyAA = clip2.op(clip0, clip1, op);
|
|
|
|
bool nonEmptyBW = rgn2.op(rgn0, rgn1, op);
|
|
|
|
if (nonEmptyAA != nonEmptyBW || clip2.getBounds() != rgn2.getBounds()) {
|
|
|
|
SkDebugf("[%d %d %d %d] %s [%d %d %d %d] = BW:[%d %d %d %d] AA:[%d %d %d %d]\n",
|
|
|
|
r0.fLeft, r0.fTop, r0.right(), r0.bottom(),
|
|
|
|
gRgnOpNames[j],
|
|
|
|
r1.fLeft, r1.fTop, r1.right(), r1.bottom(),
|
|
|
|
rgn2.getBounds().fLeft, rgn2.getBounds().fTop,
|
|
|
|
rgn2.getBounds().right(), rgn2.getBounds().bottom(),
|
|
|
|
clip2.getBounds().fLeft, clip2.getBounds().fTop,
|
|
|
|
clip2.getBounds().right(), clip2.getBounds().bottom());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, nonEmptyAA == nonEmptyBW);
|
|
|
|
REPORTER_ASSERT(reporter, clip2.getBounds() == rgn2.getBounds());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-16 18:56:17 +00:00
|
|
|
SkMask maskBW, maskAA;
|
|
|
|
copyToMask(rgn2, &maskBW);
|
|
|
|
clip2.copyToMask(&maskAA);
|
2012-03-15 18:16:39 +00:00
|
|
|
SkAutoMaskFreeImage freeBW(maskBW.fImage);
|
|
|
|
SkAutoMaskFreeImage freeAA(maskAA.fImage);
|
2012-02-16 18:56:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, maskBW == maskAA);
|
2011-10-26 18:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 18:56:17 +00:00
|
|
|
static void test_path_with_hole(skiatest::Reporter* reporter) {
|
|
|
|
static const uint8_t gExpectedImage[] = {
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
0xFF, 0xFF, 0xFF, 0xFF,
|
|
|
|
};
|
|
|
|
SkMask expected;
|
|
|
|
expected.fBounds.set(0, 0, 4, 6);
|
|
|
|
expected.fRowBytes = 4;
|
|
|
|
expected.fFormat = SkMask::kA8_Format;
|
|
|
|
expected.fImage = (uint8_t*)gExpectedImage;
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(SkRect::MakeXYWH(0, 0,
|
|
|
|
SkIntToScalar(4), SkIntToScalar(2)));
|
|
|
|
path.addRect(SkRect::MakeXYWH(0, SkIntToScalar(4),
|
|
|
|
SkIntToScalar(4), SkIntToScalar(2)));
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
SkAAClip clip;
|
|
|
|
clip.setPath(path, NULL, 1 == i);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-16 18:56:17 +00:00
|
|
|
SkMask mask;
|
|
|
|
clip.copyToMask(&mask);
|
2012-03-15 18:16:39 +00:00
|
|
|
SkAutoMaskFreeImage freeM(mask.fImage);
|
|
|
|
|
2012-02-16 18:56:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, expected == mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 18:48:10 +00:00
|
|
|
static void test_really_a_rect(skiatest::Reporter* reporter) {
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(SkRect::MakeWH(100, 100), 5, 5);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addRRect(rrect);
|
|
|
|
|
|
|
|
SkAAClip clip;
|
|
|
|
clip.setPath(path);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, clip.getBounds() == SkIRect::MakeWH(100, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !clip.isRect());
|
|
|
|
|
|
|
|
// This rect should intersect the clip, but slice-out all of the "soft" parts,
|
|
|
|
// leaving just a rect.
|
|
|
|
const SkIRect ir = SkIRect::MakeLTRB(10, -10, 50, 90);
|
|
|
|
|
|
|
|
clip.op(ir, SkRegion::kIntersect_Op);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, clip.getBounds() == SkIRect::MakeLTRB(10, 0, 50, 90));
|
|
|
|
// the clip recognized that that it is just a rect!
|
|
|
|
REPORTER_ASSERT(reporter, clip.isRect());
|
|
|
|
}
|
|
|
|
|
2012-05-11 20:57:25 +00:00
|
|
|
#include "SkRasterClip.h"
|
|
|
|
|
|
|
|
static void copyToMask(const SkRasterClip& rc, SkMask* mask) {
|
|
|
|
if (rc.isAA()) {
|
|
|
|
rc.aaRgn().copyToMask(mask);
|
|
|
|
} else {
|
|
|
|
copyToMask(rc.bwRgn(), mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool operator==(const SkRasterClip& a, const SkRasterClip& b) {
|
|
|
|
if (a.isEmpty()) {
|
|
|
|
return b.isEmpty();
|
|
|
|
}
|
|
|
|
if (b.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkMask ma, mb;
|
|
|
|
copyToMask(a, &ma);
|
|
|
|
copyToMask(b, &mb);
|
2012-08-16 14:58:06 +00:00
|
|
|
SkAutoMaskFreeImage aCleanUp(ma.fImage);
|
|
|
|
SkAutoMaskFreeImage bCleanUp(mb.fImage);
|
|
|
|
|
2012-05-11 20:57:25 +00:00
|
|
|
return ma == mb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void did_dx_affect(skiatest::Reporter* reporter, const SkScalar dx[],
|
|
|
|
size_t count, bool changed) {
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
const SkISize baseSize = SkISize::Make(10, 10);
|
2012-05-11 20:57:25 +00:00
|
|
|
SkIRect ir = { 0, 0, 10, 10 };
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(ir);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-11 20:57:25 +00:00
|
|
|
SkRasterClip rc0(ir);
|
|
|
|
SkRasterClip rc1(ir);
|
|
|
|
SkRasterClip rc2(ir);
|
|
|
|
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
rc0.op(r, baseSize, SkRegion::kIntersect_Op, false);
|
2012-05-11 20:57:25 +00:00
|
|
|
r.offset(dx[i], 0);
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
rc1.op(r, baseSize, SkRegion::kIntersect_Op, true);
|
2012-05-11 20:57:25 +00:00
|
|
|
r.offset(-2*dx[i], 0);
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
rc2.op(r, baseSize, SkRegion::kIntersect_Op, true);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-11 20:57:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, changed != (rc0 == rc1));
|
|
|
|
REPORTER_ASSERT(reporter, changed != (rc0 == rc2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_nearly_integral(skiatest::Reporter* reporter) {
|
|
|
|
// All of these should generate equivalent rasterclips
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-11 20:57:25 +00:00
|
|
|
static const SkScalar gSafeX[] = {
|
|
|
|
0, SK_Scalar1/1000, SK_Scalar1/100, SK_Scalar1/10,
|
|
|
|
};
|
|
|
|
did_dx_affect(reporter, gSafeX, SK_ARRAY_COUNT(gSafeX), false);
|
|
|
|
|
|
|
|
static const SkScalar gUnsafeX[] = {
|
|
|
|
SK_Scalar1/4, SK_Scalar1/3,
|
|
|
|
};
|
|
|
|
did_dx_affect(reporter, gUnsafeX, SK_ARRAY_COUNT(gUnsafeX), true);
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void test_regressions() {
|
2012-02-29 13:59:15 +00:00
|
|
|
// these should not assert in the debug build
|
|
|
|
// bug was introduced in rev. 3209
|
|
|
|
{
|
|
|
|
SkAAClip clip;
|
|
|
|
SkRect r;
|
2013-11-25 19:44:07 +00:00
|
|
|
r.fLeft = 129.892181f;
|
|
|
|
r.fTop = 10.3999996f;
|
|
|
|
r.fRight = 130.892181f;
|
|
|
|
r.fBottom = 20.3999996f;
|
2012-02-29 13:59:15 +00:00
|
|
|
clip.setRect(r, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 14:05:09 +00:00
|
|
|
// Building aaclip meant aa-scan-convert a path into a huge clip.
|
|
|
|
// the old algorithm sized the supersampler to the size of the clip, which overflowed
|
|
|
|
// its internal 16bit coordinates. The fix was to intersect the clip+path_bounds before
|
|
|
|
// sizing the supersampler.
|
|
|
|
//
|
|
|
|
// Before the fix, the following code would assert in debug builds.
|
|
|
|
//
|
|
|
|
static void test_crbug_422693(skiatest::Reporter* reporter) {
|
|
|
|
SkRasterClip rc(SkIRect::MakeLTRB(-25000, -25000, 25000, 25000));
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(50, 50, 50);
|
|
|
|
rc.op(path, rc.getBounds().size(), SkRegion::kIntersect_Op, true);
|
|
|
|
}
|
|
|
|
|
2013-09-19 20:56:46 +00:00
|
|
|
DEF_TEST(AAClip, reporter) {
|
2011-10-26 18:01:25 +00:00
|
|
|
test_empty(reporter);
|
|
|
|
test_path_bounds(reporter);
|
|
|
|
test_irect(reporter);
|
2011-11-23 03:12:58 +00:00
|
|
|
test_rgn(reporter);
|
2012-02-16 18:56:17 +00:00
|
|
|
test_path_with_hole(reporter);
|
2013-02-27 19:17:41 +00:00
|
|
|
test_regressions();
|
2012-05-11 20:57:25 +00:00
|
|
|
test_nearly_integral(reporter);
|
2014-08-07 18:48:10 +00:00
|
|
|
test_really_a_rect(reporter);
|
2014-10-15 14:05:09 +00:00
|
|
|
test_crbug_422693(reporter);
|
2011-10-26 15:03:48 +00:00
|
|
|
}
|