blob: fae1c8560631be9abc5a4b2dfcf09d412930d05c [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
8#ifndef SKSL_UTIL
9#define SKSL_UTIL
10
ethannicholasb3058bd2016-07-01 08:22:01 -070011#include "stdlib.h"
12#include "assert.h"
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050013#include "SkOpts.h"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050014#include "SkRefCnt.h"
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050015#include "SkStream.h"
16#include "SkString.h"
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050017#include "SkTypes.h"
18#include "glsl/GrGLSLCaps.h"
19#include "GrContextOptions.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070020
21namespace SkSL {
22
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050023// Various sets of caps for use in tests
24class GLSLCapsFactory {
25public:
26 static sk_sp<GrGLSLCaps> Default() {
27 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
28 result->fVersionDeclString = "#version 400";
29 result->fShaderDerivativeSupport = true;
30 return result;
31 }
32
33 static sk_sp<GrGLSLCaps> Version450Core() {
34 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
35 result->fVersionDeclString = "#version 450 core";
36 return result;
37 }
38
39 static sk_sp<GrGLSLCaps> Version110() {
40 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
41 result->fVersionDeclString = "#version 110";
42 result->fGLSLGeneration = GrGLSLGeneration::k110_GrGLSLGeneration;
43 return result;
44 }
45
46 static sk_sp<GrGLSLCaps> UsesPrecisionModifiers() {
47 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
48 result->fVersionDeclString = "#version 400";
49 result->fUsesPrecisionModifiers = true;
50 return result;
51 }
52
53 static sk_sp<GrGLSLCaps> CannotUseMinAndAbsTogether() {
54 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
55 result->fVersionDeclString = "#version 400";
56 result->fCanUseMinAndAbsTogether = false;
57 return result;
58 }
59
60 static sk_sp<GrGLSLCaps> MustForceNegatedAtanParamToFloat() {
61 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
62 result->fVersionDeclString = "#version 400";
63 result->fMustForceNegatedAtanParamToFloat = true;
64 return result;
65 }
66
67 static sk_sp<GrGLSLCaps> ShaderDerivativeExtensionString() {
68 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
69 result->fVersionDeclString = "#version 400";
70 result->fShaderDerivativeSupport = true;
71 result->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
72 return result;
73 }
Ethan Nicholas3605ace2016-11-21 15:59:48 -050074
75 static sk_sp<GrGLSLCaps> VariousCaps() {
76 sk_sp<GrGLSLCaps> result = sk_make_sp<GrGLSLCaps>(GrContextOptions());
77 result->fVersionDeclString = "#version 400";
78 result->fExternalTextureSupport = true;
79 result->fFBFetchSupport = false;
80 result->fDropsTileOnZeroDivide = true;
81 result->fTexelFetchSupport = true;
82 result->fCanUseAnyFunctionInShader = false;
83 return result;
84 }
Ethan Nicholas7ef4b742016-11-11 15:16:46 -050085};
86
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050087void write_data(const SkData& d, SkWStream& out);
ethannicholasb3058bd2016-07-01 08:22:01 -070088
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050089SkString operator+(const SkString& s, const char* c);
ethannicholas5961bc92016-10-12 06:39:56 -070090
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050091SkString operator+(const char* c, const SkString& s);
ethannicholas5961bc92016-10-12 06:39:56 -070092
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050093SkString operator+(const SkString& s1, const SkString& s2);
ethannicholas5961bc92016-10-12 06:39:56 -070094
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050095bool operator==(const SkString& s1, const char* s2);
ethannicholas5961bc92016-10-12 06:39:56 -070096
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050097bool operator!=(const SkString& s1, const char* s2);
98
99bool operator!=(const char* s1, const SkString& s2);
100
101SkString to_string(double value);
102
103SkString to_string(int32_t value);
104
105SkString to_string(uint32_t value);
106
107SkString to_string(int64_t value);
108
109SkString to_string(uint64_t value);
ethannicholasb3058bd2016-07-01 08:22:01 -0700110
111#if _MSC_VER
112#define NORETURN __declspec(noreturn)
113#else
114#define NORETURN __attribute__((__noreturn__))
115#endif
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500116int stoi(SkString s);
ethannicholasb3058bd2016-07-01 08:22:01 -0700117
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500118double stod(SkString s);
ethannicholasb3058bd2016-07-01 08:22:01 -0700119
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500120long stol(SkString s);
ethannicholasb3058bd2016-07-01 08:22:01 -0700121
122NORETURN void sksl_abort();
123
124} // namespace
125
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500126#define ASSERT(x) SkASSERT(x)
127#define ASSERT_RESULT(x) SkAssertResult(x);
ethannicholasb3058bd2016-07-01 08:22:01 -0700128
129#ifdef SKIA
130#define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); }
131#else
132#define ABORT(...) { sksl_abort(); }
133#endif
134
Ethan Nicholas9e1138d2016-11-21 10:39:35 -0500135namespace std {
136 template<> struct hash<SkString> {
137 size_t operator()(const SkString& s) const {
138 return SkOpts::hash_fn(s.c_str(), s.size(), 0);
139 }
140 };
141}
ethannicholasb3058bd2016-07-01 08:22:01 -0700142#endif