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>
SelectOption(SkSpan<const sk_sp<T>> options,int desiredOption)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>
AddToKey(const KeyContext & keyContext,PaintParamsKeyBuilder * builder,PipelineDataGatherer * gatherer,SkSpan<const sk_sp<T>> options,int desiredOption)31 void PrecompileBase::AddToKey(const KeyContext& keyContext,
32 PaintParamsKeyBuilder* builder,
33 PipelineDataGatherer* gatherer,
34 SkSpan<const sk_sp<T>> options,
35 int desiredOption) {
36 auto [option, childOptions] = SelectOption(options, desiredOption);
37 if (option) {
38 option->priv().addToKey(keyContext, builder, gatherer, childOptions);
39 }
40 }
41
42 } // namespace skgpu::graphite
43
44 #endif // skgpu_graphite_precompile_PrecompileBaseComplete_DEFINED
45