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