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 #ifndef __STDC_FORMAT_MACROS 15 #define __STDC_FORMAT_MACROS 16 #endif 17 18 namespace SkSL { 19 20 #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU MakeShaderCaps()21ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { 22 return std::make_unique<StandaloneShaderCaps>(); 23 } 24 #else 25 ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { 26 return std::make_unique<GrShaderCaps>(); 27 } 28 #endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU 29 write_stringstream(const StringStream & s,OutputStream & out)30void write_stringstream(const StringStream& s, OutputStream& out) { 31 out.write(s.str().c_str(), s.str().size()); 32 } 33 34 #if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU type_to_grsltype(const Context & context,const Type & type,GrSLType * outType)35bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType) { 36 // If a new GrSL type is added, this function will need to be updated. 37 static_assert(kGrSLTypeCount == 41); 38 39 if (type == *context.fTypes.fVoid ) { *outType = kVoid_GrSLType; return true; } 40 if (type == *context.fTypes.fBool ) { *outType = kBool_GrSLType; return true; } 41 if (type == *context.fTypes.fBool2 ) { *outType = kBool2_GrSLType; return true; } 42 if (type == *context.fTypes.fBool3 ) { *outType = kBool3_GrSLType; return true; } 43 if (type == *context.fTypes.fBool4 ) { *outType = kBool4_GrSLType; return true; } 44 if (type == *context.fTypes.fShort ) { *outType = kShort_GrSLType; return true; } 45 if (type == *context.fTypes.fShort2 ) { *outType = kShort2_GrSLType; return true; } 46 if (type == *context.fTypes.fShort3 ) { *outType = kShort3_GrSLType; return true; } 47 if (type == *context.fTypes.fShort4 ) { *outType = kShort4_GrSLType; return true; } 48 if (type == *context.fTypes.fUShort ) { *outType = kUShort_GrSLType; return true; } 49 if (type == *context.fTypes.fUShort2 ) { *outType = kUShort2_GrSLType; return true; } 50 if (type == *context.fTypes.fUShort3 ) { *outType = kUShort3_GrSLType; return true; } 51 if (type == *context.fTypes.fUShort4 ) { *outType = kUShort4_GrSLType; return true; } 52 if (type == *context.fTypes.fFloat ) { *outType = kFloat_GrSLType; return true; } 53 if (type == *context.fTypes.fFloat2 ) { *outType = kFloat2_GrSLType; return true; } 54 if (type == *context.fTypes.fFloat3 ) { *outType = kFloat3_GrSLType; return true; } 55 if (type == *context.fTypes.fFloat4 ) { *outType = kFloat4_GrSLType; return true; } 56 if (type == *context.fTypes.fFloat2x2) { *outType = kFloat2x2_GrSLType; return true; } 57 if (type == *context.fTypes.fFloat3x3) { *outType = kFloat3x3_GrSLType; return true; } 58 if (type == *context.fTypes.fFloat4x4) { *outType = kFloat4x4_GrSLType; return true; } 59 if (type == *context.fTypes.fHalf ) { *outType = kHalf_GrSLType; return true; } 60 if (type == *context.fTypes.fHalf2 ) { *outType = kHalf2_GrSLType; return true; } 61 if (type == *context.fTypes.fHalf3 ) { *outType = kHalf3_GrSLType; return true; } 62 if (type == *context.fTypes.fHalf4 ) { *outType = kHalf4_GrSLType; return true; } 63 if (type == *context.fTypes.fHalf2x2 ) { *outType = kHalf2x2_GrSLType; return true; } 64 if (type == *context.fTypes.fHalf3x3 ) { *outType = kHalf3x3_GrSLType; return true; } 65 if (type == *context.fTypes.fHalf4x4 ) { *outType = kHalf4x4_GrSLType; return true; } 66 if (type == *context.fTypes.fInt ) { *outType = kInt_GrSLType; return true; } 67 if (type == *context.fTypes.fInt2 ) { *outType = kInt2_GrSLType; return true; } 68 if (type == *context.fTypes.fInt3 ) { *outType = kInt3_GrSLType; return true; } 69 if (type == *context.fTypes.fInt4 ) { *outType = kInt4_GrSLType; return true; } 70 if (type == *context.fTypes.fUInt ) { *outType = kUInt_GrSLType; return true; } 71 if (type == *context.fTypes.fUInt2 ) { *outType = kUInt2_GrSLType; return true; } 72 if (type == *context.fTypes.fUInt3 ) { *outType = kUInt3_GrSLType; return true; } 73 if (type == *context.fTypes.fUInt4 ) { *outType = kUInt4_GrSLType; return true; } 74 return false; 75 } 76 #endif 77 78 } // namespace SkSL 79