Index: ui/display/chromeos/virtual_display_delegate.cc |
diff --git a/ui/display/chromeos/virtual_display_delegate.cc b/ui/display/chromeos/virtual_display_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0c7b5c9b29e1ad313eb86ff1ee0d1b061c0cca2d |
--- /dev/null |
+++ b/ui/display/chromeos/virtual_display_delegate.cc |
@@ -0,0 +1,189 @@ |
+// 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 "ui/display/chromeos/virtual_display_delegate.h" |
+ |
+#include <string> |
+ |
+#include "base/command_line.h" |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/strings/string_split.h" |
+#include "ui/display/display.h" |
+#include "ui/display/display_switches.h" |
+#include "ui/display/types/native_display_observer.h" |
+#include "ui/display/util/display_util.h" |
+ |
+namespace display { |
+ |
+namespace { |
+ |
+// The EDID specification marks the top bit of the manufacturer id as reserved. |
+const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); |
+ |
+} // namespace |
+ |
+VirtualDisplayDelegate::VirtualDisplayDelegate() {} |
+ |
+VirtualDisplayDelegate::~VirtualDisplayDelegate() {} |
+ |
+int64_t VirtualDisplayDelegate::AddVirtualDisplay( |
+ const gfx::Size& display_size) { |
+ if (next_virtual_display_id_ == 0xff) { |
+ LOG(WARNING) << "Exceeded virtual display id limit"; |
+ return display::Display::kInvalidDisplayID; |
+ } |
+ |
+ int64_t display_id = GenerateDisplayID(kReservedManufacturerID, 0x0, |
+ ++next_virtual_display_id_); |
+ displays_.push_back( |
+ base::MakeUnique<ui::DisplaySnapshotVirtual>(display_id, display_size)); |
+ OnConfigurationChanged(); |
+ |
+ return display_id; |
+} |
+ |
+bool VirtualDisplayDelegate::RemoveVirtualDisplay(int64_t display_id) { |
+ auto iter = displays_.begin(); |
+ for (; iter != displays_.end(); ++iter) { |
+ if ((*iter)->display_id() == display_id) |
+ break; |
+ } |
+ |
+ if (iter == displays_.end()) |
+ return false; |
+ |
+ displays_.erase(iter); |
+ OnConfigurationChanged(); |
+ |
+ return true; |
+} |
+ |
+void VirtualDisplayDelegate::Initialize() { |
+ DCHECK(!initialized_); |
+ InitFromCommandLine(); |
+ |
+ // If no command line flags are provided then initialize a default display. |
+ if (displays_.empty()) |
+ AddVirtualDisplay(gfx::Size(1024, 768)); |
+ |
+ initialized_ = true; |
+} |
+ |
+void VirtualDisplayDelegate::GrabServer() {} |
+ |
+void VirtualDisplayDelegate::UngrabServer() {} |
+ |
+void VirtualDisplayDelegate::TakeDisplayControl( |
+ const ui::DisplayControlCallback& callback) { |
+ callback.Run(false); |
+} |
+ |
+void VirtualDisplayDelegate::RelinquishDisplayControl( |
+ const ui::DisplayControlCallback& callback) { |
+ callback.Run(false); |
+} |
+ |
+void VirtualDisplayDelegate::SyncWithServer() {} |
+ |
+void VirtualDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {} |
+ |
+void VirtualDisplayDelegate::ForceDPMSOn() {} |
+ |
+void VirtualDisplayDelegate::GetDisplays( |
+ const ui::GetDisplaysCallback& callback) { |
+ std::vector<ui::DisplaySnapshot*> displays; |
+ for (const auto& display : displays_) |
+ displays.push_back(display.get()); |
+ callback.Run(displays); |
+} |
+ |
+void VirtualDisplayDelegate::AddMode(const ui::DisplaySnapshot& output, |
+ const ui::DisplayMode* mode) {} |
+ |
+void VirtualDisplayDelegate::Configure(const ui::DisplaySnapshot& output, |
+ const ui::DisplayMode* mode, |
+ const gfx::Point& origin, |
+ const ui::ConfigureCallback& callback) { |
+ callback.Run(true); |
+} |
+ |
+void VirtualDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} |
+ |
+void VirtualDisplayDelegate::GetHDCPState( |
+ const ui::DisplaySnapshot& output, |
+ const ui::GetHDCPStateCallback& callback) { |
+ callback.Run(false, ui::HDCP_STATE_UNDESIRED); |
+} |
+ |
+void VirtualDisplayDelegate::SetHDCPState( |
+ const ui::DisplaySnapshot& output, |
+ ui::HDCPState state, |
+ const ui::SetHDCPStateCallback& callback) { |
+ callback.Run(false); |
+} |
+ |
+std::vector<ui::ColorCalibrationProfile> |
+VirtualDisplayDelegate::GetAvailableColorCalibrationProfiles( |
+ const ui::DisplaySnapshot& output) { |
+ return std::vector<ui::ColorCalibrationProfile>(); |
+} |
+ |
+bool VirtualDisplayDelegate::SetColorCalibrationProfile( |
+ const ui::DisplaySnapshot& output, |
+ ui::ColorCalibrationProfile new_profile) { |
+ return false; |
+} |
+ |
+bool VirtualDisplayDelegate::SetColorCorrection( |
+ const ui::DisplaySnapshot& output, |
+ const std::vector<ui::GammaRampRGBEntry>& degamma_lut, |
+ const std::vector<ui::GammaRampRGBEntry>& gamma_lut, |
+ const std::vector<float>& correction_matrix) { |
+ return false; |
+} |
+ |
+void VirtualDisplayDelegate::AddObserver(ui::NativeDisplayObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void VirtualDisplayDelegate::RemoveObserver( |
+ ui::NativeDisplayObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+VirtualDisplayController* |
+VirtualDisplayDelegate::GetVirtualDisplayController() { |
+ return static_cast<VirtualDisplayController*>(this); |
+} |
+ |
+void VirtualDisplayDelegate::InitFromCommandLine() { |
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
+ if (!command_line->HasSwitch(switches::kDisplayBounds)) |
+ return; |
+ |
+ const std::string command_string = |
+ command_line->GetSwitchValueASCII(switches::kDisplayBounds); |
+ for (std::string part : base::SplitString( |
+ command_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
+ int width = 0; |
+ int height = 0; |
+ if (sscanf(part.c_str(), "%dx%d", &width, &height) >= 2) { |
+ gfx::Size display_size(width, height); |
+ AddVirtualDisplay(display_size); |
+ } else { |
+ LOG(WARNING) << "Failed to parse display \"" << part << "\""; |
+ } |
+ } |
+} |
+ |
+void VirtualDisplayDelegate::OnConfigurationChanged() { |
+ if (!initialized_) |
+ return; |
+ |
+ FOR_EACH_OBSERVER(ui::NativeDisplayObserver, observers_, |
+ OnConfigurationChanged()); |
+} |
+ |
+} // namespace display |