blob: f1b3b8583cb6e2ad2da9d353f145a08634c62e57 [file] [log] [blame]
Brian Salomon217522c2019-06-11 15:55:30 -04001/*
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
Greg Danielf91aeb22019-06-18 09:58:02 -04008#include "src/gpu/GrSwizzle.h"
Brian Salomon217522c2019-06-11 15:55:30 -04009
Greg Daniel2c19e7f2019-06-18 13:29:21 -040010#include "src/core/SkRasterPipeline.h"
11
Brian Salomon217522c2019-06-11 15:55:30 -040012void GrSwizzle::apply(SkRasterPipeline* pipeline) const {
13 SkASSERT(pipeline);
14 switch (fKey) {
Brian Salomonf30b1c12019-06-20 12:25:02 -040015 case GrSwizzle("rgba").asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040016 return;
Brian Salomonf30b1c12019-06-20 12:25:02 -040017 case GrSwizzle("bgra").asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040018 pipeline->append(SkRasterPipeline::swap_rb);
19 return;
Brian Salomonf30b1c12019-06-20 12:25:02 -040020 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;
Brian Salomon217522c2019-06-11 15:55:30 -040026 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}