GrSwizzle.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #include "src/gpu/GrSwizzle.h"
  8. #include "src/core/SkRasterPipeline.h"
  9. void GrSwizzle::apply(SkRasterPipeline* pipeline) const {
  10. SkASSERT(pipeline);
  11. switch (fKey) {
  12. case GrSwizzle("rgba").asKey():
  13. return;
  14. case GrSwizzle("bgra").asKey():
  15. pipeline->append(SkRasterPipeline::swap_rb);
  16. return;
  17. case GrSwizzle("aaa1").asKey():
  18. pipeline->append(SkRasterPipeline::alpha_to_gray);
  19. return;
  20. case GrSwizzle("rgb1").asKey():
  21. pipeline->append(SkRasterPipeline::force_opaque);
  22. return;
  23. default: {
  24. GR_STATIC_ASSERT(sizeof(uintptr_t) >= 4 * sizeof(char));
  25. // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
  26. // into a uintptr_t context.
  27. uintptr_t ctx;
  28. memcpy(&ctx, fSwiz, 4 * sizeof(char));
  29. pipeline->append(SkRasterPipeline::swizzle, ctx);
  30. return;
  31. }
  32. }
  33. }