OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/desktop_shape_tracker.h" | 5 #include "remoting/host/desktop_shape_tracker.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/win/scoped_gdi_object.h" | 11 #include "base/win/scoped_gdi_object.h" |
11 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 13 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
13 | 14 |
14 namespace remoting { | 15 namespace remoting { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 struct EnumDesktopShapeData { | 19 struct EnumDesktopShapeData { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void DesktopShapeTrackerWin::RefreshDesktopShape() { | 57 void DesktopShapeTrackerWin::RefreshDesktopShape() { |
57 // Accumulate a new desktop shape from current window positions. | 58 // Accumulate a new desktop shape from current window positions. |
58 scoped_ptr<EnumDesktopShapeData> shape_data(new EnumDesktopShapeData); | 59 scoped_ptr<EnumDesktopShapeData> shape_data(new EnumDesktopShapeData); |
59 if (!EnumWindows(EnumWindowsCallback, (LPARAM)shape_data.get())) { | 60 if (!EnumWindows(EnumWindowsCallback, (LPARAM)shape_data.get())) { |
60 PLOG(ERROR) << "Failed to enumerate windows"; | 61 PLOG(ERROR) << "Failed to enumerate windows"; |
61 desktop_shape_.Clear(); | 62 desktop_shape_.Clear(); |
62 return; | 63 return; |
63 } | 64 } |
64 | 65 |
65 // If the shape has changed, refresh |desktop_shape_|. | 66 // If the shape has changed, refresh |desktop_shape_|. |
66 if (!EqualRgn(shape_data->desktop_region, old_desktop_region_)) { | 67 if (!EqualRgn(shape_data->desktop_region.get(), old_desktop_region_.get())) { |
67 old_desktop_region_.Set(shape_data->desktop_region.release()); | 68 old_desktop_region_ = shape_data->desktop_region.Pass(); |
68 | 69 |
69 // Determine the size of output buffer required to receive the region. | 70 // Determine the size of output buffer required to receive the region. |
70 DWORD bytes_size = GetRegionData(old_desktop_region_, 0, nullptr); | 71 DWORD bytes_size = GetRegionData(old_desktop_region_.get(), 0, nullptr); |
71 CHECK(bytes_size != 0); | 72 CHECK(bytes_size != 0); |
72 | 73 |
73 // Fetch the Windows RECTs that comprise the region. | 74 // Fetch the Windows RECTs that comprise the region. |
74 std::vector<char> buffer(bytes_size); | 75 std::vector<char> buffer(bytes_size); |
75 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data()); | 76 LPRGNDATA region_data = reinterpret_cast<LPRGNDATA>(buffer.data()); |
76 DWORD result = GetRegionData(old_desktop_region_, bytes_size, region_data); | 77 DWORD result = |
| 78 GetRegionData(old_desktop_region_.get(), bytes_size, region_data); |
77 CHECK(result == bytes_size); | 79 CHECK(result == bytes_size); |
78 const LPRECT rects = reinterpret_cast<LPRECT>(®ion_data->Buffer[0]); | 80 const LPRECT rects = reinterpret_cast<LPRECT>(®ion_data->Buffer[0]); |
79 | 81 |
80 // Reset |desktop_shape_| and add new rectangles into it. | 82 // Reset |desktop_shape_| and add new rectangles into it. |
81 desktop_shape_.Clear(); | 83 desktop_shape_.Clear(); |
82 for (size_t i = 0; i < region_data->rdh.nCount; ++i) { | 84 for (size_t i = 0; i < region_data->rdh.nCount; ++i) { |
83 desktop_shape_.AddRect(webrtc::DesktopRect::MakeLTRB( | 85 desktop_shape_.AddRect(webrtc::DesktopRect::MakeLTRB( |
84 rects[i].left, rects[i].top, rects[i].right, rects[i].bottom)); | 86 rects[i].left, rects[i].top, rects[i].right, rects[i].bottom)); |
85 } | 87 } |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
89 const webrtc::DesktopRegion& DesktopShapeTrackerWin::desktop_shape() { | 91 const webrtc::DesktopRegion& DesktopShapeTrackerWin::desktop_shape() { |
90 return desktop_shape_; | 92 return desktop_shape_; |
91 } | 93 } |
92 | 94 |
93 // static | 95 // static |
94 BOOL DesktopShapeTrackerWin::EnumWindowsCallback(HWND window, LPARAM lparam) { | 96 BOOL DesktopShapeTrackerWin::EnumWindowsCallback(HWND window, LPARAM lparam) { |
95 EnumDesktopShapeData* data = reinterpret_cast<EnumDesktopShapeData*>(lparam); | 97 EnumDesktopShapeData* data = reinterpret_cast<EnumDesktopShapeData*>(lparam); |
96 HRGN desktop_region = data->desktop_region.Get(); | 98 HRGN desktop_region = data->desktop_region.get(); |
97 HRGN window_region = data->window_region.Get(); | 99 HRGN window_region = data->window_region.get(); |
98 | 100 |
99 // Is the window visible? | 101 // Is the window visible? |
100 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) | 102 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) |
101 return TRUE; | 103 return TRUE; |
102 | 104 |
103 // Find the desktop position of the window (including non-client-area). | 105 // Find the desktop position of the window (including non-client-area). |
104 RECT window_rect; | 106 RECT window_rect; |
105 if (!GetWindowRect(window, &window_rect)) | 107 if (!GetWindowRect(window, &window_rect)) |
106 return TRUE; | 108 return TRUE; |
107 | 109 |
(...skipping 24 matching lines...) Expand all Loading... |
132 | 134 |
133 } // namespace | 135 } // namespace |
134 | 136 |
135 // static | 137 // static |
136 scoped_ptr<DesktopShapeTracker> DesktopShapeTracker::Create( | 138 scoped_ptr<DesktopShapeTracker> DesktopShapeTracker::Create( |
137 webrtc::DesktopCaptureOptions options) { | 139 webrtc::DesktopCaptureOptions options) { |
138 return make_scoped_ptr(new DesktopShapeTrackerWin()); | 140 return make_scoped_ptr(new DesktopShapeTrackerWin()); |
139 } | 141 } |
140 | 142 |
141 } // namespace remoting | 143 } // namespace remoting |
OLD | NEW |