blob: 9b8a73752c3bdfd93f9c5eea6376f7eb08c94568 [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
15void GrCCClipPath::init(GrProxyProvider* proxyProvider,
16 const SkPath& deviceSpacePath, const SkIRect& accessRect,
17 int rtWidth, int rtHeight) {
18 SkASSERT(!this->isInitialized());
19
20 fAtlasLazyProxy = proxyProvider->createFullyLazyProxy(
21 [this](GrResourceProvider* resourceProvider) {
22 if (!resourceProvider) {
23 return sk_sp<GrTexture>();
24 }
25 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);
32 return sk_sp<GrTexture>();
33 }
34
35 SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
36
37 fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()};
38 fAtlasTranslate = {fAtlasOffsetX * fAtlasScale.x(),
39 fAtlasOffsetY * fAtlasScale.y()};
40 SkDEBUGCODE(fHasAtlasTransform = true);
41
42 return sk_ref_sp(textureProxy->priv().peekTexture());
43 },
44 GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig);
45
46 fDeviceSpacePath = deviceSpacePath;
47 fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
48 fAccessRect = accessRect;
49}
50
Chris Dalton5dd3fcc2018-05-22 18:58:22 -060051void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
52 GrOnFlushResourceProvider* onFlushRP) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -060053 SkASSERT(this->isInitialized());
54 SkASSERT(!fHasAtlas);
Chris Dalton5dd3fcc2018-05-22 18:58:22 -060055 fAtlas = resources->renderDeviceSpacePathInAtlas(*onFlushRP->caps(), fAccessRect,
56 fDeviceSpacePath, fPathDevIBounds,
57 &fAtlasOffsetX, &fAtlasOffsetY);
Chris Dalton5ba36ba2018-05-09 01:08:38 -060058 SkDEBUGCODE(fHasAtlas = true);
59}