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

Side by Side Diff: resolution_selector.cc

Issue 6854002: Merge monitor_reconfigure into powerd. (Closed) Base URL: ssh://gitrw.chromium.org:9222/power_manager.git@master
Patch Set: . Created 9 years, 8 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
« no previous file with comments | « resolution_selector.h ('k') | resolution_selector_unittest.cc » ('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 (c) 2011 The Chromium OS 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 "power_manager/resolution_selector.h"
6
7 #include "base/logging.h"
8
9 namespace power_manager {
10
11 using std::vector;
12
13 const int ResolutionSelector::kMaxProjectorPixels = 1280 * 720;
14
15 ResolutionSelector::Mode::Mode(int width, int height, std::string name, int id)
16 : width(width),
17 height(height),
18 name(name),
19 id(id) {
20 }
21
22 ResolutionSelector::Mode::Mode()
23 : width(0),
24 height(0),
25 name(""),
26 id(0) {
27 }
28
29 ResolutionSelector::ResolutionSelector() {
30 }
31
32 ResolutionSelector::~ResolutionSelector() {
33 }
34
35 bool ResolutionSelector::FindBestResolutions(
36 const vector<Mode>& lcd_modes,
37 const vector<Mode>& external_modes,
38 Mode* lcd_resolution,
39 Mode* external_resolution,
40 Mode* screen_resolution) {
41 DCHECK(!lcd_modes.empty());
42
43 // If there's no external display, just use the highest resolution
44 // available from the LCD.
45 if (external_modes.empty()) {
46 *lcd_resolution = *screen_resolution = lcd_modes[0];
47 external_resolution->name.clear();
48 return true;
49 }
50
51 const int max_lcd_size = lcd_modes[0].width * lcd_modes[0].height;
52 const int max_external_size =
53 external_modes[0].width * external_modes[0].height;
54
55 if (max_lcd_size >= max_external_size) {
56 return FindNearestResolutions(
57 lcd_modes, external_modes,
58 lcd_resolution, external_resolution, screen_resolution);
59 } else {
60 // If the external output is large enough that we think it's a monitor
61 // (as opposed to a projector), then we just use its max resolution and
62 // forget about trying to choose a screen size that'll fit on the
63 // built-in display.
64 if (max_external_size > kMaxProjectorPixels) {
65 *external_resolution = *screen_resolution = external_modes[0];
66 lcd_resolution->name.clear();
67 return true;
68 }
69 return FindNearestResolutions(
70 external_modes, lcd_modes,
71 external_resolution, lcd_resolution, screen_resolution);
72 }
73 }
74
75 bool ResolutionSelector::FindNearestResolutions(
76 const vector<Mode>& larger_device_modes,
77 const vector<Mode>& smaller_device_modes,
78 Mode* larger_resolution,
79 Mode* smaller_resolution,
80 Mode* screen_resolution) {
81 DCHECK(!larger_device_modes.empty());
82 DCHECK(!smaller_device_modes.empty());
83 DCHECK(larger_resolution);
84 DCHECK(smaller_resolution);
85 DCHECK(screen_resolution);
86
87 // Start with the best that the smaller device has to offer.
88 *smaller_resolution = smaller_device_modes[0];
89 *screen_resolution = *smaller_resolution;
90 int smaller_width = smaller_device_modes[0].width;
91 int smaller_height = smaller_device_modes[0].height;
92
93 for (vector<Mode>::const_reverse_iterator it =
94 larger_device_modes.rbegin();
95 it != larger_device_modes.rend(); ++it) {
96 if (it->width >= smaller_width && it->height >= smaller_height) {
97 *larger_resolution = *it;
98 return true;
99 }
100 }
101
102 LOG(WARNING) << "Failed to find a resolution from larger device "
103 << "exceeding chosen resolution from smaller device ("
104 << smaller_resolution->name << ")";
105 return false;
106 }
107
108 } // namespace power_manager
OLDNEW
« no previous file with comments | « resolution_selector.h ('k') | resolution_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698