Flutter Engine
The Flutter Engine
Swizzle.cpp
Go to the documentation of this file.
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
8#include "src/gpu/Swizzle.h"
9
12
13#include <cstring>
14
15namespace skgpu {
16
17void Swizzle::apply(SkRasterPipeline* pipeline) const {
18 SkASSERT(pipeline);
19 switch (fKey) {
20 case Swizzle("rgba").asKey():
21 return;
22 case Swizzle("bgra").asKey():
23 pipeline->append(SkRasterPipelineOp::swap_rb);
24 return;
25 case Swizzle("aaa1").asKey():
26 pipeline->append(SkRasterPipelineOp::alpha_to_gray);
27 return;
28 case Swizzle("rgb1").asKey():
29 pipeline->append(SkRasterPipelineOp::force_opaque);
30 return;
31 case Swizzle("a001").asKey():
32 pipeline->append(SkRasterPipelineOp::alpha_to_red);
33 return;
34 default: {
35 static_assert(sizeof(uintptr_t) >= 4 * sizeof(char));
36 // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
37 // into a uintptr_t context.
38 uintptr_t ctx = {};
39 memcpy(&ctx, this->asString().c_str(), 4 * sizeof(char));
40 pipeline->append(SkRasterPipelineOp::swizzle, ctx);
41 return;
42 }
43 }
44}
45
47 char swiz[5];
48 uint16_t key = fKey;
49 for (int i = 0; i < 4; ++i) {
50 swiz[i] = IToC(key & 0xfU);
51 key >>= 4;
52 }
53 swiz[4] = '\0';
54 return SkString(swiz);
55}
56
57} // namespace skgpu
#define SkASSERT(cond)
Definition: SkAssert.h:116
void append(SkRasterPipelineOp, void *=nullptr)
constexpr Swizzle()
Definition: Swizzle.h:31
SkString asString() const
Definition: Swizzle.cpp:46
void apply(SkRasterPipeline *) const
Definition: Swizzle.cpp:17
Definition: GpuTools.h:21