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