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