OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #include "SkPoint.h" | 9 #include "SkPoint.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 | 14 |
| 15 #include "GrRenderTargetContext.h" |
15 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
| 17 #include "GrPipelineBuilder.h" |
16 #include "gl/GrGLGpu.h" | 18 #include "gl/GrGLGpu.h" |
17 #include "gl/debug/DebugGLTestContext.h" | 19 #include "gl/debug/DebugGLTestContext.h" |
18 | 20 |
19 typedef std::vector<SkPoint> SamplePattern; | 21 typedef std::vector<SkPoint> SamplePattern; |
20 | 22 |
21 static const SamplePattern kTestPatterns[] = { | 23 static const SamplePattern kTestPatterns[] = { |
22 SamplePattern{ // Intel on mac, msaa8, offscreen. | 24 SamplePattern{ // Intel on mac, msaa8, offscreen. |
23 {0.562500, 0.312500}, | 25 {0.562500, 0.312500}, |
24 {0.437500, 0.687500}, | 26 {0.437500, 0.687500}, |
25 {0.812500, 0.562500}, | 27 {0.812500, 0.562500}, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 82 } |
81 }; | 83 }; |
82 constexpr int numTestPatterns = SK_ARRAY_COUNT(kTestPatterns); | 84 constexpr int numTestPatterns = SK_ARRAY_COUNT(kTestPatterns); |
83 | 85 |
84 class TestSampleLocationsInterface : public SkNoncopyable { | 86 class TestSampleLocationsInterface : public SkNoncopyable { |
85 public: | 87 public: |
86 virtual void overrideSamplePattern(const SamplePattern&) = 0; | 88 virtual void overrideSamplePattern(const SamplePattern&) = 0; |
87 virtual ~TestSampleLocationsInterface() {} | 89 virtual ~TestSampleLocationsInterface() {} |
88 }; | 90 }; |
89 | 91 |
90 GrRenderTarget* SK_WARN_UNUSED_RESULT create_render_target(GrContext* ctx, GrSur
faceOrigin origin, | 92 static GrPipeline* construct_dummy_pipeline(GrRenderTargetContext* dc, void* sto
rage) { |
91 int numSamples) { | 93 GrPipelineBuilder dummyBuilder; |
92 GrSurfaceDesc desc; | 94 GrScissorState dummyScissor; |
93 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 95 GrWindowRectsState dummyWindows; |
94 desc.fOrigin = origin; | 96 GrXPOverridesForBatch dummyOverrides; |
95 desc.fWidth = 100; | 97 |
96 desc.fHeight = 100; | 98 GrPipeline::CreateArgs args; |
97 desc.fConfig = kBGRA_8888_GrPixelConfig; | 99 args.fPipelineBuilder = &dummyBuilder; |
98 desc.fSampleCnt = numSamples; | 100 args.fRenderTargetContext = dc; |
99 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kNo, 0, 0)->a
sRenderTarget(); | 101 args.fCaps = dc->caps(); |
| 102 args.fOpts = GrPipelineOptimizations(); |
| 103 args.fScissor = &dummyScissor; |
| 104 args.fWindowRectsState = &dummyWindows; |
| 105 args.fHasStencilClip = false; |
| 106 args.fDstTexture = GrXferProcessor::DstTexture(); |
| 107 |
| 108 GrPipeline::CreateAt(storage, args, &dummyOverrides); |
| 109 return reinterpret_cast<GrPipeline*>(storage); |
100 } | 110 } |
101 | 111 |
102 void assert_equal(skiatest::Reporter* reporter, const SamplePattern& pattern, | 112 void assert_equal(skiatest::Reporter* reporter, const SamplePattern& pattern, |
103 const GrGpu::MultisampleSpecs& specs, bool flipY) { | 113 const GrGpu::MultisampleSpecs& specs, bool flipY) { |
104 GrAlwaysAssert(specs.fSampleLocations); | 114 GrAlwaysAssert(specs.fSampleLocations); |
105 if ((int)pattern.size() != specs.fEffectiveSampleCnt) { | 115 if ((int)pattern.size() != specs.fEffectiveSampleCnt) { |
106 REPORTER_ASSERT_MESSAGE(reporter, false, "Sample pattern has wrong numbe
r of samples."); | 116 REPORT_FAILURE(reporter, "", SkString("Sample pattern has wrong number o
f samples.")); |
107 return; | 117 return; |
108 } | 118 } |
109 for (int i = 0; i < specs.fEffectiveSampleCnt; ++i) { | 119 for (int i = 0; i < specs.fEffectiveSampleCnt; ++i) { |
110 SkPoint expectedLocation = specs.fSampleLocations[i]; | 120 SkPoint expectedLocation = specs.fSampleLocations[i]; |
111 if (flipY) { | 121 if (flipY) { |
112 expectedLocation.fY = 1 - expectedLocation.fY; | 122 expectedLocation.fY = 1 - expectedLocation.fY; |
113 } | 123 } |
114 if (pattern[i] != expectedLocation) { | 124 if (pattern[i] != expectedLocation) { |
115 REPORTER_ASSERT_MESSAGE(reporter, false, "Sample pattern has wrong s
ample location."); | 125 REPORT_FAILURE(reporter, "", SkString("Sample pattern has wrong samp
le location.")); |
116 return; | 126 return; |
117 } | 127 } |
118 } | 128 } |
119 } | 129 } |
120 | 130 |
121 void test_sampleLocations(skiatest::Reporter* reporter, TestSampleLocationsInter
face* testInterface, | 131 void test_sampleLocations(skiatest::Reporter* reporter, TestSampleLocationsInter
face* testInterface, |
122 GrContext* ctx) { | 132 GrContext* ctx) { |
123 SkRandom rand; | 133 SkRandom rand; |
124 SkAutoTUnref<GrRenderTarget> bottomUps[numTestPatterns]; | 134 sk_sp<GrRenderTargetContext> bottomUps[numTestPatterns]; |
125 SkAutoTUnref<GrRenderTarget> topDowns[numTestPatterns]; | 135 sk_sp<GrRenderTargetContext> topDowns[numTestPatterns]; |
126 for (int i = 0; i < numTestPatterns; ++i) { | 136 for (int i = 0; i < numTestPatterns; ++i) { |
127 int numSamples = (int)kTestPatterns[i].size(); | 137 int numSamples = (int)kTestPatterns[i].size(); |
128 GrAlwaysAssert(numSamples > 1 && SkIsPow2(numSamples)); | 138 GrAlwaysAssert(numSamples > 1 && SkIsPow2(numSamples)); |
129 bottomUps[i].reset(create_render_target(ctx, kBottomLeft_GrSurfaceOrigin
, | 139 bottomUps[i] = ctx->makeRenderTargetContextWithFallback( |
130 rand.nextRangeU(1 + numSamples /
2, numSamples))); | 140 SkBackingFit::kExact, 100, 100, kRGBA_8888_GrPixelCon
fig, nullptr, |
131 topDowns[i].reset(create_render_target(ctx, kTopLeft_GrSurfaceOrigin, | 141 rand.nextRangeU(1 + numSamples / 2, numSamples), |
132 rand.nextRangeU(1 + numSamples /
2, numSamples))); | 142 kBottomLeft_GrSurfaceOrigin); |
| 143 topDowns[i] = ctx->makeRenderTargetContextWithFallback( |
| 144 SkBackingFit::kExact, 100, 100, kRGBA_8888_GrPixelConf
ig, nullptr, |
| 145 rand.nextRangeU(1 + numSamples / 2, numSamples), |
| 146 kTopLeft_GrSurfaceOrigin); |
133 } | 147 } |
134 | 148 |
135 // Ensure all sample locations get queried and/or cached properly. | 149 // Ensure all sample locations get queried and/or cached properly. |
136 GrStencilSettings dummyStencil; | 150 SkAlignedSTStorage<1, GrPipeline> pipelineStorage; |
137 for (int repeat = 0; repeat < 2; ++repeat) { | 151 for (int repeat = 0; repeat < 2; ++repeat) { |
138 for (int i = 0; i < numTestPatterns; ++i) { | 152 for (int i = 0; i < numTestPatterns; ++i) { |
139 testInterface->overrideSamplePattern(kTestPatterns[i]); | 153 testInterface->overrideSamplePattern(kTestPatterns[i]); |
140 assert_equal(reporter, kTestPatterns[i], | 154 for (GrRenderTargetContext* dc : {bottomUps[i].get(), topDowns[i].ge
t()}) { |
141 topDowns[i]->renderTargetPriv().getMultisampleSpecs(dum
myStencil), false); | 155 GrPipeline* dummyPipe = construct_dummy_pipeline(dc, pipelineSto
rage.get()); |
142 assert_equal(reporter, kTestPatterns[i], | 156 GrRenderTarget* rt = dc->accessRenderTarget(); |
143 bottomUps[i]->renderTargetPriv().getMultisampleSpecs(du
mmyStencil), true); | 157 assert_equal(reporter, kTestPatterns[i], |
| 158 rt->renderTargetPriv().getMultisampleSpecs(*dummyPi
pe), |
| 159 kBottomLeft_GrSurfaceOrigin == rt->origin()); |
| 160 dummyPipe->~GrPipeline(); |
| 161 } |
144 } | 162 } |
145 } | 163 } |
| 164 |
146 } | 165 } |
147 | 166 |
148 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 167 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
149 | 168 |
150 class GLTestSampleLocationsInterface : public TestSampleLocationsInterface, publ
ic GrGLInterface { | 169 class GLTestSampleLocationsInterface : public TestSampleLocationsInterface, publ
ic GrGLInterface { |
151 public: | 170 public: |
152 GLTestSampleLocationsInterface() : fTestContext(sk_gpu_test::CreateDebugGLTe
stContext()) { | 171 GLTestSampleLocationsInterface() : fTestContext(sk_gpu_test::CreateDebugGLTe
stContext()) { |
153 fStandard = fTestContext->gl()->fStandard; | 172 fStandard = fTestContext->gl()->fStandard; |
154 fExtensions = fTestContext->gl()->fExtensions; | 173 fExtensions = fTestContext->gl()->fExtensions; |
155 fFunctions = fTestContext->gl()->fFunctions; | 174 fFunctions = fTestContext->gl()->fFunctions; |
(...skipping 28 matching lines...) Expand all Loading... |
184 SamplePattern fSamplePattern; | 203 SamplePattern fSamplePattern; |
185 }; | 204 }; |
186 | 205 |
187 DEF_GPUTEST(GLSampleLocations, reporter, /*factory*/) { | 206 DEF_GPUTEST(GLSampleLocations, reporter, /*factory*/) { |
188 GLTestSampleLocationsInterface testInterface; | 207 GLTestSampleLocationsInterface testInterface; |
189 SkAutoTUnref<GrContext> ctx(GrContext::Create(kOpenGL_GrBackend, testInterfa
ce)); | 208 SkAutoTUnref<GrContext> ctx(GrContext::Create(kOpenGL_GrBackend, testInterfa
ce)); |
190 test_sampleLocations(reporter, &testInterface, ctx); | 209 test_sampleLocations(reporter, &testInterface, ctx); |
191 } | 210 } |
192 | 211 |
193 #endif | 212 #endif |
OLD | NEW |