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

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

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

Powered by Google App Engine
This is Rietveld 408576698