blob: 138b24f63b48fa9aec50f1bb5b1f99780865ad85 [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
Brian Salomon3ec1f542019-06-17 17:54:57 +00008#include "src/gpu/GrSwizzle.h"
Brian Salomon217522c2019-06-11 15:55:30 -04009#include "src/core/SkRasterPipeline.h"
10
11void GrSwizzle::apply(SkRasterPipeline* pipeline) const {
12 SkASSERT(pipeline);
13 switch (fKey) {
Brian Salomon55091022019-06-17 14:08:58 -040014 case GrSwizzle("rgba").asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040015 return;
Brian Salomon55091022019-06-17 14:08:58 -040016 case GrSwizzle("bgra").asKey():
Brian Salomon217522c2019-06-11 15:55:30 -040017 pipeline->append(SkRasterPipeline::swap_rb);
18 return;
Brian Salomon55091022019-06-17 14:08:58 -040019 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 Salomon217522c2019-06-11 15:55:30 -040025 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}