2 * Copyright 2019 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/gpu/Swizzle.h"
10 #include "src/core/SkRasterPipeline.h"
14 void Swizzle::apply(SkRasterPipeline* pipeline) const {
17 case Swizzle("rgba").asKey():
19 case Swizzle("bgra").asKey():
20 pipeline->append(SkRasterPipeline::swap_rb);
22 case Swizzle("aaa1").asKey():
23 pipeline->append(SkRasterPipeline::alpha_to_gray);
25 case Swizzle("rgb1").asKey():
26 pipeline->append(SkRasterPipeline::force_opaque);
28 case Swizzle("a001").asKey():
29 pipeline->append(SkRasterPipeline::alpha_to_red);
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.
36 memcpy(&ctx, this->asString().c_str(), 4 * sizeof(char));
37 pipeline->append(SkRasterPipeline::swizzle, ctx);
43 SkString Swizzle::asString() const {
46 for (int i = 0; i < 4; ++i) {
47 swiz[i] = IToC(key & 0xfU);
51 return SkString(swiz);