1 /* 2 * Copyright 2016 Google Inc. 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 "src/sksl/SkSLUtil.h" 9 10 #include "src/sksl/SkSLContext.h" 11 #include "src/sksl/SkSLStringStream.h" 12 #include "src/sksl/ir/SkSLType.h" 13 14 #include "src/gpu/GrShaderCaps.h" 15 16 #ifndef __STDC_FORMAT_MACROS 17 #define __STDC_FORMAT_MACROS 18 #endif 19 20 namespace SkSL { 21 22 #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU MakeShaderCaps()23std::unique_ptr<ShaderCaps> ShaderCapsFactory::MakeShaderCaps() { 24 std::unique_ptr<ShaderCaps> standalone = std::make_unique<ShaderCaps>(); 25 standalone->fShaderDerivativeSupport = true; 26 standalone->fFlatInterpolationSupport = true; 27 standalone->fNoPerspectiveInterpolationSupport = true; 28 standalone->fSampleMaskSupport = true; 29 standalone->fExternalTextureSupport = true; 30 return standalone; 31 } 32 #else 33 std::unique_ptr<ShaderCaps> ShaderCapsFactory::MakeShaderCaps() { 34 return std::make_unique<GrShaderCaps>(); 35 } 36 #endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU 37 write_stringstream(const StringStream & s,OutputStream & out)38void write_stringstream(const StringStream& s, OutputStream& out) { 39 out.write(s.str().c_str(), s.str().size()); 40 } 41 42 #if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU type_to_sksltype(const Context & context,const Type & type,SkSLType * outType)43bool type_to_sksltype(const Context& context, const Type& type, SkSLType* outType) { 44 // If a new GrSL type is added, this function will need to be updated. 45 static_assert(kSkSLTypeCount == 41); 46 47 if (type.matches(*context.fTypes.fVoid )) { *outType = SkSLType::kVoid; return true; } 48 if (type.matches(*context.fTypes.fBool )) { *outType = SkSLType::kBool; return true; } 49 if (type.matches(*context.fTypes.fBool2 )) { *outType = SkSLType::kBool2; return true; } 50 if (type.matches(*context.fTypes.fBool3 )) { *outType = SkSLType::kBool3; return true; } 51 if (type.matches(*context.fTypes.fBool4 )) { *outType = SkSLType::kBool4; return true; } 52 if (type.matches(*context.fTypes.fShort )) { *outType = SkSLType::kShort; return true; } 53 if (type.matches(*context.fTypes.fShort2 )) { *outType = SkSLType::kShort2; return true; } 54 if (type.matches(*context.fTypes.fShort3 )) { *outType = SkSLType::kShort3; return true; } 55 if (type.matches(*context.fTypes.fShort4 )) { *outType = SkSLType::kShort4; return true; } 56 if (type.matches(*context.fTypes.fUShort )) { *outType = SkSLType::kUShort; return true; } 57 if (type.matches(*context.fTypes.fUShort2 )) { *outType = SkSLType::kUShort2; return true; } 58 if (type.matches(*context.fTypes.fUShort3 )) { *outType = SkSLType::kUShort3; return true; } 59 if (type.matches(*context.fTypes.fUShort4 )) { *outType = SkSLType::kUShort4; return true; } 60 if (type.matches(*context.fTypes.fFloat )) { *outType = SkSLType::kFloat; return true; } 61 if (type.matches(*context.fTypes.fFloat2 )) { *outType = SkSLType::kFloat2; return true; } 62 if (type.matches(*context.fTypes.fFloat3 )) { *outType = SkSLType::kFloat3; return true; } 63 if (type.matches(*context.fTypes.fFloat4 )) { *outType = SkSLType::kFloat4; return true; } 64 if (type.matches(*context.fTypes.fFloat2x2)) { *outType = SkSLType::kFloat2x2; return true; } 65 if (type.matches(*context.fTypes.fFloat3x3)) { *outType = SkSLType::kFloat3x3; return true; } 66 if (type.matches(*context.fTypes.fFloat4x4)) { *outType = SkSLType::kFloat4x4; return true; } 67 if (type.matches(*context.fTypes.fHalf )) { *outType = SkSLType::kHalf; return true; } 68 if (type.matches(*context.fTypes.fHalf2 )) { *outType = SkSLType::kHalf2; return true; } 69 if (type.matches(*context.fTypes.fHalf3 )) { *outType = SkSLType::kHalf3; return true; } 70 if (type.matches(*context.fTypes.fHalf4 )) { *outType = SkSLType::kHalf4; return true; } 71 if (type.matches(*context.fTypes.fHalf2x2 )) { *outType = SkSLType::kHalf2x2; return true; } 72 if (type.matches(*context.fTypes.fHalf3x3 )) { *outType = SkSLType::kHalf3x3; return true; } 73 if (type.matches(*context.fTypes.fHalf4x4 )) { *outType = SkSLType::kHalf4x4; return true; } 74 if (type.matches(*context.fTypes.fInt )) { *outType = SkSLType::kInt; return true; } 75 if (type.matches(*context.fTypes.fInt2 )) { *outType = SkSLType::kInt2; return true; } 76 if (type.matches(*context.fTypes.fInt3 )) { *outType = SkSLType::kInt3; return true; } 77 if (type.matches(*context.fTypes.fInt4 )) { *outType = SkSLType::kInt4; return true; } 78 if (type.matches(*context.fTypes.fUInt )) { *outType = SkSLType::kUInt; return true; } 79 if (type.matches(*context.fTypes.fUInt2 )) { *outType = SkSLType::kUInt2; return true; } 80 if (type.matches(*context.fTypes.fUInt3 )) { *outType = SkSLType::kUInt3; return true; } 81 if (type.matches(*context.fTypes.fUInt4 )) { *outType = SkSLType::kUInt4; return true; } 82 return false; 83 } 84 #endif 85 86 } // namespace SkSL 87