blob: 9374a955cfb9575e234fd875a4ce672a10fff9c0 [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
10#include "src/sksl/ir/SkSLBinaryExpression.h"
11#include "src/sksl/ir/SkSLConstructor.h"
12#include "src/sksl/ir/SkSLDoStatement.h"
13#include "src/sksl/ir/SkSLExpression.h"
14#include "src/sksl/ir/SkSLExpressionStatement.h"
15#include "src/sksl/ir/SkSLFieldAccess.h"
16#include "src/sksl/ir/SkSLForStatement.h"
17#include "src/sksl/ir/SkSLFunctionCall.h"
18#include "src/sksl/ir/SkSLIfStatement.h"
19#include "src/sksl/ir/SkSLIndexExpression.h"
20#include "src/sksl/ir/SkSLPostfixExpression.h"
21#include "src/sksl/ir/SkSLPrefixExpression.h"
22#include "src/sksl/ir/SkSLProgram.h"
23#include "src/sksl/ir/SkSLReturnStatement.h"
24#include "src/sksl/ir/SkSLSwitchStatement.h"
25#include "src/sksl/ir/SkSLSwizzle.h"
26#include "src/sksl/ir/SkSLTernaryExpression.h"
Brian Osman1298bc42020-06-30 13:39:35 -040027#include "src/sksl/ir/SkSLVariable.h"
Brian Osman1298bc42020-06-30 13:39:35 -040028
29namespace SkSL {
30
31SampleUsage SampleUsage::merge(const SampleUsage& other) {
Brian Osman83dae922021-04-28 10:44:06 -040032 // This function is only used when processing SkSL, to determine the combined SampleUsage for
33 // a child fp/shader/etc. We should never see matrix sampling here.
34 SkASSERT(fKind != Kind::kUniformMatrix && other.fKind != Kind::kUniformMatrix);
Brian Osman1298bc42020-06-30 13:39:35 -040035
Brian Osman83dae922021-04-28 10:44:06 -040036 static_assert(Kind::kExplicit > Kind::kPassThrough);
37 static_assert(Kind::kPassThrough > Kind::kNone);
38 fKind = std::max(fKind, other.fKind);
Brian Osman1298bc42020-06-30 13:39:35 -040039
40 return *this;
41}
42
Brian Osman83dae922021-04-28 10:44:06 -040043std::string SampleUsage::constructor() const {
44 // This function is only used when processing SkSL. We should never see matrix sampling here.
45 SkASSERT(fKind != Kind::kUniformMatrix);
Brian Osman1298bc42020-06-30 13:39:35 -040046
Brian Osman1298bc42020-06-30 13:39:35 -040047 switch (fKind) {
Brian Osman83dae922021-04-28 10:44:06 -040048 case Kind::kNone: return "SkSL::SampleUsage()";
49 case Kind::kPassThrough: return "SkSL::SampleUsage::PassThrough()";
50 case Kind::kExplicit: return "SkSL::SampleUsage::Explicit()";
51 default: SkUNREACHABLE;
Brian Osman1298bc42020-06-30 13:39:35 -040052 }
Brian Osman1298bc42020-06-30 13:39:35 -040053}
54
John Stilesa6841be2020-08-06 14:11:56 -040055} // namespace SkSL