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 | |
| 15 | void GrCCClipPath::init(GrProxyProvider* proxyProvider, |
| 16 | const SkPath& deviceSpacePath, const SkIRect& accessRect, |
| 17 | int rtWidth, int rtHeight) { |
| 18 | SkASSERT(!this->isInitialized()); |
| 19 | |
| 20 | fAtlasLazyProxy = proxyProvider->createFullyLazyProxy( |
| 21 | [this](GrResourceProvider* resourceProvider) { |
| 22 | if (!resourceProvider) { |
| 23 | return sk_sp<GrTexture>(); |
| 24 | } |
| 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); |
| 32 | return sk_sp<GrTexture>(); |
| 33 | } |
| 34 | |
| 35 | SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin()); |
| 36 | |
| 37 | fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()}; |
| 38 | fAtlasTranslate = {fAtlasOffsetX * fAtlasScale.x(), |
| 39 | fAtlasOffsetY * fAtlasScale.y()}; |
| 40 | SkDEBUGCODE(fHasAtlasTransform = true); |
| 41 | |
| 42 | return sk_ref_sp(textureProxy->priv().peekTexture()); |
| 43 | }, |
| 44 | GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig); |
| 45 | |
| 46 | fDeviceSpacePath = deviceSpacePath; |
| 47 | fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds); |
| 48 | fAccessRect = accessRect; |
| 49 | } |
| 50 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 51 | void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* resourceSpecs) const { |
| 52 | SkASSERT(this->isInitialized()); |
| 53 | |
| 54 | ++resourceSpecs->fNumClipPaths; |
| 55 | resourceSpecs->fParsingPathStats.statPath(fDeviceSpacePath); |
| 56 | |
| 57 | SkIRect ibounds; |
| 58 | if (ibounds.intersect(fAccessRect, fPathDevIBounds)) { |
| 59 | resourceSpecs->fAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height()); |
| 60 | } |
| 61 | } |
| 62 | |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 63 | void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources, |
| 64 | GrOnFlushResourceProvider* onFlushRP) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 65 | SkASSERT(this->isInitialized()); |
| 66 | SkASSERT(!fHasAtlas); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 67 | fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds, |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 68 | &fAtlasOffsetX, &fAtlasOffsetY); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 69 | SkDEBUGCODE(fHasAtlas = true); |
| 70 | } |