• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SKSL_UTIL
9 #define SKSL_UTIL
10 
11 #include "stdlib.h"
12 #include "assert.h"
13 #include "SkOpts.h"
14 #include "SkRefCnt.h"
15 #include "SkStream.h"
16 #include "SkString.h"
17 #include "SkTypes.h"
18 #include "GrContextOptions.h"
19 #include "GrShaderCaps.h"
20 
21 namespace SkSL {
22 
23 // Various sets of caps for use in tests
24 class ShaderCapsFactory {
25 public:
Default()26     static sk_sp<GrShaderCaps> Default() {
27         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
28         result->fVersionDeclString = "#version 400";
29         result->fShaderDerivativeSupport = true;
30         return result;
31     }
32 
Version450Core()33     static sk_sp<GrShaderCaps> Version450Core() {
34         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
35         result->fVersionDeclString = "#version 450 core";
36         return result;
37     }
38 
Version110()39     static sk_sp<GrShaderCaps> Version110() {
40         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
41         result->fVersionDeclString = "#version 110";
42         result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
43         return result;
44     }
45 
UsesPrecisionModifiers()46     static sk_sp<GrShaderCaps> UsesPrecisionModifiers() {
47         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
48         result->fVersionDeclString = "#version 400";
49         result->fUsesPrecisionModifiers = true;
50         return result;
51     }
52 
CannotUseMinAndAbsTogether()53     static sk_sp<GrShaderCaps> CannotUseMinAndAbsTogether() {
54         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
55         result->fVersionDeclString = "#version 400";
56         result->fCanUseMinAndAbsTogether = false;
57         return result;
58     }
59 
MustForceNegatedAtanParamToFloat()60     static sk_sp<GrShaderCaps> MustForceNegatedAtanParamToFloat() {
61         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
62         result->fVersionDeclString = "#version 400";
63         result->fMustForceNegatedAtanParamToFloat = true;
64         return result;
65     }
66 
ShaderDerivativeExtensionString()67     static sk_sp<GrShaderCaps> ShaderDerivativeExtensionString() {
68         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
69         result->fVersionDeclString = "#version 400";
70         result->fShaderDerivativeSupport = true;
71         result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
72         return result;
73     }
74 
FragCoordsOld()75     static sk_sp<GrShaderCaps> FragCoordsOld() {
76         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
77         result->fVersionDeclString = "#version 110";
78         result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
79         result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
80         return result;
81     }
82 
FragCoordsNew()83     static sk_sp<GrShaderCaps> FragCoordsNew() {
84         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
85         result->fVersionDeclString = "#version 400";
86         result->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
87         return result;
88     }
89 
VariousCaps()90     static sk_sp<GrShaderCaps> VariousCaps() {
91         sk_sp<GrShaderCaps> result = sk_make_sp<GrShaderCaps>(GrContextOptions());
92         result->fVersionDeclString = "#version 400";
93         result->fExternalTextureSupport = true;
94         result->fFBFetchSupport = false;
95         result->fDropsTileOnZeroDivide = true;
96         result->fTexelFetchSupport = true;
97         result->fCanUseAnyFunctionInShader = false;
98         return result;
99     }
100 };
101 
102 void write_data(const SkData& d, SkWStream& out);
103 
104 SkString operator+(const SkString& s, const char* c);
105 
106 SkString operator+(const char* c, const SkString& s);
107 
108 SkString operator+(const SkString& s1, const SkString& s2);
109 
110 bool operator==(const SkString& s1, const char* s2);
111 
112 bool operator!=(const SkString& s1, const char* s2);
113 
114 bool operator!=(const char* s1, const SkString& s2);
115 
116 SkString to_string(double value);
117 
118 SkString to_string(int32_t value);
119 
120 SkString to_string(uint32_t value);
121 
122 SkString to_string(int64_t value);
123 
124 SkString to_string(uint64_t value);
125 
126 #if _MSC_VER
127 #define NORETURN __declspec(noreturn)
128 #else
129 #define NORETURN __attribute__((__noreturn__))
130 #endif
131 int stoi(SkString s);
132 
133 double stod(SkString s);
134 
135 long stol(SkString s);
136 
137 NORETURN void sksl_abort();
138 
139 } // namespace
140 
141 #define ASSERT(x) SkASSERT(x)
142 #define ASSERT_RESULT(x) SkAssertResult(x);
143 
144 #ifdef SKIA
145 #define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
146 #else
147 #define ABORT(...) { sksl_abort(); }
148 #endif
149 
150 namespace std {
151     template<> struct hash<SkString> {
152         size_t operator()(const SkString& s) const {
153             return SkOpts::hash_fn(s.c_str(), s.size(), 0);
154         }
155     };
156 }
157 #endif
158