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 { |
11 | 11 |
12 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { | 12 void CreateBitmapHeaderWithColorDepth(LONG width, |
13 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); | 13 LONG height, |
14 } | 14 WORD color_depth, |
15 | |
16 void CreateBitmapHeaderWithColorDepth(int width, int height, int color_depth, | |
17 BITMAPINFOHEADER* hdr) { | 15 BITMAPINFOHEADER* hdr) { |
18 // These values are shared with gfx::PlatformDevice | 16 // These values are shared with gfx::PlatformDevice |
19 hdr->biSize = sizeof(BITMAPINFOHEADER); | 17 hdr->biSize = sizeof(BITMAPINFOHEADER); |
20 hdr->biWidth = width; | 18 hdr->biWidth = width; |
21 hdr->biHeight = -height; // minus means top-down bitmap | 19 hdr->biHeight = -height; // minus means top-down bitmap |
22 hdr->biPlanes = 1; | 20 hdr->biPlanes = 1; |
23 hdr->biBitCount = color_depth; | 21 hdr->biBitCount = color_depth; |
24 hdr->biCompression = BI_RGB; // no compression | 22 hdr->biCompression = BI_RGB; // no compression |
25 hdr->biSizeImage = 0; | 23 hdr->biSizeImage = 0; |
26 hdr->biXPelsPerMeter = 1; | 24 hdr->biXPelsPerMeter = 1; |
27 hdr->biYPelsPerMeter = 1; | 25 hdr->biYPelsPerMeter = 1; |
28 hdr->biClrUsed = 0; | 26 hdr->biClrUsed = 0; |
29 hdr->biClrImportant = 0; | 27 hdr->biClrImportant = 0; |
30 } | 28 } |
31 | 29 |
| 30 } // namespace |
| 31 |
| 32 namespace gfx { |
| 33 |
| 34 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
| 35 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); |
| 36 } |
| 37 |
32 void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr) { | 38 void CreateBitmapV4Header(int width, int height, BITMAPV4HEADER* hdr) { |
33 // Because bmp v4 header is just an extension, we just create a v3 header and | 39 // Because bmp v4 header is just an extension, we just create a v3 header and |
34 // copy the bits over to the v4 header. | 40 // copy the bits over to the v4 header. |
35 BITMAPINFOHEADER header_v3; | 41 BITMAPINFOHEADER header_v3; |
36 CreateBitmapHeader(width, height, &header_v3); | 42 CreateBitmapHeader(width, height, &header_v3); |
37 memset(hdr, 0, sizeof(BITMAPV4HEADER)); | 43 memset(hdr, 0, sizeof(BITMAPV4HEADER)); |
38 memcpy(hdr, &header_v3, sizeof(BITMAPINFOHEADER)); | 44 memcpy(hdr, &header_v3, sizeof(BITMAPINFOHEADER)); |
39 | 45 |
40 // Correct the size of the header and fill in the mask values. | 46 // Correct the size of the header and fill in the mask values. |
41 hdr->bV4Size = sizeof(BITMAPV4HEADER); | 47 hdr->bV4Size = sizeof(BITMAPV4HEADER); |
42 hdr->bV4RedMask = 0x00ff0000; | 48 hdr->bV4RedMask = 0x00ff0000; |
43 hdr->bV4GreenMask = 0x0000ff00; | 49 hdr->bV4GreenMask = 0x0000ff00; |
44 hdr->bV4BlueMask = 0x000000ff; | 50 hdr->bV4BlueMask = 0x000000ff; |
45 hdr->bV4AlphaMask = 0xff000000; | 51 hdr->bV4AlphaMask = 0xff000000; |
46 } | 52 } |
47 | 53 |
48 // Creates a monochrome bitmap header. | 54 // Creates a monochrome bitmap header. |
49 void CreateMonochromeBitmapHeader(int width, | 55 void CreateMonochromeBitmapHeader(int width, |
50 int height, | 56 int height, |
51 BITMAPINFOHEADER* hdr) { | 57 BITMAPINFOHEADER* hdr) { |
52 hdr->biSize = sizeof(BITMAPINFOHEADER); | 58 CreateBitmapHeaderWithColorDepth(width, height, 1, hdr); |
53 hdr->biWidth = width; | |
54 hdr->biHeight = -height; | |
55 hdr->biPlanes = 1; | |
56 hdr->biBitCount = 1; | |
57 hdr->biCompression = BI_RGB; | |
58 hdr->biSizeImage = 0; | |
59 hdr->biXPelsPerMeter = 1; | |
60 hdr->biYPelsPerMeter = 1; | |
61 hdr->biClrUsed = 0; | |
62 hdr->biClrImportant = 0; | |
63 } | 59 } |
64 | 60 |
65 void SubtractRectanglesFromRegion(HRGN hrgn, | 61 void SubtractRectanglesFromRegion(HRGN hrgn, |
66 const std::vector<gfx::Rect>& cutouts) { | 62 const std::vector<gfx::Rect>& cutouts) { |
67 if (cutouts.size()) { | 63 if (cutouts.size()) { |
68 HRGN cutout = ::CreateRectRgn(0, 0, 0, 0); | 64 HRGN cutout = ::CreateRectRgn(0, 0, 0, 0); |
69 for (size_t i = 0; i < cutouts.size(); i++) { | 65 for (size_t i = 0; i < cutouts.size(); i++) { |
70 ::SetRectRgn(cutout, | 66 ::SetRectRgn(cutout, |
71 cutouts[i].x(), | 67 cutouts[i].x(), |
72 cutouts[i].y(), | 68 cutouts[i].y(), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } else { | 132 } else { |
137 rv = ::StretchDIBits(hdc, | 133 rv = ::StretchDIBits(hdc, |
138 dest_x, dest_y, dest_w, dest_h, | 134 dest_x, dest_y, dest_w, dest_h, |
139 src_x, bottom_up_src_y, src_w, src_h, | 135 src_x, bottom_up_src_y, src_w, src_h, |
140 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | 136 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); |
141 } | 137 } |
142 DCHECK(rv != GDI_ERROR); | 138 DCHECK(rv != GDI_ERROR); |
143 } | 139 } |
144 | 140 |
145 } // namespace gfx | 141 } // namespace gfx |
OLD | NEW |