OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/corewm/cursor_height_provider_win.h" | 5 #include "ui/views/corewm/cursor_height_provider_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 17 matching lines...) Expand all Loading... |
28 sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD); | 28 sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD); |
29 | 29 |
30 HeightStorage* cached_heights = nullptr; | 30 HeightStorage* cached_heights = nullptr; |
31 | 31 |
32 // Extracts the pixel data of provided bitmap | 32 // Extracts the pixel data of provided bitmap |
33 PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) { | 33 PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) { |
34 PixelData data; | 34 PixelData data; |
35 // Masks are monochromatic. | 35 // Masks are monochromatic. |
36 DCHECK_EQ(info.bmiHeader.biBitCount, 1); | 36 DCHECK_EQ(info.bmiHeader.biBitCount, 1); |
37 if (info.bmiHeader.biBitCount != 1) | 37 if (info.bmiHeader.biBitCount != 1) |
38 return data.Pass(); | 38 return data; |
39 | 39 |
40 // When getting pixel data palette is appended to memory pointed by | 40 // When getting pixel data palette is appended to memory pointed by |
41 // BITMAPINFO passed so allocate additional memory to store additional data. | 41 // BITMAPINFO passed so allocate additional memory to store additional data. |
42 scoped_ptr<char[]> header(new char[KHeaderAndPalette]); | 42 scoped_ptr<char[]> header(new char[KHeaderAndPalette]); |
43 memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader)); | 43 memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader)); |
44 | 44 |
45 data.reset(new uint32_t[info.bmiHeader.biSizeImage / sizeof(uint32_t)]); | 45 data.reset(new uint32_t[info.bmiHeader.biSizeImage / sizeof(uint32_t)]); |
46 | 46 |
47 int result = GetDIBits(hdc, | 47 int result = GetDIBits(hdc, |
48 handle, | 48 handle, |
49 0, | 49 0, |
50 info.bmiHeader.biHeight, | 50 info.bmiHeader.biHeight, |
51 data.get(), | 51 data.get(), |
52 reinterpret_cast<BITMAPINFO*>(header.get()), | 52 reinterpret_cast<BITMAPINFO*>(header.get()), |
53 DIB_RGB_COLORS); | 53 DIB_RGB_COLORS); |
54 | 54 |
55 if (result == 0) | 55 if (result == 0) |
56 data.reset(); | 56 data.reset(); |
57 | 57 |
58 return data.Pass(); | 58 return data; |
59 } | 59 } |
60 | 60 |
61 // Checks if the specifed row is transparent in provided bitmap. | 61 // Checks if the specifed row is transparent in provided bitmap. |
62 bool IsRowTransparent(const PixelData& data, | 62 bool IsRowTransparent(const PixelData& data, |
63 const uint32_t row_size, | 63 const uint32_t row_size, |
64 const uint32_t last_byte_mask, | 64 const uint32_t last_byte_mask, |
65 const uint32_t y) { | 65 const uint32_t y) { |
66 // Set the padding bits to 1 to make mask matching easier. | 66 // Set the padding bits to 1 to make mask matching easier. |
67 *(data.get() + (y + 1) * row_size - 1) |= last_byte_mask; | 67 *(data.get() + (y + 1) * row_size - 1) |= last_byte_mask; |
68 for (uint32_t i = y * row_size; i < (y + 1) * row_size; ++i) { | 68 for (uint32_t i = y * row_size; i < (y + 1) * row_size; ++i) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return cached_height->second; | 168 return cached_height->second; |
169 | 169 |
170 const int height = CalculateCursorHeight(cursor.hCursor); | 170 const int height = CalculateCursorHeight(cursor.hCursor); |
171 (*cached_heights)[cursor.hCursor] = height; | 171 (*cached_heights)[cursor.hCursor] = height; |
172 | 172 |
173 return height; | 173 return height; |
174 } | 174 } |
175 | 175 |
176 } // namespace corewm | 176 } // namespace corewm |
177 } // namespace views | 177 } // namespace views |
OLD | NEW |