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

Side by Side Diff: gm/bigrrectaaeffect.cpp

Issue 1930623003: Clean up test drawContext usage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix typo 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 unified diff | Download patch
« no previous file with comments | « gm/beziereffects.cpp ('k') | gm/constcolorprocessor.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 "gm.h" 8 #include "gm.h"
9 #if SK_SUPPORT_GPU 9 #if SK_SUPPORT_GPU
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 protected: 42 protected:
43 SkString onShortName() override { 43 SkString onShortName() override {
44 SkString name; 44 SkString name;
45 name.printf("big_rrect_%s_aa_effect", fName); 45 name.printf("big_rrect_%s_aa_effect", fName);
46 return name; 46 return name;
47 } 47 }
48 48
49 SkISize onISize() override { return SkISize::Make(fWidth, fHeight); } 49 SkISize onISize() override { return SkISize::Make(fWidth, fHeight); }
50 50
51 void onDraw(SkCanvas* canvas) override { 51 void onDraw(SkCanvas* canvas) override {
52 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget (); 52 GrDrawContext* drawContext = canvas->internal_private_accessTopLayerDraw Context();
53 GrContext* context = rt ? rt->getContext() : nullptr; 53 if (!drawContext) {
54 if (!context) {
55 skiagm::GM::DrawGpuOnlyMessage(canvas); 54 skiagm::GM::DrawGpuOnlyMessage(canvas);
56 return; 55 return;
57 } 56 }
58 57
59 sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
60 if (!drawContext) {
61 return;
62 }
63
64 SkPaint paint; 58 SkPaint paint;
65 59
66 int y = kPad; 60 int y = kPad;
67 int x = kPad; 61 int x = kPad;
68 static const GrPrimitiveEdgeType kEdgeTypes[] = { 62 static const GrPrimitiveEdgeType kEdgeTypes[] = {
69 kFillAA_GrProcessorEdgeType, 63 kFillAA_GrProcessorEdgeType,
70 kInverseFillAA_GrProcessorEdgeType, 64 kInverseFillAA_GrProcessorEdgeType,
71 }; 65 };
72 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight); 66 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight);
73 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) { 67 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) {
74 GrPrimitiveEdgeType edgeType = kEdgeTypes[et]; 68 GrPrimitiveEdgeType edgeType = kEdgeTypes[et];
75 canvas->save(); 69 canvas->save();
76 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 70 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
77 71
78 // Draw a background for the test case 72 // Draw a background for the test case
79 SkPaint paint; 73 SkPaint paint;
80 paint.setColor(SK_ColorWHITE); 74 paint.setColor(SK_ColorWHITE);
81 canvas->drawRect(testBounds, paint); 75 canvas->drawRect(testBounds, paint);
82 76
83 GrPipelineBuilder pipelineBuilder; 77 GrPipelineBuilder pipelineBuilder;
84 pipelineBuilder.setXPFactory( 78 pipelineBuilder.setXPFactory(
85 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref (); 79 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref ();
86 80
87 SkRRect rrect = fRRect; 81 SkRRect rrect = fRRect;
88 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap)); 82 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap));
89 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeT ype, rrect)); 83 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeT ype, rrect));
90 SkASSERT(fp); 84 SkASSERT(fp);
91 if (fp) { 85 if (fp) {
92 pipelineBuilder.addCoverageFragmentProcessor(fp); 86 pipelineBuilder.addCoverageFragmentProcessor(fp);
93 pipelineBuilder.setRenderTarget(rt); 87 pipelineBuilder.setRenderTarget(drawContext->accessRenderTar get());
94 88
95 SkRect bounds = testBounds; 89 SkRect bounds = testBounds;
96 bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); 90 bounds.offset(SkIntToScalar(x), SkIntToScalar(y));
97 91
98 SkAutoTUnref<GrDrawBatch> batch( 92 SkAutoTUnref<GrDrawBatch> batch(
99 GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMa trix::I(), bounds, 93 GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMa trix::I(), bounds,
100 nullptr, nullptr )); 94 nullptr, nullptr ));
101 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch); 95 drawContext->drawContextPriv().testingOnly_drawBatch(pipelin eBuilder, batch);
102 } 96 }
103 canvas->restore(); 97 canvas->restore();
(...skipping 25 matching lines...) Expand all
129 123
130 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeIWH(kSize, kSize)), "rect"); ) 124 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeIWH(kSize, kSize)), "rect"); )
131 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize, kSize)), "circle"); ) 125 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize, kSize)), "circle"); )
132 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize - 1, kSize - 10)), "ellipse"); ) 126 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize - 1, kSize - 10)), "ellipse"); )
133 // The next two have small linear segments between the corners 127 // The next two have small linear segments between the corners
134 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 10.f), "circular_corner"); ) 128 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 10.f), "circular_corner"); )
135 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 15.f), "elliptical_corner"); ) 129 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize - 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 15.f), "elliptical_corner"); )
136 130
137 } 131 }
138 #endif 132 #endif
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | gm/constcolorprocessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698