OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrTest.h" | 10 #include "GrContext.h" |
| 11 #include "GrDrawContext.h" |
| 12 #include "batches/GrDrawBatch.h" |
| 13 #include "batches/GrRectBatchFactory.h" |
11 #include "effects/GrRRectEffect.h" | 14 #include "effects/GrRRectEffect.h" |
12 #endif | 15 #endif |
13 #include "SkDevice.h" | 16 #include "SkDevice.h" |
14 #include "SkRRect.h" | 17 #include "SkRRect.h" |
15 | 18 |
16 namespace skiagm { | 19 namespace skiagm { |
17 | 20 |
18 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
19 | 22 |
20 class RRectGM : public GM { | 23 class RRectGM : public GM { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return name; | 60 return name; |
58 } | 61 } |
59 | 62 |
60 SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight)
; } | 63 SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight)
; } |
61 | 64 |
62 void onDraw(SkCanvas* canvas) override { | 65 void onDraw(SkCanvas* canvas) override { |
63 GrContext* context = nullptr; | 66 GrContext* context = nullptr; |
64 #if SK_SUPPORT_GPU | 67 #if SK_SUPPORT_GPU |
65 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); | 68 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); |
66 context = rt ? rt->getContext() : nullptr; | 69 context = rt ? rt->getContext() : nullptr; |
| 70 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); |
| 71 if (!drawContext) { |
| 72 return; |
| 73 } |
67 #endif | 74 #endif |
68 if (kEffect_Type == fType && nullptr == context) { | 75 if (kEffect_Type == fType && nullptr == context) { |
69 skiagm::GM::DrawGpuOnlyMessage(canvas); | 76 skiagm::GM::DrawGpuOnlyMessage(canvas); |
70 return; | 77 return; |
71 } | 78 } |
72 | 79 |
73 SkPaint paint; | 80 SkPaint paint; |
74 if (kAA_Draw_Type == fType) { | 81 if (kAA_Draw_Type == fType) { |
75 paint.setAntiAlias(true); | 82 paint.setAntiAlias(true); |
76 } | 83 } |
(...skipping 19 matching lines...) Expand all Loading... |
96 #ifdef SK_DEBUG | 103 #ifdef SK_DEBUG |
97 SkASSERT(kMaxTileBound.contains(fRRects[curRRect].getBounds())); | 104 SkASSERT(kMaxTileBound.contains(fRRects[curRRect].getBounds())); |
98 SkRect imageSpaceBounds = fRRects[curRRect].getBounds(); | 105 SkRect imageSpaceBounds = fRRects[curRRect].getBounds(); |
99 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y)); | 106 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y)); |
100 SkASSERT(kMaxImageBound.contains(imageSpaceBounds)); | 107 SkASSERT(kMaxImageBound.contains(imageSpaceBounds)); |
101 #endif | 108 #endif |
102 canvas->save(); | 109 canvas->save(); |
103 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 110 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
104 if (kEffect_Type == fType) { | 111 if (kEffect_Type == fType) { |
105 #if SK_SUPPORT_GPU | 112 #if SK_SUPPORT_GPU |
106 GrTestTarget tt; | |
107 context->getTestTarget(&tt, rt); | |
108 if (nullptr == tt.target()) { | |
109 SkDEBUGFAIL("Couldn't get Gr test target."); | |
110 return; | |
111 } | |
112 GrPipelineBuilder pipelineBuilder; | 113 GrPipelineBuilder pipelineBuilder; |
113 pipelineBuilder.setXPFactory( | 114 pipelineBuilder.setXPFactory( |
114 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)
)->unref(); | 115 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)
)->unref(); |
115 | 116 |
116 SkRRect rrect = fRRects[curRRect]; | 117 SkRRect rrect = fRRects[curRRect]; |
117 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); | 118 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); |
118 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; | 119 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; |
119 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Crea
te(edgeType, | 120 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Crea
te(edgeType, |
120
rrect)); | 121
rrect)); |
121 if (fp) { | 122 if (fp) { |
122 pipelineBuilder.addCoverageFragmentProcessor(fp); | 123 pipelineBuilder.addCoverageFragmentProcessor(fp); |
123 pipelineBuilder.setRenderTarget(rt); | 124 pipelineBuilder.setRenderTarget(rt); |
124 | 125 |
125 SkRect bounds = rrect.getBounds(); | 126 SkRect bounds = rrect.getBounds(); |
126 bounds.outset(2.f, 2.f); | 127 bounds.outset(2.f, 2.f); |
127 | 128 |
128 tt.target()->drawNonAARect(pipelineBuilder, | 129 SkAutoTUnref<GrDrawBatch> batch( |
129 0xff000000, | 130 GrRectBatchFactory::CreateNonAAFill(0xff0000
00, SkMatrix::I(), |
130 SkMatrix::I(), | 131 bounds,
nullptr, nullptr)); |
131 bounds); | 132 drawContext->internal_drawBatch(pipelineBuilder, bat
ch); |
132 } else { | 133 } else { |
133 drew = false; | 134 drew = false; |
134 } | 135 } |
135 #endif | 136 #endif |
136 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ | 137 } else if (kBW_Clip_Type == fType || kAA_Clip_Type == fType)
{ |
137 bool aaClip = (kAA_Clip_Type == fType); | 138 bool aaClip = (kAA_Clip_Type == fType); |
138 canvas->clipRRect(fRRects[curRRect], SkRegion::kReplace_
Op, aaClip); | 139 canvas->clipRRect(fRRects[curRRect], SkRegion::kReplace_
Op, aaClip); |
139 canvas->drawRect(kMaxTileBound, paint); | 140 canvas->drawRect(kMaxTileBound, paint); |
140 } else { | 141 } else { |
141 canvas->drawRRect(fRRects[curRRect], paint); | 142 canvas->drawRRect(fRRects[curRRect], paint); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 263 |
263 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) | 264 DEF_GM( return new RRectGM(RRectGM::kAA_Draw_Type); ) |
264 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) | 265 DEF_GM( return new RRectGM(RRectGM::kBW_Draw_Type); ) |
265 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) | 266 DEF_GM( return new RRectGM(RRectGM::kAA_Clip_Type); ) |
266 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) | 267 DEF_GM( return new RRectGM(RRectGM::kBW_Clip_Type); ) |
267 #if SK_SUPPORT_GPU | 268 #if SK_SUPPORT_GPU |
268 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) | 269 DEF_GM( return new RRectGM(RRectGM::kEffect_Type); ) |
269 #endif | 270 #endif |
270 | 271 |
271 } | 272 } |
OLD | NEW |