blob: 099487f93db616d48bb3c051887c37cd6a170e30 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/sksl/SkSLUtil.h"
ethannicholasb3058bd2016-07-01 08:22:01 -07009
Brian Osman3000d6b2020-07-31 15:57:28 -040010#include "src/sksl/SkSLContext.h"
Mike Klein4b432fa2019-06-06 11:44:05 -050011#include "src/sksl/SkSLStringStream.h"
John Stiles54e7c052021-01-11 14:22:36 -050012#include "src/sksl/ir/SkSLType.h"
Ethan Nicholasfc994162019-06-06 10:04:27 -040013
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050014#ifndef __STDC_FORMAT_MACROS
15#define __STDC_FORMAT_MACROS
16#endif
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050017
ethannicholasb3058bd2016-07-01 08:22:01 -070018namespace SkSL {
19
Brian Osmanfb32ddf2019-06-18 10:14:20 -040020#if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
Ethan Nicholas0df1b042017-03-31 13:56:23 -040021StandaloneShaderCaps standaloneCaps;
John Stiles194b9b92020-09-15 15:37:24 -040022
23ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() {
24 return std::make_shared<StandaloneShaderCaps>();
25}
26#else
27ShaderCapsPointer ShaderCapsFactory::MakeShaderCaps() {
28 return sk_make_sp<GrShaderCaps>(GrContextOptions());
29}
30#endif // defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU
ethannicholasb3058bd2016-07-01 08:22:01 -070031
Ethan Nicholas0df1b042017-03-31 13:56:23 -040032void write_stringstream(const StringStream& s, OutputStream& out) {
Ethan Nicholas762466e2017-06-29 10:03:38 -040033 out.write(s.str().c_str(), s.str().size());
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050034}
35
Brian Osman3000d6b2020-07-31 15:57:28 -040036#if !defined(SKSL_STANDALONE)
37bool type_to_grsltype(const Context& context, const Type& type, GrSLType* outType) {
John Stilesabef5ef2021-01-19 22:57:39 -050038 // If a new GrSL type is added, this function will need to be updated.
John Stiles9fc9b872021-02-01 15:50:32 -050039 static_assert(kGrSLTypeCount == 49);
John Stilesabef5ef2021-01-19 22:57:39 -050040
41 if (type == *context.fTypes.fVoid ) { *outType = kVoid_GrSLType; return true; }
42 if (type == *context.fTypes.fBool ) { *outType = kBool_GrSLType; return true; }
John Stiles9fc9b872021-02-01 15:50:32 -050043 if (type == *context.fTypes.fBool2 ) { *outType = kBool2_GrSLType; return true; }
44 if (type == *context.fTypes.fBool3 ) { *outType = kBool3_GrSLType; return true; }
45 if (type == *context.fTypes.fBool4 ) { *outType = kBool4_GrSLType; return true; }
John Stilesabef5ef2021-01-19 22:57:39 -050046 if (type == *context.fTypes.fShort ) { *outType = kShort_GrSLType; return true; }
47 if (type == *context.fTypes.fShort2 ) { *outType = kShort2_GrSLType; return true; }
48 if (type == *context.fTypes.fShort3 ) { *outType = kShort3_GrSLType; return true; }
49 if (type == *context.fTypes.fShort4 ) { *outType = kShort4_GrSLType; return true; }
50 if (type == *context.fTypes.fUShort ) { *outType = kUShort_GrSLType; return true; }
51 if (type == *context.fTypes.fUShort2 ) { *outType = kUShort2_GrSLType; return true; }
52 if (type == *context.fTypes.fUShort3 ) { *outType = kUShort3_GrSLType; return true; }
53 if (type == *context.fTypes.fUShort4 ) { *outType = kUShort4_GrSLType; return true; }
54 if (type == *context.fTypes.fFloat ) { *outType = kFloat_GrSLType; return true; }
55 if (type == *context.fTypes.fFloat2 ) { *outType = kFloat2_GrSLType; return true; }
56 if (type == *context.fTypes.fFloat3 ) { *outType = kFloat3_GrSLType; return true; }
57 if (type == *context.fTypes.fFloat4 ) { *outType = kFloat4_GrSLType; return true; }
John Stiles54e7c052021-01-11 14:22:36 -050058 if (type == *context.fTypes.fFloat2x2) { *outType = kFloat2x2_GrSLType; return true; }
John Stiles54e7c052021-01-11 14:22:36 -050059 if (type == *context.fTypes.fFloat3x3) { *outType = kFloat3x3_GrSLType; return true; }
John Stiles54e7c052021-01-11 14:22:36 -050060 if (type == *context.fTypes.fFloat4x4) { *outType = kFloat4x4_GrSLType; return true; }
John Stilesabef5ef2021-01-19 22:57:39 -050061 if (type == *context.fTypes.fHalf ) { *outType = kHalf_GrSLType; return true; }
62 if (type == *context.fTypes.fHalf2 ) { *outType = kHalf2_GrSLType; return true; }
63 if (type == *context.fTypes.fHalf3 ) { *outType = kHalf3_GrSLType; return true; }
64 if (type == *context.fTypes.fHalf4 ) { *outType = kHalf4_GrSLType; return true; }
65 if (type == *context.fTypes.fHalf2x2 ) { *outType = kHalf2x2_GrSLType; return true; }
66 if (type == *context.fTypes.fHalf3x3 ) { *outType = kHalf3x3_GrSLType; return true; }
67 if (type == *context.fTypes.fHalf4x4 ) { *outType = kHalf4x4_GrSLType; return true; }
68 if (type == *context.fTypes.fInt ) { *outType = kInt_GrSLType; return true; }
69 if (type == *context.fTypes.fInt2 ) { *outType = kInt2_GrSLType; return true; }
70 if (type == *context.fTypes.fInt3 ) { *outType = kInt3_GrSLType; return true; }
71 if (type == *context.fTypes.fInt4 ) { *outType = kInt4_GrSLType; return true; }
72 if (type == *context.fTypes.fUInt ) { *outType = kUint_GrSLType; return true; }
73 if (type == *context.fTypes.fUInt2 ) { *outType = kUint2_GrSLType; return true; }
74 if (type == *context.fTypes.fUInt3 ) { *outType = kUint3_GrSLType; return true; }
75 if (type == *context.fTypes.fUInt4 ) { *outType = kUint4_GrSLType; return true; }
Brian Osman3000d6b2020-07-31 15:57:28 -040076 return false;
77}
78#endif
79
John Stilesa6841be2020-08-06 14:11:56 -040080} // namespace SkSL