blob: 075e2b20addfef0f6fc9119254f60f2e6238b76b [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
Ben Wagner729a23f2019-05-17 16:29:34 -04008#include "src/gpu/ccpr/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 Daniele877dce2019-07-11 10:52:43 -040019 const GrBackendFormat format = caps.getBackendFormatFromColorType(GrColorType::kAlpha_F16);
Greg Daniel4065d452018-11-16 15:43:41 -050020
Chris Dalton4c458b12018-06-16 17:22:59 -060021 fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
Brian Salomonb6a3a3b2019-04-01 12:29:34 -040022 [this](GrResourceProvider* resourceProvider)
23 -> GrSurfaceProxy::LazyInstantiationResult {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060024 SkASSERT(fHasAtlas);
25 SkASSERT(!fHasAtlasTransform);
26
27 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
Chris Daltonf91b7552019-04-29 16:21:18 -060028
Chris Dalton5ba36ba2018-05-09 01:08:38 -060029 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
Chris Daltonf91b7552019-04-29 16:21:18 -060035 sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
36 SkASSERT(texture);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060037 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
38
Chris Daltonf91b7552019-04-29 16:21:18 -060039 fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
Chris Dalton9414c962018-06-14 10:14:50 -060040 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
41 fDevToAtlasOffset.fY * fAtlasScale.y());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060042 SkDEBUGCODE(fHasAtlasTransform = true);
43
Chris Daltonf91b7552019-04-29 16:21:18 -060044 return std::move(texture);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060045 },
Brian Salomone8a766b2019-07-19 14:24:36 -040046 format, GrProxyProvider::Renderable::kYes, GrProtected::kNo, kTopLeft_GrSurfaceOrigin,
Greg Daniel4065d452018-11-16 15:43:41 -050047 kAlpha_half_GrPixelConfig, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060048
49 fDeviceSpacePath = deviceSpacePath;
50 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
51 fAccessRect = accessRect;
52}
53
Chris Dalton4da70192018-06-18 09:51:36 -060054void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
Chris Dalton42c21152018-06-13 15:28:19 -060055 SkASSERT(this->isInitialized());
56
Chris Dalton4da70192018-06-18 09:51:36 -060057 ++specs->fNumClipPaths;
Chris Dalton09a7bb22018-08-31 19:53:15 +080058 specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
Chris Dalton42c21152018-06-13 15:28:19 -060059
60 SkIRect ibounds;
61 if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
Chris Dalton4da70192018-06-18 09:51:36 -060062 specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
Chris Dalton42c21152018-06-13 15:28:19 -060063 }
64}
65
Chris Daltondaef06a2018-05-23 17:11:09 -060066void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
67 GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060068 SkASSERT(this->isInitialized());
69 SkASSERT(!fHasAtlas);
Chris Dalton42c21152018-06-13 15:28:19 -060070 fAtlas = resources->renderDeviceSpacePathInAtlas(fAccessRect, fDeviceSpacePath, fPathDevIBounds,
Chris Dalton9414c962018-06-14 10:14:50 -060071 &fDevToAtlasOffset);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060072 SkDEBUGCODE(fHasAtlas = true);
73}