Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: ui/gfx/gdi_util.cc

Issue 10662037: basic nc paint, moving, resizing for views_examples_exe on win (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: GetHwnd->hwnd Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/gdi_util.h ('k') | ui/gfx/path_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/gdi_util.h" 5 #include "ui/gfx/gdi_util.h"
6 6
7 #include "base/memory/scoped_ptr.h"
8
7 namespace gfx { 9 namespace gfx {
8 10
9 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { 11 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) {
10 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); 12 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr);
11 } 13 }
12 14
13 void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, 15 void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth,
14 BITMAPINFOHEADER* hdr) { 16 BITMAPINFOHEADER* hdr) {
15 // These values are shared with gfx::PlatformDevice 17 // These values are shared with gfx::PlatformDevice
16 hdr->biSize = sizeof(BITMAPINFOHEADER); 18 hdr->biSize = sizeof(BITMAPINFOHEADER);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 cutouts[i].x(), 71 cutouts[i].x(),
70 cutouts[i].y(), 72 cutouts[i].y(),
71 cutouts[i].right(), 73 cutouts[i].right(),
72 cutouts[i].bottom()); 74 cutouts[i].bottom());
73 ::CombineRgn(hrgn, hrgn, cutout, RGN_DIFF); 75 ::CombineRgn(hrgn, hrgn, cutout, RGN_DIFF);
74 } 76 }
75 ::DeleteObject(cutout); 77 ::DeleteObject(cutout);
76 } 78 }
77 } 79 }
78 80
81 HRGN ConvertPathToHRGN(const gfx::Path& path) {
82 #if defined(USE_AURA)
83 int point_count = path.getPoints(NULL, 0);
84 scoped_array<SkPoint> points(new SkPoint[point_count]);
85 path.getPoints(points.get(), point_count);
86 scoped_array<POINT> windows_points(new POINT[point_count]);
87 for (int i = 0; i < point_count; ++i) {
88 windows_points[i].x = SkScalarRound(points[i].fX);
89 windows_points[i].y = SkScalarRound(points[i].fY);
90 }
91
92 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE);
93 #elif defined(OS_WIN)
94 return path.CreateNativeRegion();
95 #endif
96 }
97
98
79 double CalculatePageScale(HDC dc, int page_width, int page_height) { 99 double CalculatePageScale(HDC dc, int page_width, int page_height) {
80 int dc_width = GetDeviceCaps(dc, HORZRES); 100 int dc_width = GetDeviceCaps(dc, HORZRES);
81 int dc_height = GetDeviceCaps(dc, VERTRES); 101 int dc_height = GetDeviceCaps(dc, VERTRES);
82 102
83 // If page fits DC - no scaling needed. 103 // If page fits DC - no scaling needed.
84 if (dc_width >= page_width && dc_height >= page_height) 104 if (dc_width >= page_width && dc_height >= page_height)
85 return 1.0; 105 return 1.0;
86 106
87 double x_factor = 107 double x_factor =
88 static_cast<double>(dc_width) / static_cast<double>(page_width); 108 static_cast<double>(dc_width) / static_cast<double>(page_width);
89 double y_factor = 109 double y_factor =
90 static_cast<double>(dc_height) / static_cast<double>(page_height); 110 static_cast<double>(dc_height) / static_cast<double>(page_height);
91 return std::min(x_factor, y_factor); 111 return std::min(x_factor, y_factor);
92 } 112 }
93 113
94 // Apply scaling to the DC. 114 // Apply scaling to the DC.
95 bool ScaleDC(HDC dc, double scale_factor) { 115 bool ScaleDC(HDC dc, double scale_factor) {
96 SetGraphicsMode(dc, GM_ADVANCED); 116 SetGraphicsMode(dc, GM_ADVANCED);
97 XFORM xform = {0}; 117 XFORM xform = {0};
98 xform.eM11 = xform.eM22 = scale_factor; 118 xform.eM11 = xform.eM22 = scale_factor;
99 return !!ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); 119 return !!ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
100 } 120 }
101 121
102 } // namespace gfx 122 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gdi_util.h ('k') | ui/gfx/path_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698