blob: d70b4f7faaed364debf2cc22b90ce9579274369c [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
Chris Dalton4c458b12018-06-16 17:22:59 -060019 fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
Chris Dalton5ba36ba2018-05-09 01:08:38 -060020 [this](GrResourceProvider* resourceProvider) {
21 if (!resourceProvider) {
22 return sk_sp<GrTexture>();
23 }
24 SkASSERT(fHasAtlas);
25 SkASSERT(!fHasAtlasTransform);
26
27 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
28 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
29 fAtlasScale = fAtlasTranslate = {0, 0};
30 SkDEBUGCODE(fHasAtlasTransform = true);
31 return sk_sp<GrTexture>();
32 }
33
34 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
35
36 fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()};
Chris Dalton9414c962018-06-14 10:14:50 -060037 fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
38 fDevToAtlasOffset.fY * fAtlasScale.y());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060039 SkDEBUGCODE(fHasAtlasTransform = true);
40
Brian Salomonfd98c2c2018-07-31 17:25:29 -040041 return sk_ref_sp(textureProxy->peekTexture());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060042 },
Greg Danield7157b22018-11-14 15:28:10 +000043 GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig,
44 caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060045
46 fDeviceSpacePath = deviceSpacePath;
47 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
48 fAccessRect = accessRect;
49}
50
Chris Dalton4da70192018-06-18 09:51:36 -060051void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
Chris Dalton42c21152018-06-13 15:28:19 -060052 SkASSERT(this->isInitialized());
53
Chris Dalton4da70192018-06-18 09:51:36 -060054 ++specs->fNumClipPaths;
Chris Dalton09a7bb22018-08-31 19:53:15 +080055 specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
Chris Dalton42c21152018-06-13 15:28:19 -060056
57 SkIRect ibounds;
58 if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
Chris Dalton4da70192018-06-18 09:51:36 -060059 specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
Chris Dalton42c21152018-06-13 15:28:19 -060060 }
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 Dalton9414c962018-06-14 10:14:50 -060068 &fDevToAtlasOffset);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060069 SkDEBUGCODE(fHasAtlas = true);
70}