blob: 8b8d8a6f5e0aee29e27dd6fab440bbf33180cdfe [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(
Chris Dalton5ba36ba2018-05-09 01:08:38 -060023 [this](GrResourceProvider* resourceProvider) {
24 if (!resourceProvider) {
25 return sk_sp<GrTexture>();
26 }
27 SkASSERT(fHasAtlas);
28 SkASSERT(!fHasAtlasTransform);
29
30 GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
31 if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
32 fAtlasScale = fAtlasTranslate = {0, 0};
33 SkDEBUGCODE(fHasAtlasTransform = true);
34 return sk_sp<GrTexture>();
35 }
36
37 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
38
39 fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->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
Brian Salomonfd98c2c2018-07-31 17:25:29 -040044 return sk_ref_sp(textureProxy->peekTexture());
Chris Dalton5ba36ba2018-05-09 01:08:38 -060045 },
Greg Daniel4065d452018-11-16 15:43:41 -050046 format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin,
47 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}