path_win.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/gfx/path_win.h"
  5. #include <memory>
  6. #include "base/win/scoped_gdi_object.h"
  7. #include "third_party/skia/include/core/SkPath.h"
  8. #include "third_party/skia/include/core/SkRegion.h"
  9. namespace gfx {
  10. HRGN CreateHRGNFromSkRegion(const SkRegion& region) {
  11. base::win::ScopedRegion temp(::CreateRectRgn(0, 0, 0, 0));
  12. base::win::ScopedRegion result(::CreateRectRgn(0, 0, 0, 0));
  13. for (SkRegion::Iterator i(region); !i.done(); i.next()) {
  14. const SkIRect& rect = i.rect();
  15. ::SetRectRgn(temp.get(),
  16. rect.left(), rect.top(), rect.right(), rect.bottom());
  17. ::CombineRgn(result.get(), result.get(), temp.get(), RGN_OR);
  18. }
  19. return result.release();
  20. }
  21. HRGN CreateHRGNFromSkPath(const SkPath& path) {
  22. SkRegion clip_region;
  23. clip_region.setRect(path.getBounds().round());
  24. SkRegion region;
  25. region.setPath(path, clip_region);
  26. return CreateHRGNFromSkRegion(region);
  27. }
  28. } // namespace gfx