OLD | NEW |
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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 windows_points[i].y = SkScalarRoundToInt(points[i].fY); | 89 windows_points[i].y = SkScalarRoundToInt(points[i].fY); |
90 } | 90 } |
91 | 91 |
92 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE); | 92 return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE); |
93 #elif defined(OS_WIN) | 93 #elif defined(OS_WIN) |
94 return path.CreateNativeRegion(); | 94 return path.CreateNativeRegion(); |
95 #endif | 95 #endif |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 double CalculatePageScale(HDC dc, int page_width, int page_height) { | 99 float CalculatePageScale(HDC dc, int page_width, int page_height) { |
100 int dc_width = GetDeviceCaps(dc, HORZRES); | 100 int dc_width = GetDeviceCaps(dc, HORZRES); |
101 int dc_height = GetDeviceCaps(dc, VERTRES); | 101 int dc_height = GetDeviceCaps(dc, VERTRES); |
102 | 102 |
103 // If page fits DC - no scaling needed. | 103 // If page fits DC - no scaling needed. |
104 if (dc_width >= page_width && dc_height >= page_height) | 104 if (dc_width >= page_width && dc_height >= page_height) |
105 return 1.0; | 105 return 1.0; |
106 | 106 |
107 double x_factor = | 107 float x_factor = |
108 static_cast<double>(dc_width) / static_cast<double>(page_width); | 108 static_cast<float>(dc_width) / static_cast<float>(page_width); |
109 double y_factor = | 109 float y_factor = |
110 static_cast<double>(dc_height) / static_cast<double>(page_height); | 110 static_cast<float>(dc_height) / static_cast<float>(page_height); |
111 return std::min(x_factor, y_factor); | 111 return std::min(x_factor, y_factor); |
112 } | 112 } |
113 | 113 |
114 // Apply scaling to the DC. | 114 // Apply scaling to the DC. |
115 bool ScaleDC(HDC dc, double scale_factor) { | 115 bool ScaleDC(HDC dc, float scale_factor) { |
116 SetGraphicsMode(dc, GM_ADVANCED); | 116 SetGraphicsMode(dc, GM_ADVANCED); |
117 XFORM xform = {0}; | 117 XFORM xform = {0}; |
118 xform.eM11 = xform.eM22 = scale_factor; | 118 xform.eM11 = xform.eM22 = scale_factor; |
119 return !!ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); | 119 return !!ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY); |
120 } | 120 } |
121 | 121 |
122 void StretchDIBits(HDC hdc, int dest_x, int dest_y, int dest_w, int dest_h, | 122 void StretchDIBits(HDC hdc, int dest_x, int dest_y, int dest_w, int dest_h, |
123 int src_x, int src_y, int src_w, int src_h, void* pixels, | 123 int src_x, int src_y, int src_w, int src_h, void* pixels, |
124 const BITMAPINFO* bitmap_info) { | 124 const BITMAPINFO* bitmap_info) { |
125 // When blitting a rectangle that touches the bottom, left corner of the | 125 // When blitting a rectangle that touches the bottom, left corner of the |
(...skipping 10 matching lines...) Expand all Loading... |
136 } else { | 136 } else { |
137 rv = ::StretchDIBits(hdc, | 137 rv = ::StretchDIBits(hdc, |
138 dest_x, dest_y, dest_w, dest_h, | 138 dest_x, dest_y, dest_w, dest_h, |
139 src_x, bottom_up_src_y, src_w, src_h, | 139 src_x, bottom_up_src_y, src_w, src_h, |
140 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | 140 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); |
141 } | 141 } |
142 DCHECK(rv != GDI_ERROR); | 142 DCHECK(rv != GDI_ERROR); |
143 } | 143 } |
144 | 144 |
145 } // namespace gfx | 145 } // namespace gfx |
OLD | NEW |