@@ -57,7 +57,7 @@ GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode modeX, Mode modeY, i
5757
5858static void append_wrap (GrGLSLShaderBuilder* builder, GrTextureDomain::Mode mode,
5959 const char * inCoord, const char * domainStart, const char * domainEnd,
60- const char * out) {
60+ bool is2D, const char * out) {
6161 switch (mode) {
6262 case GrTextureDomain::kIgnore_Mode :
6363 builder->codeAppendf (" %s = %s;\n " , out, inCoord);
@@ -73,10 +73,11 @@ static void append_wrap(GrGLSLShaderBuilder* builder, GrTextureDomain::Mode mode
7373 domainEnd, domainStart, domainStart);
7474 break ;
7575 case GrTextureDomain::kMirrorRepeat_Mode : {
76+ const char * type = is2D ? " float2" : " float" ;
7677 builder->codeAppend (" {" );
77- builder->codeAppendf (" float w = %s - %s;" , domainEnd, domainStart);
78- builder->codeAppendf (" float w2 = 2 * w;" );
79- builder->codeAppendf (" float m = mod(%s - %s, w2);" , inCoord, domainStart);
78+ builder->codeAppendf (" %s w = %s - %s;" , type , domainEnd, domainStart);
79+ builder->codeAppendf (" %s w2 = 2 * w;" , type );
80+ builder->codeAppendf (" %s m = mod(%s - %s, w2);" , type , inCoord, domainStart);
8081 builder->codeAppendf (" %s = mix(m, w2 - m, step(w, m)) + %s;" , out, domainStart);
8182 builder->codeAppend (" }" );
8283 break ;
@@ -163,18 +164,27 @@ void GrTextureDomain::GLDomain::sample(GrGLSLShaderBuilder* builder,
163164 builder->codeAppend (" float2 clampedCoord;" );
164165 SkString start;
165166 SkString end;
166- // Apply x mode to the x coordinate using the left and right edges of the domain rect
167- // (stored as the x and z components of the domain uniform).
168- start.printf (" %s.x" , fDomainName .c_str ());
169- end.printf (" %s.z" , fDomainName .c_str ());
170- append_wrap (builder, textureDomain.modeX (), " origCoord.x" , start.c_str (), end.c_str (),
171- " clampedCoord.x" );
172- // Repeat the same logic for y.
173- start.printf (" %s.y" , fDomainName .c_str ());
174- end.printf (" %s.w" , fDomainName .c_str ());
175- append_wrap (builder, textureDomain.modeY (), " origCoord.y" , start.c_str (), end.c_str (),
176- " clampedCoord.y" );
177-
167+ bool is2D = textureDomain.modeX () == textureDomain.modeY ();
168+ if (is2D) {
169+ // Doing the domain setup using vectors seems to avoid shader compilation issues on
170+ // Chromecast, possibly due to reducing shader length.
171+ start.printf (" %s.xy" , fDomainName .c_str ());
172+ end.printf (" %s.zw" , fDomainName .c_str ());
173+ append_wrap (builder, textureDomain.modeX (), " origCoord" , start.c_str (), end.c_str (),
174+ true , " clampedCoord" );
175+ } else {
176+ // Apply x mode to the x coordinate using the left and right edges of the domain rect
177+ // (stored as the x and z components of the domain uniform).
178+ start.printf (" %s.x" , fDomainName .c_str ());
179+ end.printf (" %s.z" , fDomainName .c_str ());
180+ append_wrap (builder, textureDomain.modeX (), " origCoord.x" , start.c_str (), end.c_str (),
181+ false , " clampedCoord.x" );
182+ // Repeat the same logic for y.
183+ start.printf (" %s.y" , fDomainName .c_str ());
184+ end.printf (" %s.w" , fDomainName .c_str ());
185+ append_wrap (builder, textureDomain.modeY (), " origCoord.y" , start.c_str (), end.c_str (),
186+ false , " clampedCoord.y" );
187+ }
178188 // Sample 'appendSample' at the clamped coordinate location.
179189 SkString color = appendSample (" clampedCoord" );
180190
0 commit comments