• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/ccpr/GrCCClipPath.h"
9 
10 #include "include/gpu/GrTexture.h"
11 #include "src/gpu/GrOnFlushResourceProvider.h"
12 #include "src/gpu/GrProxyProvider.h"
13 #include "src/gpu/GrRenderTarget.h"
14 #include "src/gpu/ccpr/GrCCPerFlushResources.h"
15 
init(const SkPath & deviceSpacePath,const SkIRect & accessRect,GrCCAtlas::CoverageType atlasCoverageType,const GrCaps & caps)16 void GrCCClipPath::init(
17         const SkPath& deviceSpacePath, const SkIRect& accessRect,
18         GrCCAtlas::CoverageType atlasCoverageType, const GrCaps& caps) {
19     SkASSERT(!this->isInitialized());
20 
21     fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy(
22             [this](GrResourceProvider* resourceProvider, GrPixelConfig,
23                    const GrBackendFormat& format, int sampleCount) {
24                 SkASSERT(fHasAtlas);
25                 SkASSERT(!fHasAtlasTransform);
26 
27                 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
28 
29                 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
30                     fAtlasScale = fAtlasTranslate = {0, 0};
31                     SkDEBUGCODE(fHasAtlasTransform = true);
32                     return sk_sp<GrTexture>();
33                 }
34 
35                 sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
36                 SkASSERT(texture);
37                 SkASSERT(texture->backendFormat() == format);
38                 SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount);
39                 SkASSERT(textureProxy->origin() == kTopLeft_GrSurfaceOrigin);
40 
41                 fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
42                 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
43                                     fDevToAtlasOffset.fY * fAtlasScale.y());
44                 SkDEBUGCODE(fHasAtlasTransform = true);
45 
46                 return texture;
47             },
48             atlasCoverageType, caps);
49 
50     fDeviceSpacePath = deviceSpacePath;
51     fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
52     fAccessRect = accessRect;
53 }
54 
accountForOwnPath(GrCCPerFlushResourceSpecs * specs) const55 void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
56     SkASSERT(this->isInitialized());
57 
58     ++specs->fNumClipPaths;
59     specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
60 
61     SkIRect ibounds;
62     if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
63         specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
64     }
65 }
66 
renderPathInAtlas(GrCCPerFlushResources * resources,GrOnFlushResourceProvider * onFlushRP)67 void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
68                                      GrOnFlushResourceProvider* onFlushRP) {
69     SkASSERT(this->isInitialized());
70     SkASSERT(!fHasAtlas);
71     fAtlas = resources->renderDeviceSpacePathInAtlas(
72             fAccessRect, fDeviceSpacePath, fPathDevIBounds, GrFillRuleForSkPath(fDeviceSpacePath),
73             &fDevToAtlasOffset);
74     SkDEBUGCODE(fHasAtlas = true);
75 }
76