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 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 } | 268 } |
269 | 269 |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 void DxgiOutputDuplicator::Setup(Context* context) { | 273 void DxgiOutputDuplicator::Setup(Context* context) { |
274 RTC_DCHECK(context->updated_region.is_empty()); | 274 RTC_DCHECK(context->updated_region.is_empty()); |
275 // Always copy entire monitor during the first Duplicate() function call. | 275 // Always copy entire monitor during the first Duplicate() function call. |
276 context->updated_region.AddRect(desktop_rect_); | 276 context->updated_region.AddRect(desktop_rect_); |
277 for (size_t i = 0; i < contexts_.size(); i++) { | 277 for (size_t i = 0; i < contexts_.size(); i++) { |
278 if (contexts_[i] == nullptr) { | 278 if (contexts_[i] == nullptr) { |
Sergey Ulanov
2016/11/11 18:27:18
I guess this loop can be removed now.
Hzj_jie
2016/11/11 21:51:31
Yes. Updated.
| |
279 contexts_[i] = context; | 279 contexts_[i] = context; |
280 return; | 280 return; |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 contexts_.push_back(context); | 284 contexts_.push_back(context); |
285 } | 285 } |
286 | 286 |
287 void DxgiOutputDuplicator::Unregister(const Context* const context) { | 287 void DxgiOutputDuplicator::Unregister(const Context* const context) { |
288 for (size_t i = 0; i < contexts_.size(); i++) { | 288 for (auto it = contexts_.begin(); it != contexts_.end(); it++) { |
Sergey Ulanov
2016/11/11 18:27:18
This loop can be replaced with std::find:
contex
Hzj_jie
2016/11/11 21:51:31
Done.
| |
289 if (contexts_[i] == context) { | 289 if (*it == context) { |
290 contexts_[i] = nullptr; | 290 contexts_.erase(it); |
Sergey Ulanov
2016/11/11 18:27:18
What was the reason this code was implemented this
Hzj_jie
2016/11/11 21:51:31
Because std::vector::erase is O(n) instead of O(1)
Sergey Ulanov
2016/11/11 22:57:35
FWIW it can be O(1) if you swap it with the last e
Hzj_jie
2016/11/11 23:28:22
Oh, yes, since we have searched already. But the n
| |
291 return; | 291 return; |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 RTC_NOTREACHED(); | 295 RTC_NOTREACHED(); |
296 } | 296 } |
297 | 297 |
298 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { | 298 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { |
299 for (Context* dest : contexts_) { | 299 for (Context* dest : contexts_) { |
300 RTC_DCHECK(dest); | |
300 if (dest != source) { | 301 if (dest != source) { |
301 dest->updated_region.AddRegion(source->updated_region); | 302 dest->updated_region.AddRegion(source->updated_region); |
302 } | 303 } |
303 } | 304 } |
304 } | 305 } |
305 | 306 |
306 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) { | 307 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) { |
307 // |texture_|->AsDesktopFrame() starts from (0, 0). | 308 // |texture_|->AsDesktopFrame() starts from (0, 0). |
308 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top()); | 309 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top()); |
309 return rect; | 310 return rect; |
310 } | 311 } |
311 | 312 |
312 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect, | 313 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect, |
313 DesktopVector offset) { | 314 DesktopVector offset) { |
314 rect = SourceRect(rect); | 315 rect = SourceRect(rect); |
315 rect.Translate(offset); | 316 rect.Translate(offset); |
316 return rect; | 317 return rect; |
317 } | 318 } |
318 | 319 |
319 } // namespace webrtc | 320 } // namespace webrtc |
OLD | NEW |