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