| OLD | NEW |
| 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 "GrTest.h" | 10 #include "GrContext.h" |
| 11 #include "effects/GrRRectEffect.h" | 11 #include "GrDrawContext.h" |
| 12 #include "GrPipelineBuilder.h" |
| 12 #include "SkDevice.h" | 13 #include "SkDevice.h" |
| 13 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "batches/GrDrawBatch.h" |
| 16 #include "batches/GrRectBatchFactory.h" |
| 17 #include "effects/GrRRectEffect.h" |
| 14 | 18 |
| 15 namespace skiagm { | 19 namespace skiagm { |
| 16 | 20 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 18 | 22 |
| 19 class BigRRectAAEffectGM : public GM { | 23 class BigRRectAAEffectGM : public GM { |
| 20 public: | 24 public: |
| 21 BigRRectAAEffectGM(const SkRRect& rrect, const char* name) | 25 BigRRectAAEffectGM(const SkRRect& rrect, const char* name) |
| 22 : fRRect(rrect) | 26 : fRRect(rrect) |
| 23 , fName(name) { | 27 , fName(name) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 46 SkISize onISize() override { return SkISize::Make(fWidth, fHeight); } | 50 SkISize onISize() override { return SkISize::Make(fWidth, fHeight); } |
| 47 | 51 |
| 48 void onDraw(SkCanvas* canvas) override { | 52 void onDraw(SkCanvas* canvas) override { |
| 49 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); | 53 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); |
| 50 GrContext* context = rt ? rt->getContext() : nullptr; | 54 GrContext* context = rt ? rt->getContext() : nullptr; |
| 51 if (!context) { | 55 if (!context) { |
| 52 skiagm::GM::DrawGpuOnlyMessage(canvas); | 56 skiagm::GM::DrawGpuOnlyMessage(canvas); |
| 53 return; | 57 return; |
| 54 } | 58 } |
| 55 | 59 |
| 60 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); |
| 61 if (!drawContext) { |
| 62 return; |
| 63 } |
| 64 |
| 56 SkPaint paint; | 65 SkPaint paint; |
| 57 | 66 |
| 58 int y = kPad; | 67 int y = kPad; |
| 59 int x = kPad; | 68 int x = kPad; |
| 60 static const GrPrimitiveEdgeType kEdgeTypes[] = { | 69 static const GrPrimitiveEdgeType kEdgeTypes[] = { |
| 61 kFillAA_GrProcessorEdgeType, | 70 kFillAA_GrProcessorEdgeType, |
| 62 kInverseFillAA_GrProcessorEdgeType, | 71 kInverseFillAA_GrProcessorEdgeType, |
| 63 }; | 72 }; |
| 64 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight); | 73 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight); |
| 65 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) { | 74 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) { |
| 66 GrPrimitiveEdgeType edgeType = kEdgeTypes[et]; | 75 GrPrimitiveEdgeType edgeType = kEdgeTypes[et]; |
| 67 canvas->save(); | 76 canvas->save(); |
| 68 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
| 77 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
| 69 | 78 |
| 70 // Draw a background for the test case | 79 // Draw a background for the test case |
| 71 SkPaint paint; | 80 SkPaint paint; |
| 72 paint.setColor(SK_ColorWHITE); | 81 paint.setColor(SK_ColorWHITE); |
| 73 canvas->drawRect(testBounds, paint); | 82 canvas->drawRect(testBounds, paint); |
| 74 | 83 |
| 75 GrTestTarget tt; | |
| 76 context->getTestTarget(&tt, rt); | |
| 77 if (!tt.target()) { | |
| 78 SkDEBUGFAIL("Couldn't get Gr test target."); | |
| 79 return; | |
| 80 } | |
| 81 GrPipelineBuilder pipelineBuilder; | 84 GrPipelineBuilder pipelineBuilder; |
| 82 pipelineBuilder.setXPFactory( | 85 pipelineBuilder.setXPFactory( |
| 83 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref
(); | 86 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref
(); |
| 84 | 87 |
| 85 SkRRect rrect = fRRect; | 88 SkRRect rrect = fRRect; |
| 86 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap)); | 89 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap)); |
| 87 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeT
ype, rrect)); | 90 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeT
ype, rrect)); |
| 88 SkASSERT(fp); | 91 SkASSERT(fp); |
| 89 if (fp) { | 92 if (fp) { |
| 90 pipelineBuilder.addCoverageFragmentProcessor(fp); | 93 pipelineBuilder.addCoverageFragmentProcessor(fp); |
| 91 pipelineBuilder.setRenderTarget(rt); | 94 pipelineBuilder.setRenderTarget(rt); |
| 92 | 95 |
| 93 SkRect bounds = testBounds; | 96 SkRect bounds = testBounds; |
| 94 bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); | 97 bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); |
| 95 | 98 |
| 96 tt.target()->drawNonAARect(pipelineBuilder, | 99 SkAutoTUnref<GrDrawBatch> batch( |
| 97 0xff000000, | 100 GrRectBatchFactory::CreateNonAAFill(0xff000000, SkMa
trix::I(), bounds, |
| 98 SkMatrix::I(), | 101 nullptr, nullptr
)); |
| 99 bounds); | 102 drawContext->internal_drawBatch(pipelineBuilder, batch); |
| 100 } | 103 } |
| 101 canvas->restore(); | 104 canvas->restore(); |
| 102 x = x + fTestOffsetX; | 105 x = x + fTestOffsetX; |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 | 108 |
| 106 private: | 109 private: |
| 107 // pad between test cases | 110 // pad between test cases |
| 108 static const int kPad = 7; | 111 static const int kPad = 7; |
| 109 // gap between rect for each case that is rendered and exterior of rrect | 112 // gap between rect for each case that is rendered and exterior of rrect |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 | 130 |
| 128 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeIWH(kSize,
kSize)), "rect"); ) | 131 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeIWH(kSize,
kSize)), "rect"); ) |
| 129 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize,
kSize)), "circle"); ) | 132 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize,
kSize)), "circle"); ) |
| 130 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize -
1, kSize - 10)), "ellipse"); ) | 133 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize -
1, kSize - 10)), "ellipse"); ) |
| 131 // The next two have small linear segments between the corners | 134 // The next two have small linear segments between the corners |
| 132 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 - 10.f), "circular_corner"); ) |
| 133 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 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"); ) |
| 134 | 137 |
| 135 } | 138 } |
| 136 #endif | 139 #endif |
| OLD | NEW |