blob: 707b272937f5e0b3b1d948ba36ee23b5595afa63 [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) {
Robert Phillipsc34d9932019-06-18 11:57:12 +000015 case GrSwizzle::RGBA().asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040016 return;
Robert Phillipsc34d9932019-06-18 11:57:12 +000017 case GrSwizzle::BGRA().asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040018 pipeline->append(SkRasterPipeline::swap_rb);
19 return;
Brian Salomon217522c2019-06-11 15:55:30 -040020 default: {
21 GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char));
22 // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
23 // into a uintptr_t context.
24 uintptr_t ctx;
25 memcpy(&ctx, fSwiz, 4 * sizeof(char));
26 pipeline->append(SkRasterPipeline::swizzle, ctx);
27 return;
28 }
29 }
30}