| /* | |
| * Copyright 2026 Google LLC | |
| * | |
| * Use of this source code is governed by a BSD-style license that can be | |
| * found in the LICENSE file. | |
| */ | |
| #ifndef SkSharedContext_DEFINED | |
| #define SkSharedContext_DEFINED | |
| #include "include/core/SkRefCnt.h" | |
| #include <memory> | |
| class SkOpenTypeSVGDecoder; | |
| class SkStrikeCache; | |
| class SkSynchronizedResourceCache; | |
| class SkTypefaceCache; | |
| struct SkContextOptions; | |
| using OpenTypeSVGDecoderFactory = std::unique_ptr<SkOpenTypeSVGDecoder> (*)(const uint8_t* svg, | |
| size_t length); | |
| class SkSharedContext : public SkRefCnt { | |
| public: | |
| explicit SkSharedContext(const SkContextOptions& options); | |
| ~SkSharedContext() override; | |
| const SkSynchronizedResourceCache* synchronizedResourceCache() const { | |
| return fResourceCache.get(); | |
| } | |
| SkSynchronizedResourceCache* synchronizedResourceCache() { return fResourceCache.get(); } | |
| const SkStrikeCache* strikeCache() const { return fStrikeCache.get(); } | |
| SkStrikeCache* strikeCache() { return fStrikeCache.get(); } | |
| const SkTypefaceCache* typefaceCache() const { return fTypefaceCache.get(); } | |
| SkTypefaceCache* typefaceCache() { return fTypefaceCache.get(); } | |
| int typefaceCacheCountLimit() const { return fTypefaceCacheCountLimit; } | |
| int setTypefaceCacheCountLimit(int count) { | |
| const int prev = fTypefaceCacheCountLimit; | |
| fTypefaceCacheCountLimit = count; | |
| return prev; | |
| } | |
| int setSVGDecoderFactory(OpenTypeSVGDecoderFactory factory) { | |
| const int prev = fSVGDecoderFactory != nullptr; | |
| fSVGDecoderFactory = std::move(factory); | |
| return prev; | |
| } | |
| private: | |
| int fTypefaceCacheCountLimit = 1024; // historical default value | |
| OpenTypeSVGDecoderFactory fSVGDecoderFactory = nullptr; | |
| std::unique_ptr<SkSynchronizedResourceCache> fResourceCache; | |
| std::unique_ptr<SkStrikeCache> fStrikeCache; | |
| std::unique_ptr<SkTypefaceCache> fTypefaceCache; | |
| }; | |
| #endif // SkSharedContext_DEFINED |