• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
QueryPathAtlasSupport(const Caps * caps)22 AtlasProvider::PathAtlasFlagsBitMask AtlasProvider::QueryPathAtlasSupport(const Caps* caps) {
23     // The raster-backend path atlas is always supported.
24     PathAtlasFlagsBitMask flags = PathAtlasFlags::kRaster;
25     if (RendererProvider::IsVelloRendererSupported(caps)) {
26         flags |= PathAtlasFlags::kCompute;
27     }
28     return flags;
29 }
30 
AtlasProvider(Recorder * recorder)31 AtlasProvider::AtlasProvider(Recorder* recorder)
32         : fTextAtlasManager(std::make_unique<TextAtlasManager>(recorder))
33         , fRasterPathAtlas(std::make_unique<RasterPathAtlas>(recorder))
34         , fPathAtlasFlags(QueryPathAtlasSupport(recorder->priv().caps())) {}
35 
createComputePathAtlas(Recorder * recorder) const36 std::unique_ptr<ComputePathAtlas> AtlasProvider::createComputePathAtlas(Recorder* recorder) const {
37     if (this->isAvailable(PathAtlasFlags::kCompute)) {
38         return ComputePathAtlas::CreateDefault(recorder);
39     }
40     return nullptr;
41 }
42 
getRasterPathAtlas() const43 RasterPathAtlas* AtlasProvider::getRasterPathAtlas() const {
44     return fRasterPathAtlas.get();
45 }
46 
getAtlasTexture(Recorder * recorder,uint16_t width,uint16_t height,SkColorType colorType,uint16_t identifier,bool requireStorageUsage)47 sk_sp<TextureProxy> AtlasProvider::getAtlasTexture(Recorder* recorder,
48                                                    uint16_t width,
49                                                    uint16_t height,
50                                                    SkColorType colorType,
51                                                    uint16_t identifier,
52                                                    bool requireStorageUsage) {
53     uint64_t key = static_cast<uint64_t>(width)  << 48 |
54                    static_cast<uint64_t>(height) << 32 |
55                    static_cast<uint64_t>(colorType) << 16 |
56                    static_cast<uint64_t>(identifier);
57     auto iter = fTexturePool.find(key);
58     if (iter != fTexturePool.end()) {
59         return iter->second;
60     }
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     const Caps* caps = recorder->priv().caps();
66     auto textureInfo = requireStorageUsage
67             ? caps->getDefaultStorageTextureInfo(colorType)
68             : caps->getDefaultSampledTextureInfo(colorType,
69                                                  Mipmapped::kNo,
70                                                  recorder->priv().isProtected(),
71                                                  Renderable::kNo);
72     sk_sp<TextureProxy> proxy = TextureProxy::Make(caps,
73                                                    recorder->priv().resourceProvider(),
74                                                    SkISize::Make((int32_t) width, (int32_t) height),
75                                                    textureInfo,
76                                                    "AtlasProviderTexture",
77                                                    Budgeted::kYes);
78     if (!proxy) {
79         return nullptr;
80     }
81 
82     fTexturePool[key] = proxy;
83     return proxy;
84 }
85 
clearTexturePool()86 void AtlasProvider::clearTexturePool() {
87     fTexturePool.clear();
88 }
89 
recordUploads(DrawContext * dc)90 void AtlasProvider::recordUploads(DrawContext* dc) {
91     if (!fTextAtlasManager->recordUploads(dc)) {
92         SKGPU_LOG_E("TextAtlasManager uploads have failed -- may see invalid results.");
93     }
94 
95     if (fRasterPathAtlas) {
96         fRasterPathAtlas->recordUploads(dc);
97     }
98 }
99 
postFlush()100 void AtlasProvider::postFlush() {
101     fTextAtlasManager->postFlush();
102     if (fRasterPathAtlas) {
103         fRasterPathAtlas->postFlush();
104     }
105 }
106 
107 }  // namespace skgpu::graphite
108