blob: 77de299741c8f8db6a0570de538dbaac378d7591 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/GrCCClipPath.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -06009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/gpu/GrTexture.h"
11#include "src/gpu/GrOnFlushResourceProvider.h"
12#include "src/gpu/GrProxyProvider.h"
13#include "src/gpu/ccpr/GrCCPerFlushResources.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060014
Chris Dalton4c458b12018-06-16 17:22:59 -060015void GrCCClipPath::init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth,
16 int rtHeight, const GrCaps& caps) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060017 SkASSERT(!this->isInitialized());
18
Greg Daniel4065d452018-11-16 15:43:41 -050019 const GrBackendFormat format = caps.getBackendFormatFromGrColorType(GrColorType::kAlpha_F16,
20 GrSRGBEncoded::kNo);
21
Chris Dalton4c458b12018-06-16 17:22:59 -060022 fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040023 [this](GrResourceProvider* resourceProvider)
24 -> GrSurfaceProxy::LazyInstantiationResult {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060025 SkASSERT(fHasAtlas);
26 SkASSERT(!fHasAtlasTransform);
27
28 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
Chris Daltonf91b7552019-04-29 16:21:18 -060029
Chris Dalton5ba36ba2018-05-09 01:08:38 -060030 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
31 fAtlasScale = fAtlasTranslate = {0, 0};
32 SkDEBUGCODE(fHasAtlasTransform = true);
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040033 return {};
Chris Dalton5ba36ba2018-05-09 01:08:38 -060034 }
35
Chris Daltonf91b7552019-04-29 16:21:18 -060036 sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
37 SkASSERT(texture);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060038 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
39
Chris Daltonf91b7552019-04-29 16:21:18 -060040 fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
Chris Dalton9414c962018-06-14 10:14:50 -060041 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
42 fDevToAtlasOffset.fY * fAtlasScale.y());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060043 SkDEBUGCODE(fHasAtlasTransform = true);
44
Chris Daltonf91b7552019-04-29 16:21:18 -060045 return std::move(texture);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060046 },
Greg Daniel4065d452018-11-16 15:43:41 -050047 format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin,
48 kAlpha_half_GrPixelConfig, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060049
50 fDeviceSpacePath = deviceSpacePath;
51 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
52 fAccessRect = accessRect;
53}
54
Chris Dalton4da70192018-06-18 09:51:36 -060055void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
Chris Dalton42c21152018-06-13 15:28:19 -060056 SkASSERT(this->isInitialized());
57
Chris Dalton4da70192018-06-18 09:51:36 -060058 ++specs->fNumClipPaths;
Chris Dalton09a7bb22018-08-31 19:53:15 +080059 specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
Chris Dalton42c21152018-06-13 15:28:19 -060060
61 SkIRect ibounds;
62 if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
Chris Dalton4da70192018-06-18 09:51:36 -060063 specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
Chris Dalton42c21152018-06-13 15:28:19 -060064 }
65}
66
Chris Daltondaef06a2018-05-23 17:11:09 -060067void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
68 GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060069 SkASSERT(this->isInitialized());
70 SkASSERT(!fHasAtlas);
Chris Dalton42c21152018-06-13 15:28:19 -060071 fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
Chris Dalton9414c962018-06-14 10:14:50 -060072 &fDevToAtlasOffset);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060073 SkDEBUGCODE(fHasAtlas = true);
74}