Flutter Engine
The Flutter Engine
PrecompileBaseComplete.h
Go to the documentation of this file.
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
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.
16namespace skgpu::graphite {
17
18template<typename T>
19std::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
30template<typename T>
31void PrecompileBase::AddToKey(const KeyContext& keyContext,
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
const char * options
static void AddToKey(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, SkSpan< const sk_sp< T > > options, int desiredOption)
static std::pair< sk_sp< T >, int > SelectOption(SkSpan< const sk_sp< T > > options, int desiredOption)