Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "tests/Test.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 9 | |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 10 | #include "include/core/SkBitmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrBackendSemaphore.h" |
| 12 | #include "include/gpu/GrTexture.h" |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 13 | #include "src/core/SkPointPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrClip.h" |
| 15 | #include "src/gpu/GrContextPriv.h" |
| 16 | #include "src/gpu/GrDefaultGeoProcFactory.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 19 | #include "src/gpu/GrProxyProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetContextPriv.h" |
| 21 | #include "src/gpu/GrResourceProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/effects/generated/GrSimpleTextureEffect.h" |
Michael Ludwig | fd4f4df | 2019-05-29 09:51:09 -0400 | [diff] [blame] | 23 | #include "src/gpu/geometry/GrQuad.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 25 | #include "tests/TestUtils.h" |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 26 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 27 | namespace { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 28 | // This is a simplified mesh drawing op that can be used in the atlas generation test. |
| 29 | // Please see AtlasedRectOp below. |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 30 | class NonAARectOp : public GrMeshDrawOp { |
| 31 | protected: |
| 32 | using Helper = GrSimpleMeshDrawOpHelper; |
| 33 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 34 | public: |
| 35 | DEFINE_OP_CLASS_ID |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 36 | |
| 37 | // This creates an instance of a simple non-AA solid color rect-drawing Op |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 38 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 39 | GrPaint&& paint, |
| 40 | const SkRect& r) { |
| 41 | return Helper::FactoryHelper<NonAARectOp>(context, std::move(paint), r, nullptr, ClassID()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // This creates an instance of a simple non-AA textured rect-drawing Op |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 45 | static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 46 | GrPaint&& paint, |
| 47 | const SkRect& r, |
| 48 | const SkRect& local) { |
| 49 | return Helper::FactoryHelper<NonAARectOp>(context, std::move(paint), r, &local, ClassID()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 52 | const SkPMColor4f& color() const { return fColor; } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 53 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 54 | NonAARectOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, const SkRect& r, |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 55 | const SkRect* localRect, int32_t classID) |
| 56 | : INHERITED(classID) |
| 57 | , fColor(color) |
| 58 | , fHasLocalRect(SkToBool(localRect)) |
| 59 | , fRect(r) |
| 60 | , fHelper(helperArgs, GrAAType::kNone) { |
| 61 | if (fHasLocalRect) { |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 62 | fLocalQuad = GrQuad(*localRect); |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 63 | } |
| 64 | // Choose some conservative values for aa bloat and zero area. |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 65 | this->setBounds(r, HasAABloat::kYes, IsHairline::kYes); |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 68 | const char* name() const override { return "NonAARectOp"; } |
| 69 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 70 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 71 | fHelper.visitProxies(func); |
| 72 | } |
| 73 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 74 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 75 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 76 | GrProcessorSet::Analysis finalize( |
| 77 | const GrCaps& caps, const GrAppliedClip*, bool hasMixedSampledCoverage, |
| 78 | GrClampType clampType) override { |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 79 | // Set the color to unknown because the subclass may change the color later. |
| 80 | GrProcessorAnalysisColor gpColor; |
| 81 | gpColor.setToUnknown(); |
| 82 | // We ignore the clip so pass this rather than the GrAppliedClip param. |
| 83 | static GrAppliedClip kNoClip; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 84 | return fHelper.finalizeProcessors(caps, &kNoClip, hasMixedSampledCoverage, clampType, |
| 85 | GrProcessorAnalysisCoverage::kNone, &gpColor); |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 88 | protected: |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 89 | SkPMColor4f fColor; |
| 90 | bool fHasLocalRect; |
| 91 | GrQuad fLocalQuad; |
| 92 | SkRect fRect; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 93 | |
| 94 | private: |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 95 | void onPrepareDraws(Target* target) override { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 96 | using namespace GrDefaultGeoProcFactory; |
| 97 | |
| 98 | // The vertex attrib order is always pos, color, local coords. |
| 99 | static const int kColorOffset = sizeof(SkPoint); |
| 100 | static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 101 | |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 102 | GrGeometryProcessor* gp = GrDefaultGeoProcFactory::Make( |
| 103 | target->allocator(), |
| 104 | target->caps().shaderCaps(), |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 105 | Color::kPremulGrColorAttribute_Type, |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 106 | Coverage::kSolid_Type, |
| 107 | fHasLocalRect ? LocalCoords::kHasExplicit_Type |
| 108 | : LocalCoords::kUnused_Type, |
| 109 | SkMatrix::I()); |
| 110 | if (!gp) { |
| 111 | SkDebugf("Couldn't create GrGeometryProcessor for GrAtlasedOp\n"); |
| 112 | return; |
| 113 | } |
| 114 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 115 | size_t vertexStride = gp->vertexStride(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 116 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 117 | sk_sp<const GrBuffer> indexBuffer; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 118 | int firstIndex; |
| 119 | uint16_t* indices = target->makeIndexSpace(6, &indexBuffer, &firstIndex); |
| 120 | if (!indices) { |
| 121 | SkDebugf("Indices could not be allocated for GrAtlasedOp.\n"); |
| 122 | return; |
| 123 | } |
| 124 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 125 | sk_sp<const GrBuffer> vertexBuffer; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 126 | int firstVertex; |
| 127 | void* vertices = target->makeVertexSpace(vertexStride, 4, &vertexBuffer, &firstVertex); |
| 128 | if (!vertices) { |
| 129 | SkDebugf("Vertices could not be allocated for GrAtlasedOp.\n"); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | // Setup indices |
| 134 | indices[0] = 0; |
| 135 | indices[1] = 1; |
| 136 | indices[2] = 2; |
Brian Salomon | 57caa66 | 2017-10-18 12:21:05 +0000 | [diff] [blame] | 137 | indices[3] = 2; |
| 138 | indices[4] = 1; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 139 | indices[5] = 3; |
| 140 | |
| 141 | // Setup positions |
| 142 | SkPoint* position = (SkPoint*) vertices; |
Brian Salomon | ec42e15 | 2018-05-18 12:52:22 -0400 | [diff] [blame] | 143 | SkPointPriv::SetRectTriStrip(position, fRect, vertexStride); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 144 | |
| 145 | // Setup vertex colors |
| 146 | GrColor* color = (GrColor*)((intptr_t)vertices + kColorOffset); |
| 147 | for (int i = 0; i < 4; ++i) { |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 148 | *color = fColor.toBytes_RGBA(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 149 | color = (GrColor*)((intptr_t)color + vertexStride); |
| 150 | } |
| 151 | |
| 152 | // Setup local coords |
| 153 | if (fHasLocalRect) { |
| 154 | SkPoint* coords = (SkPoint*)((intptr_t) vertices + kLocalOffset); |
| 155 | for (int i = 0; i < 4; i++) { |
| 156 | *coords = fLocalQuad.point(i); |
| 157 | coords = (SkPoint*)((intptr_t) coords + vertexStride); |
| 158 | } |
| 159 | } |
| 160 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 161 | GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles); |
| 162 | mesh->setIndexed(indexBuffer, 6, firstIndex, 0, 3, GrPrimitiveRestart::kNo); |
| 163 | mesh->setVertexData(vertexBuffer, firstVertex); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 164 | |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 165 | target->recordDraw(gp, mesh, 1, GrPrimitiveType::kTriangles); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
| 169 | fHelper.executeDrawsAndUploads(this, flushState, chainBounds); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 172 | Helper fHelper; |
| 173 | |
| 174 | typedef GrMeshDrawOp INHERITED; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 175 | }; |
| 176 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 177 | } // anonymous namespace |
| 178 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 179 | static constexpr SkRect kEmptyRect = SkRect::MakeEmpty(); |
| 180 | |
| 181 | namespace { |
| 182 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 183 | /* |
| 184 | * Atlased ops just draw themselves as textured rects with the texture pixels being |
| 185 | * pulled out of the atlas. Their color is based on their ID. |
| 186 | */ |
| 187 | class AtlasedRectOp final : public NonAARectOp { |
| 188 | public: |
| 189 | DEFINE_OP_CLASS_ID |
| 190 | |
| 191 | ~AtlasedRectOp() override { |
| 192 | fID = -1; |
| 193 | } |
| 194 | |
| 195 | const char* name() const override { return "AtlasedRectOp"; } |
| 196 | |
| 197 | int id() const { return fID; } |
| 198 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 199 | static std::unique_ptr<AtlasedRectOp> Make(GrContext* context, |
| 200 | GrPaint&& paint, |
| 201 | const SkRect& r, |
| 202 | int id) { |
| 203 | GrDrawOp* op = Helper::FactoryHelper<AtlasedRectOp>(context, std::move(paint), |
| 204 | r, id).release(); |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 205 | return std::unique_ptr<AtlasedRectOp>(static_cast<AtlasedRectOp*>(op)); |
| 206 | } |
| 207 | |
| 208 | // We set the initial color of the NonAARectOp based on the ID. |
| 209 | // Note that we force creation of a NonAARectOp that has local coords in anticipation of |
| 210 | // pulling from the atlas. |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 211 | AtlasedRectOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, const SkRect& r, |
Brian Osman | 936fe7d | 2018-10-30 15:30:35 -0400 | [diff] [blame] | 212 | int id) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 213 | : INHERITED(helperArgs, SkPMColor4f::FromBytes_RGBA(kColors[id]), r, &kEmptyRect, |
| 214 | ClassID()) |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 215 | , fID(id) |
| 216 | , fNext(nullptr) { |
| 217 | SkASSERT(fID < kMaxIDs); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 220 | void setColor(const SkPMColor4f& color) { fColor = color; } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 221 | void setLocalRect(const SkRect& localRect) { |
| 222 | SkASSERT(fHasLocalRect); // This should've been created to anticipate this |
Brian Salomon | a33b67c | 2018-05-17 10:42:14 -0400 | [diff] [blame] | 223 | fLocalQuad = GrQuad(localRect); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | AtlasedRectOp* next() const { return fNext; } |
| 227 | void setNext(AtlasedRectOp* next) { |
| 228 | fNext = next; |
| 229 | } |
| 230 | |
| 231 | private: |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 232 | |
| 233 | static const int kMaxIDs = 9; |
Brian Osman | 1be2b7c | 2018-10-29 16:07:15 -0400 | [diff] [blame] | 234 | static const GrColor kColors[kMaxIDs]; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 235 | |
| 236 | int fID; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 237 | // The Atlased ops have an internal singly-linked list of ops that land in the same opsTask |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 238 | AtlasedRectOp* fNext; |
| 239 | |
| 240 | typedef NonAARectOp INHERITED; |
| 241 | }; |
| 242 | |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 243 | } // anonymous namespace |
| 244 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 245 | const GrColor AtlasedRectOp::kColors[kMaxIDs] = { |
| 246 | GrColorPackRGBA(255, 0, 0, 255), |
| 247 | GrColorPackRGBA(0, 255, 0, 255), |
| 248 | GrColorPackRGBA(0, 0, 255, 255), |
| 249 | GrColorPackRGBA(0, 255, 255, 255), |
| 250 | GrColorPackRGBA(255, 0, 255, 255), |
| 251 | GrColorPackRGBA(255, 255, 0, 255), |
| 252 | GrColorPackRGBA(0, 0, 0, 255), |
| 253 | GrColorPackRGBA(128, 128, 128, 255), |
| 254 | GrColorPackRGBA(255, 255, 255, 255) |
| 255 | }; |
| 256 | |
| 257 | static const int kDrawnTileSize = 16; |
| 258 | |
| 259 | /* |
| 260 | * Rather than performing any rect packing, this atlaser just lays out constant-sized |
| 261 | * tiles in an Nx1 row |
| 262 | */ |
| 263 | static const int kAtlasTileSize = 2; |
| 264 | |
| 265 | /* |
| 266 | * This class aggregates the op information required for atlasing |
| 267 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 268 | class AtlasObject final : public GrOnFlushCallbackObject { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 269 | public: |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 270 | AtlasObject(skiatest::Reporter* reporter) : fDone(false), fReporter(reporter) {} |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 271 | |
| 272 | ~AtlasObject() override { |
| 273 | SkASSERT(fDone); |
| 274 | } |
| 275 | |
| 276 | void markAsDone() { |
| 277 | fDone = true; |
| 278 | } |
| 279 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 280 | // Insert the new op in an internal singly-linked list for 'opsTaskID' |
| 281 | void addOp(uint32_t opsTaskID, AtlasedRectOp* op) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 282 | LinkedListHeader* header = nullptr; |
| 283 | for (int i = 0; i < fOps.count(); ++i) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 284 | if (opsTaskID == fOps[i].fID) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 285 | header = &(fOps[i]); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (!header) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 290 | fOps.push_back({opsTaskID, nullptr}); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 291 | header = &(fOps[fOps.count()-1]); |
| 292 | } |
| 293 | |
| 294 | op->setNext(header->fHead); |
| 295 | header->fHead = op; |
| 296 | } |
| 297 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 298 | int numOps() const { return fOps.count(); } |
| 299 | |
| 300 | // Get the fully lazy proxy that is backing the atlas. Its actual width isn't |
| 301 | // known until flush time. |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 302 | sk_sp<GrTextureProxy> getAtlasProxy(GrProxyProvider* proxyProvider, const GrCaps* caps) { |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 303 | if (fAtlasProxy) { |
| 304 | return fAtlasProxy; |
| 305 | } |
| 306 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 307 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 308 | GrRenderable::kYes); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 309 | |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 310 | fAtlasProxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 311 | [format](GrResourceProvider* resourceProvider) |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 312 | -> GrSurfaceProxy::LazyCallbackResult { |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 313 | GrSurfaceDesc desc; |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 314 | // TODO: until partial flushes in MDB lands we're stuck having |
| 315 | // all 9 atlas draws occur |
| 316 | desc.fWidth = 9 /*this->numOps()*/ * kAtlasTileSize; |
| 317 | desc.fHeight = kAtlasTileSize; |
| 318 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 319 | |
Robert Phillips | aee18c9 | 2019-09-06 11:48:27 -0400 | [diff] [blame] | 320 | return resourceProvider->createTexture(desc, format, GrRenderable::kYes, 1, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 321 | GrMipMapped::kNo, SkBudgeted::kYes, |
| 322 | GrProtected::kNo); |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 323 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 324 | format, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 325 | GrRenderable::kYes, |
| 326 | 1, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 327 | GrProtected::kNo, |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 328 | kBottomLeft_GrSurfaceOrigin, |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 329 | kRGBA_8888_GrPixelConfig, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 330 | *proxyProvider->caps(), |
| 331 | GrSurfaceProxy::UseAllocator::kNo); |
Robert Phillips | 5f78adf | 2019-04-22 12:41:39 -0400 | [diff] [blame] | 332 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 333 | return fAtlasProxy; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 336 | /* |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 337 | * This callback creates the atlas and updates the AtlasedRectOps to read from it |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 338 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 339 | void preFlush(GrOnFlushResourceProvider* resourceProvider, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 340 | const uint32_t* opsTaskIDs, |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 341 | int numOpsTaskIDs) override { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 342 | // Until MDB is landed we will most-likely only have one opsTask. |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 343 | SkTDArray<LinkedListHeader*> lists; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 344 | for (int i = 0; i < numOpsTaskIDs; ++i) { |
| 345 | if (LinkedListHeader* list = this->getList(opsTaskIDs[i])) { |
Mike Reed | 5edcd31 | 2018-08-08 11:23:41 -0400 | [diff] [blame] | 346 | lists.push_back(list); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | if (!lists.count()) { |
| 351 | return; // nothing to atlas |
| 352 | } |
| 353 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 354 | if (!resourceProvider->instatiateProxy(fAtlasProxy.get())) { |
| 355 | return; |
| 356 | } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 357 | |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 358 | // At this point 'fAtlasProxy' should be instantiated and have: |
| 359 | // 1 ref from the 'fAtlasProxy' sk_sp |
| 360 | // 9 refs from the 9 AtlasedRectOps |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 361 | // The backing GrSurface should have only 1 though bc there is only one proxy |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 362 | CheckSingleThreadedProxyRefs(fReporter, fAtlasProxy.get(), 10, 1); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 363 | auto rtc = resourceProvider->makeRenderTargetContext(fAtlasProxy, GrColorType::kRGBA_8888, |
| 364 | nullptr, nullptr); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 365 | |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 366 | // clear the atlas |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 367 | rtc->clear(nullptr, SK_PMColor4fTRANSPARENT, |
| 368 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 369 | |
| 370 | int blocksInAtlas = 0; |
| 371 | for (int i = 0; i < lists.count(); ++i) { |
| 372 | for (AtlasedRectOp* op = lists[i]->fHead; op; op = op->next()) { |
| 373 | SkIRect r = SkIRect::MakeXYWH(blocksInAtlas*kAtlasTileSize, 0, |
| 374 | kAtlasTileSize, kAtlasTileSize); |
| 375 | |
| 376 | // For now, we avoid the resource buffer issues and just use clears |
| 377 | #if 1 |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 378 | rtc->clear(&r, op->color(), GrRenderTargetContext::CanClearFullscreen::kNo); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 379 | #else |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 380 | GrPaint paint; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 381 | paint.setColor4f(op->color()); |
Brian Salomon | 9a03642 | 2017-07-13 17:04:43 -0400 | [diff] [blame] | 382 | std::unique_ptr<GrDrawOp> drawOp(NonAARectOp::Make(std::move(paint), |
| 383 | SkRect::Make(r))); |
| 384 | rtc->priv().testingOnly_addDrawOp(std::move(drawOp)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 385 | #endif |
| 386 | blocksInAtlas++; |
| 387 | |
| 388 | // Set the atlased Op's color to white (so we know we're not using it for |
| 389 | // the final draw). |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 390 | op->setColor(SK_PMColor4fWHITE); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 391 | |
| 392 | // Set the atlased Op's localRect to point to where it landed in the atlas |
| 393 | op->setLocalRect(SkRect::Make(r)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // We've updated all these ops and we certainly don't want to process them again |
| 397 | this->clearOpsFor(lists[i]); |
| 398 | } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | private: |
| 402 | typedef struct { |
| 403 | uint32_t fID; |
| 404 | AtlasedRectOp* fHead; |
| 405 | } LinkedListHeader; |
| 406 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 407 | LinkedListHeader* getList(uint32_t opsTaskID) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 408 | for (int i = 0; i < fOps.count(); ++i) { |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 409 | if (opsTaskID == fOps[i].fID) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 410 | return &(fOps[i]); |
| 411 | } |
| 412 | } |
| 413 | return nullptr; |
| 414 | } |
| 415 | |
| 416 | void clearOpsFor(LinkedListHeader* header) { |
| 417 | // The AtlasedRectOps have yet to execute (and this class doesn't own them) so just |
| 418 | // forget about them in the laziest way possible. |
| 419 | header->fHead = nullptr; |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 420 | header->fID = 0; // invalid opsTask ID |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 421 | } |
| 422 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 423 | // Each opsTask containing AtlasedRectOps gets its own internal singly-linked list |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 424 | SkTDArray<LinkedListHeader> fOps; |
| 425 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 426 | // The fully lazy proxy for the atlas |
| 427 | sk_sp<GrTextureProxy> fAtlasProxy; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 428 | |
| 429 | // Set to true when the testing harness expects this object to be no longer used |
| 430 | bool fDone; |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 431 | |
| 432 | skiatest::Reporter* fReporter; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | // This creates an off-screen rendertarget whose ops which eventually pull from the atlas. |
| 436 | static sk_sp<GrTextureProxy> make_upstream_image(GrContext* context, AtlasObject* object, int start, |
Greg Daniel | c594e62 | 2019-10-15 14:01:49 -0400 | [diff] [blame] | 437 | sk_sp<GrTextureProxy> atlasProxy, |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 438 | GrColorType atlasColorType) { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 439 | auto rtc = context->priv().makeDeferredRenderTargetContext(SkBackingFit::kApprox, |
| 440 | 3* kDrawnTileSize, |
| 441 | kDrawnTileSize, |
| 442 | GrColorType::kRGBA_8888, |
| 443 | nullptr); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 444 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 445 | rtc->clear(nullptr, { 1, 0, 0, 1 }, GrRenderTargetContext::CanClearFullscreen::kYes); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 446 | |
| 447 | for (int i = 0; i < 3; ++i) { |
| 448 | SkRect r = SkRect::MakeXYWH(i*kDrawnTileSize, 0, kDrawnTileSize, kDrawnTileSize); |
| 449 | |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 450 | auto fp = GrSimpleTextureEffect::Make(atlasProxy, atlasColorType, SkMatrix::I()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 451 | GrPaint paint; |
| 452 | paint.addColorFragmentProcessor(std::move(fp)); |
| 453 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 454 | std::unique_ptr<AtlasedRectOp> op(AtlasedRectOp::Make(context, |
| 455 | std::move(paint), r, start + i)); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 456 | |
| 457 | AtlasedRectOp* sparePtr = op.get(); |
| 458 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 459 | uint32_t opsTaskID; |
Brian Salomon | 348a037 | 2018-10-31 10:42:18 -0400 | [diff] [blame] | 460 | rtc->priv().testingOnly_addDrawOp(GrNoClip(), std::move(op), |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 461 | [&opsTaskID](GrOp* op, uint32_t id) { opsTaskID = id; }); |
| 462 | SkASSERT(SK_InvalidUniqueID != opsTaskID); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 463 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 464 | object->addOp(opsTaskID, sparePtr); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | return rtc->asTextureProxyRef(); |
| 468 | } |
| 469 | |
| 470 | // Enable this if you want to debug the final draws w/o having the atlasCallback create the |
| 471 | // atlas |
| 472 | #if 0 |
| 473 | #include "SkGrPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 474 | #include "include/core/SkImageEncoder.h" |
| 475 | #include "tools/ToolUtils.h" |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 476 | |
| 477 | static void save_bm(const SkBitmap& bm, const char name[]) { |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 478 | bool result = ToolUtils::EncodeImageToFile(name, bm, SkEncodedImageFormat::kPNG, 100); |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 479 | SkASSERT(result); |
| 480 | } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 481 | |
| 482 | sk_sp<GrTextureProxy> pre_create_atlas(GrContext* context) { |
| 483 | SkBitmap bm; |
| 484 | bm.allocN32Pixels(18, 2, true); |
| 485 | bm.erase(SK_ColorRED, SkIRect::MakeXYWH(0, 0, 2, 2)); |
| 486 | bm.erase(SK_ColorGREEN, SkIRect::MakeXYWH(2, 0, 2, 2)); |
| 487 | bm.erase(SK_ColorBLUE, SkIRect::MakeXYWH(4, 0, 2, 2)); |
| 488 | bm.erase(SK_ColorCYAN, SkIRect::MakeXYWH(6, 0, 2, 2)); |
| 489 | bm.erase(SK_ColorMAGENTA, SkIRect::MakeXYWH(8, 0, 2, 2)); |
| 490 | bm.erase(SK_ColorYELLOW, SkIRect::MakeXYWH(10, 0, 2, 2)); |
| 491 | bm.erase(SK_ColorBLACK, SkIRect::MakeXYWH(12, 0, 2, 2)); |
| 492 | bm.erase(SK_ColorGRAY, SkIRect::MakeXYWH(14, 0, 2, 2)); |
| 493 | bm.erase(SK_ColorWHITE, SkIRect::MakeXYWH(16, 0, 2, 2)); |
| 494 | |
| 495 | #if 1 |
| 496 | save_bm(bm, "atlas-fake.png"); |
| 497 | #endif |
| 498 | |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 499 | GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bm.info()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 500 | desc.fFlags |= kRenderTarget_GrSurfaceFlag; |
| 501 | |
| 502 | sk_sp<GrSurfaceProxy> tmp = GrSurfaceProxy::MakeDeferred(*context->caps(), |
| 503 | context->textureProvider(), |
| 504 | desc, SkBudgeted::kYes, |
| 505 | bm.getPixels(), bm.rowBytes()); |
| 506 | |
| 507 | return sk_ref_sp(tmp->asTextureProxy()); |
| 508 | } |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 509 | #endif |
| 510 | |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 511 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 512 | static void test_color(skiatest::Reporter* reporter, const SkBitmap& bm, int x, SkColor expected) { |
| 513 | SkColor readback = bm.getColor(x, kDrawnTileSize/2); |
| 514 | REPORTER_ASSERT(reporter, expected == readback); |
| 515 | if (expected != readback) { |
| 516 | SkDebugf("Color mismatch: %x %x\n", expected, readback); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * For the atlasing test we make a DAG that looks like: |
| 522 | * |
| 523 | * RT1 with ops: 0,1,2 RT2 with ops: 3,4,5 RT3 with ops: 6,7,8 |
| 524 | * \ / |
| 525 | * \ / |
| 526 | * RT4 |
| 527 | * We then flush RT4 and expect only ops 0-5 to be atlased together. |
| 528 | * Each op is just a solid colored rect so both the atlas and the final image should appear as: |
| 529 | * R G B C M Y |
| 530 | * with the atlas having width = 6*kAtlasTileSize and height = kAtlasTileSize. |
| 531 | * |
Robert Phillips | 7d79e7b | 2018-02-14 11:09:57 -0500 | [diff] [blame] | 532 | * Note: until partial flushes in MDB lands, the atlas will actually have width= 9*kAtlasTileSize |
| 533 | * and look like: |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 534 | * R G B C M Y K Grey White |
| 535 | */ |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 536 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(OnFlushCallbackTest, reporter, ctxInfo) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 537 | static const int kNumProxies = 3; |
| 538 | |
| 539 | GrContext* context = ctxInfo.grContext(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 540 | auto proxyProvider = context->priv().proxyProvider(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 541 | |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 542 | AtlasObject object(reporter); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 543 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 544 | context->priv().addOnFlushCallbackObject(&object); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 545 | |
| 546 | sk_sp<GrTextureProxy> proxies[kNumProxies]; |
| 547 | for (int i = 0; i < kNumProxies; ++i) { |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 548 | proxies[i] = make_upstream_image(context, &object, i*3, |
| 549 | object.getAtlasProxy(proxyProvider, |
| 550 | context->priv().caps()), |
| 551 | GrColorType::kRGBA_8888); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static const int kFinalWidth = 6*kDrawnTileSize; |
| 555 | static const int kFinalHeight = kDrawnTileSize; |
| 556 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 557 | auto rtc = context->priv().makeDeferredRenderTargetContext( |
| 558 | SkBackingFit::kApprox, kFinalWidth, kFinalHeight, GrColorType::kRGBA_8888, nullptr); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 559 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 560 | rtc->clear(nullptr, SK_PMColor4fWHITE, GrRenderTargetContext::CanClearFullscreen::kYes); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 561 | |
| 562 | // Note that this doesn't include the third texture proxy |
| 563 | for (int i = 0; i < kNumProxies-1; ++i) { |
| 564 | SkRect r = SkRect::MakeXYWH(i*3*kDrawnTileSize, 0, 3*kDrawnTileSize, kDrawnTileSize); |
| 565 | |
| 566 | SkMatrix t = SkMatrix::MakeTrans(-i*3*kDrawnTileSize, 0); |
| 567 | |
| 568 | GrPaint paint; |
Brian Salomon | 078e8fa | 2019-11-22 04:10:18 +0000 | [diff] [blame^] | 569 | auto fp = GrSimpleTextureEffect::Make(std::move(proxies[i]), GrColorType::kRGBA_8888, t); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 570 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 571 | paint.addColorFragmentProcessor(std::move(fp)); |
| 572 | |
| 573 | rtc->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r); |
| 574 | } |
| 575 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 576 | rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo()); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 577 | |
| 578 | SkBitmap readBack; |
| 579 | readBack.allocN32Pixels(kFinalWidth, kFinalHeight); |
| 580 | |
| 581 | SkDEBUGCODE(bool result =) rtc->readPixels(readBack.info(), readBack.getPixels(), |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 582 | readBack.rowBytes(), {0, 0}); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 583 | SkASSERT(result); |
| 584 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 585 | context->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&object); |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 586 | |
| 587 | object.markAsDone(); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 588 | |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 589 | int x = kDrawnTileSize/2; |
| 590 | test_color(reporter, readBack, x, SK_ColorRED); |
| 591 | x += kDrawnTileSize; |
| 592 | test_color(reporter, readBack, x, SK_ColorGREEN); |
| 593 | x += kDrawnTileSize; |
| 594 | test_color(reporter, readBack, x, SK_ColorBLUE); |
| 595 | x += kDrawnTileSize; |
| 596 | test_color(reporter, readBack, x, SK_ColorCYAN); |
| 597 | x += kDrawnTileSize; |
| 598 | test_color(reporter, readBack, x, SK_ColorMAGENTA); |
| 599 | x += kDrawnTileSize; |
| 600 | test_color(reporter, readBack, x, SK_ColorYELLOW); |
| 601 | } |