Add SkRasterPipeline support for more load/store formats and GrSwizzle.
Adds loads/stores (but not dst loads/gathers) for:
*fp16 single and two channel
*fp32 two channel
*normalized unsigned 8 bit two channel
*normalized unsigned 16 bit single and two channel
TODO: 4 channel unsigned normalized 16 bit.
MISSING: fp32 single channel. No matching current or future GrColorType
planned AFAIK.
Intent is to support all (noncompressed) GrColorType load/stores in
order to implement fallbacks for 3D API limitations on texture uploads
and render target readbacks (some of which require swizzling).
Also, can be used to support YUV<->RGB planar
splitters/joiners on CPU.
Bug: skia:8962
Change-Id: I258d5682a1f4025b31639a97b1a1a02077a2453f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219999
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrSwizzle.cpp b/src/gpu/GrSwizzle.cpp
new file mode 100644
index 0000000..21fe834
--- /dev/null
+++ b/src/gpu/GrSwizzle.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/gpu/GrSwizzle.h"
+#include "src/core/SkRasterPipeline.h"
+
+void GrSwizzle::apply(SkRasterPipeline* pipeline) const {
+ SkASSERT(pipeline);
+ switch (fKey) {
+ case GrSwizzle::RGBA().asKey():
+ return;
+ case GrSwizzle::BGRA().asKey():
+ pipeline->append(SkRasterPipeline::swap_rb);
+ return;
+ default: {
+ GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char));
+ // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
+ // into a uintptr_t context.
+ uintptr_t ctx;
+ memcpy(&ctx, fSwiz, 4 * sizeof(char));
+ pipeline->append(SkRasterPipeline::swizzle, ctx);
+ return;
+ }
+ }
+}