OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/views/tabs/native_view_photobooth_win.h" | 5 #include "chrome/browser/views/tabs/native_view_photobooth_win.h" |
6 | 6 |
7 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
8 #include "gfx/canvas.h" | 8 #include "gfx/canvas_skia.h" |
9 #include "gfx/point.h" | 9 #include "gfx/point.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "views/widget/widget_win.h" | 11 #include "views/widget/widget_win.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, HDC monitor_dc, | 15 static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, HDC monitor_dc, |
16 RECT* monitor_rect, LPARAM data) { | 16 RECT* monitor_rect, LPARAM data) { |
17 gfx::Point* point = reinterpret_cast<gfx::Point*>(data); | 17 gfx::Point* point = reinterpret_cast<gfx::Point*>(data); |
18 if (monitor_rect->right > point->x() && monitor_rect->bottom > point->y()) { | 18 if (monitor_rect->right > point->x() && monitor_rect->bottom > point->y()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 GetParent(current_hwnd_) != capture_window_->GetNativeView()) { | 93 GetParent(current_hwnd_) != capture_window_->GetNativeView()) { |
94 Replace(current_hwnd_); | 94 Replace(current_hwnd_); |
95 } | 95 } |
96 | 96 |
97 // We compel the contained HWND to paint now, synchronously. We do this to | 97 // We compel the contained HWND to paint now, synchronously. We do this to |
98 // populate the device context with valid and current data. | 98 // populate the device context with valid and current data. |
99 RedrawWindow(current_hwnd_, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); | 99 RedrawWindow(current_hwnd_, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); |
100 | 100 |
101 // Transfer the contents of the layered capture window to the screen-shot | 101 // Transfer the contents of the layered capture window to the screen-shot |
102 // canvas' DIB. | 102 // canvas' DIB. |
103 HDC target_dc = canvas->beginPlatformPaint(); | 103 HDC target_dc = canvas->AsCanvasSkia()->beginPlatformPaint(); |
104 HDC source_dc = GetDC(current_hwnd_); | 104 HDC source_dc = GetDC(current_hwnd_); |
105 RECT window_rect = {0}; | 105 RECT window_rect = {0}; |
106 GetWindowRect(current_hwnd_, &window_rect); | 106 GetWindowRect(current_hwnd_, &window_rect); |
107 BitBlt(target_dc, target_bounds.x(), target_bounds.y(), | 107 BitBlt(target_dc, target_bounds.x(), target_bounds.y(), |
108 target_bounds.width(), target_bounds.height(), source_dc, 0, 0, | 108 target_bounds.width(), target_bounds.height(), source_dc, 0, 0, |
109 SRCCOPY); | 109 SRCCOPY); |
110 // Windows screws up the alpha channel on all text it draws, and so we need | 110 // Windows screws up the alpha channel on all text it draws, and so we need |
111 // to call makeOpaque _after_ the blit to correct for this. | 111 // to call makeOpaque _after_ the blit to correct for this. |
112 canvas->getTopPlatformDevice().makeOpaque(target_bounds.x(), | 112 canvas->AsCanvasSkia()->getTopPlatformDevice().makeOpaque( |
113 target_bounds.y(), | 113 target_bounds.x(), target_bounds.y(), target_bounds.width(), |
114 target_bounds.width(), | 114 target_bounds.height()); |
115 target_bounds.height()); | |
116 ReleaseDC(current_hwnd_, source_dc); | 115 ReleaseDC(current_hwnd_, source_dc); |
117 canvas->endPlatformPaint(); | 116 canvas->AsCanvasSkia()->endPlatformPaint(); |
118 } | 117 } |
119 | 118 |
120 /////////////////////////////////////////////////////////////////////////////// | 119 /////////////////////////////////////////////////////////////////////////////// |
121 // NativeViewPhotoboothWin, private: | 120 // NativeViewPhotoboothWin, private: |
122 | 121 |
123 void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { | 122 void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { |
124 // Snapshotting a HWND is tricky - if the HWND is clipped (e.g. positioned | 123 // Snapshotting a HWND is tricky - if the HWND is clipped (e.g. positioned |
125 // partially off-screen) then just blitting from the HWND' DC to the capture | 124 // partially off-screen) then just blitting from the HWND' DC to the capture |
126 // bitmap would be incorrect, since the capture bitmap would show only the | 125 // bitmap would be incorrect, since the capture bitmap would show only the |
127 // visible area of the HWND. | 126 // visible area of the HWND. |
(...skipping 29 matching lines...) Expand all Loading... |
157 capture_window_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); | 156 capture_window_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW); |
158 capture_window_->Init(NULL, capture_bounds); | 157 capture_window_->Init(NULL, capture_bounds); |
159 // If the capture window isn't visible, blitting from the TabContents' | 158 // If the capture window isn't visible, blitting from the TabContents' |
160 // HWND's DC to the capture bitmap produces blankness. | 159 // HWND's DC to the capture bitmap produces blankness. |
161 capture_window_->Show(); | 160 capture_window_->Show(); |
162 SetLayeredWindowAttributes( | 161 SetLayeredWindowAttributes( |
163 capture_window_->GetNativeView(), RGB(0xFF, 0xFF, 0xFF), 0xFF, LWA_ALPHA); | 162 capture_window_->GetNativeView(), RGB(0xFF, 0xFF, 0xFF), 0xFF, LWA_ALPHA); |
164 | 163 |
165 Replace(initial_hwnd); | 164 Replace(initial_hwnd); |
166 } | 165 } |
OLD | NEW |