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

Unified Diff: src/gpu/GrDrawContext.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 | « include/core/SkPaint.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawContext.cpp
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index d057984f9c67b61e399cfc967437091aad4230f7..5474707191178bd7fda41fd19a91ac714574dc6e 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -311,11 +311,12 @@ void GrDrawContext::drawRect(const GrClip& clip,
AutoCheckFlush acf(fDrawingManager);
const SkStrokeRec& stroke = style->strokeRec();
- SkScalar width = stroke.getWidth();
-
- // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking
- // cases where the RT is fully inside a stroke.
- if (width < 0) {
+ bool useHWAA;
+ bool snapToPixelCenters = false;
+ SkAutoTUnref<GrDrawBatch> batch;
+ if (stroke.getStyle() == SkStrokeRec::kFill_Style) {
+ // Check if this is a full RT draw and can be replaced with a clear. We don't bother
+ // checking cases where the RT is fully inside a stroke.
SkRect rtRect;
fRenderTarget->getBoundsRect(&rtRect);
// Does the clip contain the entire RT?
@@ -339,32 +340,54 @@ void GrDrawContext::drawRect(const GrClip& clip,
}
}
}
- }
-
- bool useHWAA;
- bool snapToPixelCenters = false;
- SkAutoTUnref<GrDrawBatch> batch;
- if (width < 0) {
batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA));
- } else {
+ } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
+ stroke.getStyle() == SkStrokeRec::kHairline_Style) {
+ if ((!rect.width() || !rect.height()) &&
+ SkStrokeRec::kHairline_Style != stroke.getStyle()) {
+ SkScalar r = stroke.getWidth() / 2;
+ // TODO: Move these stroke->fill fallbacks to GrShape?
+ switch (stroke.getJoin()) {
+ case SkPaint::kMiter_Join:
+ this->drawRect(clip, paint, viewMatrix,
+ {rect.fLeft - r, rect.fTop - r,
+ rect.fRight + r, rect.fBottom + r},
+ &GrStyle::SimpleFill());
+ return;
+ case SkPaint::kRound_Join:
+ // Raster draws nothing when both dimensions are empty.
+ if (rect.width() || rect.height()){
+ SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r), r, r);
+ this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle::SimpleFill());
+ return;
+ }
+ case SkPaint::kBevel_Join:
+ if (!rect.width()) {
+ this->drawRect(clip, paint, viewMatrix,
+ {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom},
+ &GrStyle::SimpleFill());
+ } else {
+ this->drawRect(clip, paint, viewMatrix,
+ {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r},
+ &GrStyle::SimpleFill());
+ }
+ return;
+ }
+ }
GrColor color = paint.getColor();
-
if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
// The stroke path needs the rect to remain axis aligned (no rotation or skew).
if (viewMatrix.rectStaysRect()) {
- batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect,
- stroke));
+ batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, stroke));
}
} else {
- // Non-AA hairlines are snapped to pixel centers to make which pixels are hit
- // deterministic
- snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisampled());
- batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect,
- width, snapToPixelCenters));
-
// Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of
// hairline rects. We jam all the vertices to pixel centers to avoid this, but not
// when MSAA is enabled because it can cause ugly artifacts.
+ snapToPixelCenters = stroke.getStyle() == SkStrokeRec::kHairline_Style &&
+ !fRenderTarget->isUnifiedMultisampled();
+ batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect,
+ stroke, snapToPixelCenters));
}
}
« no previous file with comments | « include/core/SkPaint.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698