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

Unified Diff: src/gpu/batches/GrNonAAStrokeRectBatch.cpp

Issue 2125663003: Add gm that tests shaded stroked rectangles. (Closed) Base URL: https://skia.googlesource.com/skia.git@fixgmwidth
Patch Set: fix windows double->scalar warning Created 4 years, 5 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
« no previous file with comments | « src/gpu/batches/GrNonAAStrokeRectBatch.h ('k') | src/gpu/batches/GrRectBatchFactory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrNonAAStrokeRectBatch.cpp
diff --git a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
index a38760c362ea14b8f04796bf07f9b5fe8c8972f2..fb906081d48a66b17bc7359e2807676a061e69fb 100644
--- a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
+++ b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp
@@ -211,29 +211,30 @@ private:
typedef GrVertexBatch INHERITED;
};
+// Allow all hairlines and all miters, so long as the miter limit doesn't produce beveled corners.
+inline static bool allowed_stroke(const SkStrokeRec& stroke) {
+ SkASSERT(stroke.getStyle() == SkStrokeRec::kStroke_Style ||
+ stroke.getStyle() == SkStrokeRec::kHairline_Style);
+ return !stroke.getWidth() ||
+ (stroke.getJoin() == SkPaint::kMiter_Join && stroke.getMiter() > SK_ScalarSqrt2);
+}
+
namespace GrNonAAStrokeRectBatch {
GrDrawBatch* Create(GrColor color,
const SkMatrix& viewMatrix,
const SkRect& rect,
- SkScalar strokeWidth,
+ const SkStrokeRec& stroke,
bool snapToPixelCenters) {
+ if (!allowed_stroke(stroke)) {
+ return nullptr;
+ }
NonAAStrokeRectBatch* batch = NonAAStrokeRectBatch::Create();
- batch->append(color, viewMatrix, rect, strokeWidth);
+ batch->append(color, viewMatrix, rect, stroke.getWidth());
batch->init(snapToPixelCenters);
return batch;
}
-void Append(GrBatch* origBatch,
- GrColor color,
- const SkMatrix& viewMatrix,
- const SkRect& rect,
- SkScalar strokeWidth,
- bool snapToPixelCenters) {
- NonAAStrokeRectBatch* batch = origBatch->cast<NonAAStrokeRectBatch>();
- batch->appendAndUpdateBounds(color, viewMatrix, rect, strokeWidth, snapToPixelCenters);
-}
-
};
#ifdef GR_TEST_UTILS
@@ -242,9 +243,13 @@ DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) {
SkMatrix viewMatrix = GrTest::TestMatrix(random);
GrColor color = GrRandomColor(random);
SkRect rect = GrTest::TestRect(random);
- SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f;
-
- return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool());
+ SkScalar strokeWidth = random->nextBool() ? 0.0f : 2.0f;
+ SkPaint paint;
+ paint.setStrokeWidth(strokeWidth);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeJoin(SkPaint::kMiter_Join);
+ SkStrokeRec strokeRec(paint);
+ return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeRec, random->nextBool());
}
#endif
« no previous file with comments | « src/gpu/batches/GrNonAAStrokeRectBatch.h ('k') | src/gpu/batches/GrRectBatchFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698