Commit b39238a8 authored by kylechar's avatar kylechar Committed by Commit bot

Add mojom::DisplayController.

Add a new mojo interface mojom::DisplayController to allow privileged
clients to make changes to the display state. The initial interface
contains methods needed by mash to provide display state related
keyboard accelerators that exist in cash currently.

Have PlatformScreenOzone implement this new interface and provide mostly
stub implementations. Right now the interface isn't wired up so that
will happen in a subsequent CL.

Also adds PlatformScreen::GetInstance() so PlatformScreen doesn't need
to be passed so many places.

BUG=611475

Review-Url: https://codereview.chromium.org/2310133002
Cr-Commit-Position: refs/heads/master@{#417578}
parent 375ad756
...@@ -7,6 +7,7 @@ import("//testing/test.gni") ...@@ -7,6 +7,7 @@ import("//testing/test.gni")
source_set("display") { source_set("display") {
sources = [ sources = [
"platform_screen.cc",
"platform_screen.h", "platform_screen.h",
"platform_screen_delegate.h", "platform_screen_delegate.h",
] ]
...@@ -24,6 +25,7 @@ source_set("display") { ...@@ -24,6 +25,7 @@ source_set("display") {
] ]
deps += [ deps += [
"//services/ui/public/interfaces/display",
"//skia", "//skia",
"//ui/ozone", "//ui/ozone",
] ]
......
// Copyright 2016 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 "services/ui/display/platform_screen.h"
#include "base/logging.h"
namespace display {
// static
PlatformScreen* PlatformScreen::instance_ = nullptr;
PlatformScreen::PlatformScreen() {
DCHECK(!instance_);
instance_ = this;
}
PlatformScreen::~PlatformScreen() {
DCHECK_EQ(instance_, this);
instance_ = nullptr;
}
// static
PlatformScreen* PlatformScreen::GetInstance() {
DCHECK(instance_);
return instance_;
}
} // namespace display
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/macros.h"
#include "services/ui/display/platform_screen_delegate.h" #include "services/ui/display/platform_screen_delegate.h"
namespace display { namespace display {
...@@ -15,10 +16,12 @@ namespace display { ...@@ -15,10 +16,12 @@ namespace display {
// attached physical displays. // attached physical displays.
class PlatformScreen { class PlatformScreen {
public: public:
virtual ~PlatformScreen() {} PlatformScreen();
virtual ~PlatformScreen();
// Creates a PlatformScreen instance. // Creates a singleton PlatformScreen instance.
static std::unique_ptr<PlatformScreen> Create(); static std::unique_ptr<PlatformScreen> Create();
static PlatformScreen* GetInstance();
// Triggers initial display configuration to start. On device this will // Triggers initial display configuration to start. On device this will
// configuration the connected displays. Off device this will create one or // configuration the connected displays. Off device this will create one or
...@@ -28,6 +31,11 @@ class PlatformScreen { ...@@ -28,6 +31,11 @@ class PlatformScreen {
virtual void Init(PlatformScreenDelegate* delegate) = 0; virtual void Init(PlatformScreenDelegate* delegate) = 0;
virtual int64_t GetPrimaryDisplayId() const = 0; virtual int64_t GetPrimaryDisplayId() const = 0;
private:
static PlatformScreen* instance_; // Instance is not owned.
DISALLOW_COPY_AND_ASSIGN(PlatformScreen);
}; };
} // namespace display } // namespace display
......
...@@ -23,9 +23,7 @@ class PlatformScreenDelegate { ...@@ -23,9 +23,7 @@ class PlatformScreenDelegate {
// displays are added or modified. // displays are added or modified.
// Called when a display is added. |bounds| is in DIP. // Called when a display is added. |bounds| is in DIP.
virtual void OnDisplayAdded(PlatformScreen* platform_screen, virtual void OnDisplayAdded(int64_t id, const gfx::Rect& bounds) = 0;
int64_t id,
const gfx::Rect& bounds) = 0;
// Called when a display is removed. // Called when a display is removed.
virtual void OnDisplayRemoved(int64_t id) = 0; virtual void OnDisplayRemoved(int64_t id) = 0;
......
...@@ -64,6 +64,25 @@ int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { ...@@ -64,6 +64,25 @@ int64_t PlatformScreenOzone::GetPrimaryDisplayId() const {
return primary_display_id_; return primary_display_id_;
} }
void PlatformScreenOzone::ToggleVirtualDisplay(
const ToggleVirtualDisplayCallback& callback) {
if (base::SysInfo::IsRunningOnChromeOS()) {
callback.Run(false);
return;
}
if (cached_displays_.size() == 1) {
display_configurator_.AddVirtualDisplay(cached_displays_[0].bounds.size());
callback.Run(true);
} else if (cached_displays_.size() > 1) {
callback.Run(
display_configurator_.RemoveVirtualDisplay(cached_displays_.back().id));
} else {
NOTREACHED();
callback.Run(false);
}
}
void PlatformScreenOzone::ProcessRemovedDisplays( void PlatformScreenOzone::ProcessRemovedDisplays(
const ui::DisplayConfigurator::DisplayStateList& snapshots) { const ui::DisplayConfigurator::DisplayStateList& snapshots) {
std::vector<int64_t> current_ids; std::vector<int64_t> current_ids;
...@@ -155,7 +174,7 @@ void PlatformScreenOzone::AddNewDisplays( ...@@ -155,7 +174,7 @@ void PlatformScreenOzone::AddNewDisplays(
primary_display_id_ = id; primary_display_id_ = id;
cached_displays_.push_back(DisplayInfo(id, bounds)); cached_displays_.push_back(DisplayInfo(id, bounds));
delegate_->OnDisplayAdded(this, id, bounds); delegate_->OnDisplayAdded(id, bounds);
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "services/ui/display/platform_screen.h" #include "services/ui/display/platform_screen.h"
#include "services/ui/public/interfaces/display/display_controller.mojom.h"
#include "ui/display/chromeos/display_configurator.h" #include "ui/display/chromeos/display_configurator.h"
#include "ui/display/display.h" #include "ui/display/display.h"
...@@ -21,7 +22,8 @@ namespace display { ...@@ -21,7 +22,8 @@ namespace display {
// PlatformScreenOzone provides the necessary functionality to configure all // PlatformScreenOzone provides the necessary functionality to configure all
// attached physical displays on the ozone platform. // attached physical displays on the ozone platform.
class PlatformScreenOzone : public PlatformScreen, class PlatformScreenOzone : public PlatformScreen,
public ui::DisplayConfigurator::Observer { public ui::DisplayConfigurator::Observer,
public mojom::DisplayController {
public: public:
PlatformScreenOzone(); PlatformScreenOzone();
~PlatformScreenOzone() override; ~PlatformScreenOzone() override;
...@@ -30,6 +32,10 @@ class PlatformScreenOzone : public PlatformScreen, ...@@ -30,6 +32,10 @@ class PlatformScreenOzone : public PlatformScreen,
void Init(PlatformScreenDelegate* delegate) override; void Init(PlatformScreenDelegate* delegate) override;
int64_t GetPrimaryDisplayId() const override; int64_t GetPrimaryDisplayId() const override;
// mojom::DisplayController:
void ToggleVirtualDisplay(
const ToggleVirtualDisplayCallback& callback) override;
private: private:
// TODO(kylechar): This struct is just temporary until we migrate // TODO(kylechar): This struct is just temporary until we migrate
// DisplayManager code out of ash so it can be used here. // DisplayManager code out of ash so it can be used here.
......
...@@ -79,9 +79,7 @@ class TestPlatformScreenDelegate : public PlatformScreenDelegate { ...@@ -79,9 +79,7 @@ class TestPlatformScreenDelegate : public PlatformScreenDelegate {
} }
private: private:
void OnDisplayAdded(PlatformScreen* platform_screen, void OnDisplayAdded(int64_t id, const gfx::Rect& bounds) override {
int64_t id,
const gfx::Rect& bounds) override {
added_.push_back({id, bounds}); added_.push_back({id, bounds});
} }
......
...@@ -29,7 +29,7 @@ PlatformScreenStub::PlatformScreenStub() : weak_ptr_factory_(this) {} ...@@ -29,7 +29,7 @@ PlatformScreenStub::PlatformScreenStub() : weak_ptr_factory_(this) {}
PlatformScreenStub::~PlatformScreenStub() {} PlatformScreenStub::~PlatformScreenStub() {}
void PlatformScreenStub::FixedSizeScreenConfiguration() { void PlatformScreenStub::FixedSizeScreenConfiguration() {
delegate_->OnDisplayAdded(this, kDisplayId, gfx::Rect(1024, 768)); delegate_->OnDisplayAdded(kDisplayId, gfx::Rect(1024, 768));
} }
void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) { void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) {
......
...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("display") { mojom("display") {
sources = [ sources = [
"display.mojom", "display.mojom",
"display_controller.mojom",
] ]
public_deps = [ public_deps = [
......
// Copyright 2016 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.
module display.mojom;
// An interface for clients that are allowed to make changes to the display
// state.
interface DisplayController {
// Toggles adding or removing a virtual display. If there is only one display
// a second display is added. If there is more than one display then the last
// display is removed.
ToggleVirtualDisplay() => (bool success);
// TODO(kylechar): This interface will need to be expanded to provide
// additional functionality for the display settings page and other ash
// keyboard accelerators.
};
...@@ -167,13 +167,10 @@ void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, ...@@ -167,13 +167,10 @@ void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id,
current_window_manager_state->Activate(mouse_location_on_screen); current_window_manager_state->Activate(mouse_location_on_screen);
} }
void DisplayManager::OnDisplayAdded(display::PlatformScreen* platform_screen, void DisplayManager::OnDisplayAdded(int64_t id, const gfx::Rect& bounds) {
int64_t id,
const gfx::Rect& bounds) {
PlatformDisplayInitParams params; PlatformDisplayInitParams params;
params.display_bounds = bounds; params.display_bounds = bounds;
params.display_id = id; params.display_id = id;
params.platform_screen = platform_screen;
params.surfaces_state = window_server_->GetSurfacesState(); params.surfaces_state = window_server_->GetSurfacesState();
ws::Display* display = new ws::Display(window_server_, params); ws::Display* display = new ws::Display(window_server_, params);
......
...@@ -82,9 +82,7 @@ class DisplayManager : public UserIdTrackerObserver, ...@@ -82,9 +82,7 @@ class DisplayManager : public UserIdTrackerObserver,
const UserId& active_id) override; const UserId& active_id) override;
// display::PlatformScreenDelegate: // display::PlatformScreenDelegate:
void OnDisplayAdded(display::PlatformScreen* platform_screen_, void OnDisplayAdded(int64_t id, const gfx::Rect& bounds) override;
int64_t id,
const gfx::Rect& bounds) override;
void OnDisplayRemoved(int64_t id) override; void OnDisplayRemoved(int64_t id) override;
void OnDisplayModified(int64_t id, const gfx::Rect& bounds) override; void OnDisplayModified(int64_t id, const gfx::Rect& bounds) override;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "gpu/ipc/client/gpu_channel_host.h" #include "gpu/ipc/client/gpu_channel_host.h"
#include "services/shell/public/cpp/connection.h" #include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/connector.h" #include "services/shell/public/cpp/connector.h"
#include "services/ui/display/platform_screen.h"
#include "services/ui/surfaces/display_compositor.h" #include "services/ui/surfaces/display_compositor.h"
#include "services/ui/surfaces/surfaces_state.h" #include "services/ui/surfaces/surfaces_state.h"
#include "services/ui/ws/platform_display_factory.h" #include "services/ui/ws/platform_display_factory.h"
...@@ -55,7 +56,6 @@ PlatformDisplay* PlatformDisplay::Create( ...@@ -55,7 +56,6 @@ PlatformDisplay* PlatformDisplay::Create(
DefaultPlatformDisplay::DefaultPlatformDisplay( DefaultPlatformDisplay::DefaultPlatformDisplay(
const PlatformDisplayInitParams& init_params) const PlatformDisplayInitParams& init_params)
: id_(init_params.display_id), : id_(init_params.display_id),
platform_screen_(init_params.platform_screen),
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
cursor_loader_(ui::CursorLoader::Create()), cursor_loader_(ui::CursorLoader::Create()),
#endif #endif
...@@ -169,7 +169,7 @@ gfx::Rect DefaultPlatformDisplay::GetBounds() const { ...@@ -169,7 +169,7 @@ gfx::Rect DefaultPlatformDisplay::GetBounds() const {
} }
bool DefaultPlatformDisplay::IsPrimaryDisplay() const { bool DefaultPlatformDisplay::IsPrimaryDisplay() const {
return platform_screen_->GetPrimaryDisplayId() == id_; return display::PlatformScreen::GetInstance()->GetPrimaryDisplayId() == id_;
} }
void DefaultPlatformDisplay::OnGpuChannelEstablished( void DefaultPlatformDisplay::OnGpuChannelEstablished(
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "services/ui/display/platform_screen.h"
#include "services/ui/public/interfaces/window_manager.mojom.h" #include "services/ui/public/interfaces/window_manager.mojom.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h" #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "services/ui/public/interfaces/window_tree.mojom.h" #include "services/ui/public/interfaces/window_tree.mojom.h"
...@@ -172,7 +171,6 @@ class DefaultPlatformDisplay : public PlatformDisplay, ...@@ -172,7 +171,6 @@ class DefaultPlatformDisplay : public PlatformDisplay,
const ViewportMetrics& GetViewportMetrics() override; const ViewportMetrics& GetViewportMetrics() override;
int64_t id_; int64_t id_;
display::PlatformScreen* platform_screen_;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
std::unique_ptr<ui::CursorLoader> cursor_loader_; std::unique_ptr<ui::CursorLoader> cursor_loader_;
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace display {
class PlatformScreen;
}
namespace shell { namespace shell {
class Connector; class Connector;
} }
...@@ -34,7 +30,6 @@ struct PlatformDisplayInitParams { ...@@ -34,7 +30,6 @@ struct PlatformDisplayInitParams {
gfx::Rect display_bounds; gfx::Rect display_bounds;
int64_t display_id; int64_t display_id;
display::PlatformScreen* platform_screen = nullptr;
}; };
} // namespace ws } // namespace ws
......
...@@ -103,7 +103,8 @@ class WindowManagerState::ProcessedEventTarget { ...@@ -103,7 +103,8 @@ class WindowManagerState::ProcessedEventTarget {
bool WindowManagerState::DebugAccelerator::Matches( bool WindowManagerState::DebugAccelerator::Matches(
const ui::KeyEvent& event) const { const ui::KeyEvent& event) const {
return key_code == event.key_code() && return key_code == event.key_code() &&
event_flags == (kAcceleratorEventFlags & event.flags()); event_flags == (kAcceleratorEventFlags & event.flags()) &&
!event.is_char();
} }
WindowManagerState::QueuedEvent::QueuedEvent() {} WindowManagerState::QueuedEvent::QueuedEvent() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment