| OLD | NEW |
| 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 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. |
| 10 | 10 |
| 11 #include "gm.h" | 11 #include "gm.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 | 14 |
| 15 #include "GrContext.h" | 15 #include "GrContext.h" |
| 16 #include "GrTest.h" | 16 #include "GrDrawContext.h" |
| 17 #include "effects/GrConstColorProcessor.h" | 17 #include "GrPipelineBuilder.h" |
| 18 #include "SkGrPriv.h" | 18 #include "SkGrPriv.h" |
| 19 #include "SkGradientShader.h" | 19 #include "SkGradientShader.h" |
| 20 #include "batches/GrDrawBatch.h" |
| 21 #include "batches/GrRectBatchFactory.h" |
| 22 #include "effects/GrConstColorProcessor.h" |
| 20 | 23 |
| 21 namespace skiagm { | 24 namespace skiagm { |
| 22 /** | 25 /** |
| 23 * This GM directly exercises GrConstColorProcessor. | 26 * This GM directly exercises GrConstColorProcessor. |
| 24 */ | 27 */ |
| 25 class ConstColorProcessor : public GM { | 28 class ConstColorProcessor : public GM { |
| 26 public: | 29 public: |
| 27 ConstColorProcessor() { | 30 ConstColorProcessor() { |
| 28 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 31 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
| 29 } | 32 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); | 51 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); |
| 49 if (nullptr == rt) { | 52 if (nullptr == rt) { |
| 50 return; | 53 return; |
| 51 } | 54 } |
| 52 GrContext* context = rt->getContext(); | 55 GrContext* context = rt->getContext(); |
| 53 if (nullptr == context) { | 56 if (nullptr == context) { |
| 54 skiagm::GM::DrawGpuOnlyMessage(canvas); | 57 skiagm::GM::DrawGpuOnlyMessage(canvas); |
| 55 return; | 58 return; |
| 56 } | 59 } |
| 57 | 60 |
| 61 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); |
| 62 if (!drawContext) { |
| 63 return; |
| 64 } |
| 65 |
| 58 static const GrColor kColors[] = { | 66 static const GrColor kColors[] = { |
| 59 0xFFFFFFFF, | 67 0xFFFFFFFF, |
| 60 0xFFFF00FF, | 68 0xFFFF00FF, |
| 61 0x80000000, | 69 0x80000000, |
| 62 0x00000000, | 70 0x00000000, |
| 63 }; | 71 }; |
| 64 | 72 |
| 65 static const SkColor kPaintColors[] = { | 73 static const SkColor kPaintColors[] = { |
| 66 0xFFFFFFFF, | 74 0xFFFFFFFF, |
| 67 0xFFFF0000, | 75 0xFFFF0000, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 for (size_t procColor = 0; procColor < SK_ARRAY_COUNT(kColors); ++pr
ocColor) { | 91 for (size_t procColor = 0; procColor < SK_ARRAY_COUNT(kColors); ++pr
ocColor) { |
| 84 for (int m = 0; m < GrConstColorProcessor::kInputModeCnt; ++m) { | 92 for (int m = 0; m < GrConstColorProcessor::kInputModeCnt; ++m) { |
| 85 // translate by x,y for the canvas draws and the test target
draws. | 93 // translate by x,y for the canvas draws and the test target
draws. |
| 86 canvas->save(); | 94 canvas->save(); |
| 87 canvas->translate(x, y); | 95 canvas->translate(x, y); |
| 88 const SkMatrix viewMatrix = SkMatrix::MakeTrans(x, y); | 96 const SkMatrix viewMatrix = SkMatrix::MakeTrans(x, y); |
| 89 | 97 |
| 90 // rect to draw | 98 // rect to draw |
| 91 SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectS
ize); | 99 SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectS
ize); |
| 92 | 100 |
| 93 GrTestTarget tt; | |
| 94 context->getTestTarget(&tt, rt); | |
| 95 if (nullptr == tt.target()) { | |
| 96 SkDEBUGFAIL("Couldn't get Gr test target."); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 GrPaint grPaint; | 101 GrPaint grPaint; |
| 101 SkPaint skPaint; | 102 SkPaint skPaint; |
| 102 if (paintType >= SK_ARRAY_COUNT(kPaintColors)) { | 103 if (paintType >= SK_ARRAY_COUNT(kPaintColors)) { |
| 103 skPaint.setShader(fShader); | 104 skPaint.setShader(fShader); |
| 104 } else { | 105 } else { |
| 105 skPaint.setColor(kPaintColors[paintType]); | 106 skPaint.setColor(kPaintColors[paintType]); |
| 106 } | 107 } |
| 107 SkAssertResult(SkPaintToGrPaint(context, skPaint, viewMatrix
, &grPaint)); | 108 SkAssertResult(SkPaintToGrPaint(context, skPaint, viewMatrix
, &grPaint)); |
| 108 | 109 |
| 109 GrConstColorProcessor::InputMode mode = (GrConstColorProcess
or::InputMode) m; | 110 GrConstColorProcessor::InputMode mode = (GrConstColorProcess
or::InputMode) m; |
| 110 GrColor color = kColors[procColor]; | 111 GrColor color = kColors[procColor]; |
| 111 SkAutoTUnref<GrFragmentProcessor> fp(GrConstColorProcessor::
Create(color, mode)); | 112 SkAutoTUnref<GrFragmentProcessor> fp(GrConstColorProcessor::
Create(color, mode)); |
| 112 | 113 |
| 113 GrClip clip; | 114 GrClip clip; |
| 114 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); | 115 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); |
| 115 pipelineBuilder.addColorFragmentProcessor(fp); | 116 pipelineBuilder.addColorFragmentProcessor(fp); |
| 116 | 117 |
| 117 tt.target()->drawNonAARect(pipelineBuilder, | 118 SkAutoTUnref<GrDrawBatch> batch( |
| 118 grPaint.getColor(), | 119 GrRectBatchFactory::CreateNonAAFill(grPaint.getColor
(), viewMatrix, |
| 119 viewMatrix, | 120 renderRect, null
ptr, nullptr)); |
| 120 renderRect); | 121 drawContext->internal_drawBatch(pipelineBuilder, batch); |
| 121 | 122 |
| 122 // Draw labels for the input to the processor and the proces
sor to the right of | 123 // Draw labels for the input to the processor and the proces
sor to the right of |
| 123 // the test rect. The input label appears above the processo
r label. | 124 // the test rect. The input label appears above the processo
r label. |
| 124 SkPaint labelPaint; | 125 SkPaint labelPaint; |
| 125 sk_tool_utils::set_portable_typeface(&labelPaint); | 126 sk_tool_utils::set_portable_typeface(&labelPaint); |
| 126 labelPaint.setAntiAlias(true); | 127 labelPaint.setAntiAlias(true); |
| 127 labelPaint.setTextSize(10.f); | 128 labelPaint.setTextSize(10.f); |
| 128 SkString inputLabel; | 129 SkString inputLabel; |
| 129 inputLabel.set("Input: "); | 130 inputLabel.set("Input: "); |
| 130 if (paintType >= SK_ARRAY_COUNT(kPaintColors)) { | 131 if (paintType >= SK_ARRAY_COUNT(kPaintColors)) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 typedef GM INHERITED; | 189 typedef GM INHERITED; |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 const SkScalar ConstColorProcessor::kPad = 10.f; | 192 const SkScalar ConstColorProcessor::kPad = 10.f; |
| 192 const SkScalar ConstColorProcessor::kRectSize = 20.f; | 193 const SkScalar ConstColorProcessor::kRectSize = 20.f; |
| 193 | 194 |
| 194 DEF_GM(return new ConstColorProcessor;) | 195 DEF_GM(return new ConstColorProcessor;) |
| 195 } | 196 } |
| 196 | 197 |
| 197 #endif | 198 #endif |
| OLD | NEW |