Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" | |
| 12 | |
| 13 #include <utility> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 #include "webrtc/base/timeutils.h" | |
| 17 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 18 #include "webrtc/modules/desktop_capture/differ.h" | |
| 19 | |
| 20 namespace webrtc { | |
| 21 | |
| 22 ScreenCapturerDifferWrapper::ScreenCapturerDifferWrapper( | |
| 23 std::unique_ptr<ScreenCapturer> impl) | |
| 24 : impl_(std::move(impl)) { | |
| 25 RTC_DCHECK(impl_); | |
| 26 } | |
| 27 | |
| 28 ScreenCapturerDifferWrapper::~ScreenCapturerDifferWrapper() = default; | |
| 29 | |
| 30 void ScreenCapturerDifferWrapper::Start(DesktopCapturer::Callback* callback) { | |
| 31 callback_ = callback; | |
| 32 impl_->Start(this); | |
| 33 } | |
| 34 | |
| 35 void ScreenCapturerDifferWrapper::SetSharedMemoryFactory( | |
| 36 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | |
| 37 impl_->SetSharedMemoryFactory(std::move(shared_memory_factory)); | |
| 38 } | |
| 39 | |
| 40 void ScreenCapturerDifferWrapper::Capture(const DesktopRegion& region) { | |
| 41 impl_->Capture(region); | |
| 42 } | |
| 43 | |
| 44 bool ScreenCapturerDifferWrapper::GetScreenList(ScreenList* screens) { | |
| 45 return impl_->GetScreenList(screens); | |
| 46 } | |
| 47 | |
| 48 bool ScreenCapturerDifferWrapper::SelectScreen(ScreenId id) { | |
| 49 return impl_->SelectScreen(id); | |
| 50 } | |
| 51 | |
| 52 void ScreenCapturerDifferWrapper::OnCaptureResult( | |
| 53 Result result, | |
| 54 std::unique_ptr<DesktopFrame> frame) { | |
| 55 int64_t start_time_nanos = rtc::TimeNanos(); | |
| 56 if (result == Result::SUCCESS && frame) { | |
| 57 if (!differ_ || | |
| 58 differ_->width() != frame->size().width() || | |
| 59 differ_->height() != frame->size().height() || | |
| 60 differ_->bytes_per_row() != frame->stride()) { | |
| 61 differ_.reset(new Differ(frame->size().width(), | |
| 62 frame->size().height(), | |
| 63 DesktopFrame::kBytesPerPixel, | |
| 64 frame->stride())); | |
| 65 last_frame_ = nullptr; | |
| 66 } | |
| 67 if (last_frame_) { | |
| 68 if (frame->updated_region().is_empty()) { | |
|
Sergey Ulanov
2016/08/03 23:19:11
This will cause the this capturer to scan the whol
Hzj_jie
2016/08/04 02:28:07
Good point. Update.
| |
| 69 differ_->CalcDirtyRegion(last_frame_->data(), | |
| 70 frame->data(), | |
| 71 frame->mutable_updated_region()); | |
| 72 } else { | |
| 73 // If underlying ScreenCapturer provides updated_region(), use it as | |
| 74 // hints. | |
| 75 differ_->CalcDirtyRegionWithHints(last_frame_->data(), | |
| 76 frame->data(), | |
| 77 frame->updated_region(), | |
| 78 frame->mutable_updated_region()); | |
| 79 } | |
| 80 } else { | |
| 81 frame->mutable_updated_region()->SetRect( | |
| 82 DesktopRect::MakeSize(frame->size())); | |
| 83 } | |
| 84 last_frame_ = static_cast<SharedDesktopFrame*>(frame.get())->Share(); | |
| 85 } | |
| 86 | |
| 87 frame->set_capture_time_ms(frame->capture_time_ms() + | |
| 88 (rtc::TimeNanos() - start_time_nanos) / rtc::kNumNanosecsPerMillisec); | |
| 89 callback_->OnCaptureResult(result, std::move(frame)); | |
| 90 } | |
| 91 | |
| 92 } // namespace webrtc | |
| OLD | NEW |