blob: c98865765ea412a95633937eb9cf3616dd46d739 [file] [log] [blame]
Chris Dalton5ba36ba2018-05-09 01:08:38 -06001/*
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
15void 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 Dalton42c21152018-06-13 15:28:19 -060051void 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 Daltondaef06a2018-05-23 17:11:09 -060063void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
64 GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060065 SkASSERT(this->isInitialized());
66 SkASSERT(!fHasAtlas);
Chris Dalton42c21152018-06-13 15:28:19 -060067 fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
Chris Daltondaef06a2018-05-23 17:11:09 -060068 &fAtlasOffsetX, &fAtlasOffsetY);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060069 SkDEBUGCODE(fHasAtlas = true);
70}