Modulate.cpp 1.3 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  3. #include "tools/fiddle/examples.h"
  4. // HASH=3fdac2b2f48bd227d2e74234c260bc8e
  5. REG_FIDDLE(Modulate, 256, 256, false, 0) {
  6. void draw(SkCanvas* canvas) {
  7. auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void {
  8. const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
  9. const SkPoint horz[] = { { 0, 0 }, { 128, 0 } };
  10. SkPaint paint;
  11. paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors),
  12. SkTileMode::kClamp));
  13. paint.setBlendMode(mode);
  14. canvas->translate(dx, dy);
  15. canvas->drawRect({0, 0, 128, 128}, paint);
  16. paint.setBlendMode(SkBlendMode::kXor);
  17. SkFont font;
  18. canvas->drawString(label, 40, 100, font, paint);
  19. };
  20. drawSquare(0, 0, SkBlendMode::kSrc, "destination");
  21. drawSquare(128, 0, SkBlendMode::kSrc, "");
  22. drawSquare(0, 128, SkBlendMode::kSrc, "");
  23. canvas->translate(-128, -128);
  24. canvas->rotate(90, 0, 128);
  25. drawSquare(0, 0, SkBlendMode::kSrc, "source");
  26. drawSquare(0, -128, SkBlendMode::kModulate, "modulate");
  27. drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply");
  28. }
  29. } // END FIDDLE