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 // Many of these functions are based on those found in | 5 // Many of these functions are based on those found in |
6 // webkit/port/platform/PasteboardWin.cpp | 6 // webkit/port/platform/PasteboardWin.cpp |
7 | 7 |
8 #include "ui/base/clipboard/clipboard_win.h" | 8 #include "ui/base/clipboard/clipboard_win.h" |
9 | 9 |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ::GlobalAlloc(GMEM_MOVEABLE, ((str.size() + 1) * sizeof(charT))); | 153 ::GlobalAlloc(GMEM_MOVEABLE, ((str.size() + 1) * sizeof(charT))); |
154 if (data) { | 154 if (data) { |
155 charT* raw_data = static_cast<charT*>(::GlobalLock(data)); | 155 charT* raw_data = static_cast<charT*>(::GlobalLock(data)); |
156 memcpy(raw_data, str.data(), str.size() * sizeof(charT)); | 156 memcpy(raw_data, str.data(), str.size() * sizeof(charT)); |
157 raw_data[str.size()] = '\0'; | 157 raw_data[str.size()] = '\0'; |
158 ::GlobalUnlock(data); | 158 ::GlobalUnlock(data); |
159 } | 159 } |
160 return data; | 160 return data; |
161 } | 161 } |
162 | 162 |
163 bool BitmapHasInvalidPremultipliedColors(const SkBitmap& bitmap) { | 163 bool BitmapHasInvalidPremultipliedColors(const SkPixmap& pixmap) { |
164 for (int x = 0; x < bitmap.width(); ++x) { | 164 for (int x = 0; x < pixmap.width(); ++x) { |
165 for (int y = 0; y < bitmap.height(); ++y) { | 165 for (int y = 0; y < pixmap.height(); ++y) { |
166 uint32_t pixel = *bitmap.getAddr32(x, y); | 166 uint32_t pixel = *pixmap.addr32(x, y); |
167 if (SkColorGetR(pixel) > SkColorGetA(pixel) || | 167 if (SkColorGetR(pixel) > SkColorGetA(pixel) || |
168 SkColorGetG(pixel) > SkColorGetA(pixel) || | 168 SkColorGetG(pixel) > SkColorGetA(pixel) || |
169 SkColorGetB(pixel) > SkColorGetA(pixel)) | 169 SkColorGetB(pixel) > SkColorGetA(pixel)) |
170 return true; | 170 return true; |
171 } | 171 } |
172 } | 172 } |
173 return false; | 173 return false; |
174 } | 174 } |
175 | 175 |
176 void MakeBitmapOpaque(const SkBitmap& bitmap) { | 176 void MakeBitmapOpaque(SkPixmap* pixmap) { |
177 for (int x = 0; x < bitmap.width(); ++x) { | 177 for (int x = 0; x < pixmap->width(); ++x) { |
178 for (int y = 0; y < bitmap.height(); ++y) { | 178 for (int y = 0; y < pixmap->height(); ++y) { |
179 *bitmap.getAddr32(x, y) = SkColorSetA(*bitmap.getAddr32(x, y), 0xFF); | 179 *pixmap->writable_addr32(x, y) = SkColorSetA(*pixmap->addr32(x, y), 0xFF); |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 void ParseBookmarkClipboardFormat(const base::string16& bookmark, | 184 void ParseBookmarkClipboardFormat(const base::string16& bookmark, |
185 base::string16* title, | 185 base::string16* title, |
186 std::string* url) { | 186 std::string* url) { |
187 const base::string16 kDelim = base::ASCIIToUTF16("\r\n"); | 187 const base::string16 kDelim = base::ASCIIToUTF16("\r\n"); |
188 | 188 |
189 const size_t title_end = bookmark.find_first_of(kDelim); | 189 const size_t title_end = bookmark.find_first_of(kDelim); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 DIB_RGB_COLORS); | 624 DIB_RGB_COLORS); |
625 } | 625 } |
626 // Windows doesn't really handle alpha channels well in many situations. When | 626 // Windows doesn't really handle alpha channels well in many situations. When |
627 // the source image is < 32 bpp, we force the bitmap to be opaque. When the | 627 // the source image is < 32 bpp, we force the bitmap to be opaque. When the |
628 // source image is 32 bpp, the alpha channel might still contain garbage data. | 628 // source image is 32 bpp, the alpha channel might still contain garbage data. |
629 // Since Windows uses premultiplied alpha, we scan for instances where | 629 // Since Windows uses premultiplied alpha, we scan for instances where |
630 // (R, G, B) > A. If there are any invalid premultiplied colors in the image, | 630 // (R, G, B) > A. If there are any invalid premultiplied colors in the image, |
631 // we assume the alpha channel contains garbage and force the bitmap to be | 631 // we assume the alpha channel contains garbage and force the bitmap to be |
632 // opaque as well. Note that this heuristic will fail on a transparent bitmap | 632 // opaque as well. Note that this heuristic will fail on a transparent bitmap |
633 // containing only black pixels... | 633 // containing only black pixels... |
634 const SkBitmap& device_bitmap = | 634 SkPixmap device_pixels; |
635 canvas.sk_canvas()->getDevice()->accessBitmap(true); | 635 skia::GetWritablePixels(canvas.sk_canvas(), &device_pixels); |
636 { | 636 { |
637 SkAutoLockPixels lock(device_bitmap); | |
638 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || | 637 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || |
639 BitmapHasInvalidPremultipliedColors(device_bitmap); | 638 BitmapHasInvalidPremultipliedColors(device_pixels); |
640 if (has_invalid_alpha_channel) { | 639 if (has_invalid_alpha_channel) { |
641 MakeBitmapOpaque(device_bitmap); | 640 MakeBitmapOpaque(&device_pixels); |
642 } | 641 } |
643 } | 642 } |
644 | 643 |
645 return canvas.ExtractImageRep().sk_bitmap(); | 644 return canvas.ExtractImageRep().sk_bitmap(); |
646 } | 645 } |
647 | 646 |
648 void ClipboardWin::ReadCustomData(ClipboardType clipboard_type, | 647 void ClipboardWin::ReadCustomData(ClipboardType clipboard_type, |
649 const base::string16& type, | 648 const base::string16& type, |
650 base::string16* result) const { | 649 base::string16* result) const { |
651 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); | 650 DCHECK_EQ(clipboard_type, CLIPBOARD_TYPE_COPY_PASTE); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 if (!clipboard_owner_) | 882 if (!clipboard_owner_) |
884 return NULL; | 883 return NULL; |
885 | 884 |
886 if (clipboard_owner_->hwnd() == NULL) | 885 if (clipboard_owner_->hwnd() == NULL) |
887 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); | 886 clipboard_owner_->Create(base::Bind(&ClipboardOwnerWndProc)); |
888 | 887 |
889 return clipboard_owner_->hwnd(); | 888 return clipboard_owner_->hwnd(); |
890 } | 889 } |
891 | 890 |
892 } // namespace ui | 891 } // namespace ui |
OLD | NEW |