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 | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 51 | void GrCCClipPath::placePathInAtlas(GrCCPerFlushResources* resources, |
| 52 | GrOnFlushResourceProvider* onFlushRP) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 53 | SkASSERT(this->isInitialized()); |
| 54 | SkASSERT(!fHasAtlas); |
Chris Dalton | 13235d8 | 2018-05-23 22:51:22 +0000 | [diff] [blame^] | 55 | fAtlas = resources->addDeviceSpacePathToAtlas(*onFlushRP->caps(), fAccessRect, fDeviceSpacePath, |
| 56 | fPathDevIBounds, &fAtlasOffsetX, &fAtlasOffsetY); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 57 | SkDEBUGCODE(fHasAtlas = true); |
| 58 | } |