| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/win/resource_util.h" | 14 #include "base/win/resource_util.h" |
| 15 #include "base/win/scoped_gdi_object.h" | 15 #include "base/win/scoped_gdi_object.h" |
| 16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 17 #include "base/win/scoped_hdc.h" | 17 #include "base/win/scoped_hdc.h" |
| 18 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
| 19 #include "skia/ext/skia_utils_win.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/gfx/gdi_util.h" | |
| 21 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "ui/gfx/image/image_family.h" | 23 #include "ui/gfx/image/image_family.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Used for indicating that the .ico contains an icon (rather than a cursor) | 27 // Used for indicating that the .ico contains an icon (rather than a cursor) |
| 28 // image. This value is set in the |idType| field of the ICONDIR structure. | 28 // image. This value is set in the |idType| field of the ICONDIR structure. |
| 29 const int kResourceTypeIcon = 1; | 29 const int kResourceTypeIcon = 1; |
| 30 | 30 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); | 314 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); |
| 315 return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, icon_size)); | 315 return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, icon_size)); |
| 316 } | 316 } |
| 317 | 317 |
| 318 base::win::ScopedHICON IconUtil::CreateCursorFromDIB(const gfx::Size& icon_size, | 318 base::win::ScopedHICON IconUtil::CreateCursorFromDIB(const gfx::Size& icon_size, |
| 319 const gfx::Point& hotspot, | 319 const gfx::Point& hotspot, |
| 320 const void* dib_bits, | 320 const void* dib_bits, |
| 321 size_t dib_size) { | 321 size_t dib_size) { |
| 322 BITMAPINFO icon_bitmap_info = {}; | 322 BITMAPINFO icon_bitmap_info = {}; |
| 323 gfx::CreateBitmapHeader( | 323 skia::CreateBitmapHeader( |
| 324 icon_size.width(), | 324 icon_size.width(), |
| 325 icon_size.height(), | 325 icon_size.height(), |
| 326 reinterpret_cast<BITMAPINFOHEADER*>(&icon_bitmap_info)); | 326 reinterpret_cast<BITMAPINFOHEADER*>(&icon_bitmap_info)); |
| 327 | 327 |
| 328 base::win::ScopedGetDC dc(NULL); | 328 base::win::ScopedGetDC dc(NULL); |
| 329 base::win::ScopedCreateDC working_dc(CreateCompatibleDC(dc)); | 329 base::win::ScopedCreateDC working_dc(CreateCompatibleDC(dc)); |
| 330 base::win::ScopedGDIObject<HBITMAP> bitmap_handle( | 330 base::win::ScopedGDIObject<HBITMAP> bitmap_handle( |
| 331 CreateDIBSection(dc, | 331 CreateDIBSection(dc, |
| 332 &icon_bitmap_info, | 332 &icon_bitmap_info, |
| 333 DIB_RGB_COLORS, | 333 DIB_RGB_COLORS, |
| (...skipping 356 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 | 690 // 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 | 691 // 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 | 692 // 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. | 693 // for the monochrome bitmap representing the AND mask. |
| 694 size_t and_line_length = (bitmap.width() + 7) >> 3; | 694 size_t and_line_length = (bitmap.width() + 7) >> 3; |
| 695 and_line_length = (and_line_length + 3) & ~3; | 695 and_line_length = (and_line_length + 3) & ~3; |
| 696 size_t and_mask_size = and_line_length * bitmap.height(); | 696 size_t and_mask_size = and_line_length * bitmap.height(); |
| 697 size_t masks_size = *xor_mask_size + and_mask_size; | 697 size_t masks_size = *xor_mask_size + and_mask_size; |
| 698 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); | 698 *bytes_in_resource = masks_size + sizeof(BITMAPINFOHEADER); |
| 699 } | 699 } |
| OLD | NEW |