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

Unified Diff: ash/display/display_util_x11.cc

Issue 21297003: Add ability to set resolution on external display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ash/display/display_util_x11.cc
diff --git a/ash/display/display_util_x11.cc b/ash/display/display_util_x11.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1fc19c2a00fc449b50de62fe8b86f320d62276e7
--- /dev/null
+++ b/ash/display/display_util_x11.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/display/display_util_x11.h"
+
+#include <algorithm>
+#include <map>
+#include <X11/extensions/Xrandr.h>
+
+#include "ash/display/display_info.h"
+#include "base/logging.h"
+#include "chromeos/display/output_util.h"
+
+namespace ash {
+namespace internal {
+namespace {
+
+// A list of bogus sizes in mm that X detects and should be ignored.
Daniel Erat 2013/07/31 17:34:05 nit: s/and should/and that should/
oshima 2013/07/31 21:59:49 Done.
+// See crbug.com/136533.
+const unsigned long kInvalidDisplaySizeList[][2] = {
Daniel Erat 2013/07/31 17:34:05 add a comment stating that this needs to be sorted
oshima 2013/07/31 21:59:49 Only requirement is the 1st element is minimum siz
+ {40, 30},
+ {50, 40},
+ {160, 90},
+ {160, 100},
+};
+
+// Resolution list are sorted by area and the larger one comes first.
+struct ResolutionSorter {
+ bool operator()(const Resolution& a, const Resolution& b) {
+ return a.size.width() * a.size.height() > b.size.width() * b.size.height();
+ }
+};
+
+} // namespace
+
+bool ShouldIgnoreSize(unsigned long mm_width, unsigned long mm_height) {
+ // Ignore if the reported display is smaller than minimum size.
+ if (mm_width <= kInvalidDisplaySizeList[0][0] ||
+ mm_height <= kInvalidDisplaySizeList[0][1]) {
+ LOG(WARNING) << "Smaller than minimum display size";
+ return true;
+ }
+ for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) {
+ const unsigned long* size = kInvalidDisplaySizeList[i];
+ if (mm_width == size[0] && mm_height == size[1]) {
+ LOG(WARNING) << "Black listed display size detected:"
+ << size[0] << "x" << size[1];
+ return true;
+ }
+ }
+ return false;
+}
+
+std::vector<Resolution> GetResolutionList(
+ XRRScreenResources* screen_resources,
+ XRROutputInfo* output_info) {
+ typedef std::map<std::pair<int,int>, Resolution> ResolutionMap;
+
+ ResolutionMap resolution_map;
+
+ for (int i = 0; i < output_info->nmode; i++) {
+ RRMode mode = output_info->modes[i];
+ const XRRModeInfo* info = chromeos::FindModeInfo(screen_resources, mode);
+ DCHECK(info);
+ // Just ignore bad entry on Release build.
+ if (!info)
+ continue;
+ ResolutionMap::key_type size = std::make_pair(info->width, info->height);
+ bool interlaced = (info->modeFlags & RR_Interlace) != 0;
+
+ ResolutionMap::iterator iter = resolution_map.find(size);
+
+ // Add new resolution if it's new size or override interlaced mode.
+ if (iter == resolution_map.end()) {
+ resolution_map.insert(ResolutionMap::value_type(
Daniel Erat 2013/07/31 17:34:05 why not just do: resolution_map[size] = Resolut
oshima 2013/07/31 21:59:49 That didn't work because Resolution doesn't have d
Daniel Erat 2013/07/31 22:10:17 ah, makes sense. this seems fine
+ size,
+ Resolution(gfx::Size(info->width, info->height), interlaced)));
+ } else if (iter->second.interlaced && !interlaced) {
+ iter->second.interlaced = false;
+ }
+ }
+
+ std::vector<Resolution> resolution_list;
+ for (ResolutionMap::const_iterator iter = resolution_map.begin();
+ iter != resolution_map.end();
+ ++iter) {
+ resolution_list.push_back(iter->second);
+ }
+ std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter());
+ return resolution_list;
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698