• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 SkUniform_DEFINED
9 #define SkUniform_DEFINED
10 
11 #include "src/core/SkSLTypeShared.h"
12 
13 // TODO: can SkRuntimeEffect::Uniform be absorbed into this class!?
14 
15 /**
16  * Describes a uniform. Uniforms consist of:
17  *  type:       The type of the uniform
18  *  count:      Number of elements of 'type' in the array or kNonArray if not an array.
19  */
20 class SkUniform {
21 public:
22     static constexpr int kNonArray = 0;
23 
SkUniform(const char * name,SkSLType type)24     constexpr SkUniform(const char* name, SkSLType type) : SkUniform(name, type, kNonArray) {}
25 
SkUniform(const char * name,SkSLType type,int count)26     constexpr SkUniform(const char* name, SkSLType type, int count)
27             : fType      (static_cast<unsigned>(type))
28             , fCount     (static_cast<unsigned>(count))
29             , fName      (name) {
30     }
31 
32     constexpr SkUniform(const SkUniform&) = default;
33     SkUniform& operator=(const SkUniform&) = default;
34 
isInitialized()35     constexpr bool isInitialized() const { return this->type() != SkSLType::kVoid; }
36 
name()37     constexpr const char* name() const  { return fName; }
type()38     constexpr SkSLType    type() const  { return static_cast<SkSLType>(fType);  }
count()39     constexpr uint32_t    count() const { return static_cast<uint32_t>(fCount); }
40 
41 private:
42     uint32_t    fType    : 6;
43     uint32_t    fCount   : 26;
44     const char* fName;
45 
46     static_assert(kSkSLTypeCount <= (1 << 6));
47 };
48 
49 #endif // SkUniform_DEFINED
50