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 14 #include <chrono> 15 #include <memory> 16 17 class SkData; 18 19 namespace skgpu::graphite { 20 21 class SharedContext; 22 class PrecompileContextPriv; 23 class ResourceProvider; 24 25 class SK_API PrecompileContext { 26 public: 27 ~PrecompileContext(); 28 29 /** 30 * Purge Pipelines that haven't been used in the past 'msNotUsed' milliseconds 31 * regardless of whether the pipeline cache is under budget. 32 * 33 * @param msNotUsed Pipelines not used in these last milliseconds will be cleaned up. 34 */ 35 void purgePipelinesNotUsedInMs(std::chrono::milliseconds msNotUsed); 36 37 /** 38 * Precompile one specific Pipeline that has been previously serialized. Serialized pipeline 39 * keys can be acquired via the ContextOptions::PipelineCallback. 40 * 41 * @param serializedPipelineKey serialized Pipeline key. 42 * @return true if a Pipeline was created from the key; false otherwise 43 */ 44 bool precompile(sk_sp<SkData> serializedPipelineKey); 45 46 /** 47 * Get a human-readable version of a serialized pipeline key. 48 * 49 * @param serializedPipelineKey serialized Pipeline key. 50 * @return A human-readable version of the provided key; "" on failure. 51 */ 52 std::string getPipelineLabel(sk_sp<SkData> serializedPipelineKey); 53 54 // Provides access to functions that aren't part of the public API. 55 PrecompileContextPriv priv(); 56 const PrecompileContextPriv priv() const; // NOLINT(readability-const-return-type) 57 58 private: 59 friend class PrecompileContextPriv; 60 friend class Context; // for ctor 61 62 PrecompileContext(sk_sp<SharedContext>); 63 64 mutable SingleOwner fSingleOwner; 65 sk_sp<SharedContext> fSharedContext; 66 std::unique_ptr<ResourceProvider> fResourceProvider; 67 }; 68 69 } // namespace skgpu::graphite 70 71 #endif // skgpu_graphite_PrecompileContext_DEFINED 72