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) { |
Robert Phillips | c34d993 | 2019-06-18 11:57:12 +0000 | [diff] [blame] | 14 | case GrSwizzle::RGBA().asKey(): |
Brian Salomon | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 15 | return; |
Robert Phillips | c34d993 | 2019-06-18 11:57:12 +0000 | [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 | 217522c | 2019-06-11 15:55:30 -0400 | [diff] [blame] | 19 | default: { |
| 20 | GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char)); |
| 21 | // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right |
| 22 | // into a uintptr_t context. |
| 23 | uintptr_t ctx; |
| 24 | memcpy(&ctx, fSwiz, 4 * sizeof(char)); |
| 25 | pipeline->append(SkRasterPipeline::swizzle, ctx); |
| 26 | return; |
| 27 | } |
| 28 | } |
| 29 | } |