blob: a3987286810f00f94d42c82accdb1b04abee302c [file] [log] [blame]
Brian Osman1298bc42020-06-30 13:39:35 -04001/*
2 * Copyright 2020 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#include "include/private/SkSLSampleUsage.h"
9
Brian Osmanb1e9cb02021-05-21 12:03:51 -040010#include <algorithm>
Brian Osman1298bc42020-06-30 13:39:35 -040011
12namespace SkSL {
13
14SampleUsage SampleUsage::merge(const SampleUsage& other) {
Brian Osman83dae922021-04-28 10:44:06 -040015 // This function is only used when processing SkSL, to determine the combined SampleUsage for
16 // a child fp/shader/etc. We should never see matrix sampling here.
17 SkASSERT(fKind != Kind::kUniformMatrix && other.fKind != Kind::kUniformMatrix);
Brian Osman1298bc42020-06-30 13:39:35 -040018
Brian Osman83dae922021-04-28 10:44:06 -040019 static_assert(Kind::kExplicit > Kind::kPassThrough);
20 static_assert(Kind::kPassThrough > Kind::kNone);
21 fKind = std::max(fKind, other.fKind);
Brian Osman1298bc42020-06-30 13:39:35 -040022
23 return *this;
24}
25
Brian Osman83dae922021-04-28 10:44:06 -040026std::string SampleUsage::constructor() const {
27 // This function is only used when processing SkSL. We should never see matrix sampling here.
28 SkASSERT(fKind != Kind::kUniformMatrix);
Brian Osman1298bc42020-06-30 13:39:35 -040029
Brian Osman1298bc42020-06-30 13:39:35 -040030 switch (fKind) {
Brian Osman83dae922021-04-28 10:44:06 -040031 case Kind::kNone: return "SkSL::SampleUsage()";
32 case Kind::kPassThrough: return "SkSL::SampleUsage::PassThrough()";
33 case Kind::kExplicit: return "SkSL::SampleUsage::Explicit()";
34 default: SkUNREACHABLE;
Brian Osman1298bc42020-06-30 13:39:35 -040035 }
Brian Osman1298bc42020-06-30 13:39:35 -040036}
37
John Stilesa6841be2020-08-06 14:11:56 -040038} // namespace SkSL