 Chromium Code Reviews
 Chromium Code Reviews Issue 1456623002:
  Add support for virtual displays  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1456623002:
  Add support for virtual displays  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: ui/display/chromeos/display_configurator.cc | 
| diff --git a/ui/display/chromeos/display_configurator.cc b/ui/display/chromeos/display_configurator.cc | 
| index 68c026ea0c6f8d9d41cca7660f75f6e96b117d80..ee1c17b7729d0cf85cc438dd24ff24093b251946 100644 | 
| --- a/ui/display/chromeos/display_configurator.cc | 
| +++ b/ui/display/chromeos/display_configurator.cc | 
| @@ -11,12 +11,15 @@ | 
| #include "base/time/time.h" | 
| #include "ui/display/chromeos/apply_content_protection_task.h" | 
| #include "ui/display/chromeos/display_layout_manager.h" | 
| +#include "ui/display/chromeos/display_snapshot_virtual.h" | 
| #include "ui/display/chromeos/display_util.h" | 
| #include "ui/display/chromeos/update_display_configuration_task.h" | 
| #include "ui/display/display_switches.h" | 
| #include "ui/display/types/display_mode.h" | 
| #include "ui/display/types/display_snapshot.h" | 
| #include "ui/display/types/native_display_delegate.h" | 
| +#include "ui/display/util/display_util.h" | 
| +#include "ui/gfx/display.h" | 
| namespace ui { | 
| @@ -661,6 +664,15 @@ void DisplayConfigurator::QueryContentProtectionStatus( | 
| ContentProtectionClientId client_id, | 
| int64_t display_id, | 
| const QueryProtectionCallback& callback) { | 
| + // Exclude virtual displays. | 
| 
oshima
2015/12/02 20:34:27
please mention the possibility to be recaptured.
 
robert.bradford
2015/12/03 18:44:57
Done.
 | 
| + for (const DisplaySnapshot* display : cached_displays_) { | 
| + if (display->display_id() == display_id && | 
| + !IsPhysicalDisplayType(display->type())) { | 
| + callback.Run(QueryProtectionResponse()); | 
| + return; | 
| + } | 
| + } | 
| + | 
| if (!configure_display_ || display_externally_controlled_) { | 
| callback.Run(QueryProtectionResponse()); | 
| return; | 
| @@ -779,7 +791,8 @@ DisplayConfigurator::GetAvailableColorCalibrationProfiles(int64_t display_id) { | 
| if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| switches::kDisableDisplayColorCalibration)) { | 
| for (const DisplaySnapshot* display : cached_displays_) { | 
| - if (display->display_id() == display_id) { | 
| + if (display->display_id() == display_id && | 
| + IsPhysicalDisplayType(display->type())) { | 
| return native_display_delegate_->GetAvailableColorCalibrationProfiles( | 
| *display); | 
| } | 
| @@ -793,7 +806,8 @@ bool DisplayConfigurator::SetColorCalibrationProfile( | 
| int64_t display_id, | 
| ui::ColorCalibrationProfile new_profile) { | 
| for (const DisplaySnapshot* display : cached_displays_) { | 
| - if (display->display_id() == display_id) { | 
| + if (display->display_id() == display_id && | 
| + IsPhysicalDisplayType(display->type())) { | 
| return native_display_delegate_->SetColorCalibrationProfile(*display, | 
| new_profile); | 
| } | 
| @@ -964,6 +978,8 @@ void DisplayConfigurator::RunPendingConfiguration() { | 
| requested_display_state_, requested_power_state_, requested_power_flags_, | 
| 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, | 
| weak_ptr_factory_.GetWeakPtr()))); | 
| + configuration_task_->set_virtual_display_snapshots( | 
| + virtual_display_snapshots_.get()); | 
| // Reset the flags before running the task; otherwise it may end up scheduling | 
| // another configuration. | 
| @@ -1079,4 +1095,32 @@ void DisplayConfigurator::NotifyObservers( | 
| } | 
| } | 
| +int64_t DisplayConfigurator::AddVirtualDisplay(gfx::Size display_size) { | 
| + if (last_virtual_display_id_ == 0xff) { | 
| + LOG(WARNING) << "Exceeded virtual display id limit"; | 
| + return gfx::Display::kInvalidDisplayID; | 
| + } | 
| + | 
| + DisplaySnapshotVirtual* virtual_snapshot = new DisplaySnapshotVirtual( | 
| + GetDisplayID(0x8000, 0x0, ++last_virtual_display_id_), display_size); | 
| 
robert.bradford
2015/11/26 16:29:41
Would you prefer a kReservedManufacturerID constan
 
oshima
2015/12/02 20:34:27
Yes, and you can put it in the anonymous namespace
 
robert.bradford
2015/12/03 18:44:57
Done. And I used 1 << 15 to further clarify.
 | 
| + virtual_display_snapshots_.push_back(virtual_snapshot); | 
| + ConfigureDisplays(); | 
| + | 
| + return virtual_snapshot->display_id(); | 
| +} | 
| + | 
| +bool DisplayConfigurator::RemoveVirtualDisplay(int64_t display_id) { | 
| + for (auto it = virtual_display_snapshots_.begin(); | 
| + it != virtual_display_snapshots_.end(); ++it) { | 
| + if ((*it)->display_id() == display_id) { | 
| + if ((display_id & 0xff) == last_virtual_display_id_) | 
| + last_virtual_display_id_--; | 
| 
oshima
2015/12/02 20:34:27
can you walk through the list (after erase) and se
 
robert.bradford
2015/12/03 18:44:57
Done.
 | 
| + virtual_display_snapshots_.erase(it); | 
| + ConfigureDisplays(); | 
| + return true; | 
| + } | 
| + } | 
| + return false; | 
| +} | 
| + | 
| } // namespace ui |