Debian Codegraph @

src/gpu/graphite/precompile/PrecompileBaseComplete.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_precompile_PrecompileBaseComplete_DEFINED
9 #define skgpu_graphite_precompile_PrecompileBaseComplete_DEFINED
10
11 #include "include/gpu/graphite/precompile/PrecompileBase.h"
12
13 // This file simply provides the missing implementations of SelectOption and AddToKey.
14 // In practice PrecompileBase.h should never be used internally and this header should be
15 // used in its place.
16 namespace skgpu::graphite {
17
18 template<typename T>
19 std::pair<sk_sp<T>, int> PrecompileBase::SelectOption(SkSpan<const sk_sp<T>> options,
20 int desiredOption) {
21 for (const sk_sp<T>& option : options) {
22 if (desiredOption < (option ? option->numCombinations() : 1)) {
23 return { option, desiredOption };
24 }
25 desiredOption -= option ? option->numCombinations() : 1;
26 }
27 return { nullptr, 0 };
28 }
29
30 template<typename T>
31 void PrecompileBase::AddToKey(const KeyContext& keyContext,
32 SkSpan<const sk_sp<T>> options,
33 int desiredOption) {
34 auto [option, childOptions] = SelectOption(options, desiredOption);
35 if (option) {
36 option->priv().addToKey(keyContext, childOptions);
37 }
38 }
39
40 } // namespace skgpu::graphite
41
42 #endif // skgpu_graphite_precompile_PrecompileBaseComplete_DEFINED