Chromium Code Reviews| Index: ui/base/clipboard/clipboard_win.cc |
| diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc |
| index 344951e799756b6f767636e285bd4e7f05b2d146..c2880e8303c1a943e367efe6eeab6fad425e5200 100644 |
| --- a/ui/base/clipboard/clipboard_win.cc |
| +++ b/ui/base/clipboard/clipboard_win.cc |
| @@ -25,6 +25,7 @@ |
| #include "base/win/message_window.h" |
| #include "base/win/scoped_gdi_object.h" |
| #include "base/win/scoped_hdc.h" |
| +#include "skia/ext/skia_utils_win.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "ui/base/clipboard/clipboard_util_win.h" |
| #include "ui/base/clipboard/custom_data_helper.h" |
| @@ -611,16 +612,21 @@ SkBitmap ClipboardWin::ReadImage(ClipboardType type) const { |
| const void* bitmap_bits = reinterpret_cast<const char*>(bitmap) |
| + bitmap->bmiHeader.biSize + color_table_length * sizeof(RGBQUAD); |
| - gfx::Canvas canvas(gfx::Size(bitmap->bmiHeader.biWidth, |
| - bitmap->bmiHeader.biHeight), |
| - 1.0f, |
| - false); |
| + void* dst_bits; |
| + // dst_hbitmap is freed by the release_proc in skia_bitmap (below) |
| + HBITMAP dst_hbitmap = |
| + skia::CreateHBitmap(bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight, |
| + false, 0, &dst_bits); |
| + |
| { |
| - HDC dc = skia::GetNativeDrawingContext(canvas.sk_canvas()); |
| - ::SetDIBitsToDevice(dc, 0, 0, bitmap->bmiHeader.biWidth, |
| - bitmap->bmiHeader.biHeight, 0, 0, 0, |
| - bitmap->bmiHeader.biHeight, bitmap_bits, bitmap, |
| - DIB_RGB_COLORS); |
| + HDC hdc = CreateCompatibleDC(NULL); |
|
dcheng
2017/01/04 22:25:36
Nit: nullptr, and use ScopedCreateDC from base/win
reed1
2017/01/05 02:24:46
I would use it like this? ScopedCreateDC scoped(::
dcheng
2017/01/05 02:39:50
Yes, it would still need to be selected, but it wo
reed1
2017/01/05 16:49:09
Done.
|
| + skia::InitializeDC(hdc); |
|
dcheng
2017/01/04 22:25:36
Just curious: do we need to do this if we're just
reed1
2017/01/05 02:24:46
I need to draw 'bitmap' into my dst_hbitmap. Don't
dcheng
2017/01/05 02:39:50
I think the DC should already be initialized; it l
reed1
2017/01/05 03:16:08
Ah, I misinterpreted your question. Got it about I
|
| + HBITMAP old_hbitmap = static_cast<HBITMAP>(SelectObject(hdc, dst_hbitmap)); |
| + ::SetDIBitsToDevice( |
| + hdc, 0, 0, bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight, 0, 0, |
| + 0, bitmap->bmiHeader.biHeight, bitmap_bits, bitmap, DIB_RGB_COLORS); |
| + SelectObject(hdc, old_hbitmap); |
| + DeleteDC(hdc); |
| } |
| // Windows doesn't really handle alpha channels well in many situations. When |
| // the source image is < 32 bpp, we force the bitmap to be opaque. When the |
| @@ -630,8 +636,10 @@ SkBitmap ClipboardWin::ReadImage(ClipboardType type) const { |
| // we assume the alpha channel contains garbage and force the bitmap to be |
| // opaque as well. Note that this heuristic will fail on a transparent bitmap |
| // containing only black pixels... |
| - SkPixmap device_pixels; |
| - skia::GetWritablePixels(canvas.sk_canvas(), &device_pixels); |
| + SkPixmap device_pixels(SkImageInfo::MakeN32Premul(bitmap->bmiHeader.biWidth, |
| + bitmap->bmiHeader.biHeight), |
| + dst_bits, bitmap->bmiHeader.biWidth * 4); |
| + |
| { |
| bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || |
| BitmapHasInvalidPremultipliedColors(device_pixels); |
| @@ -640,7 +648,14 @@ SkBitmap ClipboardWin::ReadImage(ClipboardType type) const { |
| } |
| } |
| - return canvas.ExtractImageRep().sk_bitmap(); |
| + SkBitmap skia_bitmap; |
| + skia_bitmap.installPixels(device_pixels.info(), device_pixels.writable_addr(), |
| + device_pixels.rowBytes(), nullptr, |
| + [](void* pixels, void* hbitmap) { |
| + DeleteObject(static_cast<HBITMAP>(hbitmap)); |
| + }, |
| + dst_hbitmap); |
| + return skia_bitmap; |
| } |
| void ClipboardWin::ReadCustomData(ClipboardType clipboard_type, |