mirror_window_controller.cc revision 558790d6acca3451cf3a6b497803a5f07d0bec58
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/display/mirror_window_controller.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(USE_X11) 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <X11/Xlib.h> 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Xlib.h defines RootWindow. 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#undef RootWindow 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/display/display_controller.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/display/display_info.h" 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/display/display_manager.h" 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/display/root_window_transformers.h" 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/host/root_window_host_factory.h" 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/shell.h" 207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ash/wm/window_properties.h" 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h" 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/client/capture_client.h" 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/env.h" 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/root_window.h" 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/aura/root_window_transformer.h" 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/aura/window_delegate.h" 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/cursor/cursors_aura.h" 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/hit_test.h" 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/layout.h" 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 31558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "ui/compositor/reflector.h" 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/canvas.h" 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/image/image_skia.h" 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/image/image_skia_operations.h" 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/native_widget_types.h" 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ash { 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace internal { 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace { 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(USE_X11) 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Mirror window shouldn't handle input events. 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void DisableInput(XID window) { 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) long event_mask = ExposureMask | VisibilityChangeMask | 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) StructureNotifyMask | PropertyChangeMask; 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) XSelectInput(base::MessagePumpAuraX11::GetDefaultXDisplay(), 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) window, event_mask); 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class NoneCaptureClient : public aura::client::CaptureClient { 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NoneCaptureClient() {} 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~NoneCaptureClient() {} 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Does a capture on the |window|. 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void SetCapture(aura::Window* window) OVERRIDE {} 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Releases a capture from the |window|. 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void ReleaseCapture(aura::Window* window) OVERRIDE {} 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the current capture window. 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual aura::Window* GetCaptureWindow() OVERRIDE { 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return NULL; 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NoneCaptureClient); 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CursorWindowDelegate : public aura::WindowDelegate { 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CursorWindowDelegate() {} 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~CursorWindowDelegate() {} 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // aura::WindowDelegate overrides: 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual gfx::Size GetMinimumSize() const OVERRIDE { 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return size_; 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual gfx::Size GetMaximumSize() const OVERRIDE { 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return size_; 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const gfx::Rect& new_bounds) OVERRIDE { 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return gfx::kNullCursor; 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual int GetNonClientComponent( 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const gfx::Point& point) const OVERRIDE { 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return HTNOWHERE; 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool ShouldDescendIntoChildForEventHandling( 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) aura::Window* child, 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const gfx::Point& location) OVERRIDE { 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool CanFocus() OVERRIDE { 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnCaptureLost() OVERRIDE { 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) canvas->DrawImageInt(cursor_image_, 0, 0); 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnDeviceScaleFactorChanged( 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) float device_scale_factor) OVERRIDE { 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnWindowDestroying() OVERRIDE {} 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnWindowDestroyed() OVERRIDE {} 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE { 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool HasHitTestMask() const OVERRIDE { 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return false; 11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { 12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NOTREACHED(); 12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return scoped_refptr<ui::Texture>(); 12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Set the cursor image for the |display|'s scale factor. Note that 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // mirror window's scale factor is always 1.0f, therefore we need to 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // take 2x's image and paint as if it's 1x image. 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void SetCursorImage(const gfx::ImageSkia& image, 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::Display& display) { 129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) device_scale_factor_ = 130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ui::GetScaleFactorFromScale(display.device_scale_factor()); 131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::ImageSkiaRep& image_rep = 132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) image.GetRepresentation(device_scale_factor_); 133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) size_ = image_rep.pixel_size(); 134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_image_ = gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap()); 13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::Size size() const { return size_; } 138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::ImageSkia cursor_image_; 141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ui::ScaleFactor device_scale_factor_; 142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) gfx::Size size_; 14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(CursorWindowDelegate); 14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 14690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 14790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MirrorWindowController::MirrorWindowController() 14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : current_cursor_type_(ui::kCursorNone), 1497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) current_cursor_rotation_(gfx::Display::ROTATE_0), 15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) cursor_window_(NULL), 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) cursor_window_delegate_(new CursorWindowDelegate) { 15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MirrorWindowController::~MirrorWindowController() { 15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Make sure the root window gets deleted before cursor_window_delegate. 156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Close(); 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void MirrorWindowController::UpdateWindow(const DisplayInfo& display_info) { 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static int mirror_root_window_count = 0; 161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!root_window_.get()) { 163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::Rect& bounds_in_pixel = display_info.bounds_in_pixel(); 164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) aura::RootWindow::CreateParams params(bounds_in_pixel); 165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) params.host = Shell::GetInstance()->root_window_host_factory()-> 166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CreateRootWindowHost(bounds_in_pixel); 167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_.reset(new aura::RootWindow(params)); 168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->SetName( 169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::StringPrintf("MirrorRootWindow-%d", mirror_root_window_count++)); 170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->compositor()->SetBackgroundColor(SK_ColorBLACK); 171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // No need to remove RootWindowObserver because 1727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // the DisplayController object outlives RootWindow objects. 1737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch root_window_->AddRootWindowObserver( 1747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch Shell::GetInstance()->display_controller()); 175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->AddRootWindowObserver(this); 176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // TODO(oshima): TouchHUD is using idkey. 177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->SetProperty(internal::kDisplayIdKey, display_info.id()); 178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->Init(); 17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(USE_X11) 180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DisableInput(root_window_->GetAcceleratedWidget()); 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) aura::client::SetCaptureClient(root_window_.get(), new NoneCaptureClient()); 184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->ShowRootWindow(); 185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // TODO(oshima): Start mirroring. 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) aura::Window* mirror_window = new aura::Window(NULL); 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_window->Init(ui::LAYER_TEXTURED); 189868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->AddChild(mirror_window); 190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_window->SetBounds(root_window_->bounds()); 191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_window->Show(); 192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) reflector_ = ui::ContextFactory::GetInstance()-> 193868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CreateReflector(Shell::GetPrimaryRootWindow()->compositor(), 194868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_window->layer()); 195868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_window_ = new aura::Window(cursor_window_delegate_.get()); 197868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_window_->SetTransparent(true); 198868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_window_->Init(ui::LAYER_TEXTURED); 199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->AddChild(cursor_window_); 200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_window_->Show(); 201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } else { 202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->SetProperty(internal::kDisplayIdKey, display_info.id()); 203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->SetHostBounds(display_info.bounds_in_pixel()); 204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( 208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetScreen()->GetPrimaryDisplay().id()); 209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(display_manager->mirrored_display().is_valid()); 210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<aura::RootWindowTransformer> transformer( 211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) internal::CreateRootWindowTransformerForMirroredDisplay( 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) source_display_info, 213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) display_info)); 214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->SetRootWindowTransformer(transformer.Pass()); 215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UpdateCursorLocation(); 217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void MirrorWindowController::UpdateWindow() { 220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (root_window_.get()) { 221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( 223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) display_manager->mirrored_display().id()); 224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) UpdateWindow(mirror_display_info); 225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 22690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 22790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void MirrorWindowController::Close() { 22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (root_window_.get()) { 230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ui::ContextFactory::GetInstance()->RemoveReflector(reflector_); 231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) reflector_ = NULL; 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NoneCaptureClient* capture_client = static_cast<NoneCaptureClient*>( 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) aura::client::GetCaptureClient(root_window_.get())); 23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delete capture_client; 235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->RemoveRootWindowObserver( 2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch Shell::GetInstance()->display_controller()); 238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) root_window_->RemoveRootWindowObserver(this); 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) root_window_.reset(); 24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) cursor_window_ = NULL; 24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void MirrorWindowController::UpdateCursorLocation() { 24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (cursor_window_) { 246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // TODO(oshima): Rotate cursor image (including hotpoint). 24790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Point point = aura::Env::GetInstance()->last_mouse_location(); 248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetPrimaryRootWindow()->ConvertPointToHost(&point); 24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) point.Offset(-hot_point_.x(), -hot_point_.y()); 25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect bounds = cursor_window_->bounds(); 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bounds.set_origin(point); 25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) cursor_window_->SetBounds(bounds); 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void MirrorWindowController::SetMirroredCursor(gfx::NativeCursor cursor) { 2577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Display& display = Shell::GetScreen()->GetPrimaryDisplay(); 2587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (current_cursor_type_ == cursor.native_type() && 2597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) current_cursor_rotation_ == display.rotation()) 26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return; 26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) current_cursor_type_ = cursor.native_type(); 2627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) current_cursor_rotation_ = display.rotation(); 26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int resource_id; 26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool success = ui::GetCursorDataFor( 265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) current_cursor_type_, 266868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) display.device_scale_factor(), 267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) &resource_id, 268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) &hot_point_); 26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (!success) 27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return; 27190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const gfx::ImageSkia* image = 27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 2737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gfx::ImageSkia rotated = *image; 2747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) switch (current_cursor_rotation_) { 2757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case gfx::Display::ROTATE_0: 2767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 2777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case gfx::Display::ROTATE_90: 2787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated = gfx::ImageSkiaOperations::CreateRotatedImage( 2797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) *image, SkBitmapOperations::ROTATION_90_CW); 2807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) hot_point_.SetPoint( 2817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated.width() - hot_point_.y(), 2827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) hot_point_.x()); 2837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 2847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case gfx::Display::ROTATE_180: 2857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated = gfx::ImageSkiaOperations::CreateRotatedImage( 2867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) *image, SkBitmapOperations::ROTATION_180_CW); 2877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) hot_point_.SetPoint( 2887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated.height() - hot_point_.x(), 2897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated.width() - hot_point_.y()); 2907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 2917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) case gfx::Display::ROTATE_270: 2927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated = gfx::ImageSkiaOperations::CreateRotatedImage( 2937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) *image, SkBitmapOperations::ROTATION_270_CW); 2947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) hot_point_.SetPoint( 2957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) hot_point_.y(), 2967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) rotated.height() - hot_point_.x()); 2977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) break; 2987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 2997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) cursor_window_delegate_->SetCursorImage(rotated, display); 3007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 30190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (cursor_window_) { 302868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) cursor_window_->SetBounds(gfx::Rect(cursor_window_delegate_->size())); 30390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) cursor_window_->SchedulePaintInRect( 30490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect(cursor_window_->bounds().size())); 30590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) UpdateCursorLocation(); 30690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 30890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 30990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void MirrorWindowController::SetMirroredCursorVisibility(bool visible) { 31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (cursor_window_) 31190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) visible ? cursor_window_->Show() : cursor_window_->Hide(); 31290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 31390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void MirrorWindowController::OnRootWindowHostResized( 3157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const aura::RootWindow* root) { 316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Do not use |old_size| as it contains RootWindow's (but not host's) size, 317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // and this parameter wil be removed soon. 318868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (mirror_window_host_size_ == root->GetHostSize()) 319868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return; 320868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_window_host_size_ = root->GetHostSize(); 321868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) reflector_->OnMirroringCompositorResized(); 3227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) root_window_->SetRootWindowTransformer( 3237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) CreateRootWindowTransformer().Pass()); 3247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) UpdateCursorLocation(); 3257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 3267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 3287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)scoped_ptr<aura::RootWindowTransformer> 3297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)MirrorWindowController::CreateRootWindowTransformer() const { 330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 331868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( 332868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) display_manager->mirrored_display().id()); 333868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( 334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Shell::GetScreen()->GetPrimaryDisplay().id()); 335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DCHECK(display_manager->mirrored_display().is_valid()); 3367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return scoped_ptr<aura::RootWindowTransformer>( 337868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) internal::CreateRootWindowTransformerForMirroredDisplay( 338868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) source_display_info, 339868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) mirror_display_info)); 340868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 341868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 34290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace internal 34390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace ash 344