blurpositioning.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 2017 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/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkImageFilter.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkScalar.h"
  14. #include "include/effects/SkBlurImageFilter.h"
  15. #include <initializer_list>
  16. // For all sigma, the black box should be centered in the red outline. For small sigma,
  17. // the rectangle is not blurred, but still must be centered properly.
  18. DEF_SIMPLE_GM(check_small_sigma_offset, canvas, 200, 1200) {
  19. for (auto sigma : {0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1.0, 1.2}) {
  20. // border calculation from SkBlurImageFilter
  21. int border = SkScalarCeilToInt(sigma * 3);
  22. SkRect r = SkRect::MakeXYWH(50, 50, 100, 50);
  23. SkRect b = r.makeOutset(border + 1, border + 1);
  24. b.inset(0.5f, 0.5f);
  25. SkPaint p;
  26. p.setColor(SK_ColorRED);
  27. p.setStyle(SkPaint::Style::kStroke_Style);
  28. canvas->drawRect(b, p);
  29. p.reset();
  30. p.setColor(SK_ColorBLACK);
  31. p.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
  32. canvas->drawRect(r, p);
  33. canvas->translate(0, 100);
  34. }
  35. }