12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/test/display_manager_test_api.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_info.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_split.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/display.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ash {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test {
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef std::vector<gfx::Display> DisplayList;
19c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochtypedef DisplayInfo DisplayInfo;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef std::vector<DisplayInfo> DisplayInfoList;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)std::vector<DisplayInfo> CreateDisplayInfoListFromString(
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const std::string specs,
26c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    DisplayManager* display_manager) {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<DisplayInfo> display_info_list;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<std::string> parts;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::SplitString(specs, ',', &parts);
30ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  size_t index = 0;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (std::vector<std::string>::const_iterator iter = parts.begin();
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       iter != parts.end(); ++iter, ++index) {
33ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    int64 id = index < display_manager->GetNumDisplays() ?
34ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        display_manager->GetDisplayAt(index).id() :
35ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        gfx::Display::kInvalidDisplayID;
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    display_info_list.push_back(
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        DisplayInfo::CreateFromSpecWithID(*iter, id));
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return display_info_list;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
44c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochDisplayManagerTestApi::DisplayManagerTestApi(DisplayManager* display_manager)
45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    : display_manager_(display_manager) {}
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DisplayManagerTestApi::~DisplayManagerTestApi() {}
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DisplayManagerTestApi::UpdateDisplay(
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const std::string& display_specs) {
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<DisplayInfo> display_info_list =
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      CreateDisplayInfoListFromString(display_specs, display_manager_);
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool is_host_origin_set = false;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < display_info_list.size(); ++i) {
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const DisplayInfo& display_info = display_info_list[i];
5668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      is_host_origin_set = true;
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // On non-testing environment, when a secondary display is connected, a new
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // native (i.e. X) window for the display is always created below the
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // previous one for GPU performance reasons. Try to emulate the behavior
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // unless host origins are explicitly set.
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!is_host_origin_set) {
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Sart from (1,1) so that windows won't overlap with native mouse cursor.
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // See |AshTestBase::SetUp()|.
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int next_y = 1;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (std::vector<DisplayInfo>::iterator iter = display_info_list.begin();
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         iter != display_info_list.end(); ++iter) {
7268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      gfx::Rect bounds(iter->bounds_in_native().size());
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bounds.set_x(1);
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bounds.set_y(next_y);
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      next_y += bounds.height();
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      iter->SetBounds(bounds);
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager_->OnNativeDisplaysChanged(display_info_list);
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int64 DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() {
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const gfx::Display& internal = display_manager_->displays_[0];
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(internal.id());
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::Display::InternalDisplayId();
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() {
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager_->set_change_display_upon_host_resize(false);
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
93e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochvoid DisplayManagerTestApi::SetAvailableColorProfiles(
94e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch    int64 display_id,
95e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch    const std::vector<ui::ColorCalibrationProfile>& profiles) {
96e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  display_manager_->display_info_[display_id].set_available_color_profiles(
97e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch      profiles);
98e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}
99e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace test
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace ash
102