Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/ws/platform_display.h" | 5 #include "components/mus/ws/platform_display.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "base/thread_task_runner_handle.h" | |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
| 11 #include "cc/output/delegated_frame_data.h" | 12 #include "cc/output/delegated_frame_data.h" |
| 12 #include "cc/quads/render_pass.h" | 13 #include "cc/quads/render_pass.h" |
| 13 #include "cc/quads/shared_quad_state.h" | 14 #include "cc/quads/shared_quad_state.h" |
| 14 #include "cc/quads/surface_draw_quad.h" | 15 #include "cc/quads/surface_draw_quad.h" |
| 15 #include "components/mus/gles2/gpu_state.h" | 16 #include "components/mus/gles2/gpu_state.h" |
| 16 #include "components/mus/public/interfaces/gpu.mojom.h" | 17 #include "components/mus/public/interfaces/gpu.mojom.h" |
| 17 #include "components/mus/public/interfaces/quads.mojom.h" | 18 #include "components/mus/public/interfaces/quads.mojom.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 } | 164 } |
| 164 | 165 |
| 165 DefaultPlatformDisplay::DefaultPlatformDisplay( | 166 DefaultPlatformDisplay::DefaultPlatformDisplay( |
| 166 const PlatformDisplayInitParams& init_params) | 167 const PlatformDisplayInitParams& init_params) |
| 167 : connector_(init_params.connector), | 168 : connector_(init_params.connector), |
| 168 gpu_state_(init_params.gpu_state), | 169 gpu_state_(init_params.gpu_state), |
| 169 surfaces_state_(init_params.surfaces_state), | 170 surfaces_state_(init_params.surfaces_state), |
| 170 delegate_(nullptr), | 171 delegate_(nullptr), |
| 171 draw_timer_(false, false), | 172 draw_timer_(false, false), |
| 172 frame_pending_(false), | 173 frame_pending_(false), |
| 174 is_configuring_(false), | |
| 175 should_configure_(false), | |
| 173 #if !defined(OS_ANDROID) | 176 #if !defined(OS_ANDROID) |
| 174 cursor_loader_(ui::CursorLoader::Create()), | 177 cursor_loader_(ui::CursorLoader::Create()), |
| 175 #endif | 178 #endif |
| 176 weak_factory_(this) { | 179 weak_factory_(this) { |
| 177 metrics_.size_in_pixels = mojo::Size::New(); | 180 metrics_.size_in_pixels = mojo::Size::New(); |
| 181 #if defined(USE_OZONE) | |
| 182 // The size is provided by callback from the display subsystem. | |
| 183 metrics_.size_in_pixels->width = 0; | |
| 184 metrics_.size_in_pixels->height = 0; | |
| 185 #else | |
| 178 metrics_.size_in_pixels->width = 1024; | 186 metrics_.size_in_pixels->width = 1024; |
| 179 metrics_.size_in_pixels->height = 768; | 187 metrics_.size_in_pixels->height = 768; |
| 188 | |
| 189 #endif | |
| 180 } | 190 } |
| 181 | 191 |
| 182 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { | 192 void DefaultPlatformDisplay::Init(PlatformDisplayDelegate* delegate) { |
| 183 delegate_ = delegate; | 193 delegate_ = delegate; |
| 184 | 194 |
| 185 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); | 195 gfx::Rect bounds(metrics_.size_in_pixels.To<gfx::Size>()); |
| 186 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
| 187 platform_window_.reset(new ui::WinWindow(this, bounds)); | 197 platform_window_.reset(new ui::WinWindow(this, bounds)); |
| 188 #elif defined(USE_X11) | 198 #elif defined(USE_X11) |
| 189 platform_window_.reset(new ui::X11Window(this)); | 199 platform_window_.reset(new ui::X11Window(this)); |
| 190 #elif defined(OS_ANDROID) | 200 #elif defined(OS_ANDROID) |
| 191 platform_window_.reset(new ui::PlatformWindowAndroid(this)); | 201 platform_window_.reset(new ui::PlatformWindowAndroid(this)); |
| 192 #elif defined(USE_OZONE) | 202 #elif defined(USE_OZONE) |
| 203 native_display_delegate_ = | |
| 204 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | |
| 205 native_display_delegate_->AddObserver(this); | |
| 206 native_display_delegate_->Initialize(); | |
| 193 platform_window_ = | 207 platform_window_ = |
| 194 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); | 208 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); |
| 209 // Kick off the display configuration process. | |
| 210 OnConfigurationChanged(); | |
| 195 #else | 211 #else |
| 196 NOTREACHED() << "Unsupported platform"; | 212 NOTREACHED() << "Unsupported platform"; |
| 197 #endif | 213 #endif |
| 198 platform_window_->SetBounds(bounds); | 214 platform_window_->SetBounds(bounds); |
| 199 platform_window_->Show(); | 215 platform_window_->Show(); |
| 200 } | 216 } |
| 201 | 217 |
| 202 DefaultPlatformDisplay::~DefaultPlatformDisplay() { | 218 DefaultPlatformDisplay::~DefaultPlatformDisplay() { |
| 203 // Don't notify the delegate from the destructor. | 219 // Don't notify the delegate from the destructor. |
| 204 delegate_ = nullptr; | 220 delegate_ = nullptr; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 } | 444 } |
| 429 | 445 |
| 430 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} | 446 void DefaultPlatformDisplay::OnActivationChanged(bool active) {} |
| 431 | 447 |
| 432 void DefaultPlatformDisplay::RequestCopyOfOutput( | 448 void DefaultPlatformDisplay::RequestCopyOfOutput( |
| 433 scoped_ptr<cc::CopyOutputRequest> output_request) { | 449 scoped_ptr<cc::CopyOutputRequest> output_request) { |
| 434 if (top_level_display_client_) | 450 if (top_level_display_client_) |
| 435 top_level_display_client_->RequestCopyOfOutput(std::move(output_request)); | 451 top_level_display_client_->RequestCopyOfOutput(std::move(output_request)); |
| 436 } | 452 } |
| 437 | 453 |
| 454 // TODO(rjkroege): Support multiple displays. | |
| 455 // The display subsystem tells us that the display configuration has changed on | |
| 456 // the first and subsequent change in display parameters. We have to kick this | |
| 457 // off manually the first time. | |
| 458 void DefaultPlatformDisplay::OnConfigurationChanged() { | |
| 459 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
| 460 "OnConfigurationChanged requires a " | |
| 461 "native_display_delegate_ to work."; | |
| 462 if (is_configuring_) { | |
| 463 should_configure_ = true; | |
| 464 return; | |
| 465 } | |
| 466 is_configuring_ = true; | |
| 467 native_display_delegate_->GrabServer(); | |
| 468 native_display_delegate_->GetDisplays(base::Bind( | |
| 469 &DefaultPlatformDisplay::OnDisplaysAquired, base::Unretained(this))); | |
| 470 } | |
| 471 | |
| 472 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| | |
| 473 // describing the attached displays. | |
| 474 void DefaultPlatformDisplay::OnDisplaysAquired( | |
| 475 const std::vector<ui::DisplaySnapshot*>& displays) { | |
| 476 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
| 477 "OnConfigurationChanged requires a " | |
| 478 "native_display_delegate_ to work."; | |
| 479 CHECK(displays.size() <= 1) << "Mus needs to support more than 1 display\n"; | |
| 480 gfx::Point origin; | |
| 481 for (auto display : displays) { | |
| 482 if (!display->native_mode()) { | |
| 483 LOG(ERROR) << "Display " << display->display_id() | |
| 484 << " doesn't have a native mode"; | |
| 485 continue; | |
| 486 } | |
| 487 // Setup each native display. This places a task on the DRM thread's | |
| 488 // runqueue that configures the window size correctly before the call to | |
| 489 // Configure. | |
| 490 platform_window_->SetBounds( | |
| 491 gfx::Rect(origin, display->native_mode()->size())); | |
| 492 native_display_delegate_->Configure( | |
| 493 *display, display->native_mode(), origin, | |
| 494 base::Bind(&DefaultPlatformDisplay::OnDisplayConfigured, | |
| 495 base::Unretained(this), | |
| 496 gfx::Rect(origin, display->native_mode()->size()))); | |
| 497 origin.Offset(display->native_mode()->size().width(), 0); | |
| 498 } | |
| 499 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
| |
| 500 is_configuring_ = false; | |
| 501 if (should_configure_) { | |
| 502 should_configure_ = false; | |
| 503 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 504 FROM_HERE, base::Bind(&DefaultPlatformDisplay::OnConfigurationChanged, | |
| 505 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.
| |
| 506 } | |
| 507 } | |
| 508 | |
| 509 // The display subsystem calls |OnDisplayConfigured| for each display that has | |
| 510 // been successfully configured. | |
| 511 // TODO(rjkroege): Per display design discussion, displays should have | |
| 512 // identifying tokens delivered here. | |
| 513 void DefaultPlatformDisplay::OnDisplayConfigured(const gfx::Rect& bounds, | |
| 514 bool success) { | |
| 515 if (!success) | |
| 516 LOG(ERROR) << "Failed to configure display at " << bounds.ToString(); | |
| 517 } | |
| 518 | |
| 438 } // namespace ws | 519 } // namespace ws |
| 439 | 520 |
| 440 } // namespace mus | 521 } // namespace mus |
| OLD | NEW |