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