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 13 #ifndef __STDC_FORMAT_MACROS 14 #define __STDC_FORMAT_MACROS 15 #endif 16 17 namespace SkSL { 18 19 #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU 20 StandaloneShaderCaps standaloneCaps; 21 MakeShaderCaps()22ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { 23 return std::make_shared<StandaloneShaderCaps>(); 24 } 25 #else 26 ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() { 27 return sk_make_sp<GrShaderCaps>(GrContextOptions()); 28 } 29 #endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU 30 sksl_abort()31void sksl_abort() { 32 #ifdef SKSL_STANDALONE 33 abort(); 34 #else 35 sk_abort_no_print(); 36 exit(1); 37 #endif 38 } 39 write_stringstream(const StringStream & s,OutputStream & out)40void write_stringstream(const StringStream& s, OutputStream& out) { 41 out.write(s.str().c_str(), s.str().size()); 42 } 43 44 #if !defined(SKSL_STANDALONE) type_to_grsltype(const Context & context,const Type & type,GrSLType * outType)45bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType) { 46 if (type == *context.fFloat_Type) { *outType = kFloat_GrSLType; return true; } 47 if (type == *context.fHalf_Type) { *outType = kHalf_GrSLType; return true; } 48 if (type == *context.fFloat2_Type) { *outType = kFloat2_GrSLType; return true; } 49 if (type == *context.fHalf2_Type) { *outType = kHalf2_GrSLType; return true; } 50 if (type == *context.fFloat3_Type) { *outType = kFloat3_GrSLType; return true; } 51 if (type == *context.fHalf3_Type) { *outType = kHalf3_GrSLType; return true; } 52 if (type == *context.fFloat4_Type) { *outType = kFloat4_GrSLType; return true; } 53 if (type == *context.fHalf4_Type) { *outType = kHalf4_GrSLType; return true; } 54 if (type == *context.fFloat2x2_Type) { *outType = kFloat2x2_GrSLType; return true; } 55 if (type == *context.fHalf2x2_Type) { *outType = kHalf2x2_GrSLType; return true; } 56 if (type == *context.fFloat3x3_Type) { *outType = kFloat3x3_GrSLType; return true; } 57 if (type == *context.fHalf3x3_Type) { *outType = kHalf3x3_GrSLType; return true; } 58 if (type == *context.fFloat4x4_Type) { *outType = kFloat4x4_GrSLType; return true; } 59 if (type == *context.fHalf4x4_Type) { *outType = kHalf4x4_GrSLType; return true; } 60 if (type == *context.fVoid_Type) { *outType = kVoid_GrSLType; return true; } 61 return false; 62 } 63 #endif 64 65 } // namespace SkSL 66