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
init(const SkPath & deviceSpacePath,const SkIRect & accessRect,int rtWidth,int rtHeight,const GrCaps & caps)15 void GrCCClipPath::init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth,
16 int rtHeight, const GrCaps& caps) {
17 SkASSERT(!this->isInitialized());
18
19 const GrBackendFormat format = caps.getBackendFormatFromGrColorType(GrColorType::kAlpha_F16,
20 GrSRGBEncoded::kNo);
21
22 fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
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()};
40 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
41 fDevToAtlasOffset.fY * fAtlasScale.y());
42 SkDEBUGCODE(fHasAtlasTransform = true);
43
44 return sk_ref_sp(textureProxy->peekTexture());
45 },
46 format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin,
47 kAlpha_half_GrPixelConfig, caps);
48
49 fDeviceSpacePath = deviceSpacePath;
50 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
51 fAccessRect = accessRect;
52 }
53
accountForOwnPath(GrCCPerFlushResourceSpecs * specs) const54 void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
55 SkASSERT(this->isInitialized());
56
57 ++specs->fNumClipPaths;
58 specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
59
60 SkIRect ibounds;
61 if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
62 specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
63 }
64 }
65
renderPathInAtlas(GrCCPerFlushResources * resources,GrOnFlushResourceProvider * onFlushRP)66 void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
67 GrOnFlushResourceProvider* onFlushRP) {
68 SkASSERT(this->isInitialized());
69 SkASSERT(!fHasAtlas);
70 fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
71 &fDevToAtlasOffset);
72 SkDEBUGCODE(fHasAtlas = true);
73 }
74