Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ui/display/fake_display_delegate.cc

Issue 2324163002: Add FakeDisplayDelegate for off device usage. (Closed)
Patch Set: Address rjkroege comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/fake_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 "base/strings/stringprintf.h"
14 #include "ui/display/display.h"
15 #include "ui/display/display_switches.h"
16 #include "ui/display/types/native_display_observer.h"
17 #include "ui/display/util/display_util.h"
18
19 namespace display {
20
21 namespace {
22
23 // The EDID specification marks the top bit of the manufacturer id as reserved.
24 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15);
25
26 // A random product number we'll use.
27 const int32_t kProductId = 1000;
28
29 } // namespace
30
31 FakeDisplayDelegate::FakeDisplayDelegate() {}
32
33 FakeDisplayDelegate::~FakeDisplayDelegate() {}
34
35 int64_t FakeDisplayDelegate::AddDisplay(const gfx::Size& display_size) {
36 if (next_display_id_ == 0xFF) {
37 LOG(ERROR) << "Exceeded display id limit";
38 return display::Display::kInvalidDisplayID;
39 }
40
41 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductId,
42 ++next_display_id_);
43 // Add the first display as internal.
44 ui::DisplayConnectionType type = displays_.empty()
45 ? ui::DISPLAY_CONNECTION_TYPE_INTERNAL
46 : ui::DISPLAY_CONNECTION_TYPE_UNKNOWN;
47 std::string name = base::StringPrintf("Fake Display %d", next_display_id_);
48
49 displays_.push_back(
50 base::MakeUnique<FakeDisplaySnapshot>(id, display_size, type, name));
51 OnConfigurationChanged();
52
53 return id;
54 }
55
56 bool FakeDisplayDelegate::RemoveDisplay(int64_t display_id) {
57 // Find display snapshot with matching id and remove it.
58 for (auto iter = displays_.begin(); iter != displays_.end(); ++iter) {
59 if ((*iter)->display_id() == display_id) {
60 displays_.erase(iter);
61 OnConfigurationChanged();
62 return true;
63 }
64 }
65
66 return false;
67 }
68
69 void FakeDisplayDelegate::Initialize() {
70 DCHECK(!initialized_);
71 InitFromCommandLine();
72
73 // If no command line flags are provided then initialize a default display.
74 if (displays_.empty())
75 AddDisplay(gfx::Size(1024, 768));
76
77 initialized_ = true;
78 }
79
80 void FakeDisplayDelegate::GrabServer() {}
81
82 void FakeDisplayDelegate::UngrabServer() {}
83
84 void FakeDisplayDelegate::TakeDisplayControl(
85 const ui::DisplayControlCallback& callback) {
86 callback.Run(false);
87 }
88
89 void FakeDisplayDelegate::RelinquishDisplayControl(
90 const ui::DisplayControlCallback& callback) {
91 callback.Run(false);
92 }
93
94 void FakeDisplayDelegate::SyncWithServer() {}
95
96 void FakeDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {}
97
98 void FakeDisplayDelegate::ForceDPMSOn() {}
99
100 void FakeDisplayDelegate::GetDisplays(const ui::GetDisplaysCallback& callback) {
101 std::vector<ui::DisplaySnapshot*> displays;
102 for (auto& display : displays_)
103 displays.push_back(display.get());
104 callback.Run(displays);
105 }
106
107 void FakeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output,
108 const ui::DisplayMode* mode) {}
109
110 void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output,
111 const ui::DisplayMode* mode,
112 const gfx::Point& origin,
113 const ui::ConfigureCallback& callback) {
114 callback.Run(true);
115 }
116
117 void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {}
118
119 void FakeDisplayDelegate::GetHDCPState(
120 const ui::DisplaySnapshot& output,
121 const ui::GetHDCPStateCallback& callback) {
122 callback.Run(false, ui::HDCP_STATE_UNDESIRED);
123 }
124
125 void FakeDisplayDelegate::SetHDCPState(
126 const ui::DisplaySnapshot& output,
127 ui::HDCPState state,
128 const ui::SetHDCPStateCallback& callback) {
129 callback.Run(false);
130 }
131
132 std::vector<ui::ColorCalibrationProfile>
133 FakeDisplayDelegate::GetAvailableColorCalibrationProfiles(
134 const ui::DisplaySnapshot& output) {
135 return std::vector<ui::ColorCalibrationProfile>();
136 }
137
138 bool FakeDisplayDelegate::SetColorCalibrationProfile(
139 const ui::DisplaySnapshot& output,
140 ui::ColorCalibrationProfile new_profile) {
141 return false;
142 }
143
144 bool FakeDisplayDelegate::SetColorCorrection(
145 const ui::DisplaySnapshot& output,
146 const std::vector<ui::GammaRampRGBEntry>& degamma_lut,
147 const std::vector<ui::GammaRampRGBEntry>& gamma_lut,
148 const std::vector<float>& correction_matrix) {
149 return false;
150 }
151
152 void FakeDisplayDelegate::AddObserver(ui::NativeDisplayObserver* observer) {
153 observers_.AddObserver(observer);
154 }
155
156 void FakeDisplayDelegate::RemoveObserver(ui::NativeDisplayObserver* observer) {
157 observers_.RemoveObserver(observer);
158 }
159
160 FakeDisplayController* FakeDisplayDelegate::GetFakeDisplayController() {
161 return static_cast<FakeDisplayController*>(this);
162 }
163
164 void FakeDisplayDelegate::InitFromCommandLine() {
165 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
166 if (!command_line->HasSwitch(switches::kScreenConfig))
167 return;
168
169 const std::string command_string =
170 command_line->GetSwitchValueASCII(switches::kScreenConfig);
171
172 // Split on commas and parse each display string.
173 for (std::string part : base::SplitString(
174 command_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
175 int width = 0;
176 int height = 0;
177 if (sscanf(part.c_str(), "%dx%d", &width, &height) >= 2) {
178 gfx::Size display_size(width, height);
179 AddDisplay(display_size);
180 } else {
181 LOG(ERROR) << "Failed to parse display \"" << part << "\"";
182 }
183 }
184 }
185
186 void FakeDisplayDelegate::OnConfigurationChanged() {
187 if (!initialized_)
188 return;
189
190 FOR_EACH_OBSERVER(ui::NativeDisplayObserver, observers_,
191 OnConfigurationChanged());
192 }
193
194 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698