OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ui/display/fake_display_delegate.h" | 5 #include "ui/display/fake_display_delegate.h" |
6 | 6 |
7 #include <inttypes.h> | |
Daniel Erat
2016/10/07 17:17:21
i was going to suggest including base/format_macro
| |
8 | |
7 #include <string> | 9 #include <string> |
8 #include <utility> | 10 #include <utility> |
9 | 11 |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/hash.h" | 13 #include "base/hash.h" |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
16 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
40 if (next_display_id_ == 0xFF) { | 42 if (next_display_id_ == 0xFF) { |
41 LOG(ERROR) << "Exceeded display id limit"; | 43 LOG(ERROR) << "Exceeded display id limit"; |
42 return Display::kInvalidDisplayID; | 44 return Display::kInvalidDisplayID; |
43 } | 45 } |
44 | 46 |
45 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, | 47 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, |
46 ++next_display_id_); | 48 ++next_display_id_); |
47 | 49 |
48 FakeDisplaySnapshot::Builder builder; | 50 FakeDisplaySnapshot::Builder builder; |
49 builder.SetId(id).SetNativeMode(display_size); | 51 builder.SetId(id).SetNativeMode(display_size); |
50 builder.SetName(base::StringPrintf("Fake Display %d", next_display_id_)); | 52 builder.SetName(base::StringPrintf("Fake Display %" PRId64, id)); |
51 | 53 |
52 // Add the first display as internal. | 54 // Add the first display as internal. |
53 if (displays_.empty()) | 55 if (displays_.empty()) |
54 builder.SetType(ui::DISPLAY_CONNECTION_TYPE_INTERNAL); | 56 builder.SetType(ui::DISPLAY_CONNECTION_TYPE_INTERNAL); |
55 | 57 |
56 return AddDisplay(builder.Build()) ? id : Display::kInvalidDisplayID; | 58 return AddDisplay(builder.Build()) ? id : Display::kInvalidDisplayID; |
57 } | 59 } |
58 | 60 |
59 bool FakeDisplayDelegate::AddDisplay( | 61 bool FakeDisplayDelegate::AddDisplay( |
60 std::unique_ptr<ui::DisplaySnapshot> display) { | 62 std::unique_ptr<ui::DisplaySnapshot> display) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 callback.Run(displays); | 129 callback.Run(displays); |
128 } | 130 } |
129 | 131 |
130 void FakeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output, | 132 void FakeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output, |
131 const ui::DisplayMode* mode) {} | 133 const ui::DisplayMode* mode) {} |
132 | 134 |
133 void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output, | 135 void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output, |
134 const ui::DisplayMode* mode, | 136 const ui::DisplayMode* mode, |
135 const gfx::Point& origin, | 137 const gfx::Point& origin, |
136 const ui::ConfigureCallback& callback) { | 138 const ui::ConfigureCallback& callback) { |
137 callback.Run(true); | 139 // Check the display mode is appropriate for the display snapshot. |
140 for (const auto& existing_mode : output.modes()) { | |
141 if (existing_mode.get() == mode) { | |
142 callback.Run(true); | |
143 return; | |
144 } | |
145 } | |
146 | |
147 callback.Run(false); | |
138 } | 148 } |
139 | 149 |
140 void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} | 150 void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} |
141 | 151 |
142 void FakeDisplayDelegate::GetHDCPState( | 152 void FakeDisplayDelegate::GetHDCPState( |
143 const ui::DisplaySnapshot& output, | 153 const ui::DisplaySnapshot& output, |
144 const ui::GetHDCPStateCallback& callback) { | 154 const ui::GetHDCPStateCallback& callback) { |
145 callback.Run(false, ui::HDCP_STATE_UNDESIRED); | 155 callback.Run(false, ui::HDCP_STATE_UNDESIRED); |
146 } | 156 } |
147 | 157 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 const std::string command_string = | 202 const std::string command_string = |
193 command_line->GetSwitchValueASCII(switches::kScreenConfig); | 203 command_line->GetSwitchValueASCII(switches::kScreenConfig); |
194 | 204 |
195 // Start without any displays. | 205 // Start without any displays. |
196 if (command_string == "none") | 206 if (command_string == "none") |
197 return true; | 207 return true; |
198 | 208 |
199 // Split on commas and parse each display string. | 209 // Split on commas and parse each display string. |
200 for (std::string part : base::SplitString( | 210 for (std::string part : base::SplitString( |
201 command_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 211 command_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
212 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, | |
213 next_display_id_); | |
202 std::unique_ptr<ui::DisplaySnapshot> snapshot = | 214 std::unique_ptr<ui::DisplaySnapshot> snapshot = |
203 CreateSnapshotFromSpec(part); | 215 FakeDisplaySnapshot::CreateFromSpec(id, part); |
204 if (snapshot) { | 216 if (snapshot) { |
205 AddDisplay(std::move(snapshot)); | 217 AddDisplay(std::move(snapshot)); |
218 next_display_id_++; | |
206 } else { | 219 } else { |
207 LOG(ERROR) << "Failed to parse display \"" << part << "\""; | 220 LOG(ERROR) << "Failed to parse display \"" << part << "\""; |
208 } | 221 } |
209 } | 222 } |
210 | 223 |
211 return true; | 224 return true; |
212 } | 225 } |
213 | 226 |
214 std::unique_ptr<ui::DisplaySnapshot> | |
215 FakeDisplayDelegate::CreateSnapshotFromSpec(const std::string& spec) { | |
216 int width = 0; | |
217 int height = 0; | |
218 int dpi = 0; | |
219 | |
220 // Width and height are required but DPI is optional. | |
221 int found = sscanf(spec.c_str(), "%dx%d^%d", &width, &height, &dpi); | |
222 if (found < 2) | |
223 return nullptr; | |
224 | |
225 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, | |
226 ++next_display_id_); | |
227 | |
228 FakeDisplaySnapshot::Builder builder; | |
229 builder.SetId(id).SetNativeMode(gfx::Size(width, height)); | |
230 builder.SetName(base::StringPrintf("Fake Display %d", next_display_id_)); | |
231 | |
232 if (found >= 3) | |
233 builder.SetDPI(dpi); | |
234 | |
235 // TODO(kylechar): Add type to the spec string. | |
236 if (displays_.empty()) | |
237 builder.SetType(ui::DISPLAY_CONNECTION_TYPE_INTERNAL); | |
238 | |
239 return builder.Build(); | |
240 } | |
241 | |
242 void FakeDisplayDelegate::OnConfigurationChanged() { | 227 void FakeDisplayDelegate::OnConfigurationChanged() { |
243 if (!initialized_) | 228 if (!initialized_) |
244 return; | 229 return; |
245 | 230 |
246 FOR_EACH_OBSERVER(ui::NativeDisplayObserver, observers_, | 231 FOR_EACH_OBSERVER(ui::NativeDisplayObserver, observers_, |
247 OnConfigurationChanged()); | 232 OnConfigurationChanged()); |
248 } | 233 } |
249 | 234 |
250 } // namespace display | 235 } // namespace display |
OLD | NEW |