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

Side by Side Diff: ui/base/clipboard/clipboard_win.cc

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 8 #include "ui/base/clipboard/clipboard.h"
9 9
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 break; 483 break;
484 default: 484 default:
485 NOTREACHED(); 485 NOTREACHED();
486 } 486 }
487 const void* bitmap_bits = reinterpret_cast<const char*>(bitmap) 487 const void* bitmap_bits = reinterpret_cast<const char*>(bitmap)
488 + bitmap->bmiHeader.biSize + color_table_length * sizeof(RGBQUAD); 488 + bitmap->bmiHeader.biSize + color_table_length * sizeof(RGBQUAD);
489 489
490 gfx::CanvasSkia canvas(bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight, 490 gfx::CanvasSkia canvas(bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight,
491 false); 491 false);
492 { 492 {
493 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 493 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
494 HDC dc = scoped_platform_paint.GetPlatformSurface(); 494 HDC dc = scoped_platform_paint.GetPlatformSurface();
495 ::SetDIBitsToDevice(dc, 0, 0, bitmap->bmiHeader.biWidth, 495 ::SetDIBitsToDevice(dc, 0, 0, bitmap->bmiHeader.biWidth,
496 bitmap->bmiHeader.biHeight, 0, 0, 0, 496 bitmap->bmiHeader.biHeight, 0, 0, 0,
497 bitmap->bmiHeader.biHeight, bitmap_bits, bitmap, 497 bitmap->bmiHeader.biHeight, bitmap_bits, bitmap,
498 DIB_RGB_COLORS); 498 DIB_RGB_COLORS);
499 } 499 }
500 // Windows doesn't really handle alpha channels well in many situations. When 500 // Windows doesn't really handle alpha channels well in many situations. When
501 // the source image is < 32 bpp, we force the bitmap to be opaque. When the 501 // the source image is < 32 bpp, we force the bitmap to be opaque. When the
502 // source image is 32 bpp, the alpha channel might still contain garbage data. 502 // source image is 32 bpp, the alpha channel might still contain garbage data.
503 // Since Windows uses premultiplied alpha, we scan for instances where 503 // Since Windows uses premultiplied alpha, we scan for instances where
504 // (R, G, B) > A. If there are any invalid premultiplied colors in the image, 504 // (R, G, B) > A. If there are any invalid premultiplied colors in the image,
505 // we assume the alpha channel contains garbage and force the bitmap to be 505 // we assume the alpha channel contains garbage and force the bitmap to be
506 // opaque as well. Note that this heuristic will fail on a transparent bitmap 506 // opaque as well. Note that this heuristic will fail on a transparent bitmap
507 // containing only black pixels... 507 // containing only black pixels...
508 const SkBitmap& device_bitmap = canvas.getDevice()->accessBitmap(true); 508 const SkBitmap& device_bitmap =
509 canvas.sk_canvas()->getDevice()->accessBitmap(true);
509 { 510 {
510 SkAutoLockPixels lock(device_bitmap); 511 SkAutoLockPixels lock(device_bitmap);
511 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || 512 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 ||
512 BitmapHasInvalidPremultipliedColors(device_bitmap); 513 BitmapHasInvalidPremultipliedColors(device_bitmap);
513 if (has_invalid_alpha_channel) { 514 if (has_invalid_alpha_channel) {
514 MakeBitmapOpaque(device_bitmap); 515 MakeBitmapOpaque(device_bitmap);
515 } 516 }
516 } 517 }
517 518
518 return canvas.ExtractBitmap(); 519 return canvas.ExtractBitmap();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", 716 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass",
716 L"ClipboardOwnerWindow", 717 L"ClipboardOwnerWindow",
717 0, 0, 0, 0, 0, 718 0, 0, 0, 0, 0,
718 HWND_MESSAGE, 719 HWND_MESSAGE,
719 0, 0, 0); 720 0, 0, 0);
720 } 721 }
721 return clipboard_owner_; 722 return clipboard_owner_;
722 } 723 }
723 724
724 } // namespace ui 725 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_mac.mm ('k') | ui/gfx/canvas.h » ('j') | ui/gfx/canvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698