OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h" | 11 #include "webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <unknwn.h> | 15 #include <unknwn.h> |
16 #include <DXGIFormat.h> | 16 #include <DXGIFormat.h> |
17 #include <Windows.h> | 17 #include <Windows.h> |
18 | 18 |
19 #include <algorithm> | |
20 | |
19 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
21 #include "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h" | 23 #include "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h" |
22 #include "webrtc/modules/desktop_capture/win/dxgi_texture_staging.h" | 24 #include "webrtc/modules/desktop_capture/win/dxgi_texture_staging.h" |
23 | 25 |
24 namespace webrtc { | 26 namespace webrtc { |
25 | 27 |
26 using Microsoft::WRL::ComPtr; | 28 using Microsoft::WRL::ComPtr; |
27 | 29 |
28 namespace { | 30 namespace { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 dirty_rects_count--; | 269 dirty_rects_count--; |
268 } | 270 } |
269 | 271 |
270 return true; | 272 return true; |
271 } | 273 } |
272 | 274 |
273 void DxgiOutputDuplicator::Setup(Context* context) { | 275 void DxgiOutputDuplicator::Setup(Context* context) { |
274 RTC_DCHECK(context->updated_region.is_empty()); | 276 RTC_DCHECK(context->updated_region.is_empty()); |
275 // Always copy entire monitor during the first Duplicate() function call. | 277 // Always copy entire monitor during the first Duplicate() function call. |
276 context->updated_region.AddRect(desktop_rect_); | 278 context->updated_region.AddRect(desktop_rect_); |
277 for (size_t i = 0; i < contexts_.size(); i++) { | |
278 if (contexts_[i] == nullptr) { | |
279 contexts_[i] = context; | |
280 return; | |
281 } | |
282 } | |
283 | |
284 contexts_.push_back(context); | 279 contexts_.push_back(context); |
Sergey Ulanov
2016/11/11 22:57:35
Maybe DCHECK here that context is not already in c
Hzj_jie
2016/11/11 23:28:23
Done.
| |
285 } | 280 } |
286 | 281 |
287 void DxgiOutputDuplicator::Unregister(const Context* const context) { | 282 void DxgiOutputDuplicator::Unregister(const Context* const context) { |
288 for (size_t i = 0; i < contexts_.size(); i++) { | 283 // There is no ostream operator<< defined for std::vector::iterator, so |
289 if (contexts_[i] == context) { | 284 // RTC_DCHECK_EQ will trigger build break. Refer to webrtc/base/checks.h:130. |
Sergey Ulanov
2016/11/11 22:57:35
I don't think you really need this comment, it's a
Hzj_jie
2016/11/11 23:28:23
Really, I thought it was not so common.
| |
290 contexts_[i] = nullptr; | 285 RTC_DCHECK(std::find(contexts_.begin(), contexts_.end(), context) != |
Sergey Ulanov
2016/11/11 22:57:35
I'd prefer to save result of std::find() and use i
Hzj_jie
2016/11/11 23:28:23
Done.
| |
291 return; | 286 contexts_.end()); |
292 } | 287 contexts_.erase(std::find(contexts_.begin(), contexts_.end(), context)); |
293 } | |
294 | |
295 RTC_NOTREACHED(); | |
296 } | 288 } |
297 | 289 |
298 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { | 290 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { |
299 for (Context* dest : contexts_) { | 291 for (Context* dest : contexts_) { |
292 RTC_DCHECK(dest); | |
300 if (dest != source) { | 293 if (dest != source) { |
301 dest->updated_region.AddRegion(source->updated_region); | 294 dest->updated_region.AddRegion(source->updated_region); |
302 } | 295 } |
303 } | 296 } |
304 } | 297 } |
305 | 298 |
306 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) { | 299 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) { |
307 // |texture_|->AsDesktopFrame() starts from (0, 0). | 300 // |texture_|->AsDesktopFrame() starts from (0, 0). |
308 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top()); | 301 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top()); |
309 return rect; | 302 return rect; |
310 } | 303 } |
311 | 304 |
312 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect, | 305 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect, |
313 DesktopVector offset) { | 306 DesktopVector offset) { |
314 rect = SourceRect(rect); | 307 rect = SourceRect(rect); |
315 rect.Translate(offset); | 308 rect.Translate(offset); |
316 return rect; | 309 return rect; |
317 } | 310 } |
318 | 311 |
319 } // namespace webrtc | 312 } // namespace webrtc |
OLD | NEW |