Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [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 "src/gpu/ccpr/GrCCAtlas.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkIPoint16.h" |
| 12 | #include "src/core/SkMakeUnique.h" |
| 13 | #include "src/core/SkMathPriv.h" |
| 14 | #include "src/gpu/GrCaps.h" |
| 15 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 16 | #include "src/gpu/GrProxyProvider.h" |
| 17 | #include "src/gpu/GrRectanizer_skyline.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/ccpr/GrCCPathCache.h" |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 22 | #include <atomic> |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 23 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 24 | class GrCCAtlas::Node { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 25 | public: |
| 26 | Node(std::unique_ptr<Node> previous, int l, int t, int r, int b) |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 27 | : fPrevious(std::move(previous)), fX(l), fY(t), fRectanizer(r - l, b - t) {} |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 28 | |
| 29 | Node* previous() const { return fPrevious.get(); } |
| 30 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 31 | bool addRect(int w, int h, SkIPoint16* loc, int maxAtlasSize) { |
| 32 | // Pad all paths except those that are expected to take up an entire physical texture. |
| 33 | if (w < maxAtlasSize) { |
| 34 | w = SkTMin(w + kPadding, maxAtlasSize); |
| 35 | } |
| 36 | if (h < maxAtlasSize) { |
| 37 | h = SkTMin(h + kPadding, maxAtlasSize); |
| 38 | } |
| 39 | if (!fRectanizer.addRect(w, h, loc)) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 40 | return false; |
| 41 | } |
| 42 | loc->fX += fX; |
| 43 | loc->fY += fY; |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | private: |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 48 | const std::unique_ptr<Node> fPrevious; |
| 49 | const int fX, fY; |
| 50 | GrRectanizerSkyline fRectanizer; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 51 | }; |
| 52 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> GrCCAtlas::MakeLazyAtlasProxy(const LazyInstantiateAtlasCallback& callback, |
| 54 | CoverageType coverageType, |
| 55 | const GrCaps& caps, |
| 56 | GrSurfaceProxy::UseAllocator useAllocator) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 57 | GrPixelConfig pixelConfig; |
| 58 | int sampleCount; |
| 59 | |
Brian Salomon | 2af3e70 | 2019-08-11 19:10:31 -0400 | [diff] [blame] | 60 | auto colorType = CoverageTypeToColorType(coverageType); |
| 61 | GrBackendFormat format = caps.getDefaultBackendFormat(colorType, GrRenderable::kYes); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 62 | switch (coverageType) { |
| 63 | case CoverageType::kFP16_CoverageCount: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 64 | pixelConfig = kAlpha_half_GrPixelConfig; |
| 65 | sampleCount = 1; |
| 66 | break; |
| 67 | case CoverageType::kA8_Multisample: |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 68 | SkASSERT(caps.internalMultisampleCount(format) > 1); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 69 | pixelConfig = kAlpha_8_GrPixelConfig; |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 70 | sampleCount = (caps.mixedSamplesSupport()) ? 1 : caps.internalMultisampleCount(format); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 71 | break; |
| 72 | case CoverageType::kA8_LiteralCoverage: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 73 | pixelConfig = kAlpha_8_GrPixelConfig; |
| 74 | sampleCount = 1; |
| 75 | break; |
| 76 | } |
| 77 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 78 | auto instantiate = [cb = std::move(callback), pixelConfig, format, |
| 79 | sampleCount](GrResourceProvider* rp) { |
| 80 | return cb(rp, pixelConfig, format, sampleCount); |
| 81 | }; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 82 | sk_sp<GrTextureProxy> proxy = GrProxyProvider::MakeFullyLazyProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 83 | std::move(instantiate), format, GrRenderable::kYes, sampleCount, GrProtected::kNo, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 84 | kTextureOrigin, pixelConfig, caps, useAllocator); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 85 | |
| 86 | return proxy; |
| 87 | } |
| 88 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 89 | GrCCAtlas::GrCCAtlas(CoverageType coverageType, const Specs& specs, const GrCaps& caps) |
| 90 | : fCoverageType(coverageType) |
| 91 | , fMaxTextureSize(SkTMax(SkTMax(specs.fMinHeight, specs.fMinWidth), |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 92 | specs.fMaxPreferredTextureSize)) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 93 | // Caller should have cropped any paths to the destination render target instead of asking for |
| 94 | // an atlas larger than maxRenderTargetSize. |
| 95 | SkASSERT(fMaxTextureSize <= caps.maxTextureSize()); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 96 | SkASSERT(specs.fMaxPreferredTextureSize > 0); |
| 97 | |
| 98 | // Begin with the first pow2 dimensions whose area is theoretically large enough to contain the |
| 99 | // pending paths, favoring height over width if necessary. |
| 100 | int log2area = SkNextLog2(SkTMax(specs.fApproxNumPixels, 1)); |
| 101 | fHeight = 1 << ((log2area + 1) / 2); |
| 102 | fWidth = 1 << (log2area / 2); |
| 103 | |
| 104 | fWidth = SkTClamp(fWidth, specs.fMinTextureSize, specs.fMaxPreferredTextureSize); |
| 105 | fHeight = SkTClamp(fHeight, specs.fMinTextureSize, specs.fMaxPreferredTextureSize); |
| 106 | |
| 107 | if (fWidth < specs.fMinWidth || fHeight < specs.fMinHeight) { |
| 108 | // They want to stuff a particularly large path into the atlas. Just punt and go with their |
| 109 | // min width and height. The atlas will grow as needed. |
| 110 | fWidth = SkTMin(specs.fMinWidth + kPadding, fMaxTextureSize); |
| 111 | fHeight = SkTMin(specs.fMinHeight + kPadding, fMaxTextureSize); |
| 112 | } |
| 113 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 114 | fTopNode = skstd::make_unique<Node>(nullptr, 0, 0, fWidth, fHeight); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 115 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 116 | fTextureProxy = MakeLazyAtlasProxy( |
| 117 | [this](GrResourceProvider* resourceProvider, GrPixelConfig pixelConfig, |
| 118 | const GrBackendFormat& format, int sampleCount) { |
| 119 | if (!fBackingTexture) { |
| 120 | GrSurfaceDesc desc; |
| 121 | desc.fWidth = fWidth; |
| 122 | desc.fHeight = fHeight; |
| 123 | desc.fConfig = pixelConfig; |
| 124 | fBackingTexture = resourceProvider->createTexture( |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame^] | 125 | desc, format, GrRenderable::kYes, sampleCount, GrMipMapped::kNo, |
| 126 | SkBudgeted::kYes, GrProtected::kNo); |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 127 | } |
| 128 | return fBackingTexture; |
| 129 | }, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 130 | fCoverageType, caps, GrSurfaceProxy::UseAllocator::kNo); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 131 | } |
| 132 | |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 133 | GrCCAtlas::~GrCCAtlas() { |
| 134 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 135 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 136 | bool GrCCAtlas::addRect(const SkIRect& devIBounds, SkIVector* offset) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 137 | // This can't be called anymore once makeRenderTargetContext() has been called. |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 138 | SkASSERT(!fTextureProxy->isInstantiated()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 139 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 140 | SkIPoint16 location; |
| 141 | if (!this->internalPlaceRect(devIBounds.width(), devIBounds.height(), &location)) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 142 | return false; |
| 143 | } |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 144 | offset->set(location.x() - devIBounds.left(), location.y() - devIBounds.top()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 145 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 146 | fDrawBounds.fWidth = SkTMax(fDrawBounds.width(), location.x() + devIBounds.width()); |
| 147 | fDrawBounds.fHeight = SkTMax(fDrawBounds.height(), location.y() + devIBounds.height()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 148 | return true; |
| 149 | } |
| 150 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 151 | bool GrCCAtlas::internalPlaceRect(int w, int h, SkIPoint16* loc) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 152 | for (Node* node = fTopNode.get(); node; node = node->previous()) { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 153 | if (node->addRect(w, h, loc, fMaxTextureSize)) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 154 | return true; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // The rect didn't fit. Grow the atlas and try again. |
| 159 | do { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 160 | if (fWidth == fMaxTextureSize && fHeight == fMaxTextureSize) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 161 | return false; |
| 162 | } |
| 163 | if (fHeight <= fWidth) { |
| 164 | int top = fHeight; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 165 | fHeight = SkTMin(fHeight * 2, fMaxTextureSize); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 166 | fTopNode = skstd::make_unique<Node>(std::move(fTopNode), 0, top, fWidth, fHeight); |
| 167 | } else { |
| 168 | int left = fWidth; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 169 | fWidth = SkTMin(fWidth * 2, fMaxTextureSize); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 170 | fTopNode = skstd::make_unique<Node>(std::move(fTopNode), left, 0, fWidth, fHeight); |
| 171 | } |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 172 | } while (!fTopNode->addRect(w, h, loc, fMaxTextureSize)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 173 | |
| 174 | return true; |
| 175 | } |
| 176 | |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 177 | void GrCCAtlas::setFillBatchID(int id) { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 178 | // This can't be called anymore once makeRenderTargetContext() has been called. |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 179 | SkASSERT(!fTextureProxy->isInstantiated()); |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 180 | fFillBatchID = id; |
| 181 | } |
| 182 | |
| 183 | void GrCCAtlas::setStrokeBatchID(int id) { |
| 184 | // This can't be called anymore once makeRenderTargetContext() has been called. |
| 185 | SkASSERT(!fTextureProxy->isInstantiated()); |
| 186 | fStrokeBatchID = id; |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 187 | } |
| 188 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 189 | void GrCCAtlas::setEndStencilResolveInstance(int idx) { |
| 190 | // This can't be called anymore once makeRenderTargetContext() has been called. |
| 191 | SkASSERT(!fTextureProxy->isInstantiated()); |
| 192 | fEndStencilResolveInstance = idx; |
| 193 | } |
| 194 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 195 | static uint32_t next_atlas_unique_id() { |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 196 | static std::atomic<uint32_t> nextID; |
| 197 | return nextID++; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 198 | } |
| 199 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 200 | sk_sp<GrCCCachedAtlas> GrCCAtlas::refOrMakeCachedAtlas(GrOnFlushResourceProvider* onFlushRP) { |
| 201 | if (!fCachedAtlas) { |
| 202 | static const GrUniqueKey::Domain kAtlasDomain = GrUniqueKey::GenerateDomain(); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 203 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 204 | GrUniqueKey atlasUniqueKey; |
| 205 | GrUniqueKey::Builder builder(&atlasUniqueKey, kAtlasDomain, 1, "CCPR Atlas"); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 206 | builder[0] = next_atlas_unique_id(); |
| 207 | builder.finish(); |
| 208 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 209 | onFlushRP->assignUniqueKeyToProxy(atlasUniqueKey, fTextureProxy.get()); |
Chris Dalton | d6fa454 | 2019-01-04 13:23:51 -0700 | [diff] [blame] | 210 | |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 211 | fCachedAtlas = sk_make_sp<GrCCCachedAtlas>(fCoverageType, atlasUniqueKey, fTextureProxy); |
Chris Dalton | 2e825a3 | 2019-01-04 22:14:27 +0000 | [diff] [blame] | 212 | } |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 213 | |
| 214 | SkASSERT(fCachedAtlas->coverageType() == fCoverageType); |
| 215 | SkASSERT(fCachedAtlas->getOnFlushProxy() == fTextureProxy.get()); |
| 216 | return fCachedAtlas; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 217 | } |
| 218 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 219 | std::unique_ptr<GrRenderTargetContext> GrCCAtlas::makeRenderTargetContext( |
Chris Dalton | afde18f | 2018-06-22 12:44:19 -0600 | [diff] [blame] | 220 | GrOnFlushResourceProvider* onFlushRP, sk_sp<GrTexture> backingTexture) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 221 | SkASSERT(!fTextureProxy->isInstantiated()); // This method should only be called once. |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 222 | // Caller should have cropped any paths to the destination render target instead of asking for |
| 223 | // an atlas larger than maxRenderTargetSize. |
| 224 | SkASSERT(SkTMax(fHeight, fWidth) <= fMaxTextureSize); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 225 | SkASSERT(fMaxTextureSize <= onFlushRP->caps()->maxRenderTargetSize()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 226 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame] | 227 | // Finalize the content size of our proxy. The GPU can potentially make optimizations if it |
| 228 | // knows we only intend to write out a smaller sub-rectangle of the backing texture. |
| 229 | fTextureProxy->priv().setLazySize(fDrawBounds.width(), fDrawBounds.height()); |
| 230 | |
Chris Dalton | afde18f | 2018-06-22 12:44:19 -0600 | [diff] [blame] | 231 | if (backingTexture) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 232 | #ifdef SK_DEBUG |
| 233 | auto backingRT = backingTexture->asRenderTarget(); |
| 234 | SkASSERT(backingRT); |
| 235 | SkASSERT(backingRT->config() == fTextureProxy->config()); |
| 236 | SkASSERT(backingRT->numSamples() == fTextureProxy->asRenderTargetProxy()->numSamples()); |
| 237 | SkASSERT(backingRT->width() == fWidth); |
| 238 | SkASSERT(backingRT->height() == fHeight); |
| 239 | #endif |
Chris Dalton | afde18f | 2018-06-22 12:44:19 -0600 | [diff] [blame] | 240 | fBackingTexture = std::move(backingTexture); |
| 241 | } |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 242 | auto colorType = (CoverageType::kFP16_CoverageCount == fCoverageType) |
| 243 | ? GrColorType::kAlpha_F16 : GrColorType::kAlpha_8; |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 244 | auto rtc = onFlushRP->makeRenderTargetContext(fTextureProxy, colorType, nullptr, nullptr); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 245 | if (!rtc) { |
| 246 | SkDebugf("WARNING: failed to allocate a %ix%i atlas. Some paths will not be drawn.\n", |
| 247 | fWidth, fHeight); |
| 248 | return nullptr; |
| 249 | } |
| 250 | |
| 251 | SkIRect clearRect = SkIRect::MakeSize(fDrawBounds); |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 252 | rtc->clear(&clearRect, SK_PMColor4fTRANSPARENT, |
| 253 | GrRenderTargetContext::CanClearFullscreen::kYes); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 254 | return rtc; |
| 255 | } |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 256 | |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 257 | GrCCAtlas* GrCCAtlasStack::addRect(const SkIRect& devIBounds, SkIVector* devToAtlasOffset) { |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 258 | GrCCAtlas* retiredAtlas = nullptr; |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 259 | if (fAtlases.empty() || !fAtlases.back().addRect(devIBounds, devToAtlasOffset)) { |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 260 | // The retired atlas is out of room and can't grow any bigger. |
| 261 | retiredAtlas = !fAtlases.empty() ? &fAtlases.back() : nullptr; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 262 | fAtlases.emplace_back(fCoverageType, fSpecs, *fCaps); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 263 | SkASSERT(devIBounds.width() <= fSpecs.fMinWidth); |
| 264 | SkASSERT(devIBounds.height() <= fSpecs.fMinHeight); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 265 | SkAssertResult(fAtlases.back().addRect(devIBounds, devToAtlasOffset)); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 266 | } |
| 267 | return retiredAtlas; |
| 268 | } |