Debian Codegraph @

include/gpu/graphite/PrecompileContext.h

raw
1 /*
2 * Copyright 2024 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 #ifndef skgpu_graphite_PrecompileContext_DEFINED
9 #define skgpu_graphite_PrecompileContext_DEFINED
10
11 #include "include/core/SkRefCnt.h"
12 #include "include/private/base/SingleOwner.h"
13 #include "include/private/base/SkAPI.h"
14
15 #include <chrono>
16 #include <memory>
17 #include <string>
18
19 class SkData;
20
21 namespace skgpu::graphite {
22
23 class SharedContext;
24 class PrecompileContextPriv;
25 class ResourceProvider;
26
27 class SK_API PrecompileContext {
28 public:
29 ~PrecompileContext();
30
31 /**
32 * Purge Pipelines that haven't been used in the past 'msNotUsed' milliseconds
33 * regardless of whether the pipeline cache is under budget.
34 *
35 * @param msNotUsed Pipelines not used in these last milliseconds will be cleaned up.
36 */
37 void purgePipelinesNotUsedInMs(std::chrono::milliseconds msNotUsed);
38
39 enum class StatOptions {
40 // Emit histograms (using the SK_HISTOGRAM* macros) for Skia's Precompiled Pipeline
41 // usage:
42 // Skia.Graphite.Precompile.NormalPreemptedByPrecompile
43 // Skia.Graphite.Precompile.UnpreemptedPrecompilePipelines
44 // Skia.Graphite.Precompile.UnusedPrecompiledPipelines
45 kPrecompile,
46 // Emit histograms (using the SK_HISTOGRAM* macros) for Skia's Pipeline cache usage:
47 // Skia.Graphite.PipelineCache.PipelineUsesInEpoch
48 kPipelineCache,
49 };
50
51 /**
52 * Emit histograms histograms related to Skia's Pipelines (c.f. the StatOptions enum).
53 */
54 void reportPipelineStats(StatOptions option = StatOptions::kPrecompile);
55
56 /**
57 * Precompile one specific Pipeline that has been previously serialized. Serialized pipeline
58 * keys can be acquired via the ContextOptions::PipelineCallback.
59 *
60 * @param serializedPipelineKey serialized Pipeline key.
61 * @return true if a Pipeline was created from the key; false otherwise
62 */
63 bool precompile(sk_sp<SkData> serializedPipelineKey);
64
65 /**
66 * Get a human-readable version of a serialized pipeline key.
67 *
68 * @param serializedPipelineKey serialized Pipeline key.
69 * @return A human-readable version of the provided key; "" on failure.
70 */
71 std::string getPipelineLabel(sk_sp<SkData> serializedPipelineKey);
72
73 // Provides access to functions that aren't part of the public API.
74 PrecompileContextPriv priv();
75 const PrecompileContextPriv priv() const; // NOLINT(readability-const-return-type)
76
77 private:
78 friend class PrecompileContextPriv;
79 friend class Context; // for ctor
80
81 explicit PrecompileContext(sk_sp<SharedContext>);
82
83 mutable SingleOwner fSingleOwner;
84 sk_sp<SharedContext> fSharedContext;
85 std::unique_ptr<ResourceProvider> fResourceProvider;
86 };
87
88 } // namespace skgpu::graphite
89
90 #endif // skgpu_graphite_PrecompileContext_DEFINED