summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 01:20:28 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 01:20:28 +0000
commit706bf7278b50b4292555e55adbf255b7aa49b12a (patch)
tree9286187926ce5c84a8f8da53dbddaa087ae1d8f7
parentd89ea3ced6389f04190eaa5431d32f67bca0056d (diff)
downloadchromium_src-706bf7278b50b4292555e55adbf255b7aa49b12a.zip
chromium_src-706bf7278b50b4292555e55adbf255b7aa49b12a.tar.gz
chromium_src-706bf7278b50b4292555e55adbf255b7aa49b12a.tar.bz2
Windows: Fix opacity of drag images.
BUG=11457 TEST=Go to google.com, drag logo around. Preview image should now look nice. Review URL: http://codereview.chromium.org/2963009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52249 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--views/drag_utils_win.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/views/drag_utils_win.cc b/views/drag_utils_win.cc
index 84b4ba1..7d9c6d5 100644
--- a/views/drag_utils_win.cc
+++ b/views/drag_utils_win.cc
@@ -13,6 +13,7 @@
#include "gfx/canvas_skia.h"
#include "gfx/gdi_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkUnPreMultiply.h"
namespace drag_utils {
@@ -61,8 +62,32 @@ void SetDragImageOnDataObject(const SkBitmap& sk_bitmap,
const gfx::Point& cursor_offset,
OSExchangeData* data_object) {
gfx::CanvasSkia canvas(sk_bitmap.width(), sk_bitmap.height(),
- /*is_opaque=*/false);
- canvas.DrawBitmapInt(sk_bitmap, 0, 0);
+ /*is_opaque=*/true);
+ SkBitmap opaque_bitmap;
+ if (sk_bitmap.isOpaque()) {
+ opaque_bitmap = sk_bitmap;
+ } else {
+ // InitializeFromBitmap() doesn't expect an alpha channel and is confused
+ // by premultiplied colors, so unpremultiply the bitmap.
+ SkBitmap tmp_bitmap;
+ tmp_bitmap.setConfig(
+ sk_bitmap.config(), sk_bitmap.width(), sk_bitmap.height());
+ tmp_bitmap.allocPixels();
+
+ SkAutoLockPixels lock(tmp_bitmap);
+ const int kBytesPerPixel = 4;
+ for (int y = 0; y < tmp_bitmap.height(); y++) {
+ for (int x = 0; x < tmp_bitmap.width(); x++) {
+ uint32 src_pixel = *sk_bitmap.getAddr32(x, y);
+ uint32* dst_pixel = tmp_bitmap.getAddr32(x, y);
+ SkColor unmultiplied = SkUnPreMultiply::PMColorToColor(src_pixel);
+ *dst_pixel = unmultiplied;
+ }
+ }
+ tmp_bitmap.setIsOpaque(true);
+ opaque_bitmap = tmp_bitmap;
+ }
+ canvas.DrawBitmapInt(opaque_bitmap, 0, 0);
DCHECK(data_object && !size.IsEmpty());
// SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap.