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. 4 5 #include <stdio.h> 6 7 #include "ash/ash_switches.h" 8 #include "ash/display/display_layout_store.h" 9 #include "base/command_line.h" 10 #include "base/logging.h" 11 #include "ui/gfx/display.h" 12 13 namespace ash { 14 namespace internal { 15 16 DisplayLayoutStore::DisplayLayoutStore() { 17 CommandLine* command_line = CommandLine::ForCurrentProcess(); 18 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { 19 std::string value = command_line->GetSwitchValueASCII( 20 switches::kAshSecondaryDisplayLayout); 21 char layout; 22 int offset = 0; 23 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { 24 if (layout == 't') 25 default_display_layout_.position = DisplayLayout::TOP; 26 else if (layout == 'b') 27 default_display_layout_.position = DisplayLayout::BOTTOM; 28 else if (layout == 'r') 29 default_display_layout_.position = DisplayLayout::RIGHT; 30 else if (layout == 'l') 31 default_display_layout_.position = DisplayLayout::LEFT; 32 default_display_layout_.offset = offset; 33 } 34 } 35 } 36 37 DisplayLayoutStore::~DisplayLayoutStore() { 38 } 39 40 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout& layout) { 41 CommandLine* command_line = CommandLine::ForCurrentProcess(); 42 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) 43 default_display_layout_ = layout; 44 } 45 46 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair( 47 int64 id1, 48 int64 id2, 49 const DisplayLayout& layout) { 50 paired_layouts_[std::make_pair(id1, id2)] = layout; 51 } 52 53 DisplayLayout DisplayLayoutStore::GetRegisteredDisplayLayout( 54 const DisplayIdPair& pair) { 55 std::map<DisplayIdPair, DisplayLayout>::const_iterator iter = 56 paired_layouts_.find(pair); 57 return 58 iter != paired_layouts_.end() ? iter->second : CreateDisplayLayout(pair); 59 } 60 61 DisplayLayout DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair( 62 const DisplayIdPair& pair) { 63 DisplayLayout layout = GetRegisteredDisplayLayout(pair); 64 DCHECK_NE(layout.primary_id, gfx::Display::kInvalidDisplayID); 65 // Invert if the primary was swapped. If mirrored, first is always 66 // primary. 67 return (layout.primary_id == gfx::Display::kInvalidDisplayID || 68 pair.first == layout.primary_id) ? layout : layout.Invert(); 69 } 70 71 void DisplayLayoutStore::UpdateMirrorStatus(const DisplayIdPair& pair, 72 bool mirrored) { 73 if (paired_layouts_.find(pair) == paired_layouts_.end()) 74 CreateDisplayLayout(pair); 75 paired_layouts_[pair].mirrored = mirrored; 76 } 77 78 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair& pair, 79 int64 display_id) { 80 if (paired_layouts_.find(pair) == paired_layouts_.end()) 81 CreateDisplayLayout(pair); 82 paired_layouts_[pair].primary_id = display_id; 83 } 84 85 DisplayLayout DisplayLayoutStore::CreateDisplayLayout( 86 const DisplayIdPair& pair) { 87 DisplayLayout layout = default_display_layout_; 88 layout.primary_id = pair.first; 89 paired_layouts_[pair] = layout; 90 return layout; 91 } 92 93 } // namespace internal 94 } // namespace ash 95