Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: components/mus/ws/platform_display.cc

Issue 1899923002: Basic display management for mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/mus/ws/platform_display.cc
diff --git a/components/mus/ws/platform_display.cc b/components/mus/ws/platform_display.cc
index bfb51c1ff57d554731ed1459da2f6fed6adb286d..03c3125db0f8befa379ddb4f46acc805e00a4f32 100644
--- a/components/mus/ws/platform_display.cc
+++ b/components/mus/ws/platform_display.cc
@@ -5,6 +5,7 @@
#include "components/mus/ws/platform_display.h"
#include "base/numerics/safe_conversions.h"
+#include "base/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/copy_output_request.h"
@@ -170,13 +171,22 @@ DefaultPlatformDisplay::DefaultPlatformDisplay(
delegate_(nullptr),
draw_timer_(false, false),
frame_pending_(false),
+ is_configuring_(false),
+ should_configure_(false),
#if !defined(OS_ANDROID)
cursor_loader_(ui::CursorLoader::Create()),
#endif
weak_factory_(this) {
metrics_.size_in_pixels = mojo::Size::New();
+#if defined(USE_OZONE)
+ // The size is provided by callback from the display subsystem.
+ metrics_.size_in_pixels->width = 0;
+ metrics_.size_in_pixels->height = 0;
+#else
metrics_.size_in_pixels->width = 1024;
metrics_.size_in_pixels->height = 768;
+
+#endif
}
void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) {
@@ -190,8 +200,14 @@ void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) {
#elif defined(OS_ANDROID)
platform_window_.reset(new ui::PlatformWindowAndroid(this));
#elif defined(USE_OZONE)
+ native_display_delegate_ =
+ ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate();
+ native_display_delegate_->AddObserver(this);
+ native_display_delegate_->Initialize();
platform_window_ =
ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds);
+ // Kick off the display configuration process.
+ OnConfigurationChanged();
#else
NOTREACHED() << "Unsupported platform";
#endif
@@ -435,6 +451,71 @@ void DefaultPlatformDisplay::RequestCopyOfOutput(
top_level_display_client_->RequestCopyOfOutput(std::move(output_request));
}
+// TODO(rjkroege): Support multiple displays.
+// The display subsystem tells us that the display configuration has changed on
+// the first and subsequent change in display parameters. We have to kick this
+// off manually the first time.
+void DefaultPlatformDisplay::OnConfigurationChanged() {
+ DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
+ "OnConfigurationChanged requires a "
+ "native_display_delegate_ to work.";
+ if (is_configuring_) {
+ should_configure_ = true;
+ return;
+ }
+ is_configuring_ = true;
+ native_display_delegate_->GrabServer();
+ native_display_delegate_->GetDisplays(base::Bind(
+ &DefaultPlatformDisplay::OnDisplaysAquired, base::Unretained(this)));
+}
+
+// The display subsystem calls |OnDisplaysAquired| to deliver |displays|
+// describing the attached displays.
+void DefaultPlatformDisplay::OnDisplaysAquired(
+ const std::vector<ui::DisplaySnapshot*>& displays) {
+ DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
+ "OnConfigurationChanged requires a "
+ "native_display_delegate_ to work.";
+ CHECK(displays.size() <= 1) << "Mus needs to support more than 1 display\n";
+ gfx::Point origin;
+ for (auto display : displays) {
+ if (!display->native_mode()) {
+ LOG(ERROR) << "Display " << display->display_id()
+ << " doesn't have a native mode";
+ continue;
+ }
+ // Setup each native display. This places a task on the DRM thread's
+ // runqueue that configures the window size correctly before the call to
+ // Configure.
+ platform_window_->SetBounds(
+ gfx::Rect(origin, display->native_mode()->size()));
+ native_display_delegate_->Configure(
+ *display, display->native_mode(), origin,
+ base::Bind(&DefaultPlatformDisplay::OnDisplayConfigured,
+ base::Unretained(this),
+ gfx::Rect(origin, display->native_mode()->size())));
+ origin.Offset(display->native_mode()->size().width(), 0);
+ }
+ native_display_delegate_->UngrabServer();
sky 2016/04/18 21:25:00 What happens if this is deleted after OnConfigurat
rjkroege 2016/04/21 20:19:53 Something bad. Appropriate weak pointer-y stuff ad
+ is_configuring_ = false;
+ if (should_configure_) {
+ should_configure_ = false;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&DefaultPlatformDisplay::OnConfigurationChanged,
+ base::Unretained(this)));
sky 2016/04/18 21:25:00 How is unretained safe here?
rjkroege 2016/04/21 20:19:53 It's not. Fixed.
+ }
+}
+
+// The display subsystem calls |OnDisplayConfigured| for each display that has
+// been successfully configured.
+// TODO(rjkroege): Per display design discussion, displays should have
+// identifying tokens delivered here.
+void DefaultPlatformDisplay::OnDisplayConfigured(const gfx::Rect& bounds,
+ bool success) {
+ if (!success)
+ LOG(ERROR) << "Failed to configure display at " << bounds.ToString();
+}
+
} // namespace ws
} // namespace mus
« components/mus/ws/platform_display.h ('K') | « components/mus/ws/platform_display.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698