diff options
author | esum <esum@chromium.org> | 2015-07-08 16:43:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-08 23:44:32 +0000 |
commit | 03d2f82aa65c18b8efaee7d4220b2f4a78a9c379 (patch) | |
tree | 6fe2feb2f006bb2752fd46abe0ea3b80fce08151 /chromecast | |
parent | f6eb66d02418326bcf5e427d5291366710f9ecb8 (diff) | |
download | chromium_src-03d2f82aa65c18b8efaee7d4220b2f4a78a9c379.zip chromium_src-03d2f82aa65c18b8efaee7d4220b2f4a78a9c379.tar.gz chromium_src-03d2f82aa65c18b8efaee7d4220b2f4a78a9c379.tar.bz2 |
Adding Chromecast's own minimal implementation of gfx::Screen.
Removing dependency on aura::TestScreen.
No modified or additional functionality.
Only implementing gfx::Screen virtual methods that get called.
BUG=470735
Review URL: https://codereview.chromium.org/1206323006
Cr-Commit-Position: refs/heads/master@{#337942}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/browser/cast_browser_main_parts.cc | 5 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_process.cc | 11 | ||||
-rw-r--r-- | chromecast/browser/cast_browser_process.h | 10 | ||||
-rw-r--r-- | chromecast/browser/cast_content_window.cc | 23 | ||||
-rw-r--r-- | chromecast/chromecast.gyp | 2 | ||||
-rw-r--r-- | chromecast/graphics/cast_screen.cc | 88 | ||||
-rw-r--r-- | chromecast/graphics/cast_screen.h | 54 |
7 files changed, 177 insertions, 16 deletions
diff --git a/chromecast/browser/cast_browser_main_parts.cc b/chromecast/browser/cast_browser_main_parts.cc index d3247a8..bef558f9 100644 --- a/chromecast/browser/cast_browser_main_parts.cc +++ b/chromecast/browser/cast_browser_main_parts.cc @@ -59,8 +59,8 @@ #endif #if defined(USE_AURA) +#include "chromecast/graphics/cast_screen.h" #include "ui/aura/env.h" -#include "ui/aura/test/test_screen.h" #include "ui/gfx/screen.h" #endif @@ -272,9 +272,10 @@ int CastBrowserMainParts::PreCreateThreads() { // is assumed as an interface to access display information, e.g. from metrics // code. See CastContentWindow::CreateWindowTree for update when resolution // is available. + cast_browser_process_->SetCastScreen(make_scoped_ptr(new CastScreen)); DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, - aura::TestScreen::Create(gfx::Size(0, 0))); + cast_browser_process_->cast_screen()); #endif #if !defined(OS_ANDROID) diff --git a/chromecast/browser/cast_browser_process.cc b/chromecast/browser/cast_browser_process.cc index 25fcd44..1a67bef 100644 --- a/chromecast/browser/cast_browser_process.cc +++ b/chromecast/browser/cast_browser_process.cc @@ -18,6 +18,10 @@ #include "components/crash/browser/crash_dump_manager_android.h" #endif // defined(OS_ANDROID) +#if defined(USE_AURA) +#include "chromecast/graphics/cast_screen.h" +#endif // defined(USE_AURA) + namespace chromecast { namespace shell { @@ -54,6 +58,13 @@ void CastBrowserProcess::SetCastService(scoped_ptr<CastService> cast_service) { cast_service_.swap(cast_service); } +#if defined(USE_AURA) +void CastBrowserProcess::SetCastScreen(scoped_ptr<CastScreen> cast_screen) { + DCHECK(!cast_screen_); + cast_screen_ = cast_screen.Pass(); +} +#endif // defined(USE_AURA) + void CastBrowserProcess::SetMetricsHelper( scoped_ptr<metrics::CastMetricsHelper> metrics_helper) { DCHECK(!metrics_helper_); diff --git a/chromecast/browser/cast_browser_process.h b/chromecast/browser/cast_browser_process.h index f4bec89..c63724d 100644 --- a/chromecast/browser/cast_browser_process.h +++ b/chromecast/browser/cast_browser_process.h @@ -17,6 +17,7 @@ class CrashDumpManager; namespace chromecast { class CastService; +class CastScreen; class ConnectivityChecker; namespace metrics { @@ -40,6 +41,9 @@ class CastBrowserProcess { void SetBrowserContext(scoped_ptr<CastBrowserContext> browser_context); void SetCastService(scoped_ptr<CastService> cast_service); +#if defined(USE_AURA) + void SetCastScreen(scoped_ptr<CastScreen> cast_screen); +#endif // defined(USE_AURA) void SetMetricsHelper(scoped_ptr<metrics::CastMetricsHelper> metrics_helper); void SetMetricsServiceClient( scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client); @@ -57,6 +61,9 @@ class CastBrowserProcess { CastBrowserContext* browser_context() const { return browser_context_.get(); } CastService* cast_service() const { return cast_service_.get(); } +#if defined(USE_AURA) + CastScreen* cast_screen() const { return cast_screen_.get(); } +#endif // defined(USE_AURA) metrics::CastMetricsServiceClient* metrics_service_client() const { return metrics_service_client_.get(); } @@ -73,6 +80,9 @@ class CastBrowserProcess { // Note: The following order should match the order they are set in // CastBrowserMainParts. scoped_ptr<metrics::CastMetricsHelper> metrics_helper_; +#if defined(USE_AURA) + scoped_ptr<CastScreen> cast_screen_; +#endif // defined(USE_AURA) scoped_ptr<PrefService> pref_service_; scoped_refptr<ConnectivityChecker> connectivity_checker_; scoped_ptr<CastBrowserContext> browser_context_; diff --git a/chromecast/browser/cast_content_window.cc b/chromecast/browser/cast_content_window.cc index a6d546b..8ca0339 100644 --- a/chromecast/browser/cast_content_window.cc +++ b/chromecast/browser/cast_content_window.cc @@ -8,16 +8,17 @@ #include "base/threading/thread_restrictions.h" #include "chromecast/base/chromecast_switches.h" #include "chromecast/base/metrics/cast_metrics_helper.h" +#include "chromecast/browser/cast_browser_process.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "ipc/ipc_message.h" #if defined(USE_AURA) +#include "chromecast/graphics/cast_screen.h" #include "ui/aura/env.h" #include "ui/aura/layout_manager.h" #include "ui/aura/test/test_focus_client.h" -#include "ui/aura/test/test_screen.h" #include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" #endif @@ -70,19 +71,13 @@ void CastContentWindow::CreateWindowTree( content::WebContents* web_contents) { #if defined(USE_AURA) // Aura initialization - // TODO(lcwu): We only need a minimal implementation of gfx::Screen - // and aura's TestScreen will do for us now. We should change to use - // ozone's screen implementation when it is ready. - gfx::Screen* old_screen = - gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); - if (!old_screen || old_screen->GetPrimaryDisplay().size() != initial_size) { - gfx::Screen* new_screen = aura::TestScreen::Create(initial_size); - DCHECK(new_screen) << "New screen not created."; - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, new_screen); - if (old_screen) { - delete old_screen; - } - } + CastScreen* cast_screen = + shell::CastBrowserProcess::GetInstance()->cast_screen(); + if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)) + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, cast_screen); + if (cast_screen->GetPrimaryDisplay().size() != initial_size) + cast_screen->UpdateDisplaySize(initial_size); + CHECK(aura::Env::GetInstance()); window_tree_host_.reset( aura::WindowTreeHost::Create(gfx::Rect(initial_size))); diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index dce5d4c..15372f4 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -362,6 +362,8 @@ 'sources': [ 'browser/metrics/external_metrics.cc', 'browser/metrics/external_metrics.h', + 'graphics/cast_screen.cc', + 'graphics/cast_screen.h', ], 'dependencies': [ '../components/components.gyp:metrics_serialization', diff --git a/chromecast/graphics/cast_screen.cc b/chromecast/graphics/cast_screen.cc new file mode 100644 index 0000000..2cf113f --- /dev/null +++ b/chromecast/graphics/cast_screen.cc @@ -0,0 +1,88 @@ +// Copyright 2015 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 "chromecast/graphics/cast_screen.h" + +#include "ui/aura/env.h" +#include "ui/gfx/geometry/rect_conversions.h" +#include "ui/gfx/geometry/size_conversions.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/screen.h" + +namespace chromecast { + +namespace { + +const int64 kDisplayId = 1; + +const int k720pWidth = 1280; +const int k720pHeight = 720; + +// When CastScreen is first initialized, we may not have any display info +// available. These constants hold the initial size that we default to, and +// the size can be updated when we have actual display info at hand with +// UpdateDisplaySize(). +const int kInitDisplayWidth = k720pWidth; +const int kInitDisplayHeight = k720pHeight; + +} // namespace + +CastScreen::~CastScreen() { +} + +void CastScreen::UpdateDisplaySize(const gfx::Size& size) { + display_.SetScaleAndBounds(1.0f, gfx::Rect(size)); +} + +gfx::Point CastScreen::GetCursorScreenPoint() { + return aura::Env::GetInstance()->last_mouse_location(); +} + +gfx::NativeWindow CastScreen::GetWindowUnderCursor() { + NOTIMPLEMENTED(); + return gfx::NativeWindow(nullptr); +} + +gfx::NativeWindow CastScreen::GetWindowAtScreenPoint(const gfx::Point& point) { + NOTIMPLEMENTED(); + return gfx::NativeWindow(nullptr); +} + +int CastScreen::GetNumDisplays() const { + return 1; +} + +std::vector<gfx::Display> CastScreen::GetAllDisplays() const { + return std::vector<gfx::Display>(1, display_); +} + +gfx::Display CastScreen::GetDisplayNearestWindow( + gfx::NativeWindow window) const { + return display_; +} + +gfx::Display CastScreen::GetDisplayNearestPoint(const gfx::Point& point) const { + return display_; +} + +gfx::Display CastScreen::GetDisplayMatching(const gfx::Rect& match_rect) const { + return display_; +} + +gfx::Display CastScreen::GetPrimaryDisplay() const { + return display_; +} + +void CastScreen::AddObserver(gfx::DisplayObserver* observer) { +} + +void CastScreen::RemoveObserver(gfx::DisplayObserver* observer) { +} + +CastScreen::CastScreen() : display_(kDisplayId) { + display_.SetScaleAndBounds(1.0f, + gfx::Rect(kInitDisplayWidth, kInitDisplayHeight)); +} + +} // namespace chromecast diff --git a/chromecast/graphics/cast_screen.h b/chromecast/graphics/cast_screen.h new file mode 100644 index 0000000..50fbf70 --- /dev/null +++ b/chromecast/graphics/cast_screen.h @@ -0,0 +1,54 @@ +// Copyright 2015 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. + +#ifndef CHROMECAST_GRAPHICS_CAST_SCREEN_H_ +#define CHROMECAST_GRAPHICS_CAST_SCREEN_H_ + +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" + +namespace chromecast { + +namespace shell { +class CastBrowserMainParts; +} // namespace shell + +// CastScreen is Chromecast's own minimal implementation of gfx::Screen. +// Right now, it almost exactly duplicates the behavior of aura's TestScreen +// class for necessary methods. The instantiation of CastScreen occurs in +// CastBrowserMainParts, where its ownership is assigned to CastBrowserProcess. +// To then subsequently access CastScreen, see CastBrowerProcess. +class CastScreen : public gfx::Screen { + public: + ~CastScreen() override; + + // Updates the primary display size. + void UpdateDisplaySize(const gfx::Size& size); + + // gfx::Screen overrides: + gfx::Point GetCursorScreenPoint() override; + gfx::NativeWindow GetWindowUnderCursor() override; + gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; + int GetNumDisplays() const override; + std::vector<gfx::Display> GetAllDisplays() const override; + gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override; + gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; + gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; + gfx::Display GetPrimaryDisplay() const override; + void AddObserver(gfx::DisplayObserver* observer) override; + void RemoveObserver(gfx::DisplayObserver* observer) override; + + private: + CastScreen(); + + gfx::Display display_; + + friend class shell::CastBrowserMainParts; + + DISALLOW_COPY_AND_ASSIGN(CastScreen); +}; + +} // namespace chromecast + +#endif // CHROMECAST_GRAPHICS_CAST_SCREEN_H_ |