Chromium Code Reviews| 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/icon_util.h" | 5 #include "ui/gfx/icon_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/important_file_writer.h" | 10 #include "base/files/important_file_writer.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 304 |
| 305 ScopedICONINFO icon_info; | 305 ScopedICONINFO icon_info; |
| 306 BITMAP bitmap_info = { 0 }; | 306 BITMAP bitmap_info = { 0 }; |
| 307 | 307 |
| 308 if (!::GetIconInfo(icon, &icon_info)) | 308 if (!::GetIconInfo(icon, &icon_info)) |
| 309 return NULL; | 309 return NULL; |
| 310 | 310 |
| 311 if (!::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info)) | 311 if (!::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info)) |
| 312 return NULL; | 312 return NULL; |
| 313 | 313 |
| 314 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); | 314 // For non-color cursors, the mask contains both an AND and an XOR mask and |
| 315 // the height includes both. Thus, the mask width is the same as image width, | |
| 316 // but we need to divide mask height by 2 to get the image height. | |
| 317 const int height = (icon_info.hbmColor == NULL) ? bitmap_info.bmHeight / 2 | |
|
msw
2016/10/20 18:54:51
nit: just check: "icon_info.hbmColor ?" otherwise,
qiangchen
2016/10/20 20:03:33
Done.
msw
2016/10/20 20:06:58
Thanks for catching and fixing the inversion error
| |
| 318 : bitmap_info.bmHeight; | |
| 319 gfx::Size icon_size(bitmap_info.bmWidth, height); | |
| 315 return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, icon_size)); | 320 return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, icon_size)); |
| 316 } | 321 } |
| 317 | 322 |
| 318 base::win::ScopedHICON IconUtil::CreateCursorFromDIB(const gfx::Size& icon_size, | 323 base::win::ScopedHICON IconUtil::CreateCursorFromDIB(const gfx::Size& icon_size, |
| 319 const gfx::Point& hotspot, | 324 const gfx::Point& hotspot, |
| 320 const void* dib_bits, | 325 const void* dib_bits, |
| 321 size_t dib_size) { | 326 size_t dib_size) { |
| 322 BITMAPINFO icon_bitmap_info = {}; | 327 BITMAPINFO icon_bitmap_info = {}; |
| 323 skia::CreateBitmapHeader( | 328 skia::CreateBitmapHeader( |
| 324 icon_size.width(), | 329 icon_size.width(), |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 // Once we compute the size for a singe AND mask scan line, we multiply that | 695 // Once we compute the size for a singe AND mask scan line, we multiply that |
| 691 // number by the image height in order to get the total number of bytes for | 696 // number by the image height in order to get the total number of bytes for |
| 692 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes | 697 // the AND mask. Thus, for a 15X15 image, we need 15 * 4 which is 60 bytes |
| 693 // for the monochrome bitmap representing the AND mask. | 698 // for the monochrome bitmap representing the AND mask. |
| 694 size_t and_line_length = (bitmap.width() + 7) >> 3; | 699 size_t and_line_length = (bitmap.width() + 7) >> 3; |
| 695 and_line_length = (and_line_length + 3) & ~3; | 700 and_line_length = (and_line_length + 3) & ~3; |
| 696 size_t and_mask_size = and_line_length * bitmap.height(); | 701 size_t and_mask_size = and_line_length * bitmap.height(); |
| 697 size_t masks_size = *xor_mask_size + and_mask_size; | 702 size_t masks_size = *xor_mask_size + and_mask_size; |
| 698 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 703 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
| 699 } | 704 } |
| OLD | NEW |