Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 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 | |
Brian Salomon | 3ec1f54 | 2019-06-17 17:54:57 +0000 | [diff] [blame] | 8 | #include "src/gpu/GrSwizzle.h" |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 9 | #include "src/core/SkRasterPipeline.h" |
| 10 | |
| 11 | void GrSwizzle::apply(SkRasterPipeline* pipeline) const { |
| 12 | SkASSERT(pipeline); |
| 13 | switch (fKey) { |
Brian Salomon | 5509102 | 2019-06-17 14:08:58 -0400 | [diff] [blame] | 14 | case GrSwizzle("rgba").asKey(): |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 15 | return; |
Brian Salomon | 5509102 | 2019-06-17 14:08:58 -0400 | [diff] [blame] | 16 | case GrSwizzle("bgra").asKey(): |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 17 | pipeline->append(SkRasterPipeline::swap_rb); |
| 18 | return; |
Brian Salomon | 5509102 | 2019-06-17 14:08:58 -0400 | [diff] [blame] | 19 | case GrSwizzle("aaa1").asKey(): |
| 20 | pipeline->append(SkRasterPipeline::alpha_to_gray); |
| 21 | return; |
| 22 | case GrSwizzle("rgb1").asKey(): |
| 23 | pipeline->append(SkRasterPipeline::force_opaque); |
| 24 | return; |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 25 | default: { |
| 26 | GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char)); |
| 27 | // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right |
| 28 | // into a uintptr_t context. |
| 29 | uintptr_t ctx; |
| 30 | memcpy(&ctx, fSwiz, 4 * sizeof(char)); |
| 31 | pipeline->append(SkRasterPipeline::swizzle, ctx); |
| 32 | return; |
| 33 | } |
| 34 | } |
| 35 | } |