OLD | NEW |
---|---|
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 #include "remoting/host/desktop_resizer.h" | 5 #include "remoting/host/desktop_resizer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 virtual SkISize GetCurrentSize() OVERRIDE; | 26 virtual SkISize GetCurrentSize() OVERRIDE; |
27 virtual std::list<SkISize> GetSupportedSizes( | 27 virtual std::list<SkISize> GetSupportedSizes( |
28 const SkISize& preferred) OVERRIDE; | 28 const SkISize& preferred) OVERRIDE; |
29 virtual void SetSize(const SkISize& size) OVERRIDE; | 29 virtual void SetSize(const SkISize& size) OVERRIDE; |
30 virtual void RestoreSize(const SkISize& original) OVERRIDE; | 30 virtual void RestoreSize(const SkISize& original) OVERRIDE; |
31 | 31 |
32 private: | 32 private: |
33 static bool IsResizeSupported(); | 33 static bool IsResizeSupported(); |
34 | 34 |
35 // Calls EnumDisplaySettingsEx() for the primary monitor. | 35 // Calls EnumDisplaySettingsEx() for the primary monitor. |
36 // Returns a DEVMODE with no fields if |mode_number| does not exist. | 36 // Returns false if |mode_number| does not exist. |
37 static bool GetPrimaryDisplayMode( | 37 static bool GetPrimaryDisplayMode( |
38 DWORD mode_number, DWORD flags, DEVMODE* mode); | 38 DWORD mode_number, DWORD flags, DEVMODE* mode); |
39 | 39 |
40 // Returns true if the mode has width, height, bits-per-pixel, frequency | 40 // Returns true if the mode has width, height, bits-per-pixel, frequency |
41 // and orientation fields. | 41 // and orientation fields. |
42 static bool IsModeValid(const DEVMODE& mode); | 42 static bool IsModeValid(const DEVMODE& mode); |
43 | 43 |
44 // Returns the width & height of |mode|, or 0x0 if they are missing. | 44 // Returns the width & height of |mode|, or 0x0 if they are missing. |
45 static SkISize GetModeSize(const DEVMODE& mode); | 45 static SkISize GetModeSize(const DEVMODE& mode); |
46 | 46 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 break; | 84 break; |
85 | 85 |
86 // Ignore modes missing the fields that we expect. | 86 // Ignore modes missing the fields that we expect. |
87 if (!IsModeValid(candidate_mode)) | 87 if (!IsModeValid(candidate_mode)) |
88 continue; | 88 continue; |
89 | 89 |
90 // Ignore modes with differing bits-per-pixel. | 90 // Ignore modes with differing bits-per-pixel. |
91 if (candidate_mode.dmBitsPerPel != current_mode.dmBitsPerPel) | 91 if (candidate_mode.dmBitsPerPel != current_mode.dmBitsPerPel) |
92 continue; | 92 continue; |
93 | 93 |
94 // If there is an existing mode of the same dimensions, prefer the | 94 // If there is an existing mode of the same dimensions, choose the |
95 // one with the higher frequency. | 95 // closest match to the current mode. |
96 SkISize candidate_size = GetModeSize(candidate_mode); | 96 SkISize candidate_size = GetModeSize(candidate_mode); |
97 if (modes_.count(candidate_size) != 0) { | 97 if (modes_.count(candidate_size) != 0) { |
98 DEVMODE existing_mode = modes_[candidate_size]; | 98 DEVMODE existing_mode = modes_[candidate_size]; |
Jamie
2013/02/13 18:21:01
Would best_mode_for_size be a better name for this
Wez
2013/02/13 22:44:55
You mean modes_ -> best_mode_for_size_?
Jamie
2013/02/14 00:10:34
I meant best_mode_for_size instead of existing_mod
| |
99 if (existing_mode.dmDisplayFrequency > | 99 |
100 candidate_mode.dmDisplayFrequency) | 100 // Skip this mode if its rotation is a worse match for the current mode. |
101 if ((candidate_mode.dmDisplayOrientation != | |
102 current_mode.dmDisplayOrientation) && | |
103 (existing_mode.dmDisplayOrientation == | |
104 current_mode.dmDisplayOrientation)) { | |
Jamie
2013/02/13 18:21:01
This will never pick a portrait mode if the physic
Wez
2013/02/13 22:44:55
No. This logic applies iff the mode we're enumera
Jamie
2013/02/14 00:10:34
Oh, I see. I had it in mind that the API returned
| |
101 continue; | 105 continue; |
106 } | |
107 | |
108 // Skip this mode if its frequency does not match, and the existing | |
109 // choice has a higher frequency. | |
110 if ((candidate_mode.dmDisplayFrequency != | |
111 current_mode.dmDisplayFrequency) && | |
112 (existing_mode.dmDisplayFrequency >= | |
113 candidate_mode.dmDisplayFrequency)) { | |
114 continue; | |
115 } | |
102 } else { | 116 } else { |
103 // If we haven't seen this size before, add it to those we return. | 117 // If we haven't seen this size before, add it to those we return. |
104 sizes.push_back(candidate_size); | 118 sizes.push_back(candidate_size); |
105 } | 119 } |
106 | 120 |
107 modes_[candidate_size] = candidate_mode; | 121 modes_[candidate_size] = candidate_mode; |
108 } | 122 } |
109 | 123 |
110 return sizes; | 124 return sizes; |
111 } | 125 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 SkISize DesktopResizerWin::GetModeSize(const DEVMODE& mode) { | 169 SkISize DesktopResizerWin::GetModeSize(const DEVMODE& mode) { |
156 DCHECK(IsModeValid(mode)); | 170 DCHECK(IsModeValid(mode)); |
157 return SkISize::Make(mode.dmPelsWidth, mode.dmPelsHeight); | 171 return SkISize::Make(mode.dmPelsWidth, mode.dmPelsHeight); |
158 } | 172 } |
159 | 173 |
160 scoped_ptr<DesktopResizer> DesktopResizer::Create() { | 174 scoped_ptr<DesktopResizer> DesktopResizer::Create() { |
161 return scoped_ptr<DesktopResizer>(new DesktopResizerWin); | 175 return scoped_ptr<DesktopResizer>(new DesktopResizerWin); |
162 } | 176 } |
163 | 177 |
164 } // namespace remoting | 178 } // namespace remoting |
OLD | NEW |