Chromium Code Reviews| Index: webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc |
| diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86ca27316e9bff8ef8667990c036403bb5f7e5cd |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc |
| @@ -0,0 +1,92 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" |
| + |
| +#include <utility> |
| + |
| +#include "webrtc/base/checks.h" |
| +#include "webrtc/base/timeutils.h" |
| +#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| +#include "webrtc/modules/desktop_capture/differ.h" |
| + |
| +namespace webrtc { |
| + |
| +ScreenCapturerDifferWrapper::ScreenCapturerDifferWrapper( |
| + std::unique_ptr<ScreenCapturer> impl) |
| + : impl_(std::move(impl)) { |
| + RTC_DCHECK(impl_); |
| +} |
| + |
| +ScreenCapturerDifferWrapper::~ScreenCapturerDifferWrapper() = default; |
| + |
| +void ScreenCapturerDifferWrapper::Start(DesktopCapturer::Callback* callback) { |
| + callback_ = callback; |
| + impl_->Start(this); |
| +} |
| + |
| +void ScreenCapturerDifferWrapper::SetSharedMemoryFactory( |
| + std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
| + impl_->SetSharedMemoryFactory(std::move(shared_memory_factory)); |
| +} |
| + |
| +void ScreenCapturerDifferWrapper::Capture(const DesktopRegion& region) { |
| + impl_->Capture(region); |
| +} |
| + |
| +bool ScreenCapturerDifferWrapper::GetScreenList(ScreenList* screens) { |
| + return impl_->GetScreenList(screens); |
| +} |
| + |
| +bool ScreenCapturerDifferWrapper::SelectScreen(ScreenId id) { |
| + return impl_->SelectScreen(id); |
| +} |
| + |
| +void ScreenCapturerDifferWrapper::OnCaptureResult( |
| + Result result, |
| + std::unique_ptr<DesktopFrame> frame) { |
| + int64_t start_time_nanos = rtc::TimeNanos(); |
| + if (result == Result::SUCCESS && frame) { |
| + if (!differ_ || |
| + differ_->width() != frame->size().width() || |
| + differ_->height() != frame->size().height() || |
| + differ_->bytes_per_row() != frame->stride()) { |
| + differ_.reset(new Differ(frame->size().width(), |
| + frame->size().height(), |
| + DesktopFrame::kBytesPerPixel, |
| + frame->stride())); |
| + last_frame_ = nullptr; |
| + } |
| + if (last_frame_) { |
| + 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.
|
| + differ_->CalcDirtyRegion(last_frame_->data(), |
| + frame->data(), |
| + frame->mutable_updated_region()); |
| + } else { |
| + // If underlying ScreenCapturer provides updated_region(), use it as |
| + // hints. |
| + differ_->CalcDirtyRegionWithHints(last_frame_->data(), |
| + frame->data(), |
| + frame->updated_region(), |
| + frame->mutable_updated_region()); |
| + } |
| + } else { |
| + frame->mutable_updated_region()->SetRect( |
| + DesktopRect::MakeSize(frame->size())); |
| + } |
| + last_frame_ = static_cast<SharedDesktopFrame*>(frame.get())->Share(); |
| + } |
| + |
| + frame->set_capture_time_ms(frame->capture_time_ms() + |
| + (rtc::TimeNanos() - start_time_nanos) / rtc::kNumNanosecsPerMillisec); |
| + callback_->OnCaptureResult(result, std::move(frame)); |
| +} |
| + |
| +} // namespace webrtc |