// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "remoting/host/single_window_desktop_environment.h" #include #include "base/logging.h" #include "base/macros.h" #include "base/single_thread_task_runner.h" #include "remoting/host/single_window_input_injector.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" namespace remoting { // Enables capturing and streaming of windows. class SingleWindowDesktopEnvironment : public BasicDesktopEnvironment { public: ~SingleWindowDesktopEnvironment() override; // DesktopEnvironment interface. scoped_ptr CreateVideoCapturer() override; scoped_ptr CreateInputInjector() override; protected: friend class SingleWindowDesktopEnvironmentFactory; SingleWindowDesktopEnvironment( scoped_refptr caller_task_runner, scoped_refptr video_capture_task_runner, scoped_refptr input_task_runner, scoped_refptr ui_task_runner, webrtc::WindowId window_id, bool supports_touch_events); private: webrtc::WindowId window_id_; DISALLOW_COPY_AND_ASSIGN(SingleWindowDesktopEnvironment); }; SingleWindowDesktopEnvironment::~SingleWindowDesktopEnvironment() {} scoped_ptr SingleWindowDesktopEnvironment::CreateVideoCapturer() { DCHECK(caller_task_runner()->BelongsToCurrentThread()); webrtc::DesktopCaptureOptions options = webrtc::DesktopCaptureOptions::CreateDefault(); options.set_use_update_notifications(true); scoped_ptr window_capturer( webrtc::WindowCapturer::Create(options)); window_capturer->SelectWindow(window_id_); return std::move(window_capturer); } scoped_ptr SingleWindowDesktopEnvironment::CreateInputInjector() { DCHECK(caller_task_runner()->BelongsToCurrentThread()); scoped_ptr input_injector( InputInjector::Create(input_task_runner(), ui_task_runner())); return SingleWindowInputInjector::CreateForWindow( window_id_, std::move(input_injector)); } SingleWindowDesktopEnvironment::SingleWindowDesktopEnvironment( scoped_refptr caller_task_runner, scoped_refptr video_capture_task_runner, scoped_refptr input_task_runner, scoped_refptr ui_task_runner, webrtc::WindowId window_id, bool supports_touch_events) : BasicDesktopEnvironment(caller_task_runner, video_capture_task_runner, input_task_runner, ui_task_runner, supports_touch_events), window_id_(window_id) {} SingleWindowDesktopEnvironmentFactory::SingleWindowDesktopEnvironmentFactory( scoped_refptr caller_task_runner, scoped_refptr video_capture_task_runner, scoped_refptr input_task_runner, scoped_refptr ui_task_runner, webrtc::WindowId window_id) : BasicDesktopEnvironmentFactory(caller_task_runner, video_capture_task_runner, input_task_runner, ui_task_runner), window_id_(window_id) {} SingleWindowDesktopEnvironmentFactory:: ~SingleWindowDesktopEnvironmentFactory() { } scoped_ptr SingleWindowDesktopEnvironmentFactory::Create( base::WeakPtr client_session_control) { DCHECK(caller_task_runner()->BelongsToCurrentThread()); return make_scoped_ptr(new SingleWindowDesktopEnvironment( caller_task_runner(), video_capture_task_runner(), input_task_runner(), ui_task_runner(), window_id_, supports_touch_events())); } } // namespace remoting