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

Side by Side Diff: chromeos/display/output_configurator.h

Issue 24081004: chromeos: Fix display failures when going to mirrored mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: uploading yet again Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ 5 #ifndef CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_
6 #define CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ 6 #define CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 }; 37 };
38 38
39 // This class interacts directly with the underlying Xrandr API to manipulate 39 // This class interacts directly with the underlying Xrandr API to manipulate
40 // CTRCs and Outputs. 40 // CTRCs and Outputs.
41 class CHROMEOS_EXPORT OutputConfigurator 41 class CHROMEOS_EXPORT OutputConfigurator
42 : public base::MessageLoop::Dispatcher, 42 : public base::MessageLoop::Dispatcher,
43 public base::MessagePumpObserver { 43 public base::MessagePumpObserver {
44 public: 44 public:
45 struct ModeInfo { 45 struct ModeInfo {
46 ModeInfo(); 46 ModeInfo();
47 ModeInfo(int width, int height, bool interlaced); 47 ModeInfo(int width, int height, bool interlaced, float refresh_rate);
48 48
49 int width; 49 int width;
50 int height; 50 int height;
51 bool interlaced; 51 bool interlaced;
52 float refresh_rate;
52 }; 53 };
53 54
55 typedef std::map<RRMode, ModeInfo> ModeInfoMap;
56
54 struct CoordinateTransformation { 57 struct CoordinateTransformation {
55 // Initialized to the identity transformation. 58 // Initialized to the identity transformation.
56 CoordinateTransformation(); 59 CoordinateTransformation();
57 60
58 float x_scale; 61 float x_scale;
59 float x_offset; 62 float x_offset;
60 float y_scale; 63 float y_scale;
61 float y_offset; 64 float y_offset;
62 }; 65 };
63 66
(...skipping 25 matching lines...) Expand all
89 int y; 92 int y;
90 93
91 // Output's physical dimensions. 94 // Output's physical dimensions.
92 uint64 width_mm; 95 uint64 width_mm;
93 uint64 height_mm; 96 uint64 height_mm;
94 97
95 bool is_internal; 98 bool is_internal;
96 bool is_aspect_preserving_scaling; 99 bool is_aspect_preserving_scaling;
97 100
98 // Map from mode IDs to details about the corresponding modes. 101 // Map from mode IDs to details about the corresponding modes.
99 std::map<RRMode, ModeInfo> mode_infos; 102 ModeInfoMap mode_infos;
100 103
101 // XInput device ID or 0 if this output isn't a touchscreen. 104 // XInput device ID or 0 if this output isn't a touchscreen.
102 int touch_device_id; 105 int touch_device_id;
103 106
104 CoordinateTransformation transform; 107 CoordinateTransformation transform;
105 108
106 // Display id for this output. 109 // Display id for this output.
107 int64 display_id; 110 int64 display_id;
108 111
109 bool has_display_id; 112 bool has_display_id;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 156
154 // Called when the hardware mirroring failed. 157 // Called when the hardware mirroring failed.
155 virtual void SetSoftwareMirroring(bool enabled) = 0; 158 virtual void SetSoftwareMirroring(bool enabled) = 0;
156 }; 159 };
157 160
158 // Interface for classes that perform actions on behalf of OutputController. 161 // Interface for classes that perform actions on behalf of OutputController.
159 class Delegate { 162 class Delegate {
160 public: 163 public:
161 virtual ~Delegate() {} 164 virtual ~Delegate() {}
162 165
163 virtual void SetPanelFittingEnabled(bool enabled) = 0;
164
165 // Initializes the XRandR extension, saving the base event ID to 166 // Initializes the XRandR extension, saving the base event ID to
166 // |event_base|. 167 // |event_base|.
167 virtual void InitXRandRExtension(int* event_base) = 0; 168 virtual void InitXRandRExtension(int* event_base) = 0;
168 169
169 // Tells XRandR to update its configuration in response to |event|, an 170 // Tells XRandR to update its configuration in response to |event|, an
170 // RRScreenChangeNotify event. 171 // RRScreenChangeNotify event.
171 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0; 172 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) = 0;
172 173
173 // Grabs the X server and refreshes XRandR-related resources. While 174 // Grabs the X server and refreshes XRandR-related resources. While
174 // the server is grabbed, other clients are blocked. Must be balanced 175 // the server is grabbed, other clients are blocked. Must be balanced
175 // by a call to UngrabServer(). 176 // by a call to UngrabServer().
176 virtual void GrabServer() = 0; 177 virtual void GrabServer() = 0;
177 178
178 // Ungrabs the server and frees XRandR-related resources. 179 // Ungrabs the server and frees XRandR-related resources.
179 virtual void UngrabServer() = 0; 180 virtual void UngrabServer() = 0;
180 181
181 // Flushes all pending requests and waits for replies. 182 // Flushes all pending requests and waits for replies.
182 virtual void SyncWithServer() = 0; 183 virtual void SyncWithServer() = 0;
183 184
184 // Sets the window's background color to |color_argb|. 185 // Sets the window's background color to |color_argb|.
185 virtual void SetBackgroundColor(uint32 color_argb) = 0; 186 virtual void SetBackgroundColor(uint32 color_argb) = 0;
186 187
187 // Enables DPMS and forces it to the "on" state. 188 // Enables DPMS and forces it to the "on" state.
188 virtual void ForceDPMSOn() = 0; 189 virtual void ForceDPMSOn() = 0;
189 190
190 // Returns information about the current outputs. 191 // Returns information about the current outputs. This method may block for
191 // This method may block for 60 milliseconds or more. 192 // 60 milliseconds or more. The returned outputs are not fully initialized;
192 virtual std::vector<OutputSnapshot> GetOutputs( 193 // the rest of the work happens in OutputConfigurator::GetOutputs().
193 const StateController* state_controller) = 0; 194 virtual std::vector<OutputSnapshot> GetOutputs() = 0;
195
196 // Adds |mode| to |output|.
197 virtual void AddOutputMode(RROutput output, RRMode mode) = 0;
194 198
195 // Calls XRRSetCrtcConfig() with the given options but some of our default 199 // Calls XRRSetCrtcConfig() with the given options but some of our default
196 // output count and rotation arguments. Returns true on success. 200 // output count and rotation arguments. Returns true on success.
197 virtual bool ConfigureCrtc(RRCrtc crtc, 201 virtual bool ConfigureCrtc(RRCrtc crtc,
198 RRMode mode, 202 RRMode mode,
199 RROutput output, 203 RROutput output,
200 int x, 204 int x,
201 int y) = 0; 205 int y) = 0;
202 206
203 // Called to set the frame buffer (underlying XRR "screen") size. Has 207 // Called to set the frame buffer (underlying XRR "screen") size. Has
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // determining the DPI of the screen and rationalizing which screen we 268 // determining the DPI of the screen and rationalizing which screen we
265 // need to use for the DPI calculation. 269 // need to use for the DPI calculation.
266 // See crbug.com/130188 for initial discussion. 270 // See crbug.com/130188 for initial discussion.
267 static const int kVerticalGap = 60; 271 static const int kVerticalGap = 60;
268 272
269 // Returns a pointer to the ModeInfo struct in |output| corresponding to 273 // Returns a pointer to the ModeInfo struct in |output| corresponding to
270 // |mode|, or NULL if the struct isn't present. 274 // |mode|, or NULL if the struct isn't present.
271 static const ModeInfo* GetModeInfo(const OutputSnapshot& output, 275 static const ModeInfo* GetModeInfo(const OutputSnapshot& output,
272 RRMode mode); 276 RRMode mode);
273 277
278 // Returns the mode within |output| that matches the given size with highest
279 // refresh rate. Returns None if no matching output was found.
280 static RRMode FindOutputModeMatchingSize(const OutputSnapshot& output,
281 int width,
282 int height);
283
274 OutputConfigurator(); 284 OutputConfigurator();
275 virtual ~OutputConfigurator(); 285 virtual ~OutputConfigurator();
276 286
277 OutputState output_state() const { return output_state_; } 287 OutputState output_state() const { return output_state_; }
278 DisplayPowerState power_state() const { return power_state_; } 288 DisplayPowerState power_state() const { return power_state_; }
279 289
280 void set_state_controller(StateController* controller) { 290 void set_state_controller(StateController* controller) {
281 state_controller_ = controller; 291 state_controller_ = controller;
282 } 292 }
283 void set_mirroring_controller(SoftwareMirroringController* controller) { 293 void set_mirroring_controller(SoftwareMirroringController* controller) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 352
343 const std::map<int, float>& GetMirroredDisplayAreaRatioMap() { 353 const std::map<int, float>& GetMirroredDisplayAreaRatioMap() {
344 return mirrored_display_area_ratio_map_; 354 return mirrored_display_area_ratio_map_;
345 } 355 }
346 356
347 // Configure outputs with |kConfigureDelayMs| delay, 357 // Configure outputs with |kConfigureDelayMs| delay,
348 // so that time-consuming ConfigureOutputs() won't be called multiple times. 358 // so that time-consuming ConfigureOutputs() won't be called multiple times.
349 void ScheduleConfigureOutputs(); 359 void ScheduleConfigureOutputs();
350 360
351 private: 361 private:
352 // Configure outputs. 362 // Returns currently-connected outputs. This method is a wrapper around
363 // |delegate_->GetOutputs()| that does additional work, like finding the
364 // mirror mode and setting user-preferred modes. Note that the server must
365 // be grabbed via |delegate_->GrabServer()| first.
366 std::vector<OutputSnapshot> GetOutputs();
367
368 // Helper method for GetOutputs() that initializes the passed-in outputs'
369 // |mirror_mode| fields by looking for a mode in |internal_output| and
370 // |external_output| having the same resolution. Returns false if a shared
371 // mode wasn't found or created.
372 //
373 // |try_creating| allows creating a panel-fitting mode for |internal_output|
oshima 2013/09/17 15:22:14 nit: isn't it better to call this |try_panel_fitti
Daniel Erat 2013/09/17 15:53:27 Sure, done. (Also renamed the method to FindMirror
374 // instead of only searching for a matching mode (note that it may lead to a
375 // crash if |internal_info| is not capable of panel fitting).
376 //
377 // |preserve_aspect| limits the search/creation only to the modes having the
378 // native aspect ratio of |external_output|.
379 bool FindOrCreateMirrorMode(OutputSnapshot* internal_output,
380 OutputSnapshot* external_output,
381 bool try_creating,
382 bool preserve_aspect);
383
384 // Configures outputs.
353 void ConfigureOutputs(); 385 void ConfigureOutputs();
354 386
355 // Notifies observers about an attempted state change. 387 // Notifies observers about an attempted state change.
356 void NotifyObservers(bool success, OutputState attempted_state); 388 void NotifyObservers(bool success, OutputState attempted_state);
357 389
358 // Switches to the state specified in |output_state| and |power_state|. 390 // Switches to the state specified in |output_state| and |power_state|.
359 // If the hardware mirroring failed and |mirroring_controller_| is set, 391 // If the hardware mirroring failed and |mirroring_controller_| is set,
360 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()| 392 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()|
361 // to enable software based mirroring. 393 // to enable software based mirroring.
362 // On success, updates |output_state_|, |power_state_|, and |cached_outputs_| 394 // On success, updates |output_state_|, |power_state_|, and |cached_outputs_|
(...skipping 23 matching lines...) Expand all
386 418
387 // Returns the ratio between mirrored mode area and native mode area: 419 // Returns the ratio between mirrored mode area and native mode area:
388 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) 420 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height)
389 float GetMirroredDisplayAreaRatio( 421 float GetMirroredDisplayAreaRatio(
390 const OutputConfigurator::OutputSnapshot& output); 422 const OutputConfigurator::OutputSnapshot& output);
391 423
392 StateController* state_controller_; 424 StateController* state_controller_;
393 SoftwareMirroringController* mirroring_controller_; 425 SoftwareMirroringController* mirroring_controller_;
394 scoped_ptr<Delegate> delegate_; 426 scoped_ptr<Delegate> delegate_;
395 427
428 // Used to enable modes which rely on panel fitting.
429 bool is_panel_fitting_enabled_;
430
396 // Key of the map is the touch display's id, and the value of the map is the 431 // Key of the map is the touch display's id, and the value of the map is the
397 // touch display's area ratio in mirror mode defined as : 432 // touch display's area ratio in mirror mode defined as :
398 // mirror_mode_area / native_mode_area. 433 // mirror_mode_area / native_mode_area.
399 // This is used for scaling touch event's radius when the touch display is in 434 // This is used for scaling touch event's radius when the touch display is in
400 // mirror mode : 435 // mirror mode :
401 // new_touch_radius = sqrt(area_ratio) * old_touch_radius 436 // new_touch_radius = sqrt(area_ratio) * old_touch_radius
402 std::map<int, float> mirrored_display_area_ratio_map_; 437 std::map<int, float> mirrored_display_area_ratio_map_;
403 438
404 // This is detected by the constructor to determine whether or not we should 439 // This is detected by the constructor to determine whether or not we should
405 // be enabled. If we aren't running on ChromeOS, we can't assume that the 440 // be enabled. If we aren't running on ChromeOS, we can't assume that the
(...skipping 23 matching lines...) Expand all
429 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_; 464 scoped_ptr<base::OneShotTimer<OutputConfigurator> > configure_timer_;
430 465
431 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator); 466 DISALLOW_COPY_AND_ASSIGN(OutputConfigurator);
432 }; 467 };
433 468
434 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList; 469 typedef std::vector<OutputConfigurator::OutputSnapshot> OutputSnapshotList;
435 470
436 } // namespace chromeos 471 } // namespace chromeos
437 472
438 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_ 473 #endif // CHROMEOS_DISPLAY_OUTPUT_CONFIGURATOR_H_
OLDNEW
« no previous file with comments | « no previous file | chromeos/display/output_configurator.cc » ('j') | chromeos/display/output_configurator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698