Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkTypes.h" |
| 9 | #include "Test.h" |
| 10 | |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 11 | #include "GrClip.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 12 | #include "GrContext.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 13 | #include "GrContextPriv.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 14 | #include "GrGpuResource.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 15 | #include "GrMemoryPool.h" |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 16 | #include "GrProxyProvider.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 17 | #include "GrRenderTargetContext.h" |
| 18 | #include "GrRenderTargetContextPriv.h" |
| 19 | #include "GrResourceProvider.h" |
| 20 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 21 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 22 | #include "ops/GrMeshDrawOp.h" |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 23 | #include "ops/GrRectOpFactory.h" |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 24 | |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame^] | 25 | #include <random> |
| 26 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 27 | namespace { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 28 | class TestOp : public GrMeshDrawOp { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 29 | public: |
| 30 | DEFINE_OP_CLASS_ID |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 31 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 32 | std::unique_ptr<GrFragmentProcessor> fp) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 33 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 34 | |
| 35 | return pool->allocate<TestOp>(std::move(fp)); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 36 | } |
| 37 | |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 38 | const char* name() const override { return "TestOp"; } |
| 39 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 40 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | 5f567c7 | 2017-09-14 08:27:37 -0400 | [diff] [blame] | 41 | fProcessors.visitProxies(func); |
| 42 | } |
| 43 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 44 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 45 | |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 46 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 47 | static constexpr GrProcessorAnalysisColor kUnknownColor; |
| 48 | GrColor overrideColor; |
| 49 | fProcessors.finalize(kUnknownColor, GrProcessorAnalysisCoverage::kNone, clip, false, caps, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 50 | &overrideColor); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 51 | return RequiresDstTexture::kNo; |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 52 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 53 | |
| 54 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 55 | friend class ::GrOpMemoryPool; // for ctor |
| 56 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 57 | TestOp(std::unique_ptr<GrFragmentProcessor> fp) |
| 58 | : INHERITED(ClassID()), fProcessors(std::move(fp)) { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 59 | this->setBounds(SkRect::MakeWH(100, 100), HasAABloat::kNo, IsZeroArea::kNo); |
| 60 | } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 61 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 62 | void onPrepareDraws(Target* target) override { return; } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 63 | |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 64 | GrProcessorSet fProcessors; |
| 65 | |
| 66 | typedef GrMeshDrawOp INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * FP used to test ref/IO counts on owned GrGpuResources. Can also be a parent FP to test counts |
| 71 | * of resources owned by child FPs. |
| 72 | */ |
| 73 | class TestFP : public GrFragmentProcessor { |
| 74 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 75 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) { |
| 76 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(std::move(child))); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 77 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 78 | static std::unique_ptr<GrFragmentProcessor> Make(const SkTArray<sk_sp<GrTextureProxy>>& proxies, |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 79 | const SkTArray<sk_sp<GrBuffer>>& buffers) { |
| 80 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(proxies, buffers)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | const char* name() const override { return "test"; } |
| 84 | |
| 85 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { |
| 86 | // We don't really care about reusing these. |
| 87 | static int32_t gKey = 0; |
| 88 | b->add32(sk_atomic_inc(&gKey)); |
| 89 | } |
| 90 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 91 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 92 | return std::unique_ptr<GrFragmentProcessor>(new TestFP(*this)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 95 | private: |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 96 | TestFP(const SkTArray<sk_sp<GrTextureProxy>>& proxies, const SkTArray<sk_sp<GrBuffer>>& buffers) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 97 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4) { |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 98 | for (const auto& proxy : proxies) { |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 99 | fSamplers.emplace_back(proxy); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 100 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 101 | this->setTextureSamplerCnt(fSamplers.count()); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 104 | TestFP(std::unique_ptr<GrFragmentProcessor> child) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 105 | : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4) { |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 106 | this->registerChildProcessor(std::move(child)); |
| 107 | } |
| 108 | |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 109 | explicit TestFP(const TestFP& that) |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 110 | : INHERITED(kTestFP_ClassID, that.optimizationFlags()), fSamplers(4) { |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 111 | for (int i = 0; i < that.fSamplers.count(); ++i) { |
| 112 | fSamplers.emplace_back(that.fSamplers[i]); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 113 | } |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 114 | for (int i = 0; i < that.numChildProcessors(); ++i) { |
| 115 | this->registerChildProcessor(that.childProcessor(i).clone()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 116 | } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 117 | this->setTextureSamplerCnt(fSamplers.count()); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 118 | } |
| 119 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 120 | virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 121 | class TestGLSLFP : public GrGLSLFragmentProcessor { |
| 122 | public: |
| 123 | TestGLSLFP() {} |
| 124 | void emitCode(EmitArgs& args) override { |
| 125 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 126 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); |
| 127 | } |
| 128 | |
| 129 | private: |
| 130 | }; |
| 131 | return new TestGLSLFP(); |
| 132 | } |
| 133 | |
| 134 | bool onIsEqual(const GrFragmentProcessor&) const override { return false; } |
Brian Salomon | f7dcd76 | 2018-07-30 14:48:15 -0400 | [diff] [blame] | 135 | const TextureSampler& onTextureSampler(int i) const override { return fSamplers[i]; } |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 136 | |
| 137 | GrTAllocator<TextureSampler> fSamplers; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 138 | typedef GrFragmentProcessor INHERITED; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 139 | }; |
| 140 | } |
| 141 | |
Brian Salomon | f046e15 | 2017-01-11 15:24:47 -0500 | [diff] [blame] | 142 | template <typename T> |
| 143 | inline void testingOnly_getIORefCnts(const T* resource, int* refCnt, int* readCnt, int* writeCnt) { |
| 144 | *refCnt = resource->fRefCnt; |
| 145 | *readCnt = resource->fPendingReads; |
| 146 | *writeCnt = resource->fPendingWrites; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Robert Phillips | 2f49314 | 2017-03-02 18:18:38 -0500 | [diff] [blame] | 149 | void testingOnly_getIORefCnts(GrTextureProxy* proxy, int* refCnt, int* readCnt, int* writeCnt) { |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 150 | *refCnt = proxy->getBackingRefCnt_TestOnly(); |
| 151 | *readCnt = proxy->getPendingReadCnt_TestOnly(); |
| 152 | *writeCnt = proxy->getPendingWriteCnt_TestOnly(); |
| 153 | } |
| 154 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 155 | DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) { |
| 156 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 157 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 158 | |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 159 | GrSurfaceDesc desc; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 160 | desc.fWidth = 10; |
| 161 | desc.fHeight = 10; |
Robert Phillips | 16d8ec6 | 2017-07-27 16:16:25 -0400 | [diff] [blame] | 162 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 163 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 164 | for (bool makeClone : {false, true}) { |
| 165 | for (int parentCnt = 0; parentCnt < 2; parentCnt++) { |
| 166 | sk_sp<GrRenderTargetContext> renderTargetContext( |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 167 | context->contextPriv().makeDeferredRenderTargetContext( |
| 168 | SkBackingFit::kApprox, 1, 1, |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 169 | kRGBA_8888_GrPixelConfig, nullptr)); |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 170 | { |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 171 | sk_sp<GrTextureProxy> proxy1 = proxyProvider->createProxy( |
| 172 | desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kYes); |
| 173 | sk_sp<GrTextureProxy> proxy2 = proxyProvider->createProxy( |
| 174 | desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kYes); |
| 175 | sk_sp<GrTextureProxy> proxy3 = proxyProvider->createProxy( |
| 176 | desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kYes); |
| 177 | sk_sp<GrTextureProxy> proxy4 = proxyProvider->createProxy( |
| 178 | desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kExact, SkBudgeted::kYes); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 179 | { |
| 180 | SkTArray<sk_sp<GrTextureProxy>> proxies; |
| 181 | SkTArray<sk_sp<GrBuffer>> buffers; |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 182 | proxies.push_back(proxy1); |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 183 | auto fp = TestFP::Make(std::move(proxies), std::move(buffers)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 184 | for (int i = 0; i < parentCnt; ++i) { |
| 185 | fp = TestFP::Make(std::move(fp)); |
| 186 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 187 | std::unique_ptr<GrFragmentProcessor> clone; |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 188 | if (makeClone) { |
| 189 | clone = fp->clone(); |
| 190 | } |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 191 | std::unique_ptr<GrDrawOp> op(TestOp::Make(context, std::move(fp))); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 192 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 193 | if (clone) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 194 | op = TestOp::Make(context, std::move(clone)); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 195 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
| 196 | } |
| 197 | } |
| 198 | int refCnt, readCnt, writeCnt; |
| 199 | |
| 200 | testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt); |
| 201 | // IO counts should be double if there is a clone of the FP. |
| 202 | int ioRefMul = makeClone ? 2 : 1; |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, -1 == refCnt); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 204 | REPORTER_ASSERT(reporter, ioRefMul * 1 == readCnt); |
| 205 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
| 206 | |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 207 | context->flush(); |
| 208 | |
| 209 | testingOnly_getIORefCnts(proxy1.get(), &refCnt, &readCnt, &writeCnt); |
| 210 | REPORTER_ASSERT(reporter, 1 == refCnt); |
| 211 | REPORTER_ASSERT(reporter, ioRefMul * 0 == readCnt); |
| 212 | REPORTER_ASSERT(reporter, ioRefMul * 0 == writeCnt); |
| 213 | |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 218 | |
| 219 | // This test uses the random GrFragmentProcessor test factory, which relies on static initializers. |
| 220 | #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 221 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 222 | #include "SkCommandLineFlags.h" |
| 223 | DEFINE_bool(randomProcessorTest, false, "Use non-deterministic seed for random processor tests?"); |
| 224 | |
| 225 | #if GR_TEST_UTILS |
| 226 | |
| 227 | static GrColor input_texel_color(int i, int j) { |
| 228 | GrColor color = GrColorPackRGBA((uint8_t)j, (uint8_t)(i + j), (uint8_t)(2 * j - i), (uint8_t)i); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 229 | return GrPremulColor(color); |
| 230 | } |
| 231 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 232 | static GrColor4f input_texel_color4f(int i, int j) { |
| 233 | return GrColor4f::FromGrColor(input_texel_color(i, j)); |
| 234 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 235 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 236 | void test_draw_op(GrContext* context, |
| 237 | GrRenderTargetContext* rtc, |
| 238 | std::unique_ptr<GrFragmentProcessor> fp, |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 239 | sk_sp<GrTextureProxy> inputDataProxy) { |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 240 | GrPaint paint; |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 241 | paint.addColorTextureProcessor(std::move(inputDataProxy), SkMatrix::I()); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 242 | paint.addColorFragmentProcessor(std::move(fp)); |
| 243 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 244 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 245 | auto op = GrRectOpFactory::MakeNonAAFill(context, std::move(paint), SkMatrix::I(), |
Brian Salomon | baaf439 | 2017-06-15 09:59:23 -0400 | [diff] [blame] | 246 | SkRect::MakeWH(rtc->width(), rtc->height()), |
| 247 | GrAAType::kNone); |
Brian Salomon | ac70f84 | 2017-05-08 10:43:33 -0400 | [diff] [blame] | 248 | rtc->addDrawOp(GrNoClip(), std::move(op)); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 249 | } |
| 250 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 251 | /** Initializes the two test texture proxies that are available to the FP test factories. */ |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 252 | bool init_test_textures(GrProxyProvider* proxyProvider, SkRandom* random, |
| 253 | sk_sp<GrTextureProxy> proxies[2]) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 254 | static const int kTestTextureSize = 256; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 255 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 256 | { |
| 257 | // Put premul data into the RGBA texture that the test FPs can optionally use. |
| 258 | std::unique_ptr<GrColor[]> rgbaData(new GrColor[kTestTextureSize * kTestTextureSize]); |
| 259 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 260 | for (int x = 0; x < kTestTextureSize; ++x) { |
| 261 | rgbaData[kTestTextureSize * y + x] = |
| 262 | input_texel_color(random->nextULessThan(256), random->nextULessThan(256)); |
| 263 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 264 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 265 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 266 | SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, |
| 267 | kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 268 | SkPixmap pixmap(ii, rgbaData.get(), ii.minRowBytes()); |
| 269 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
| 270 | proxies[0] = proxyProvider->createTextureProxy(img, kNone_GrSurfaceFlags, 1, |
| 271 | SkBudgeted::kYes, SkBackingFit::kExact); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 272 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 273 | |
| 274 | { |
| 275 | // Put random values into the alpha texture that the test FPs can optionally use. |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 276 | std::unique_ptr<uint8_t[]> alphaData(new uint8_t[kTestTextureSize * kTestTextureSize]); |
| 277 | for (int y = 0; y < kTestTextureSize; ++y) { |
| 278 | for (int x = 0; x < kTestTextureSize; ++x) { |
| 279 | alphaData[kTestTextureSize * y + x] = random->nextULessThan(256); |
| 280 | } |
| 281 | } |
| 282 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 283 | SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, |
| 284 | kAlpha_8_SkColorType, kPremul_SkAlphaType); |
| 285 | SkPixmap pixmap(ii, alphaData.get(), ii.minRowBytes()); |
| 286 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
| 287 | proxies[1] = proxyProvider->createTextureProxy(img, kNone_GrSurfaceFlags, 1, |
| 288 | SkBudgeted::kYes, SkBackingFit::kExact); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 289 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 290 | |
| 291 | return proxies[0] && proxies[1]; |
| 292 | } |
| 293 | |
| 294 | // Creates a texture of premul colors used as the output of the fragment processor that precedes |
| 295 | // the fragment processor under test. Color values are those provided by input_texel_color(). |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 296 | sk_sp<GrTextureProxy> make_input_texture(GrProxyProvider* proxyProvider, int width, int height) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 297 | std::unique_ptr<GrColor[]> data(new GrColor[width * height]); |
| 298 | for (int y = 0; y < width; ++y) { |
| 299 | for (int x = 0; x < height; ++x) { |
| 300 | data.get()[width * y + x] = input_texel_color(x, y); |
| 301 | } |
| 302 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 303 | |
Brian Osman | 2700abc | 2018-09-12 10:19:41 -0400 | [diff] [blame] | 304 | SkImageInfo ii = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 305 | SkPixmap pixmap(ii, data.get(), ii.minRowBytes()); |
| 306 | sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); |
| 307 | return proxyProvider->createTextureProxy(img, kNone_GrSurfaceFlags, 1, |
| 308 | SkBudgeted::kYes, SkBackingFit::kExact); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 309 | } |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 310 | |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 311 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 312 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 313 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 314 | auto resourceProvider = context->contextPriv().resourceProvider(); |
Brian Salomon | 1c05364 | 2017-07-24 10:16:19 -0400 | [diff] [blame] | 315 | using FPFactory = GrFragmentProcessorTestFactory; |
Brian Osman | c35a2d4 | 2017-03-17 10:58:53 -0400 | [diff] [blame] | 316 | |
| 317 | uint32_t seed = 0; |
| 318 | if (FLAGS_randomProcessorTest) { |
| 319 | std::random_device rd; |
| 320 | seed = rd(); |
| 321 | } |
| 322 | // If a non-deterministic bot fails this test, check the output to see what seed it used, then |
| 323 | // hard-code that value here: |
| 324 | SkRandom random(seed); |
| 325 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 326 | // Make the destination context for the test. |
| 327 | static constexpr int kRenderSize = 256; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 328 | sk_sp<GrRenderTargetContext> rtc = context->contextPriv().makeDeferredRenderTargetContext( |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 329 | SkBackingFit::kExact, kRenderSize, kRenderSize, kRGBA_8888_GrPixelConfig, nullptr); |
Brian Salomon | d1a8bdf | 2017-02-10 12:39:26 -0500 | [diff] [blame] | 330 | |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 331 | sk_sp<GrTextureProxy> proxies[2]; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 332 | if (!init_test_textures(proxyProvider, &random, proxies)) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 333 | ERRORF(reporter, "Could not create test textures"); |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 334 | return; |
| 335 | } |
Robert Phillips | e78b725 | 2017-04-06 07:59:41 -0400 | [diff] [blame] | 336 | GrProcessorTestData testData(&random, context, rtc.get(), proxies); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 337 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 338 | auto inputTexture = make_input_texture(proxyProvider, kRenderSize, kRenderSize); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 339 | |
Ben Wagner | 8c79194 | 2017-07-25 11:47:48 -0400 | [diff] [blame] | 340 | std::unique_ptr<GrColor[]> readData(new GrColor[kRenderSize * kRenderSize]); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 341 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 342 | for (int i = 0; i < FPFactory::Count(); ++i) { |
| 343 | int timesToInvokeFactory = 5; |
| 344 | // Increase the number of attempts if the FP has child FPs since optimizations likely depend |
| 345 | // on child optimizations being present. |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 346 | std::unique_ptr<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 347 | for (int j = 0; j < fp->numChildProcessors(); ++j) { |
| 348 | // This value made a reasonable trade off between time and coverage when this test was |
| 349 | // written. |
| 350 | timesToInvokeFactory *= FPFactory::Count() / 2; |
| 351 | } |
| 352 | for (int j = 0; j < timesToInvokeFactory; ++j) { |
| 353 | fp = FPFactory::MakeIdx(i, &testData); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 354 | if (!fp->instantiate(resourceProvider)) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 355 | continue; |
| 356 | } |
| 357 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 358 | if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() && |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 359 | !fp->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 360 | continue; |
| 361 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 362 | |
| 363 | // Since we transfer away ownership of the original FP, we make a clone. |
| 364 | auto clone = fp->clone(); |
| 365 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 366 | test_draw_op(context, rtc.get(), std::move(fp), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 367 | memset(readData.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 368 | rtc->readPixels(SkImageInfo::Make(kRenderSize, kRenderSize, kRGBA_8888_SkColorType, |
| 369 | kPremul_SkAlphaType), |
| 370 | readData.get(), 0, 0, 0); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 371 | bool passing = true; |
| 372 | if (0) { // Useful to see what FPs are being tested. |
| 373 | SkString children; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 374 | for (int c = 0; c < clone->numChildProcessors(); ++c) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 375 | if (!c) { |
| 376 | children.append("("); |
| 377 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 378 | children.append(clone->name()); |
| 379 | children.append(c == clone->numChildProcessors() - 1 ? ")" : ", "); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 380 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 381 | SkDebugf("%s %s\n", clone->name(), children.c_str()); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 382 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 383 | for (int y = 0; y < kRenderSize && passing; ++y) { |
| 384 | for (int x = 0; x < kRenderSize && passing; ++x) { |
| 385 | GrColor input = input_texel_color(x, y); |
| 386 | GrColor output = readData.get()[y * kRenderSize + x]; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 387 | if (clone->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 388 | // A modulating processor is allowed to modulate either the input color or |
| 389 | // just the input alpha. |
| 390 | bool legalColorModulation = |
| 391 | GrColorUnpackA(output) <= GrColorUnpackA(input) && |
| 392 | GrColorUnpackR(output) <= GrColorUnpackR(input) && |
| 393 | GrColorUnpackG(output) <= GrColorUnpackG(input) && |
| 394 | GrColorUnpackB(output) <= GrColorUnpackB(input); |
| 395 | bool legalAlphaModulation = |
| 396 | GrColorUnpackA(output) <= GrColorUnpackA(input) && |
| 397 | GrColorUnpackR(output) <= GrColorUnpackA(input) && |
| 398 | GrColorUnpackG(output) <= GrColorUnpackA(input) && |
| 399 | GrColorUnpackB(output) <= GrColorUnpackA(input); |
| 400 | if (!legalColorModulation && !legalAlphaModulation) { |
| 401 | ERRORF(reporter, |
| 402 | "\"Modulating\" processor %s made color/alpha value larger. " |
Greg Daniel | 10ed243 | 2017-12-01 16:19:43 -0500 | [diff] [blame] | 403 | "Input: 0x%08x, Output: 0x%08x, pixel (%d, %d).", |
| 404 | clone->name(), input, output, x, y); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 405 | passing = false; |
| 406 | } |
| 407 | } |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 408 | GrColor4f input4f = input_texel_color4f(x, y); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 409 | GrColor4f output4f = GrColor4f::FromGrColor(output); |
| 410 | GrColor4f expected4f; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 411 | if (clone->hasConstantOutputForConstantInput(input4f, &expected4f)) { |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 412 | float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]); |
| 413 | float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]); |
| 414 | float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]); |
| 415 | float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]); |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 416 | static constexpr float kTol = 4 / 255.f; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 417 | if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) { |
| 418 | ERRORF(reporter, |
| 419 | "Processor %s claimed output for const input doesn't match " |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 420 | "actual output. Error: %f, Tolerance: %f, input: (%f, %f, %f, " |
| 421 | "%f), actual: (%f, %f, %f, %f), expected(%f, %f, %f, %f)", |
Brian Salomon | f61711a | 2018-02-16 10:44:28 -0500 | [diff] [blame] | 422 | clone->name(), |
| 423 | SkTMax(rDiff, SkTMax(gDiff, SkTMax(bDiff, aDiff))), kTol, |
| 424 | input4f.fRGBA[0], input4f.fRGBA[1], input4f.fRGBA[2], |
Brian Salomon | 5d4cd9e | 2017-02-09 11:16:46 -0500 | [diff] [blame] | 425 | input4f.fRGBA[3], output4f.fRGBA[0], output4f.fRGBA[1], |
| 426 | output4f.fRGBA[2], output4f.fRGBA[3], expected4f.fRGBA[0], |
| 427 | expected4f.fRGBA[1], expected4f.fRGBA[2], expected4f.fRGBA[3]); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 428 | passing = false; |
| 429 | } |
| 430 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 431 | if (GrColorIsOpaque(input) && clone->preservesOpaqueInput() && |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 432 | !GrColorIsOpaque(output)) { |
| 433 | ERRORF(reporter, |
| 434 | "Processor %s claimed opaqueness is preserved but it is not. Input: " |
Brian Osman | 2f3865b | 2017-03-15 13:35:51 -0400 | [diff] [blame] | 435 | "0x%08x, Output: 0x%08x.", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 436 | clone->name(), input, output); |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 437 | passing = false; |
| 438 | } |
Brian Osman | bd1f76f | 2017-03-15 11:33:12 -0400 | [diff] [blame] | 439 | if (!passing) { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 440 | ERRORF(reporter, "Seed: 0x%08x, Processor details: %s", seed, |
| 441 | clone->dumpInfo().c_str()); |
Brian Osman | bd1f76f | 2017-03-15 11:33:12 -0400 | [diff] [blame] | 442 | } |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | } |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 448 | |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 449 | // Tests that fragment processors returned by GrFragmentProcessor::clone() are equivalent to their |
| 450 | // progenitors. |
| 451 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) { |
| 452 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 453 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 454 | auto resourceProvider = context->contextPriv().resourceProvider(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 455 | |
| 456 | SkRandom random; |
| 457 | |
| 458 | // Make the destination context for the test. |
| 459 | static constexpr int kRenderSize = 1024; |
Robert Phillips | 0c4b7b1 | 2018-03-06 08:20:37 -0500 | [diff] [blame] | 460 | sk_sp<GrRenderTargetContext> rtc = context->contextPriv().makeDeferredRenderTargetContext( |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 461 | SkBackingFit::kExact, kRenderSize, kRenderSize, kRGBA_8888_GrPixelConfig, nullptr); |
| 462 | |
| 463 | sk_sp<GrTextureProxy> proxies[2]; |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 464 | if (!init_test_textures(proxyProvider, &random, proxies)) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 465 | ERRORF(reporter, "Could not create test textures"); |
| 466 | return; |
| 467 | } |
| 468 | GrProcessorTestData testData(&random, context, rtc.get(), proxies); |
| 469 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 470 | auto inputTexture = make_input_texture(proxyProvider, kRenderSize, kRenderSize); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 471 | std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]); |
| 472 | std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]); |
| 473 | auto readInfo = SkImageInfo::Make(kRenderSize, kRenderSize, kRGBA_8888_SkColorType, |
| 474 | kPremul_SkAlphaType); |
| 475 | |
| 476 | // Because processor factories configure themselves in random ways, this is not exhaustive. |
| 477 | for (int i = 0; i < GrFragmentProcessorTestFactory::Count(); ++i) { |
| 478 | static constexpr int kTimesToInvokeFactory = 10; |
| 479 | for (int j = 0; j < kTimesToInvokeFactory; ++j) { |
| 480 | auto fp = GrFragmentProcessorTestFactory::MakeIdx(i, &testData); |
| 481 | auto clone = fp->clone(); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 482 | if (!clone) { |
Brian Salomon | 96271cd | 2017-07-31 16:27:23 -0400 | [diff] [blame] | 483 | ERRORF(reporter, "Clone of processor %s failed.", fp->name()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 484 | continue; |
| 485 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 486 | const char* name = fp->name(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 487 | if (!fp->instantiate(resourceProvider) || !clone->instantiate(resourceProvider)) { |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 488 | continue; |
| 489 | } |
Brian Salomon | ce06e26 | 2017-08-01 16:23:40 -0400 | [diff] [blame] | 490 | REPORTER_ASSERT(reporter, !strcmp(fp->name(), clone->name())); |
| 491 | REPORTER_ASSERT(reporter, fp->compatibleWithCoverageAsAlpha() == |
| 492 | clone->compatibleWithCoverageAsAlpha()); |
| 493 | REPORTER_ASSERT(reporter, fp->isEqual(*clone)); |
| 494 | REPORTER_ASSERT(reporter, fp->preservesOpaqueInput() == clone->preservesOpaqueInput()); |
| 495 | REPORTER_ASSERT(reporter, fp->hasConstantOutputForConstantInput() == |
| 496 | clone->hasConstantOutputForConstantInput()); |
| 497 | REPORTER_ASSERT(reporter, fp->numChildProcessors() == clone->numChildProcessors()); |
| 498 | REPORTER_ASSERT(reporter, fp->usesLocalCoords() == clone->usesLocalCoords()); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 499 | // Draw with original and read back the results. |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 500 | test_draw_op(context, rtc.get(), std::move(fp), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 501 | memset(readData1.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 502 | rtc->readPixels(readInfo, readData1.get(), 0, 0, 0); |
| 503 | |
| 504 | // Draw with clone and read back the results. |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 505 | test_draw_op(context, rtc.get(), std::move(clone), inputTexture); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 506 | memset(readData2.get(), 0x0, sizeof(GrColor) * kRenderSize * kRenderSize); |
| 507 | rtc->readPixels(readInfo, readData2.get(), 0, 0, 0); |
| 508 | |
| 509 | // Check that the results are the same. |
| 510 | bool passing = true; |
| 511 | for (int y = 0; y < kRenderSize && passing; ++y) { |
| 512 | for (int x = 0; x < kRenderSize && passing; ++x) { |
| 513 | int idx = y * kRenderSize + x; |
| 514 | if (readData1[idx] != readData2[idx]) { |
| 515 | ERRORF(reporter, |
| 516 | "Processor %s made clone produced different output. " |
| 517 | "Input color: 0x%08x, Original Output Color: 0x%08x, " |
| 518 | "Clone Output Color: 0x%08x..", |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 519 | name, input_texel_color(x, y), readData1[idx], readData2[idx]); |
Brian Salomon | 0e05a82 | 2017-07-25 09:43:22 -0400 | [diff] [blame] | 520 | passing = false; |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 528 | #endif // GR_TEST_UTILS |
| 529 | #endif // SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |