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

Side by Side Diff: src/gpu/GrDrawContext.cpp

Issue 1733993003: Mv DRRect drawing code from GrDrawContext into SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bug Created 4 years, 10 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/gpu/GrDrawContext.h ('k') | src/gpu/SkGpuDevice.h » ('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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrBatchTest.h" 9 #include "GrBatchTest.h"
10 #include "GrColor.h" 10 #include "GrColor.h"
11 #include "GrDrawContext.h" 11 #include "GrDrawContext.h"
12 #include "GrDrawingManager.h" 12 #include "GrDrawingManager.h"
13 #include "GrOvalRenderer.h" 13 #include "GrOvalRenderer.h"
14 #include "GrPathRenderer.h" 14 #include "GrPathRenderer.h"
15 #include "GrRenderTarget.h" 15 #include "GrRenderTarget.h"
16 #include "GrRenderTargetPriv.h" 16 #include "GrRenderTargetPriv.h"
17 #include "GrResourceProvider.h" 17 #include "GrResourceProvider.h"
18 #include "SkSurfacePriv.h" 18 #include "SkSurfacePriv.h"
19 19
20 #include "batches/GrBatch.h" 20 #include "batches/GrBatch.h"
21 #include "batches/GrDrawAtlasBatch.h" 21 #include "batches/GrDrawAtlasBatch.h"
22 #include "batches/GrDrawVerticesBatch.h" 22 #include "batches/GrDrawVerticesBatch.h"
23 #include "batches/GrRectBatchFactory.h" 23 #include "batches/GrRectBatchFactory.h"
24 #include "batches/GrNinePatch.h" // TODO Factory 24 #include "batches/GrNinePatch.h" // TODO Factory
25 25
26 #include "effects/GrRRectEffect.h"
27
28 #include "text/GrAtlasTextContext.h" 26 #include "text/GrAtlasTextContext.h"
29 #include "text/GrStencilAndCoverTextContext.h" 27 #include "text/GrStencilAndCoverTextContext.h"
30 28
31 #include "../private/GrAuditTrail.h" 29 #include "../private/GrAuditTrail.h"
32 30
33 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM anager->getContext()) 31 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM anager->getContext())
34 #define ASSERT_SINGLE_OWNER \ 32 #define ASSERT_SINGLE_OWNER \
35 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) 33 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
36 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } 34 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
37 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fa lse; } 35 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fa lse; }
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 SkPath path; 508 SkPath path;
511 path.setIsVolatile(true); 509 path.setIsVolatile(true);
512 path.addRRect(rrect); 510 path.addRRect(rrect);
513 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, 511 this->internalDrawPath(&pipelineBuilder, viewMatrix, color,
514 paint.isAntiAlias(), path, strokeInfo); 512 paint.isAntiAlias(), path, strokeInfo);
515 } 513 }
516 } 514 }
517 515
518 /////////////////////////////////////////////////////////////////////////////// 516 ///////////////////////////////////////////////////////////////////////////////
519 517
520 static bool draw_drrect(GrDrawTarget* drawTarget,
521 const GrPipelineBuilder& pipelineBuilder,
522 GrColor color,
523 const SkMatrix& viewMatrix,
524 bool useAA,
525 const SkRRect& origOuter,
526 const SkRRect& origInner,
527 GrShaderCaps* shaderCaps) {
528 bool applyAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedMultisa mpled();
529 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps;
530 if (!origInner.isEmpty()) {
531 SkTCopyOnFirstWrite<SkRRect> inner(origInner);
532 if (!viewMatrix.isIdentity()) {
533 if (!origInner.transform(viewMatrix, inner.writable())) {
534 return false;
535 }
536 }
537 GrPrimitiveEdgeType edgeType = applyAA ?
538 kInverseFillAA_GrProcessorEdgeType :
539 kInverseFillBW_GrProcessorEdgeType;
540 // TODO this needs to be a geometry processor
541 GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner);
542 if (nullptr == fp) {
543 return false;
544 }
545 arfps.set(&pipelineBuilder);
546 arfps.addCoverageFragmentProcessor(fp)->unref();
547 }
548
549 SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle);
550 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(pipelineBui lder, color,
551 viewMatrix, useAA, origOuter,
552 fillRec, sh aderCaps));
553 if (batch) {
554 drawTarget->drawBatch(pipelineBuilder, batch);
555 return true;
556 }
557
558 SkASSERT(!origOuter.isEmpty());
559 SkTCopyOnFirstWrite<SkRRect> outer(origOuter);
560 if (!viewMatrix.isIdentity()) {
561 if (!origOuter.transform(viewMatrix, outer.writable())) {
562 return false;
563 }
564 }
565 GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType :
566 kFillBW_GrProcessorEdgeType;
567 SkAutoTUnref<GrFragmentProcessor> effect(GrRRectEffect::Create(edgeType, *ou ter));
568 if (!effect) {
569 return false;
570 }
571 if (!arfps.isSet()) {
572 arfps.set(&pipelineBuilder);
573 }
574
575 SkMatrix invert;
576 if (!viewMatrix.invert(&invert)) {
577 return false;
578 }
579
580 arfps.addCoverageFragmentProcessor(effect);
581 SkRect bounds = outer->getBounds();
582 if (applyAA) {
583 bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
584 }
585 batch.reset(GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), bounds ,
586 nullptr, &invert));
587 drawTarget->drawBatch(pipelineBuilder, batch);
588 return true;
589 }
590
591 void GrDrawContext::drawDRRect(const GrClip& clip,
592 const GrPaint& paint,
593 const SkMatrix& viewMatrix,
594 const SkRRect& outer,
595 const SkRRect& inner) {
596 ASSERT_SINGLE_OWNER
597 RETURN_IF_ABANDONED
598 SkDEBUGCODE(this->validate();)
599 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect");
600
601 if (outer.isEmpty()) {
602 return;
603 }
604
605 AutoCheckFlush acf(fDrawingManager);
606
607 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
608 GrColor color = paint.getColor();
609
610 if (!draw_drrect(this->getDrawTarget(), pipelineBuilder,
611 color, viewMatrix, paint.isAntiAlias(),
612 outer, inner, fContext->caps()->shaderCaps())) {
613 SkPath path;
614 path.setIsVolatile(true);
615 path.addRRect(inner);
616 path.addRRect(outer);
617 path.setFillType(SkPath::kEvenOdd_FillType);
618
619 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
620 this->internalDrawPath(&pipelineBuilder, viewMatrix, color,
621 paint.isAntiAlias(), path, fillRec);
622 }
623 }
624
625 ///////////////////////////////////////////////////////////////////////////////
626
627 void GrDrawContext::drawOval(const GrClip& clip, 518 void GrDrawContext::drawOval(const GrClip& clip,
628 const GrPaint& paint, 519 const GrPaint& paint,
629 const SkMatrix& viewMatrix, 520 const SkMatrix& viewMatrix,
630 const SkRect& oval, 521 const SkRect& oval,
631 const GrStrokeInfo& strokeInfo) { 522 const GrStrokeInfo& strokeInfo) {
632 ASSERT_SINGLE_OWNER 523 ASSERT_SINGLE_OWNER
633 RETURN_IF_ABANDONED 524 RETURN_IF_ABANDONED
634 SkDEBUGCODE(this->validate();) 525 SkDEBUGCODE(this->validate();)
635 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); 526 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval");
636 527
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 } 819 }
929 820
930 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { 821 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) {
931 ASSERT_SINGLE_OWNER 822 ASSERT_SINGLE_OWNER
932 RETURN_IF_ABANDONED 823 RETURN_IF_ABANDONED
933 SkDEBUGCODE(this->validate();) 824 SkDEBUGCODE(this->validate();)
934 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); 825 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch");
935 826
936 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); 827 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch);
937 } 828 }
OLDNEW
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698