Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / Swizzle.cpp
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
10 #include "src/core/SkRasterPipeline.h"
11
12 namespace skgpu {
13
14 void Swizzle::apply(SkRasterPipeline* pipeline) const {
15     SkASSERT(pipeline);
16     switch (fKey) {
17         case Swizzle("rgba").asKey():
18             return;
19         case Swizzle("bgra").asKey():
20             pipeline->append(SkRasterPipeline::swap_rb);
21             return;
22         case Swizzle("aaa1").asKey():
23             pipeline->append(SkRasterPipeline::alpha_to_gray);
24             return;
25         case Swizzle("rgb1").asKey():
26             pipeline->append(SkRasterPipeline::force_opaque);
27             return;
28         case Swizzle("a001").asKey():
29             pipeline->append(SkRasterPipeline::alpha_to_red);
30             return;
31         default: {
32             static_assert(sizeof(uintptr_t) >= 4 * sizeof(char));
33             // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
34             // into a uintptr_t context.
35             uintptr_t ctx;
36             memcpy(&ctx, this->asString().c_str(), 4 * sizeof(char));
37             pipeline->append(SkRasterPipeline::swizzle, ctx);
38             return;
39         }
40     }
41 }
42
43 SkString Swizzle::asString() const {
44     char swiz[5];
45     uint16_t key = fKey;
46     for (int i = 0; i < 4; ++i) {
47         swiz[i] = IToC(key & 0xfU);
48         key >>= 4;
49     }
50     swiz[4] = '\0';
51     return SkString(swiz);
52 }
53
54 } // namespace skgpu