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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatchTest.h" 8 #include "GrBatchTest.h"
9 #include "GrColor.h" 9 #include "GrColor.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 RETURN_IF_ABANDONED 304 RETURN_IF_ABANDONED
305 SkDEBUGCODE(this->validate();) 305 SkDEBUGCODE(this->validate();)
306 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); 306 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect");
307 307
308 // Path effects should've been devolved to a path in SkGpuDevice 308 // Path effects should've been devolved to a path in SkGpuDevice
309 SkASSERT(!style->pathEffect()); 309 SkASSERT(!style->pathEffect());
310 310
311 AutoCheckFlush acf(fDrawingManager); 311 AutoCheckFlush acf(fDrawingManager);
312 312
313 const SkStrokeRec& stroke = style->strokeRec(); 313 const SkStrokeRec& stroke = style->strokeRec();
314 SkScalar width = stroke.getWidth(); 314 bool useHWAA;
315 315 bool snapToPixelCenters = false;
316 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking 316 SkAutoTUnref<GrDrawBatch> batch;
317 // cases where the RT is fully inside a stroke. 317 if (stroke.getStyle() == SkStrokeRec::kFill_Style) {
318 if (width < 0) { 318 // Check if this is a full RT draw and can be replaced with a clear. We don't bother
319 // checking cases where the RT is fully inside a stroke.
319 SkRect rtRect; 320 SkRect rtRect;
320 fRenderTarget->getBoundsRect(&rtRect); 321 fRenderTarget->getBoundsRect(&rtRect);
321 // Does the clip contain the entire RT? 322 // Does the clip contain the entire RT?
322 if (clip.quickContains(rtRect)) { 323 if (clip.quickContains(rtRect)) {
323 SkMatrix invM; 324 SkMatrix invM;
324 if (!viewMatrix.invert(&invM)) { 325 if (!viewMatrix.invert(&invM)) {
325 return; 326 return;
326 } 327 }
327 // Does the rect bound the RT? 328 // Does the rect bound the RT?
328 SkPoint srcSpaceRTQuad[4]; 329 SkPoint srcSpaceRTQuad[4];
329 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); 330 invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
330 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && 331 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
331 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && 332 rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
332 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && 333 rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
333 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { 334 rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
334 // Will it blend? 335 // Will it blend?
335 GrColor clearColor; 336 GrColor clearColor;
336 if (paint.isConstantBlendedColor(&clearColor)) { 337 if (paint.isConstantBlendedColor(&clearColor)) {
337 this->getDrawTarget()->clear(nullptr, clearColor, true, this ); 338 this->getDrawTarget()->clear(nullptr, clearColor, true, this );
338 return; 339 return;
339 } 340 }
340 } 341 }
341 } 342 }
342 }
343
344 bool useHWAA;
345 bool snapToPixelCenters = false;
346 SkAutoTUnref<GrDrawBatch> batch;
347 if (width < 0) {
348 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); 343 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA));
349 } else { 344 } else if (stroke.getStyle() == SkStrokeRec::kStroke_Style ||
345 stroke.getStyle() == SkStrokeRec::kHairline_Style) {
346 if ((!rect.width() || !rect.height()) &&
347 SkStrokeRec::kHairline_Style != stroke.getStyle()) {
348 SkScalar r = stroke.getWidth() / 2;
349 // TODO: Move these stroke->fill fallbacks to GrShape?
350 switch (stroke.getJoin()) {
351 case SkPaint::kMiter_Join:
352 this->drawRect(clip, paint, viewMatrix,
353 {rect.fLeft - r, rect.fTop - r,
354 rect.fRight + r, rect.fBottom + r},
355 &GrStyle::SimpleFill());
356 return;
357 case SkPaint::kRound_Join:
358 // Raster draws nothing when both dimensions are empty.
359 if (rect.width() || rect.height()){
360 SkRRect rrect = SkRRect::MakeRectXY(rect.makeOutset(r, r ), r, r);
361 this->drawRRect(clip, paint, viewMatrix, rrect, GrStyle: :SimpleFill());
362 return;
363 }
364 case SkPaint::kBevel_Join:
365 if (!rect.width()) {
366 this->drawRect(clip, paint, viewMatrix,
367 {rect.fLeft - r, rect.fTop, rect.fRight + r, rect.fBottom},
368 &GrStyle::SimpleFill());
369 } else {
370 this->drawRect(clip, paint, viewMatrix,
371 {rect.fLeft, rect.fTop - r, rect.fRight, rect.fBottom + r},
372 &GrStyle::SimpleFill());
373 }
374 return;
375 }
376 }
350 GrColor color = paint.getColor(); 377 GrColor color = paint.getColor();
351
352 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { 378 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) {
353 // The stroke path needs the rect to remain axis aligned (no rotatio n or skew). 379 // The stroke path needs the rect to remain axis aligned (no rotatio n or skew).
354 if (viewMatrix.rectStaysRect()) { 380 if (viewMatrix.rectStaysRect()) {
355 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix , rect, 381 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix , rect, stroke));
356 stroke));
357 } 382 }
358 } else { 383 } else {
359 // Non-AA hairlines are snapped to pixel centers to make which pixel s are hit
360 // deterministic
361 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa mpled());
362 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect,
363 width, snapToPixel Centers));
364
365 // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of 384 // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of
366 // hairline rects. We jam all the vertices to pixel centers to avoid this, but not 385 // hairline rects. We jam all the vertices to pixel centers to avoid this, but not
367 // when MSAA is enabled because it can cause ugly artifacts. 386 // when MSAA is enabled because it can cause ugly artifacts.
387 snapToPixelCenters = stroke.getStyle() == SkStrokeRec::kHairline_Sty le &&
388 !fRenderTarget->isUnifiedMultisampled();
389 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix, rect,
390 stroke, snapToPixe lCenters));
368 } 391 }
369 } 392 }
370 393
371 if (batch) { 394 if (batch) {
372 GrPipelineBuilder pipelineBuilder(paint, useHWAA); 395 GrPipelineBuilder pipelineBuilder(paint, useHWAA);
373 396
374 if (snapToPixelCenters) { 397 if (snapToPixelCenters) {
375 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag, 398 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent ers_Flag,
376 snapToPixelCenters); 399 snapToPixelCenters);
377 } 400 }
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1052
1030 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip, 1053 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr Clip& clip,
1031 GrDrawBatch* batch) { 1054 GrDrawBatch* batch) {
1032 ASSERT_SINGLE_OWNER 1055 ASSERT_SINGLE_OWNER
1033 RETURN_IF_ABANDONED 1056 RETURN_IF_ABANDONED
1034 SkDEBUGCODE(this->validate();) 1057 SkDEBUGCODE(this->validate();)
1035 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 1058 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
1036 1059
1037 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); 1060 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch);
1038 } 1061 }
OLDNEW
« 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