@@ -153,68 +153,66 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
153153 // Go through program elements, pulling out information that we need
154154 for (const auto & elem : *program) {
155155 // Variables (uniform, varying, etc.)
156- if (elem.kind () == SkSL::ProgramElement::Kind::kVar ) {
157- const auto & varDecls = static_cast <const SkSL::VarDeclarations&>(elem);
158- for (const auto & varDecl : varDecls.fVars ) {
159- const SkSL::Variable& var =
160- *(static_cast <const SkSL::VarDeclaration&>(*varDecl).fVar );
161- const SkSL::Type& varType = var.type ();
162-
163- // Varyings (only used in conjunction with drawVertices)
164- if (var.fModifiers .fFlags & SkSL::Modifiers::kVarying_Flag ) {
165- varyings.push_back ({var.name (),
166- varType.typeKind () == SkSL::Type::TypeKind::kVector
167- ? varType.columns ()
168- : 1 });
169- }
170- // Fragment Processors (aka 'shader'): These are child effects
171- else if (&varType == ctx.fFragmentProcessor_Type .get ()) {
172- children.push_back (var.name ());
173- sampleUsages.push_back (SkSL::Analysis::GetSampleUsage (*program, var));
156+ if (elem.is <SkSL::GlobalVarDeclaration>()) {
157+ const auto & varDecl = elem.as <SkSL::GlobalVarDeclaration>().fDecl ;
158+
159+ const SkSL::Variable& var = *varDecl->fVar ;
160+ const SkSL::Type& varType = var.type ();
161+
162+ // Varyings (only used in conjunction with drawVertices)
163+ if (var.fModifiers .fFlags & SkSL::Modifiers::kVarying_Flag ) {
164+ varyings.push_back ({var.name (),
165+ varType.typeKind () == SkSL::Type::TypeKind::kVector
166+ ? varType.columns ()
167+ : 1 });
168+ }
169+ // Fragment Processors (aka 'shader'): These are child effects
170+ else if (&varType == ctx.fFragmentProcessor_Type .get ()) {
171+ children.push_back (var.name ());
172+ sampleUsages.push_back (SkSL::Analysis::GetSampleUsage (*program, var));
173+ }
174+ // 'uniform' variables
175+ else if (var.fModifiers .fFlags & SkSL::Modifiers::kUniform_Flag ) {
176+ Uniform uni;
177+ uni.fName = var.name ();
178+ uni.fFlags = 0 ;
179+ uni.fCount = 1 ;
180+
181+ const SkSL::Type* type = &var.type ();
182+ if (type->typeKind () == SkSL::Type::TypeKind::kArray ) {
183+ uni.fFlags |= Uniform::kArray_Flag ;
184+ uni.fCount = type->columns ();
185+ type = &type->componentType ();
174186 }
175- // 'uniform' variables
176- else if (var.fModifiers .fFlags & SkSL::Modifiers::kUniform_Flag ) {
177- Uniform uni;
178- uni.fName = var.name ();
179- uni.fFlags = 0 ;
180- uni.fCount = 1 ;
181-
182- const SkSL::Type* type = &var.type ();
183- if (type->typeKind () == SkSL::Type::TypeKind::kArray ) {
184- uni.fFlags |= Uniform::kArray_Flag ;
185- uni.fCount = type->columns ();
186- type = &type->componentType ();
187- }
188187
189- if (!init_uniform_type (ctx, type, &uni)) {
190- RETURN_FAILURE (" Invalid uniform type: '%s'" , type->displayName ().c_str ());
191- }
188+ if (!init_uniform_type (ctx, type, &uni)) {
189+ RETURN_FAILURE (" Invalid uniform type: '%s'" , type->displayName ().c_str ());
190+ }
192191
193- const SkSL::StringFragment& marker (var.fModifiers .fLayout .fMarker );
194- if (marker.fLength ) {
195- uni.fFlags |= Uniform::kMarker_Flag ;
196- allowColorFilter = false ;
197- if (!parse_marker (marker, &uni.fMarker , &uni.fFlags )) {
198- RETURN_FAILURE (" Invalid 'marker' string: '%.*s'" , (int )marker.fLength ,
199- marker.fChars );
200- }
192+ const SkSL::StringFragment& marker (var.fModifiers .fLayout .fMarker );
193+ if (marker.fLength ) {
194+ uni.fFlags |= Uniform::kMarker_Flag ;
195+ allowColorFilter = false ;
196+ if (!parse_marker (marker, &uni.fMarker , &uni.fFlags )) {
197+ RETURN_FAILURE (" Invalid 'marker' string: '%.*s'" , (int )marker.fLength ,
198+ marker.fChars );
201199 }
200+ }
202201
203- if (var.fModifiers .fLayout .fFlags & SkSL::Layout::Flag::kSRGBUnpremul_Flag ) {
204- uni.fFlags |= Uniform::kSRGBUnpremul_Flag ;
205- }
202+ if (var.fModifiers .fLayout .fFlags & SkSL::Layout::Flag::kSRGBUnpremul_Flag ) {
203+ uni.fFlags |= Uniform::kSRGBUnpremul_Flag ;
204+ }
206205
207- uni.fOffset = offset;
208- offset += uni.sizeInBytes ();
209- SkASSERT (SkIsAlign4 (offset));
206+ uni.fOffset = offset;
207+ offset += uni.sizeInBytes ();
208+ SkASSERT (SkIsAlign4 (offset));
210209
211- uniforms.push_back (uni);
212- }
210+ uniforms.push_back (uni);
213211 }
214212 }
215213 // Functions
216- else if (elem.kind () == SkSL::ProgramElement::Kind:: kFunction ) {
217- const auto & func = static_cast < const SkSL::FunctionDefinition&>(elem );
214+ else if (elem.is < SkSL::FunctionDefinition>() ) {
215+ const auto & func = elem. as < SkSL::FunctionDefinition>( );
218216 const SkSL::FunctionDeclaration& decl = func.fDeclaration ;
219217 if (decl.name () == " main" ) {
220218 hasMain = true ;
0 commit comments