Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
RTEffectTest.cpp File Reference
#include "tests/Test.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/gpu/graphite/Context.h"
#include "src/core/SkRuntimeEffectPriv.h"
#include "src/gpu/graphite/ContextPriv.h"
#include "src/gpu/graphite/KeyHelpers.h"
#include "src/gpu/graphite/ShaderCodeDictionary.h"

Go to the source code of this file.

Functions

 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (Shader_FindOrCreateSnippetForRuntimeEffect, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ColorFilter_FindOrCreateSnippetForRuntimeEffect, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ShaderUniforms_FindOrCreateSnippetForRuntimeEffect, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ColorFilterUniforms_FindOrCreateSnippetForRuntimeEffect, reporter, context, CtsEnforcement::kNextRelease)
 

Function Documentation

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [1/4]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ColorFilter_FindOrCreateSnippetForRuntimeEffect  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 44 of file RTEffectTest.cpp.

47 {
48 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
49
50 std::unique_ptr<SkRuntimeEffect> testEffect(SkMakeRuntimeEffect(
52 "half4 main(half4 color) {"
53 "return color.gbra;"
54 "}"
55 ));
56
57 // Create a new runtime-effect snippet.
58 int snippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
60
61 // Verify that it can be looked up and its name is 'RuntimeEffect'. (The name isn't meaningful,
62 // but this is an easy way to verify that we didn't get an unrelated snippet.)
63 const ShaderSnippet* snippet = dict->getEntry(snippetID);
64 REPORTER_ASSERT(reporter, snippet);
65 REPORTER_ASSERT(reporter, std::string_view(snippet->fName) == "RuntimeEffect");
66
67 // If we pass the same effect again, we should get the same snippet ID as before.
68 int foundSnippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
69 REPORTER_ASSERT(reporter, foundSnippetID == snippetID);
70}
reporter
SkRuntimeEffect * SkMakeRuntimeEffect(SkRuntimeEffect::Result(*make)(SkString, const SkRuntimeEffect::Options &), const char *sksl, SkRuntimeEffect::Options options=SkRuntimeEffect::Options{})
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static Result MakeForColorFilter(SkString sksl, const Options &)
int findOrCreateRuntimeEffectSnippet(const SkRuntimeEffect *effect)
const ShaderSnippet * getEntry(int codeSnippetID) const SK_EXCLUDES(fSpinLock)
static constexpr int kUnknownRuntimeEffectIDStart

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [2/4]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ColorFilterUniforms_FindOrCreateSnippetForRuntimeEffect  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 115 of file RTEffectTest.cpp.

116 {
117 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
118
119 std::unique_ptr<SkRuntimeEffect> testEffect(SkMakeRuntimeEffect(
121 "uniform float3x3 MyFloat3x3Uniform;"
122 "uniform int4 MyInt4ArrayUniform[1];"
123 "uniform half2 MyHalf2ArrayUniform[99];"
124 "half4 main(half4 color) {"
125 "return color.gbra;"
126 "}"
127 ));
128
129 // Create a new runtime-effect snippet.
130 int snippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
132
133 // Delete the test effect.
134 testEffect = nullptr;
135
136 // Verify that it can be looked up by its snippet ID.
137 const ShaderSnippet* snippet = dict->getEntry(snippetID);
138 REPORTER_ASSERT(reporter, snippet);
139
140 // The uniform span should match our expectations even though the runtime effect was deleted.
141 REPORTER_ASSERT(reporter, snippet->fUniforms.size() == 3);
142
144 std::string_view(snippet->fUniforms[0].name()) == "MyFloat3x3Uniform");
146 REPORTER_ASSERT(reporter, snippet->fUniforms[0].count() == 0);
147
149 std::string_view(snippet->fUniforms[1].name()) == "MyInt4ArrayUniform");
150 REPORTER_ASSERT(reporter, snippet->fUniforms[1].type() == SkSLType::kInt4);
151 REPORTER_ASSERT(reporter, snippet->fUniforms[1].count() == 1);
152
154 std::string_view(snippet->fUniforms[2].name()) == "MyHalf2ArrayUniform");
155 REPORTER_ASSERT(reporter, snippet->fUniforms[2].type() == SkSLType::kHalf2);
156 REPORTER_ASSERT(reporter, snippet->fUniforms[2].count() == 99);
157}

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [3/4]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( Shader_FindOrCreateSnippetForRuntimeEffect  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 19 of file RTEffectTest.cpp.

20 {
21 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
22
23 std::unique_ptr<SkRuntimeEffect> testEffect(SkMakeRuntimeEffect(SkRuntimeEffect::MakeForShader,
24 "half4 main(float2 coords) {"
25 "return half4(coords.xy01);"
26 "}"
27 ));
28
29 // Create a new runtime-effect snippet.
30 int snippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
32
33 // Verify that it can be looked up and its name is 'RuntimeEffect'. (The name isn't meaningful,
34 // but this is an easy way to verify that we didn't get an unrelated snippet.)
35 const ShaderSnippet* snippet = dict->getEntry(snippetID);
36 REPORTER_ASSERT(reporter, snippet);
37 REPORTER_ASSERT(reporter, std::string_view(snippet->fName) == "RuntimeEffect");
38
39 // If we pass the same effect again, we should get the same snippet ID as before.
40 int foundSnippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
41 REPORTER_ASSERT(reporter, foundSnippetID == snippetID);
42}
static Result MakeForShader(SkString sksl, const Options &)

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [4/4]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ShaderUniforms_FindOrCreateSnippetForRuntimeEffect  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 72 of file RTEffectTest.cpp.

73 {
74 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
75
76 std::unique_ptr<SkRuntimeEffect> testEffect(SkMakeRuntimeEffect(SkRuntimeEffect::MakeForShader,
77 "uniform float3x3 MyFloat3x3Uniform;"
78 "uniform int4 MyInt4ArrayUniform[1];"
79 "uniform half2 MyHalf2ArrayUniform[99];"
80 "half4 main(float2 coords) {"
81 "return half4(coords.xy01);"
82 "}"
83 ));
84
85 // Create a new runtime-effect snippet.
86 int snippetID = dict->findOrCreateRuntimeEffectSnippet(testEffect.get());
88
89 // Delete the test effect.
90 testEffect = nullptr;
91
92 // Verify that it can be looked up by its snippet ID.
93 const ShaderSnippet* snippet = dict->getEntry(snippetID);
94 REPORTER_ASSERT(reporter, snippet);
95
96 // The uniform span should match our expectations even though the runtime effect was deleted.
97 REPORTER_ASSERT(reporter, snippet->fUniforms.size() == 3);
98
100 std::string_view(snippet->fUniforms[0].name()) == "MyFloat3x3Uniform");
102 REPORTER_ASSERT(reporter, snippet->fUniforms[0].count() == 0);
103
105 std::string_view(snippet->fUniforms[1].name()) == "MyInt4ArrayUniform");
106 REPORTER_ASSERT(reporter, snippet->fUniforms[1].type() == SkSLType::kInt4);
107 REPORTER_ASSERT(reporter, snippet->fUniforms[1].count() == 1);
108
110 std::string_view(snippet->fUniforms[2].name()) == "MyHalf2ArrayUniform");
111 REPORTER_ASSERT(reporter, snippet->fUniforms[2].type() == SkSLType::kHalf2);
112 REPORTER_ASSERT(reporter, snippet->fUniforms[2].count() == 99);
113}