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 #include "remoting/host/capturer.h" | 5 #include "remoting/host/capturer.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/native_library.h" | 12 #include "base/native_library.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/stringize_macros.h" | 14 #include "base/stringize_macros.h" |
| 15 #include "remoting/base/capture_data.h" |
15 #include "remoting/host/capturer_helper.h" | 16 #include "remoting/host/capturer_helper.h" |
16 #include "remoting/host/desktop_win.h" | 17 #include "remoting/host/desktop_win.h" |
17 #include "remoting/host/differ.h" | 18 #include "remoting/host/differ.h" |
18 #include "remoting/host/scoped_thread_desktop_win.h" | 19 #include "remoting/host/scoped_thread_desktop_win.h" |
| 20 #include "remoting/proto/control.pb.h" |
19 | 21 |
20 namespace remoting { | 22 namespace remoting { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // Constants from dwmapi.h. | 26 // Constants from dwmapi.h. |
25 const UINT DWM_EC_DISABLECOMPOSITION = 0; | 27 const UINT DWM_EC_DISABLECOMPOSITION = 0; |
26 const UINT DWM_EC_ENABLECOMPOSITION = 1; | 28 const UINT DWM_EC_ENABLECOMPOSITION = 1; |
27 | 29 |
28 typedef HRESULT (WINAPI * DwmEnableCompositionFunc)(UINT); | 30 typedef HRESULT (WINAPI * DwmEnableCompositionFunc)(UINT); |
29 | 31 |
30 const char16 kDwmapiLibraryName[] = TO_L_STRING("dwmapi"); | 32 const char16 kDwmapiLibraryName[] = TO_L_STRING("dwmapi"); |
31 | 33 |
32 // CapturerGdi captures 32bit RGB using GDI. | 34 // CapturerGdi captures 32bit RGB using GDI. |
33 // | 35 // |
34 // CapturerGdi is double-buffered as required by Capturer. See | 36 // CapturerGdi is double-buffered as required by Capturer. See |
35 // remoting/host/capturer.h. | 37 // remoting/host/capturer.h. |
36 class CapturerGdi : public Capturer { | 38 class CapturerGdi : public Capturer { |
37 public: | 39 public: |
38 CapturerGdi(); | 40 CapturerGdi(); |
39 virtual ~CapturerGdi(); | 41 virtual ~CapturerGdi(); |
40 | 42 |
41 // Capturer interface. | 43 // Capturer interface. |
42 virtual void Start() OVERRIDE; | 44 virtual void Start(const CursorShapeChangedCallback& callback) OVERRIDE; |
43 virtual void Stop() OVERRIDE; | 45 virtual void Stop() OVERRIDE; |
44 virtual void ScreenConfigurationChanged() OVERRIDE; | 46 virtual void ScreenConfigurationChanged() OVERRIDE; |
45 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 47 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
46 virtual void ClearInvalidRegion() OVERRIDE; | 48 virtual void ClearInvalidRegion() OVERRIDE; |
47 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 49 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
48 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; | 50 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; |
49 virtual void InvalidateFullScreen() OVERRIDE; | 51 virtual void InvalidateFullScreen() OVERRIDE; |
50 virtual void CaptureInvalidRegion( | 52 virtual void CaptureInvalidRegion( |
51 const CaptureCompletedCallback& callback) OVERRIDE; | 53 const CaptureCompletedCallback& callback) OVERRIDE; |
52 virtual const SkISize& size_most_recent() const OVERRIDE; | 54 virtual const SkISize& size_most_recent() const OVERRIDE; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // if the screen size has changed. | 91 // if the screen size has changed. |
90 void MaybeChangeScreenConfiguration(); | 92 void MaybeChangeScreenConfiguration(); |
91 | 93 |
92 // Gets the screen size. | 94 // Gets the screen size. |
93 SkISize GetScreenSize(); | 95 SkISize GetScreenSize(); |
94 | 96 |
95 // A thread-safe list of invalid rectangles, and the size of the most | 97 // A thread-safe list of invalid rectangles, and the size of the most |
96 // recently captured screen. | 98 // recently captured screen. |
97 CapturerHelper helper_; | 99 CapturerHelper helper_; |
98 | 100 |
| 101 // Callback notified whenever the cursor shape is changed. |
| 102 CursorShapeChangedCallback cursor_shape_changed_callback_; |
| 103 |
99 // There are two buffers for the screen images, as required by Capturer. | 104 // There are two buffers for the screen images, as required by Capturer. |
100 static const int kNumBuffers = 2; | 105 static const int kNumBuffers = 2; |
101 VideoFrameBuffer buffers_[kNumBuffers]; | 106 VideoFrameBuffer buffers_[kNumBuffers]; |
102 | 107 |
103 ScopedThreadDesktopWin desktop_; | 108 ScopedThreadDesktopWin desktop_; |
104 | 109 |
105 // Gdi specific information about screen. | 110 // Gdi specific information about screen. |
106 HWND desktop_window_; | 111 HWND desktop_window_; |
107 HDC desktop_dc_; | 112 HDC desktop_dc_; |
108 HDC memory_dc_; | 113 HDC memory_dc_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 desktop_window_ = NULL; | 212 desktop_window_ = NULL; |
208 desktop_dc_ = NULL; | 213 desktop_dc_ = NULL; |
209 } | 214 } |
210 | 215 |
211 if (memory_dc_) { | 216 if (memory_dc_) { |
212 DeleteDC(memory_dc_); | 217 DeleteDC(memory_dc_); |
213 memory_dc_ = NULL; | 218 memory_dc_ = NULL; |
214 } | 219 } |
215 } | 220 } |
216 | 221 |
217 void CapturerGdi::Start() { | 222 void CapturerGdi::Start( |
| 223 const CursorShapeChangedCallback& callback) { |
| 224 cursor_shape_changed_callback_ = callback; |
| 225 |
218 // Load dwmapi.dll dynamically since it is not available on XP. | 226 // Load dwmapi.dll dynamically since it is not available on XP. |
219 if (dwmapi_library_ == NULL) { | 227 if (dwmapi_library_ == NULL) { |
220 std::string error; | 228 std::string error; |
221 dwmapi_library_ = base::LoadNativeLibrary( | 229 dwmapi_library_ = base::LoadNativeLibrary( |
222 FilePath(base::GetNativeLibraryName(kDwmapiLibraryName)), &error); | 230 FilePath(base::GetNativeLibraryName(kDwmapiLibraryName)), &error); |
223 } | 231 } |
224 | 232 |
225 if (dwmapi_library_ != NULL && composition_func_ == NULL) { | 233 if (dwmapi_library_ != NULL && composition_func_ == NULL) { |
226 composition_func_ = reinterpret_cast<DwmEnableCompositionFunc>( | 234 composition_func_ = reinterpret_cast<DwmEnableCompositionFunc>( |
227 base::GetFunctionPointerFromNativeLibrary(dwmapi_library_, | 235 base::GetFunctionPointerFromNativeLibrary(dwmapi_library_, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 430 } |
423 | 431 |
424 } // namespace | 432 } // namespace |
425 | 433 |
426 // static | 434 // static |
427 Capturer* Capturer::Create() { | 435 Capturer* Capturer::Create() { |
428 return new CapturerGdi(); | 436 return new CapturerGdi(); |
429 } | 437 } |
430 | 438 |
431 } // namespace remoting | 439 } // namespace remoting |
OLD | NEW |