/src/skia/src/gpu/graphite/AtlasProvider.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2023 Google LLC |
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 "src/gpu/graphite/AtlasProvider.h" |
9 | | |
10 | | #include "include/gpu/graphite/Recorder.h" |
11 | | #include "src/gpu/graphite/ComputePathAtlas.h" |
12 | | #include "src/gpu/graphite/DrawContext.h" |
13 | | #include "src/gpu/graphite/Log.h" |
14 | | #include "src/gpu/graphite/RasterPathAtlas.h" |
15 | | #include "src/gpu/graphite/RecorderPriv.h" |
16 | | #include "src/gpu/graphite/RendererProvider.h" |
17 | | #include "src/gpu/graphite/TextureProxy.h" |
18 | | #include "src/gpu/graphite/text/TextAtlasManager.h" |
19 | | |
20 | | namespace skgpu::graphite { |
21 | | |
22 | 0 | AtlasProvider::PathAtlasFlagsBitMask AtlasProvider::QueryPathAtlasSupport(const Caps* caps) { |
23 | | // The raster-backend path atlas is always supported. |
24 | 0 | PathAtlasFlagsBitMask flags = PathAtlasFlags::kRaster; |
25 | 0 | if (RendererProvider::IsVelloRendererSupported(caps)) { |
26 | 0 | flags |= PathAtlasFlags::kCompute; |
27 | 0 | } |
28 | 0 | return flags; |
29 | 0 | } |
30 | | |
31 | | AtlasProvider::AtlasProvider(Recorder* recorder) |
32 | | : fTextAtlasManager(std::make_unique<TextAtlasManager>(recorder)) |
33 | | , fRasterPathAtlas(std::make_unique<RasterPathAtlas>(recorder)) |
34 | 0 | , fPathAtlasFlags(QueryPathAtlasSupport(recorder->priv().caps())) {} |
35 | | |
36 | 0 | std::unique_ptr<ComputePathAtlas> AtlasProvider::createComputePathAtlas(Recorder* recorder) const { |
37 | 0 | if (this->isAvailable(PathAtlasFlags::kCompute)) { |
38 | 0 | return ComputePathAtlas::CreateDefault(recorder); |
39 | 0 | } |
40 | 0 | return nullptr; |
41 | 0 | } |
42 | | |
43 | 0 | RasterPathAtlas* AtlasProvider::getRasterPathAtlas() const { |
44 | 0 | return fRasterPathAtlas.get(); |
45 | 0 | } |
46 | | |
47 | | sk_sp<TextureProxy> AtlasProvider::getAtlasTexture(Recorder* recorder, |
48 | | uint16_t width, |
49 | | uint16_t height, |
50 | | SkColorType colorType, |
51 | | uint16_t identifier, |
52 | 0 | bool requireStorageUsage) { |
53 | 0 | uint64_t key = static_cast<uint64_t>(width) << 48 | |
54 | 0 | static_cast<uint64_t>(height) << 32 | |
55 | 0 | static_cast<uint64_t>(colorType) << 16 | |
56 | 0 | static_cast<uint64_t>(identifier); |
57 | 0 | auto iter = fTexturePool.find(key); |
58 | 0 | if (iter != fTexturePool.end()) { |
59 | 0 | return iter->second; |
60 | 0 | } |
61 | | |
62 | | // We currently only make the distinction between a storage texture (written by a |
63 | | // compute pass) and a plain sampleable texture (written via upload) that won't be |
64 | | // used as a render attachment. |
65 | 0 | const Caps* caps = recorder->priv().caps(); |
66 | 0 | auto textureInfo = requireStorageUsage |
67 | 0 | ? caps->getDefaultStorageTextureInfo(colorType) |
68 | 0 | : caps->getDefaultSampledTextureInfo(colorType, |
69 | 0 | Mipmapped::kNo, |
70 | 0 | recorder->priv().isProtected(), |
71 | 0 | Renderable::kNo); |
72 | 0 | sk_sp<TextureProxy> proxy = TextureProxy::Make(caps, |
73 | 0 | recorder->priv().resourceProvider(), |
74 | 0 | SkISize::Make((int32_t) width, (int32_t) height), |
75 | 0 | textureInfo, |
76 | 0 | "AtlasProviderTexture", |
77 | 0 | Budgeted::kYes); |
78 | 0 | if (!proxy) { |
79 | 0 | return nullptr; |
80 | 0 | } |
81 | | |
82 | 0 | fTexturePool[key] = proxy; |
83 | 0 | return proxy; |
84 | 0 | } |
85 | | |
86 | 0 | void AtlasProvider::clearTexturePool() { |
87 | 0 | fTexturePool.clear(); |
88 | 0 | } |
89 | | |
90 | 0 | void AtlasProvider::recordUploads(DrawContext* dc) { |
91 | 0 | if (!fTextAtlasManager->recordUploads(dc)) { |
92 | 0 | SKGPU_LOG_E("TextAtlasManager uploads have failed -- may see invalid results."); |
93 | 0 | } |
94 | |
|
95 | 0 | if (fRasterPathAtlas) { |
96 | 0 | fRasterPathAtlas->recordUploads(dc); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | 0 | void AtlasProvider::postFlush() { |
101 | 0 | fTextAtlasManager->postFlush(); |
102 | 0 | if (fRasterPathAtlas) { |
103 | 0 | fRasterPathAtlas->postFlush(); |
104 | 0 | } |
105 | 0 | } |
106 | | |
107 | | } // namespace skgpu::graphite |