Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Unified Diff: tests/GrShapeTest.cpp

Issue 1970003003: Add bounds to GrShape (Closed) Base URL: https://chromium.googlesource.com/skia.git@grshapeisempty
Patch Set: minor Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/gpu/GrStyle.h ('K') | « src/gpu/GrStyle.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/GrShapeTest.cpp
diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp
index 138028d738d26d00274552913abc53fd3cda8650..1cc89bb7004f90e0e6bc826768d4c0546fc5edb3 100644
--- a/tests/GrShapeTest.cpp
+++ b/tests/GrShapeTest.cpp
@@ -10,8 +10,10 @@
#include "Test.h"
#if SK_SUPPORT_GPU
#include "GrShape.h"
-#include "SkPath.h"
+#include "SkCanvas.h"
#include "SkDashPathEffect.h"
+#include "SkPath.h"
+#include "SkSurface.h"
using Key = SkTArray<uint32_t>;
@@ -28,6 +30,33 @@ static bool make_key(Key* key, const GrShape& shape) {
}
namespace {
+static bool test_bounds_by_rasterizing(const SkPath& path, const SkRect& bounds) {
+ static constexpr int kRes = 2000;
+ static constexpr int kTol = 1;
+ GR_STATIC_ASSERT(kRes % 4 == 0);
+ SkImageInfo info = SkImageInfo::MakeA8(kRes, kRes);
+ sk_sp<SkSurface> surface = SkSurface::MakeRaster(info);
+ surface->getCanvas()->clear(0x0);
+ SkRect clip = SkRect::MakeXYWH(kRes/4, kRes/4, kRes/2, kRes/2);
+ SkMatrix matrix;
+ matrix.setRectToRect(bounds, clip, SkMatrix::kFill_ScaleToFit);
robertphillips 2016/05/12 17:18:47 Is this outset really kosher? If we're going to us
bsalomon 2016/05/12 18:37:58 For the current set of test cases it works at 0 (a
+ clip.outset(SkIntToScalar(kTol), SkIntToScalar(kTol));
+ surface->getCanvas()->clipRect(clip, SkRegion::kDifference_Op);
+ surface->getCanvas()->concat(matrix);
+ SkPaint whitePaint;
+ whitePaint.setColor(SK_ColorWHITE);
+ surface->getCanvas()->drawPath(path, whitePaint);
+ SkPixmap pixmap;
+ surface->getCanvas()->peekPixels(&pixmap);
+ static constexpr uint8_t kZeros[kRes] = {0};
+ for (int y = 0; y < kRes; ++y) {
+ const uint8_t* row = pixmap.addr8(0, y);
+ if (0 != memcmp(kZeros, row, kRes)) {
+ return false;
+ }
+ }
+ return true;
+}
class TestCase {
public:
@@ -65,6 +94,20 @@ public:
const Key& appliedPathEffectThenStrokeKey() const { return fAppliedPEThenStrokeKey; }
private:
+ static void CheckBounds(skiatest::Reporter* r, const GrShape& shape, const SkRect& bounds) {
+ SkPath path;
+ shape.asPath(&path);
+ // If the bounds are empty, the path ought to be as well.
+ if (bounds.isEmpty()) {
+ REPORTER_ASSERT(r, path.isEmpty());
+ return;
+ }
+ if (path.isEmpty()) {
+ return;
+ }
+ REPORTER_ASSERT(r, test_bounds_by_rasterizing(path, bounds));
+ }
+
void init(skiatest::Reporter* r, SkScalar scale) {
fAppliedPE = fBase.applyStyle(GrStyle::Apply::kPathEffectOnly, scale);
fAppliedPEThenStroke = fAppliedPE.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec,
@@ -93,6 +136,16 @@ private:
fAppliedFull.asPath(&path);
REPORTER_ASSERT(r, path.isEmpty() == fAppliedFull.isEmpty());
+ CheckBounds(r, fBase, fBase.bounds());
+ CheckBounds(r, fAppliedPE, fAppliedPE.bounds());
+ CheckBounds(r, fAppliedPEThenStroke, fAppliedPEThenStroke.bounds());
+ CheckBounds(r, fAppliedFull, fAppliedFull.bounds());
+ SkRect styledBounds;
+ fBase.styledBounds(&styledBounds);
+ CheckBounds(r, fAppliedFull, styledBounds);
+ fAppliedPE.styledBounds(&styledBounds);
+ CheckBounds(r, fAppliedFull, styledBounds);
+
// Check that the same path is produced when style is applied by GrShape and GrStyle.
SkPath preStyle;
SkPath postPathEffect;
« src/gpu/GrStyle.h ('K') | « src/gpu/GrStyle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698