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

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

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

Powered by Google App Engine
This is Rietveld 408576698