1 /* 2 * Copyright 2019 Google LLC 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 #include "src/gpu/GrSwizzle.h" 9 10 #include "src/core/SkRasterPipeline.h" 11 apply(SkRasterPipeline * pipeline) const12void GrSwizzle::apply(SkRasterPipeline* pipeline) const { 13 SkASSERT(pipeline); 14 switch (fKey) { 15 case GrSwizzle("rgba").asKey(): 16 return; 17 case GrSwizzle("bgra").asKey(): 18 pipeline->append(SkRasterPipeline::swap_rb); 19 return; 20 case GrSwizzle("aaa1").asKey(): 21 pipeline->append(SkRasterPipeline::alpha_to_gray); 22 return; 23 case GrSwizzle("rgb1").asKey(): 24 pipeline->append(SkRasterPipeline::force_opaque); 25 return; 26 default: { 27 GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char)); 28 // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right 29 // into a uintptr_t context. 30 uintptr_t ctx; 31 memcpy(&ctx, fSwiz, 4 * sizeof(char)); 32 pipeline->append(SkRasterPipeline::swizzle, ctx); 33 return; 34 } 35 } 36 } 37