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 | |
| 8 | #include "GrCCClipPath.h" |
| 9 | |
| 10 | #include "GrOnFlushResourceProvider.h" |
| 11 | #include "GrProxyProvider.h" |
| 12 | #include "GrTexture.h" |
| 13 | #include "ccpr/GrCCPerFlushResources.h" |
| 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( |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 23 | [this](GrResourceProvider* resourceProvider) { |
| 24 | if (!resourceProvider) { |
| 25 | return sk_sp<GrTexture>(); |
| 26 | } |
| 27 | SkASSERT(fHasAtlas); |
| 28 | SkASSERT(!fHasAtlasTransform); |
| 29 | |
| 30 | GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr; |
| 31 | if (!textureProxy || !textureProxy->instantiate(resourceProvider)) { |
| 32 | fAtlasScale = fAtlasTranslate = {0, 0}; |
| 33 | SkDEBUGCODE(fHasAtlasTransform = true); |
| 34 | return sk_sp<GrTexture>(); |
| 35 | } |
| 36 | |
| 37 | SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin()); |
| 38 | |
| 39 | fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->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 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 44 | return sk_ref_sp(textureProxy->peekTexture()); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 45 | }, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 46 | format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, |
| 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 | } |