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; |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame^] | 29 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 30 | if (!textureProxy || !textureProxy->instantiate(resourceProvider)) { |
| 31 | fAtlasScale = fAtlasTranslate = {0, 0}; |
| 32 | SkDEBUGCODE(fHasAtlasTransform = true); |
Brian Salomon | b6a3a3b | 2019-04-01 12:29:34 -0400 | [diff] [blame] | 33 | return {}; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 34 | } |
| 35 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame^] | 36 | sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture()); |
| 37 | SkASSERT(texture); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 38 | SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin()); |
| 39 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame^] | 40 | fAtlasScale = {1.f / texture->width(), 1.f / texture->height()}; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 41 | fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(), |
| 42 | fDevToAtlasOffset.fY * fAtlasScale.y()); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 43 | SkDEBUGCODE(fHasAtlasTransform = true); |
| 44 | |
Chris Dalton | f91b755 | 2019-04-29 16:21:18 -0600 | [diff] [blame^] | 45 | return std::move(texture); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 46 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 47 | format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, |
| 48 | kAlpha_half_GrPixelConfig, caps); |
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 | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 71 | fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 72 | &fDevToAtlasOffset); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 73 | SkDEBUGCODE(fHasAtlas = true); |
| 74 | } |