Don't preload rarely seen large images
[chromium-blink-merge.git] / ash / display / display_layout_store.cc
blob3ef9134d01d12d023fc7d1836cf88a49995fb60b
1 // Copyright 2013 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.
5 #include <stdio.h>
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_layout_store.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "ui/gfx/display.h"
15 namespace ash {
17 DisplayLayoutStore::DisplayLayoutStore() {
18 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
19 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) {
20 std::string value = command_line->GetSwitchValueASCII(
21 switches::kAshSecondaryDisplayLayout);
22 char layout;
23 int offset = 0;
24 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) {
25 if (layout == 't')
26 default_display_layout_.position = DisplayLayout::TOP;
27 else if (layout == 'b')
28 default_display_layout_.position = DisplayLayout::BOTTOM;
29 else if (layout == 'r')
30 default_display_layout_.position = DisplayLayout::RIGHT;
31 else if (layout == 'l')
32 default_display_layout_.position = DisplayLayout::LEFT;
33 default_display_layout_.offset = offset;
38 DisplayLayoutStore::~DisplayLayoutStore() {
41 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout& layout) {
42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout))
44 default_display_layout_ = layout;
47 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair(
48 int64 id1,
49 int64 id2,
50 const DisplayLayout& layout) {
51 auto key = std::make_pair(id1, id2);
52 paired_layouts_[key] = layout;
53 #if defined(OS_CHROMEOS)
54 // Force disabling unified desktop if the flag is not set.
55 if (!switches::UnifiedDesktopEnabled())
56 paired_layouts_[key].default_unified = false;
57 #endif
60 DisplayLayout DisplayLayoutStore::GetRegisteredDisplayLayout(
61 const DisplayIdPair& pair) {
62 std::map<DisplayIdPair, DisplayLayout>::const_iterator iter =
63 paired_layouts_.find(pair);
64 return
65 iter != paired_layouts_.end() ? iter->second : CreateDisplayLayout(pair);
68 DisplayLayout DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair(
69 const DisplayIdPair& pair) {
70 DisplayLayout layout = GetRegisteredDisplayLayout(pair);
71 DCHECK_NE(layout.primary_id, gfx::Display::kInvalidDisplayID);
72 // Invert if the primary was swapped. If mirrored, first is always
73 // primary.
74 return (layout.primary_id == gfx::Display::kInvalidDisplayID ||
75 pair.first == layout.primary_id) ? layout : layout.Invert();
78 void DisplayLayoutStore::UpdateMultiDisplayState(const DisplayIdPair& pair,
79 bool mirrored,
80 bool default_unified) {
81 if (paired_layouts_.find(pair) == paired_layouts_.end())
82 CreateDisplayLayout(pair);
83 paired_layouts_[pair].mirrored = mirrored;
84 paired_layouts_[pair].default_unified = default_unified;
87 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair& pair,
88 int64 display_id) {
89 if (paired_layouts_.find(pair) == paired_layouts_.end())
90 CreateDisplayLayout(pair);
91 paired_layouts_[pair].primary_id = display_id;
94 DisplayLayout DisplayLayoutStore::CreateDisplayLayout(
95 const DisplayIdPair& pair) {
96 DisplayLayout layout = default_display_layout_;
97 layout.primary_id = pair.first;
98 paired_layouts_[pair] = layout;
99 return layout;
102 } // namespace ash