| 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 |
| 10 #include <algorithm> | 11 #include <algorithm> |
| 11 #include <map> | 12 #include <map> |
| 13 #include <memory> |
| 12 | 14 |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/win/scoped_hdc.h" | 15 #include "base/win/scoped_hdc.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 using PixelData = scoped_ptr<uint32_t[]>; | 18 using PixelData = std::unique_ptr<uint32_t[]>; |
| 18 using HeightStorage = std::map<HCURSOR, int>; | 19 using HeightStorage = std::map<HCURSOR, int>; |
| 19 | 20 |
| 20 const uint32_t kBitsPeruint32 = sizeof(uint32_t) * 8; | 21 const uint32_t kBitsPeruint32 = sizeof(uint32_t) * 8; |
| 21 // All bits are 1 for transparent portion of monochromatic mask. | 22 // All bits are 1 for transparent portion of monochromatic mask. |
| 22 const uint32_t kTransparentMask = 0xffffffff; | 23 const uint32_t kTransparentMask = 0xffffffff; |
| 23 // This is height of default pointer arrow in Windows 7. | 24 // This is height of default pointer arrow in Windows 7. |
| 24 const int kDefaultHeight = 20; | 25 const int kDefaultHeight = 20; |
| 25 // Masks are monochromatic. | 26 // Masks are monochromatic. |
| 26 const size_t kNumberOfColors = 2; | 27 const size_t kNumberOfColors = 2; |
| 27 const size_t KHeaderAndPalette = | 28 const size_t KHeaderAndPalette = |
| 28 sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD); | 29 sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD); |
| 29 | 30 |
| 30 HeightStorage* cached_heights = nullptr; | 31 HeightStorage* cached_heights = nullptr; |
| 31 | 32 |
| 32 // Extracts the pixel data of provided bitmap | 33 // Extracts the pixel data of provided bitmap |
| 33 PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) { | 34 PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) { |
| 34 PixelData data; | 35 PixelData data; |
| 35 // Masks are monochromatic. | 36 // Masks are monochromatic. |
| 36 DCHECK_EQ(info.bmiHeader.biBitCount, 1); | 37 DCHECK_EQ(info.bmiHeader.biBitCount, 1); |
| 37 if (info.bmiHeader.biBitCount != 1) | 38 if (info.bmiHeader.biBitCount != 1) |
| 38 return data; | 39 return data; |
| 39 | 40 |
| 40 // When getting pixel data palette is appended to memory pointed by | 41 // When getting pixel data palette is appended to memory pointed by |
| 41 // BITMAPINFO passed so allocate additional memory to store additional data. | 42 // BITMAPINFO passed so allocate additional memory to store additional data. |
| 42 scoped_ptr<char[]> header(new char[KHeaderAndPalette]); | 43 std::unique_ptr<char[]> header(new char[KHeaderAndPalette]); |
| 43 memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader)); | 44 memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader)); |
| 44 | 45 |
| 45 data.reset(new uint32_t[info.bmiHeader.biSizeImage / sizeof(uint32_t)]); | 46 data.reset(new uint32_t[info.bmiHeader.biSizeImage / sizeof(uint32_t)]); |
| 46 | 47 |
| 47 int result = GetDIBits(hdc, | 48 int result = GetDIBits(hdc, |
| 48 handle, | 49 handle, |
| 49 0, | 50 0, |
| 50 info.bmiHeader.biHeight, | 51 info.bmiHeader.biHeight, |
| 51 data.get(), | 52 data.get(), |
| 52 reinterpret_cast<BITMAPINFO*>(header.get()), | 53 reinterpret_cast<BITMAPINFO*>(header.get()), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 return cached_height->second; | 169 return cached_height->second; |
| 169 | 170 |
| 170 const int height = CalculateCursorHeight(cursor.hCursor); | 171 const int height = CalculateCursorHeight(cursor.hCursor); |
| 171 (*cached_heights)[cursor.hCursor] = height; | 172 (*cached_heights)[cursor.hCursor] = height; |
| 172 | 173 |
| 173 return height; | 174 return height; |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace corewm | 177 } // namespace corewm |
| 177 } // namespace views | 178 } // namespace views |
| OLD | NEW |