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