Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: ui/base/dragdrop/drag_utils_win.cc

Issue 2792183002: Delete ash-based code for Windows drag-and-drop graphics. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/base/dragdrop/os_exchange_data.h » ('j') | ui/base/dragdrop/os_exchange_data.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/dragdrop/drag_utils_win.cc
diff --git a/ui/base/dragdrop/drag_utils_win.cc b/ui/base/dragdrop/drag_utils_win.cc
index fa482e2e026284b56e1edc4761cc0e5781c482b5..53c864a62432602a9b652e3ddc9400dfbf3ac2a1 100644
--- a/ui/base/dragdrop/drag_utils_win.cc
+++ b/ui/base/dragdrop/drag_utils_win.cc
@@ -23,65 +23,55 @@
namespace drag_utils {
-static void SetDragImageOnDataObject(HBITMAP hbitmap,
danakj 2017/04/03 22:34:01 Since these have one caller, I collapsed them all
- const gfx::Size& size_in_pixels,
- const gfx::Vector2d& cursor_offset,
- IDataObject* data_object) {
- base::win::ScopedComPtr<IDragSourceHelper> helper;
- HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
- IID_IDragSourceHelper, helper.ReceiveVoid());
- if (SUCCEEDED(rv)) {
- SHDRAGIMAGE sdi;
- sdi.sizeDragImage = size_in_pixels.ToSIZE();
- sdi.crColorKey = 0xFFFFFFFF;
- sdi.hbmpDragImage = hbitmap;
- sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT();
- helper->InitializeFromBitmap(&sdi, data_object);
- }
-}
-
-// Blit the contents of the canvas to a new HBITMAP. It is the caller's
danakj 2017/04/03 22:34:01 I read MSDN for a while and I think this comment i
-// responsibility to release the |bits| buffer.
-static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) {
- base::win::ScopedGetDC screen_dc(NULL);
- BITMAPINFOHEADER header;
- skia::CreateBitmapHeader(sk_bitmap.width(), sk_bitmap.height(), &header);
- void* bits;
- HBITMAP bitmap =
- CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header),
- DIB_RGB_COLORS, &bits, NULL, 0);
- if (!bitmap || !bits)
- return NULL;
- DCHECK_EQ(sk_bitmap.rowBytes(), static_cast<size_t>(sk_bitmap.width() * 4));
- SkAutoLockPixels lock(sk_bitmap);
- memcpy(
- bits, sk_bitmap.getPixels(), sk_bitmap.height() * sk_bitmap.rowBytes());
- return bitmap;
-}
-
void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia,
const gfx::Vector2d& cursor_offset,
ui::OSExchangeData* data_object) {
DCHECK(data_object && !image_skia.size().IsEmpty());
+
// InitializeFromBitmap() doesn't expect an alpha channel and is confused
// by premultiplied colors, so unpremultiply the bitmap.
// SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap.
- HBITMAP bitmap = CreateHBITMAPFromSkBitmap(
- SkBitmapOperations::UnPreMultiply(*image_skia.bitmap()));
- if (bitmap) {
- // Attach 'bitmap' to the data_object.
- SetDragImageOnDataObject(
- bitmap,
- gfx::Size(image_skia.bitmap()->width(), image_skia.bitmap()->height()),
- cursor_offset,
- ui::OSExchangeDataProviderWin::GetIDataObject(*data_object));
+ SkBitmap unpremul_bitmap =
+ SkBitmapOperations::UnPreMultiply(*image_skia.bitmap());
+ int width = unpremul_bitmap.width();
+ int height = unpremul_bitmap.height();
+ size_t rowbytes = unpremul_bitmap.rowBytes();
+ DCHECK_EQ(rowbytes, static_cast<size_t>(width) * 4u);
+
+ void* bits;
+ HBITMAP hbitmap;
+ {
+ BITMAPINFOHEADER header;
+ skia::CreateBitmapHeader(width, height, &header);
+
+ base::win::ScopedGetDC screen_dc(NULL);
danakj 2017/04/03 22:34:01 I scoped this DC to just be around CreateDIBSectio
Peter Kasting 2017/04/04 00:31:14 It makes me a little leery. I suggest just not pu
danakj 2017/04/04 15:25:33 I like to scope things as tightly as possible, if
+ // By giving a null hSection, the |bits| will be destroyed when the
+ // |hbitmap| is destroyed.
+ hbitmap =
+ CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header),
+ DIB_RGB_COLORS, &bits, NULL, 0);
+ }
+ if (!hbitmap)
+ return;
+
+ {
+ SkAutoLockPixels lock(unpremul_bitmap);
+ memcpy(bits, unpremul_bitmap.getPixels(), height * rowbytes);
}
- // TODO: the above code is used in non-Ash, while below is used in Ash. If we
- // could figure this context out then we wouldn't do unnecessary work. However
- // as it stands getting this information in ui/base would be a layering
- // violation.
- data_object->provider().SetDragImage(image_skia, cursor_offset);
+ base::win::ScopedComPtr<IDragSourceHelper> helper;
+ HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
+ IID_IDragSourceHelper, helper.ReceiveVoid());
+ if (!SUCCEEDED(rv))
+ return;
+
+ SHDRAGIMAGE sdi;
+ sdi.sizeDragImage.cx = width;
+ sdi.sizeDragImage.cy = height;
+ sdi.crColorKey = 0xFFFFFFFF;
+ sdi.hbmpDragImage = hbitmap;
+ sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT();
+ helper->InitializeFromBitmap(&sdi, data_object);
}
} // namespace drag_utils
« no previous file with comments | « no previous file | ui/base/dragdrop/os_exchange_data.h » ('j') | ui/base/dragdrop/os_exchange_data.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698