blob: 922e17063d5203e5fa1f1da846aa71dcfe121602 [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
Chris Daltonc3318f02019-07-19 14:20:53 -060010#include "include/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTexture.h"
12#include "src/gpu/GrOnFlushResourceProvider.h"
13#include "src/gpu/GrProxyProvider.h"
14#include "src/gpu/ccpr/GrCCPerFlushResources.h"
Chris Dalton5ba36ba2018-05-09 01:08:38 -060015
Chris Daltonc3318f02019-07-19 14:20:53 -060016void GrCCClipPath::init(
17 const SkPath& deviceSpacePath, const SkIRect& accessRect,
18 GrCCAtlas::CoverageType atlasCoverageType, const GrCaps& caps) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060019 SkASSERT(!this->isInitialized());
20
Chris Daltonc3318f02019-07-19 14:20:53 -060021 fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy([this](
22 GrResourceProvider* resourceProvider, GrPixelConfig pixelConfig, int sampleCount) {
23 SkASSERT(fHasAtlas);
24 SkASSERT(!fHasAtlasTransform);
Greg Daniel4065d452018-11-16 15:43:41 -050025
Chris Daltonc3318f02019-07-19 14:20:53 -060026 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
Chris Dalton5ba36ba2018-05-09 01:08:38 -060027
Chris Daltonc3318f02019-07-19 14:20:53 -060028 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
29 fAtlasScale = fAtlasTranslate = {0, 0};
30 SkDEBUGCODE(fHasAtlasTransform = true);
31 return sk_sp<GrTexture>();
32 }
Chris Daltonf91b7552019-04-29 16:21:18 -060033
Chris Daltonc3318f02019-07-19 14:20:53 -060034 sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
35 SkASSERT(texture);
36 SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount);
37 SkASSERT(textureProxy->origin() == kTopLeft_GrSurfaceOrigin);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060038
Chris Daltonc3318f02019-07-19 14:20:53 -060039 fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
40 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
41 fDevToAtlasOffset.fY * fAtlasScale.y());
42 SkDEBUGCODE(fHasAtlasTransform = true);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060043
Chris Daltonc3318f02019-07-19 14:20:53 -060044 return texture;
45 }, atlasCoverageType, 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 Daltonc3318f02019-07-19 14:20:53 -060068 fAtlas = resources->renderDeviceSpacePathInAtlas(
69 fAccessRect, fDeviceSpacePath, fPathDevIBounds, GrFillRuleForSkPath(fDeviceSpacePath),
70 &fDevToAtlasOffset);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060071 SkDEBUGCODE(fHasAtlas = true);
72}