Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Ben Wagner | 729a23f | 2019-05-17 16:29:34 -0400 | [diff] [blame] | 8 | #include "src/gpu/ccpr/GrCCClipPath.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrTexture.h" |
| 11 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 12 | #include "src/gpu/GrProxyProvider.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/ccpr/GrCCPerFlushResources.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 15 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 16 | void GrCCClipPath::init( |
| 17 | const SkPath& deviceSpacePath, const SkIRect& accessRect, |
| 18 | GrCCAtlas::CoverageType atlasCoverageType, const GrCaps& caps) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 19 | SkASSERT(!this->isInitialized()); |
| 20 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 21 | fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy( |
| 22 | [this](GrResourceProvider* resourceProvider, GrPixelConfig, |
| 23 | const GrBackendFormat& format, int sampleCount) { |
| 24 | SkASSERT(fHasAtlas); |
| 25 | SkASSERT(!fHasAtlasTransform); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 26 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 27 | GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 28 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 29 | if (!textureProxy || !textureProxy->instantiate(resourceProvider)) { |
| 30 | fAtlasScale = fAtlasTranslate = {0, 0}; |
| 31 | SkDEBUGCODE(fHasAtlasTransform = true); |
| 32 | return sk_sp<GrTexture>(); |
| 33 | } |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame] | 34 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 35 | sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture()); |
| 36 | SkASSERT(texture); |
| 37 | SkASSERT(texture->backendFormat() == format); |
| 38 | SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount); |
| 39 | SkASSERT(textureProxy->origin() == kTopLeft_GrSurfaceOrigin); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 40 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 41 | fAtlasScale = {1.f / texture->width(), 1.f / texture->height()}; |
| 42 | fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(), |
| 43 | fDevToAtlasOffset.fY * fAtlasScale.y()); |
| 44 | SkDEBUGCODE(fHasAtlasTransform = true); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 45 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 46 | return texture; |
| 47 | }, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 48 | atlasCoverageType, caps, GrSurfaceProxy::UseAllocator::kYes); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 49 | |
| 50 | fDeviceSpacePath = deviceSpacePath; |
| 51 | fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds); |
| 52 | fAccessRect = accessRect; |
| 53 | } |
| 54 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 55 | void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 56 | SkASSERT(this->isInitialized()); |
| 57 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 58 | ++specs->fNumClipPaths; |
Chris Dalton | 09a7bb2 | 2018-08-31 19:53:15 +0800 | [diff] [blame] | 59 | specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 60 | |
| 61 | SkIRect ibounds; |
| 62 | if (ibounds.intersect(fAccessRect, fPathDevIBounds)) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 63 | specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height()); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 67 | void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources, |
| 68 | GrOnFlushResourceProvider* onFlushRP) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 69 | SkASSERT(this->isInitialized()); |
| 70 | SkASSERT(!fHasAtlas); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 71 | fAtlas = resources->renderDeviceSpacePathInAtlas( |
| 72 | fAccessRect, fDeviceSpacePath, fPathDevIBounds, GrFillRuleForSkPath(fDeviceSpacePath), |
| 73 | &fDevToAtlasOffset); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 74 | SkDEBUGCODE(fHasAtlas = true); |
| 75 | } |