OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/display/chromeos/virtual_display_delegate.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_split.h" |
| 13 #include "ui/display/display.h" |
| 14 #include "ui/display/display_switches.h" |
| 15 #include "ui/display/types/native_display_observer.h" |
| 16 #include "ui/display/util/display_util.h" |
| 17 |
| 18 namespace display { |
| 19 |
| 20 namespace { |
| 21 |
| 22 // The EDID specification marks the top bit of the manufacturer id as reserved. |
| 23 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); |
| 24 |
| 25 } // namespace |
| 26 |
| 27 VirtualDisplayDelegate::VirtualDisplayDelegate() {} |
| 28 |
| 29 VirtualDisplayDelegate::~VirtualDisplayDelegate() {} |
| 30 |
| 31 int64_t VirtualDisplayDelegate::AddVirtualDisplay( |
| 32 const gfx::Size& display_size) { |
| 33 if (next_virtual_display_id_ == 0xff) { |
| 34 LOG(WARNING) << "Exceeded virtual display id limit"; |
| 35 return display::Display::kInvalidDisplayID; |
| 36 } |
| 37 |
| 38 int64_t display_id = GenerateDisplayID(kReservedManufacturerID, 0x0, |
| 39 ++next_virtual_display_id_); |
| 40 displays_.push_back( |
| 41 base::MakeUnique<ui::DisplaySnapshotVirtual>(display_id, display_size)); |
| 42 OnConfigurationChanged(); |
| 43 |
| 44 return display_id; |
| 45 } |
| 46 |
| 47 bool VirtualDisplayDelegate::RemoveVirtualDisplay(int64_t display_id) { |
| 48 auto iter = displays_.begin(); |
| 49 for (; iter != displays_.end(); ++iter) { |
| 50 if ((*iter)->display_id() == display_id) |
| 51 break; |
| 52 } |
| 53 |
| 54 if (iter == displays_.end()) |
| 55 return false; |
| 56 |
| 57 displays_.erase(iter); |
| 58 OnConfigurationChanged(); |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 63 void VirtualDisplayDelegate::Initialize() { |
| 64 DCHECK(!initialized_); |
| 65 InitFromCommandLine(); |
| 66 |
| 67 // If no command line flags are provided then initialize a default display. |
| 68 if (displays_.empty()) |
| 69 AddVirtualDisplay(gfx::Size(1024, 768)); |
| 70 |
| 71 initialized_ = true; |
| 72 } |
| 73 |
| 74 void VirtualDisplayDelegate::GrabServer() {} |
| 75 |
| 76 void VirtualDisplayDelegate::UngrabServer() {} |
| 77 |
| 78 void VirtualDisplayDelegate::TakeDisplayControl( |
| 79 const ui::DisplayControlCallback& callback) { |
| 80 callback.Run(false); |
| 81 } |
| 82 |
| 83 void VirtualDisplayDelegate::RelinquishDisplayControl( |
| 84 const ui::DisplayControlCallback& callback) { |
| 85 callback.Run(false); |
| 86 } |
| 87 |
| 88 void VirtualDisplayDelegate::SyncWithServer() {} |
| 89 |
| 90 void VirtualDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {} |
| 91 |
| 92 void VirtualDisplayDelegate::ForceDPMSOn() {} |
| 93 |
| 94 void VirtualDisplayDelegate::GetDisplays( |
| 95 const ui::GetDisplaysCallback& callback) { |
| 96 std::vector<ui::DisplaySnapshot*> displays; |
| 97 for (const auto& display : displays_) |
| 98 displays.push_back(display.get()); |
| 99 callback.Run(displays); |
| 100 } |
| 101 |
| 102 void VirtualDisplayDelegate::AddMode(const ui::DisplaySnapshot& output, |
| 103 const ui::DisplayMode* mode) {} |
| 104 |
| 105 void VirtualDisplayDelegate::Configure(const ui::DisplaySnapshot& output, |
| 106 const ui::DisplayMode* mode, |
| 107 const gfx::Point& origin, |
| 108 const ui::ConfigureCallback& callback) { |
| 109 callback.Run(true); |
| 110 } |
| 111 |
| 112 void VirtualDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} |
| 113 |
| 114 void VirtualDisplayDelegate::GetHDCPState( |
| 115 const ui::DisplaySnapshot& output, |
| 116 const ui::GetHDCPStateCallback& callback) { |
| 117 callback.Run(false, ui::HDCP_STATE_UNDESIRED); |
| 118 } |
| 119 |
| 120 void VirtualDisplayDelegate::SetHDCPState( |
| 121 const ui::DisplaySnapshot& output, |
| 122 ui::HDCPState state, |
| 123 const ui::SetHDCPStateCallback& callback) { |
| 124 callback.Run(false); |
| 125 } |
| 126 |
| 127 std::vector<ui::ColorCalibrationProfile> |
| 128 VirtualDisplayDelegate::GetAvailableColorCalibrationProfiles( |
| 129 const ui::DisplaySnapshot& output) { |
| 130 return std::vector<ui::ColorCalibrationProfile>(); |
| 131 } |
| 132 |
| 133 bool VirtualDisplayDelegate::SetColorCalibrationProfile( |
| 134 const ui::DisplaySnapshot& output, |
| 135 ui::ColorCalibrationProfile new_profile) { |
| 136 return false; |
| 137 } |
| 138 |
| 139 bool VirtualDisplayDelegate::SetColorCorrection( |
| 140 const ui::DisplaySnapshot& output, |
| 141 const std::vector<ui::GammaRampRGBEntry>& degamma_lut, |
| 142 const std::vector<ui::GammaRampRGBEntry>& gamma_lut, |
| 143 const std::vector<float>& correction_matrix) { |
| 144 return false; |
| 145 } |
| 146 |
| 147 void VirtualDisplayDelegate::AddObserver(ui::NativeDisplayObserver* observer) { |
| 148 observers_.AddObserver(observer); |
| 149 } |
| 150 |
| 151 void VirtualDisplayDelegate::RemoveObserver( |
| 152 ui::NativeDisplayObserver* observer) { |
| 153 observers_.RemoveObserver(observer); |
| 154 } |
| 155 |
| 156 VirtualDisplayController* |
| 157 VirtualDisplayDelegate::GetVirtualDisplayController() { |
| 158 return static_cast<VirtualDisplayController*>(this); |
| 159 } |
| 160 |
| 161 void VirtualDisplayDelegate::InitFromCommandLine() { |
| 162 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 163 if (!command_line->HasSwitch(switches::kDisplayBounds)) |
| 164 return; |
| 165 |
| 166 const std::string command_string = |
| 167 command_line->GetSwitchValueASCII(switches::kDisplayBounds); |
| 168 for (std::string part : base::SplitString( |
| 169 command_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 170 int width = 0; |
| 171 int height = 0; |
| 172 if (sscanf(part.c_str(), "%dx%d", &width, &height) >= 2) { |
| 173 gfx::Size display_size(width, height); |
| 174 AddVirtualDisplay(display_size); |
| 175 } else { |
| 176 LOG(WARNING) << "Failed to parse display \"" << part << "\""; |
| 177 } |
| 178 } |
| 179 } |
| 180 |
| 181 void VirtualDisplayDelegate::OnConfigurationChanged() { |
| 182 if (!initialized_) |
| 183 return; |
| 184 |
| 185 FOR_EACH_OBSERVER(ui::NativeDisplayObserver, observers_, |
| 186 OnConfigurationChanged()); |
| 187 } |
| 188 |
| 189 } // namespace display |
OLD | NEW |