diff options
author | alokp <alokp@chromium.org> | 2016-03-23 10:57:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-23 17:58:41 +0000 |
commit | ff847a1068a3e5872d091af9c673bc715771fa5d (patch) | |
tree | 6fa0be6086ae072215f3db5c50dbb8159d7aeb44 /chromecast | |
parent | a1fafb7d1fe7ddd214c97f47bc74a97f0848b68d (diff) | |
download | chromium_src-ff847a1068a3e5872d091af9c673bc715771fa5d.zip chromium_src-ff847a1068a3e5872d091af9c673bc715771fa5d.tar.gz chromium_src-ff847a1068a3e5872d091af9c673bc715771fa5d.tar.bz2 |
[chromecast] Pass media task runner to VideoPlaneController.
This required making VideoPlaneController non-singleton and
passed around wherever required, which is also a good change.
BUG=594234
Review URL: https://codereview.chromium.org/1824723003
Cr-Commit-Position: refs/heads/master@{#382877}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/app/cast_main_delegate.cc | 5 | ||||
-rw-r--r-- | chromecast/app/cast_main_delegate.h | 1 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_main_parts.cc | 23 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_main_parts.h | 14 | ||||
-rw-r--r-- | chromecast/browser/cast_content_browser_client.cc | 25 | ||||
-rw-r--r-- | chromecast/browser/cast_content_browser_client.h | 13 | ||||
-rw-r--r-- | chromecast/browser/cast_content_window.cc | 3 | ||||
-rw-r--r-- | chromecast/graphics/BUILD.gn | 1 | ||||
-rw-r--r-- | chromecast/graphics/cast_screen.cc | 7 | ||||
-rw-r--r-- | chromecast/graphics/cast_screen.h | 7 | ||||
-rw-r--r-- | chromecast/media/base/video_plane_controller.cc | 35 | ||||
-rw-r--r-- | chromecast/media/base/video_plane_controller.h | 8 |
12 files changed, 81 insertions, 61 deletions
diff --git a/chromecast/app/cast_main_delegate.cc b/chromecast/app/cast_main_delegate.cc index 7460175..7ae36ef 100644 --- a/chromecast/app/cast_main_delegate.cc +++ b/chromecast/app/cast_main_delegate.cc @@ -165,11 +165,6 @@ int CastMainDelegate::RunProcess( #endif // defined(OS_ANDROID) } -void CastMainDelegate::ProcessExiting(const std::string& process_type) { - if (process_type.empty()) - browser_client_->ProcessExiting(); -} - #if !defined(OS_ANDROID) void CastMainDelegate::ZygoteForked() { const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess()); diff --git a/chromecast/app/cast_main_delegate.h b/chromecast/app/cast_main_delegate.h index 19cdfa3..1e7609f 100644 --- a/chromecast/app/cast_main_delegate.h +++ b/chromecast/app/cast_main_delegate.h @@ -36,7 +36,6 @@ class CastMainDelegate : public content::ContentMainDelegate { int RunProcess( const std::string& process_type, const content::MainFunctionParams& main_function_params) override; - void ProcessExiting(const std::string& process_type) override; #if !defined(OS_ANDROID) void ZygoteForked() override; #endif // !defined(OS_ANDROID) diff --git a/chromecast/browser/cast_browser_main_parts.cc b/chromecast/browser/cast_browser_main_parts.cc index b420289..6251a34 100644 --- a/chromecast/browser/cast_browser_main_parts.cc +++ b/chromecast/browser/cast_browser_main_parts.cc @@ -251,6 +251,12 @@ CastBrowserMainParts::CastBrowserMainParts( CastBrowserMainParts::~CastBrowserMainParts() { } +scoped_refptr<base::SingleThreadTaskRunner> +CastBrowserMainParts::GetMediaTaskRunner() const { + // TODO(alokp): Obtain task runner from a local thread or mojo media app. + return media::MediaMessageLoop::GetTaskRunner(); +} + void CastBrowserMainParts::PreMainMessageLoopStart() { // GroupedHistograms needs to be initialized before any threads are created // to prevent race conditions between calls to Preregister and those threads @@ -383,16 +389,22 @@ void CastBrowserMainParts::PreMainMessageLoopRun() { // TODO(halliwell) move audio builds to use ozone_platform_cast, then can // simplify this by removing DISABLE_DISPLAY condition. Should then also // assert(ozone_platform_cast) in BUILD.gn where it depends on //ui/ozone. + video_plane_controller_.reset( + new media::VideoPlaneController(GetMediaTaskRunner())); + cast_browser_process_->cast_screen()->SetDisplayResizeCallback( + base::Bind(&media::VideoPlaneController::SetGraphicsPlaneResolution, + base::Unretained(video_plane_controller_.get()))); ui::OverlayManagerCast::SetOverlayCompositedCallback( base::Bind(&media::VideoPlaneController::SetGeometry, - base::Unretained(media::VideoPlaneController::GetInstance()))); + base::Unretained(video_plane_controller_.get()))); #endif cast_browser_process_->SetCastService( cast_browser_process_->browser_client()->CreateCastService( cast_browser_process_->browser_context(), cast_browser_process_->pref_service(), - url_request_context_factory_->GetSystemGetter())); + url_request_context_factory_->GetSystemGetter(), + video_plane_controller_.get())); cast_browser_process_->cast_service()->Initialize(); // Initializing metrics service and network delegates must happen after cast @@ -452,5 +464,12 @@ void CastBrowserMainParts::PostMainMessageLoopRun() { #endif } +void CastBrowserMainParts::PostDestroyThreads() { + // Finalize CastMediaShlib on media thread to ensure it's not accessed + // after Finalize. + GetMediaTaskRunner()->PostTask(FROM_HERE, + base::Bind(&media::CastMediaShlib::Finalize)); +} + } // namespace shell } // namespace chromecast diff --git a/chromecast/browser/cast_browser_main_parts.h b/chromecast/browser/cast_browser_main_parts.h index 84e03b3..4d7284d 100644 --- a/chromecast/browser/cast_browser_main_parts.h +++ b/chromecast/browser/cast_browser_main_parts.h @@ -6,15 +6,25 @@ #define CHROMECAST_BROWSER_CAST_BROWSER_MAIN_PARTS_H_ #include "base/macros.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" #include "content/public/common/main_function_params.h" +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace net { class NetLog; } namespace chromecast { + +namespace media { +class VideoPlaneController; +} // namespace media + namespace shell { class CastBrowserProcess; class URLRequestContextFactory; @@ -26,6 +36,8 @@ class CastBrowserMainParts : public content::BrowserMainParts { URLRequestContextFactory* url_request_context_factory); ~CastBrowserMainParts() override; + scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner() const; + // content::BrowserMainParts implementation: void PreMainMessageLoopStart() override; void PostMainMessageLoopStart() override; @@ -34,12 +46,14 @@ class CastBrowserMainParts : public content::BrowserMainParts { void PreMainMessageLoopRun() override; bool MainMessageLoopRun(int* result_code) override; void PostMainMessageLoopRun() override; + void PostDestroyThreads() override; private: scoped_ptr<CastBrowserProcess> cast_browser_process_; const content::MainFunctionParams parameters_; // For running browser tests. URLRequestContextFactory* const url_request_context_factory_; scoped_ptr<net::NetLog> net_log_; + scoped_ptr<media::VideoPlaneController> video_plane_controller_; DISALLOW_COPY_AND_ASSIGN(CastBrowserMainParts); }; diff --git a/chromecast/browser/cast_content_browser_client.cc b/chromecast/browser/cast_content_browser_client.cc index 66e08f5..ff159cb 100644 --- a/chromecast/browser/cast_content_browser_client.cc +++ b/chromecast/browser/cast_content_browser_client.cc @@ -31,8 +31,6 @@ #include "chromecast/browser/service/cast_service_simple.h" #include "chromecast/browser/url_request_context_factory.h" #include "chromecast/common/global_descriptors.h" -#include "chromecast/media/base/media_message_loop.h" -#include "chromecast/public/cast_media_shlib.h" #include "chromecast/public/media/media_pipeline_backend.h" #include "components/crash/content/app/breakpad_linux.h" #include "components/crash/content/browser/crash_handler_host_linux.h" @@ -81,8 +79,8 @@ static scoped_ptr<mojo::ShellClient> CreateCastMojoMediaApplication( } // namespace CastContentBrowserClient::CastContentBrowserClient() - : url_request_context_factory_(new URLRequestContextFactory()) { -} + : cast_browser_main_parts_(nullptr), + url_request_context_factory_(new URLRequestContextFactory()) {} CastContentBrowserClient::~CastContentBrowserClient() { content::BrowserThread::DeleteSoon( @@ -101,7 +99,8 @@ void CastContentBrowserClient::PreCreateThreads() { scoped_ptr<CastService> CastContentBrowserClient::CreateCastService( content::BrowserContext* browser_context, PrefService* pref_service, - net::URLRequestContextGetter* request_context_getter) { + net::URLRequestContextGetter* request_context_getter, + media::VideoPlaneController* video_plane_controller) { return make_scoped_ptr(new CastServiceSimple(browser_context, pref_service)); } @@ -114,13 +113,6 @@ CastContentBrowserClient::GetCmaMediaPipelineClient() { } #endif // OS_ANDROID -void CastContentBrowserClient::ProcessExiting() { - // Finalize CastMediaShlib on media thread to ensure it's not accessed - // after Finalize. - GetMediaTaskRunner()->PostTask(FROM_HERE, - base::Bind(&media::CastMediaShlib::Finalize)); -} - void CastContentBrowserClient::SetMetricsClientId( const std::string& client_id) { } @@ -135,10 +127,11 @@ bool CastContentBrowserClient::EnableRemoteDebuggingImmediately() { content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts( const content::MainFunctionParams& parameters) { - content::BrowserMainParts* parts = + DCHECK(!cast_browser_main_parts_); + cast_browser_main_parts_ = new CastBrowserMainParts(parameters, url_request_context_factory_.get()); CastBrowserProcess::GetInstance()->SetCastContentBrowserClient(this); - return parts; + return cast_browser_main_parts_; } void CastContentBrowserClient::RenderProcessWillLaunch( @@ -163,8 +156,8 @@ void CastContentBrowserClient::RenderProcessWillLaunch( scoped_refptr<base::SingleThreadTaskRunner> CastContentBrowserClient::GetMediaTaskRunner() { - // TODO(alokp): Obtain task runner from a local thread or mojo media app. - return media::MediaMessageLoop::GetTaskRunner(); + DCHECK(cast_browser_main_parts_); + return cast_browser_main_parts_->GetMediaTaskRunner(); } #if !defined(OS_ANDROID) diff --git a/chromecast/browser/cast_content_browser_client.h b/chromecast/browser/cast_content_browser_client.h index de03fb2..9d16a0a 100644 --- a/chromecast/browser/cast_content_browser_client.h +++ b/chromecast/browser/cast_content_browser_client.h @@ -32,9 +32,8 @@ namespace chromecast { class CastService; namespace media { -class MediaPipelineBackend; -struct MediaPipelineDeviceParams; class CmaMediaPipelineClient; +class VideoPlaneController; } namespace shell { @@ -62,7 +61,8 @@ class CastContentBrowserClient : public content::ContentBrowserClient { virtual scoped_ptr<CastService> CreateCastService( content::BrowserContext* browser_context, PrefService* pref_service, - net::URLRequestContextGetter* request_context_getter); + net::URLRequestContextGetter* request_context_getter, + media::VideoPlaneController* video_plane_controller); #if !defined(OS_ANDROID) // Returns CmaMediaPipelineClient which is responsible to create @@ -70,9 +70,6 @@ class CastContentBrowserClient : public content::ContentBrowserClient { scoped_refptr<media::CmaMediaPipelineClient> GetCmaMediaPipelineClient(); #endif - // Performs cleanup for process exit (but before AtExitManager cleanup). - void ProcessExiting(); - // Invoked when the metrics client ID changes. virtual void SetMetricsClientId(const std::string& client_id); @@ -160,8 +157,6 @@ class CastContentBrowserClient : public content::ContentBrowserClient { CastContentBrowserClient(); // Returns the task runner that must be used for media IO. - // TODO(alokp): We might need to make it public as we convert more callsites - // using MediaMessageLoop directly. scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner(); #if !defined(OS_ANDROID) @@ -196,6 +191,8 @@ class CastContentBrowserClient : public content::ContentBrowserClient { scoped_refptr<media::CmaMediaPipelineClient> cma_media_pipeline_client_; #endif // !defined(OS_ANDROID) + // Created by CastContentBrowserClient but owned by BrowserMainLoop. + CastBrowserMainParts* cast_browser_main_parts_; scoped_ptr<URLRequestContextFactory> url_request_context_factory_; DISALLOW_COPY_AND_ASSIGN(CastContentBrowserClient); diff --git a/chromecast/browser/cast_content_window.cc b/chromecast/browser/cast_content_window.cc index a5f63ea..bbd179b 100644 --- a/chromecast/browser/cast_content_window.cc +++ b/chromecast/browser/cast_content_window.cc @@ -8,7 +8,6 @@ #include "base/threading/thread_restrictions.h" #include "chromecast/base/metrics/cast_metrics_helper.h" #include "chromecast/browser/cast_browser_process.h" -#include "chromecast/media/base/video_plane_controller.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host_view.h" @@ -79,8 +78,6 @@ void CastContentWindow::CreateWindowTree( gfx::Screen::SetScreenInstance(cast_screen); if (cast_screen->GetPrimaryDisplay().size() != initial_size) cast_screen->UpdateDisplaySize(initial_size); - media::VideoPlaneController::GetInstance()->SetGraphicsPlaneResolution( - Size(initial_size.width(), initial_size.height())); CHECK(aura::Env::GetInstance()); window_tree_host_.reset( diff --git a/chromecast/graphics/BUILD.gn b/chromecast/graphics/BUILD.gn index 1d42322..f48251d 100644 --- a/chromecast/graphics/BUILD.gn +++ b/chromecast/graphics/BUILD.gn @@ -13,6 +13,7 @@ if (use_aura) { ] deps = [ + "//chromecast/public", "//ui/aura", "//ui/gfx", "//ui/gfx/geometry", diff --git a/chromecast/graphics/cast_screen.cc b/chromecast/graphics/cast_screen.cc index 507e234..2017dc9 100644 --- a/chromecast/graphics/cast_screen.cc +++ b/chromecast/graphics/cast_screen.cc @@ -33,8 +33,15 @@ const int kInitDisplayHeight = k720pHeight; CastScreen::~CastScreen() { } +void CastScreen::SetDisplayResizeCallback(const DisplayResizeCallback& cb) { + DCHECK(!cb.is_null()); + display_resize_cb_ = cb; +} + void CastScreen::UpdateDisplaySize(const gfx::Size& size) { display_.SetScaleAndBounds(1.0f, gfx::Rect(size)); + if (!display_resize_cb_.is_null()) + display_resize_cb_.Run(Size(size.width(), size.height())); } gfx::Point CastScreen::GetCursorScreenPoint() { diff --git a/chromecast/graphics/cast_screen.h b/chromecast/graphics/cast_screen.h index 37fcf6c..ba665be 100644 --- a/chromecast/graphics/cast_screen.h +++ b/chromecast/graphics/cast_screen.h @@ -5,12 +5,13 @@ #ifndef CHROMECAST_GRAPHICS_CAST_SCREEN_H_ #define CHROMECAST_GRAPHICS_CAST_SCREEN_H_ +#include "base/callback.h" #include "base/macros.h" +#include "chromecast/public/graphics_types.h" #include "ui/gfx/display.h" #include "ui/gfx/screen.h" namespace chromecast { - namespace shell { class CastBrowserMainParts; } // namespace shell @@ -24,6 +25,9 @@ class CastScreen : public gfx::Screen { public: ~CastScreen() override; + using DisplayResizeCallback = base::Callback<void(const Size&)>; + void SetDisplayResizeCallback(const DisplayResizeCallback& cb); + // Updates the primary display size. void UpdateDisplaySize(const gfx::Size& size); @@ -44,6 +48,7 @@ class CastScreen : public gfx::Screen { CastScreen(); gfx::Display display_; + DisplayResizeCallback display_resize_cb_; friend class shell::CastBrowserMainParts; diff --git a/chromecast/media/base/video_plane_controller.cc b/chromecast/media/base/video_plane_controller.cc index e6496f4..3d63f9b 100644 --- a/chromecast/media/base/video_plane_controller.cc +++ b/chromecast/media/base/video_plane_controller.cc @@ -14,7 +14,6 @@ #include "base/macros.h" #include "base/single_thread_task_runner.h" #include "base/time/time.h" -#include "chromecast/media/base/media_message_loop.h" #include "chromecast/public/cast_media_shlib.h" namespace chromecast { @@ -140,10 +139,21 @@ class VideoPlaneController::RateLimitedSetVideoPlaneGeometry DISALLOW_COPY_AND_ASSIGN(RateLimitedSetVideoPlaneGeometry); }; -// static -VideoPlaneController* VideoPlaneController::GetInstance() { - return base::Singleton<VideoPlaneController>::get(); -} +VideoPlaneController::VideoPlaneController( + scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) + : is_paused_(false), + have_output_res_(false), + have_graphics_res_(false), + output_res_(0, 0), + graphics_res_(0, 0), + have_video_plane_geometry_(false), + video_plane_display_rect_(0, 0), + video_plane_transform_(VideoPlane::TRANSFORM_NONE), + media_task_runner_(media_task_runner), + video_plane_wrapper_( + new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} + +VideoPlaneController::~VideoPlaneController() {} // TODO(esum): SetGeometry, SetDeviceResolution, and SetGraphicsPlaneResolution // follow the same pattern (copy/paste). Currently it's not worth modularizing @@ -224,21 +234,6 @@ bool VideoPlaneController::is_paused() const { return is_paused_; } -VideoPlaneController::VideoPlaneController() - : is_paused_(false), - have_output_res_(false), - have_graphics_res_(false), - output_res_(0, 0), - graphics_res_(0, 0), - have_video_plane_geometry_(false), - video_plane_display_rect_(0, 0), - video_plane_transform_(VideoPlane::TRANSFORM_NONE), - media_task_runner_(MediaMessageLoop::GetTaskRunner()), - video_plane_wrapper_( - new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} - -VideoPlaneController::~VideoPlaneController() {} - void VideoPlaneController::MaybeRunSetGeometry() { DCHECK(thread_checker_.CalledOnValidThread()); if (is_paused_) { diff --git a/chromecast/media/base/video_plane_controller.h b/chromecast/media/base/video_plane_controller.h index c14ae95..7b20b48 100644 --- a/chromecast/media/base/video_plane_controller.h +++ b/chromecast/media/base/video_plane_controller.h @@ -36,8 +36,9 @@ namespace media { // All calls to public methods should be from the same thread. class VideoPlaneController { public: - static VideoPlaneController* GetInstance(); - + explicit VideoPlaneController( + scoped_refptr<base::SingleThreadTaskRunner> media_task_runner); + ~VideoPlaneController(); // Sets the video plane geometry (forwards to VideoPlane::SetGeometry) // in *graphics plane coordinates*. // * This should be called on UI thread (hopping to media thread is handled @@ -77,9 +78,6 @@ class VideoPlaneController { class RateLimitedSetVideoPlaneGeometry; friend struct base::DefaultSingletonTraits<VideoPlaneController>; - VideoPlaneController(); - ~VideoPlaneController(); - // Check if HaveDataForSetGeometry. If not, this method is a no-op. Otherwise // it scales the display rect from graphics to device resolution coordinates. // Then posts task to media thread for VideoPlane::SetGeometry. |