blob: 4c82fb13d0dfe0cf8e23f47fc227e4ef27508265 [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
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;
29 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
30 fAtlasScale = fAtlasTranslate = {0, 0};
31 SkDEBUGCODE(fHasAtlasTransform = true);
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040032 return {};
Chris Dalton5ba36ba2018-05-09 01:08:38 -060033 }
34
35 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
36
37 fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()};
Chris Dalton9414c962018-06-14 10:14:50 -060038 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
39 fDevToAtlasOffset.fY * fAtlasScale.y());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060040 SkDEBUGCODE(fHasAtlasTransform = true);
41
Brian Salomonfd98c2c2018-07-31 17:25:29 -040042 return sk_ref_sp(textureProxy->peekTexture());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060043 },
Greg Daniel4065d452018-11-16 15:43:41 -050044 format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin,
45 kAlpha_half_GrPixelConfig, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060046
47 fDeviceSpacePath = deviceSpacePath;
48 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
49 fAccessRect = accessRect;
50}
51
Chris Dalton4da70192018-06-18 09:51:36 -060052void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
Chris Dalton42c21152018-06-13 15:28:19 -060053 SkASSERT(this->isInitialized());
54
Chris Dalton4da70192018-06-18 09:51:36 -060055 ++specs->fNumClipPaths;
Chris Dalton09a7bb22018-08-31 19:53:15 +080056 specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
Chris Dalton42c21152018-06-13 15:28:19 -060057
58 SkIRect ibounds;
59 if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
Chris Dalton4da70192018-06-18 09:51:36 -060060 specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
Chris Dalton42c21152018-06-13 15:28:19 -060061 }
62}
63
Chris Daltondaef06a2018-05-23 17:11:09 -060064void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
65 GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060066 SkASSERT(this->isInitialized());
67 SkASSERT(!fHasAtlas);
Chris Dalton42c21152018-06-13 15:28:19 -060068 fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
Chris Dalton9414c962018-06-14 10:14:50 -060069 &fDevToAtlasOffset);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060070 SkDEBUGCODE(fHasAtlas = true);
71}