Home | History | Annotate | Download | only in gfx
      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 
      5 #include "ui/gfx/path_win.h"
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "ui/gfx/path.h"
      9 
     10 namespace gfx {
     11 
     12 HRGN CreateHRGNFromSkPath(const SkPath& path) {
     13   int point_count = path.getPoints(NULL, 0);
     14   scoped_ptr<SkPoint[]> points(new SkPoint[point_count]);
     15   path.getPoints(points.get(), point_count);
     16   scoped_ptr<POINT[]> windows_points(new POINT[point_count]);
     17   for (int i = 0; i < point_count; ++i) {
     18     windows_points[i].x = SkScalarRound(points[i].fX);
     19     windows_points[i].y = SkScalarRound(points[i].fY);
     20   }
     21 
     22   return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE);
     23 }
     24 
     25 // See path_aura.cc for Aura definition of these methods:
     26 #if !defined(USE_AURA)
     27 
     28 NativeRegion Path::CreateNativeRegion() const {
     29   return CreateHRGNFromSkPath(*this);
     30 }
     31 
     32 // static
     33 NativeRegion Path::IntersectRegions(NativeRegion r1, NativeRegion r2) {
     34   HRGN dest = CreateRectRgn(0, 0, 1, 1);
     35   CombineRgn(dest, r1, r2, RGN_AND);
     36   return dest;
     37 }
     38 
     39 // static
     40 NativeRegion Path::CombineRegions(NativeRegion r1, NativeRegion r2) {
     41   HRGN dest = CreateRectRgn(0, 0, 1, 1);
     42   CombineRgn(dest, r1, r2, RGN_OR);
     43   return dest;
     44 }
     45 
     46 // static
     47 NativeRegion Path::SubtractRegion(NativeRegion r1, NativeRegion r2) {
     48   HRGN dest = CreateRectRgn(0, 0, 1, 1);
     49   CombineRgn(dest, r1, r2, RGN_DIFF);
     50   return dest;
     51 }
     52 
     53 #endif
     54 
     55 }  // namespace gfx
     56