plus.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2015 Google Inc.
  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 "gm/gm.h"
  8. #include "include/core/SkBlendMode.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkColor.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkPath.h"
  13. #include "include/core/SkRect.h"
  14. DEF_SIMPLE_GM(PlusMergesAA, canvas, 256, 256) {
  15. SkPaint p;
  16. p.setColor(SK_ColorRED);
  17. p.setAntiAlias(true); // <-- crucial to the test that we use AA
  18. // Draw a two red squares.
  19. canvas->drawRect(SkRect::MakeWH(100, 100), p);
  20. canvas->drawRect(SkRect::MakeXYWH(150, 0, 100, 100), p);
  21. p.setColor(0xf000ff00);
  22. // We'll draw a green square on top of each using two triangles.
  23. SkPath upperLeft;
  24. upperLeft.lineTo(100, 0);
  25. upperLeft.lineTo(0, 100);
  26. upperLeft.lineTo(0, 0);
  27. SkPath bottomRight;
  28. bottomRight.moveTo(100, 0);
  29. bottomRight.lineTo(100, 100);
  30. bottomRight.lineTo(0, 100);
  31. bottomRight.lineTo(100, 0);
  32. // The left square is drawn simply with SrcOver. It will show a red seam.
  33. canvas->drawPath(upperLeft, p);
  34. canvas->drawPath(bottomRight, p);
  35. // Using Plus on the right should merge the AA of seam together completely covering the red.
  36. canvas->saveLayer(nullptr, nullptr);
  37. p.setBlendMode(SkBlendMode::kPlus);
  38. canvas->translate(150, 0);
  39. canvas->drawPath(upperLeft, p);
  40. canvas->drawPath(bottomRight, p);
  41. canvas->restore();
  42. }