| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 #ifndef COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | |
| 6 #define COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/timer/timer.h" | |
| 14 #include "components/view_manager/display_manager_delegate.h" | |
| 15 #include "components/view_manager/public/interfaces/view_tree.mojom.h" | |
| 16 #include "components/view_manager/surfaces/top_level_display_client.h" | |
| 17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" | |
| 18 #include "ui/gfx/geometry/rect.h" | |
| 19 #include "ui/platform_window/platform_window_delegate.h" | |
| 20 | |
| 21 namespace cc { | |
| 22 class SurfaceIdAllocator; | |
| 23 class SurfaceManager; | |
| 24 } // namespace cc | |
| 25 | |
| 26 namespace gles2 { | |
| 27 class GpuState; | |
| 28 } // namespace gles2 | |
| 29 | |
| 30 namespace mojo { | |
| 31 class ApplicationImpl; | |
| 32 } // namespace mojo | |
| 33 | |
| 34 namespace surfaces { | |
| 35 class SurfacesScheduler; | |
| 36 class SurfacesState; | |
| 37 } // namespace surfaces | |
| 38 | |
| 39 namespace ui { | |
| 40 class PlatformWindow; | |
| 41 struct TextInputState; | |
| 42 } // namespace ui | |
| 43 | |
| 44 namespace view_manager { | |
| 45 | |
| 46 class DisplayManagerFactory; | |
| 47 class EventDispatcher; | |
| 48 class ServerView; | |
| 49 | |
| 50 // DisplayManager is used to connect the root ServerView to a display. | |
| 51 class DisplayManager { | |
| 52 public: | |
| 53 virtual ~DisplayManager() {} | |
| 54 | |
| 55 static DisplayManager* Create( | |
| 56 bool is_headless, | |
| 57 mojo::ApplicationImpl* app_impl, | |
| 58 const scoped_refptr<gles2::GpuState>& gpu_state, | |
| 59 const scoped_refptr<surfaces::SurfacesState>& surfaces_state); | |
| 60 | |
| 61 virtual void Init(DisplayManagerDelegate* delegate) = 0; | |
| 62 | |
| 63 // Schedules a paint for the specified region in the coordinates of |view|. | |
| 64 virtual void SchedulePaint(const ServerView* view, | |
| 65 const gfx::Rect& bounds) = 0; | |
| 66 | |
| 67 virtual void SetViewportSize(const gfx::Size& size) = 0; | |
| 68 | |
| 69 virtual void SetTitle(const base::string16& title) = 0; | |
| 70 | |
| 71 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0; | |
| 72 | |
| 73 virtual void UpdateTextInputState(const ui::TextInputState& state) = 0; | |
| 74 virtual void SetImeVisibility(bool visible) = 0; | |
| 75 | |
| 76 // Overrides factory for testing. Default (NULL) value indicates regular | |
| 77 // (non-test) environment. | |
| 78 static void set_factory_for_testing(DisplayManagerFactory* factory) { | |
| 79 DisplayManager::factory_ = factory; | |
| 80 } | |
| 81 | |
| 82 private: | |
| 83 // Static factory instance (always NULL for non-test). | |
| 84 static DisplayManagerFactory* factory_; | |
| 85 }; | |
| 86 | |
| 87 // DisplayManager implementation that connects to the services necessary to | |
| 88 // actually display. | |
| 89 class DefaultDisplayManager : | |
| 90 public DisplayManager, | |
| 91 public ui::PlatformWindowDelegate { | |
| 92 public: | |
| 93 DefaultDisplayManager( | |
| 94 bool is_headless, | |
| 95 mojo::ApplicationImpl* app_impl, | |
| 96 const scoped_refptr<gles2::GpuState>& gpu_state, | |
| 97 const scoped_refptr<surfaces::SurfacesState>& surfaces_state); | |
| 98 ~DefaultDisplayManager() override; | |
| 99 | |
| 100 // DisplayManager: | |
| 101 void Init(DisplayManagerDelegate* delegate) override; | |
| 102 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; | |
| 103 void SetViewportSize(const gfx::Size& size) override; | |
| 104 void SetTitle(const base::string16& title) override; | |
| 105 const mojo::ViewportMetrics& GetViewportMetrics() override; | |
| 106 void UpdateTextInputState(const ui::TextInputState& state) override; | |
| 107 void SetImeVisibility(bool visible) override; | |
| 108 | |
| 109 private: | |
| 110 void WantToDraw(); | |
| 111 void Draw(); | |
| 112 void DidDraw(); | |
| 113 void UpdateMetrics(const gfx::Size& size, float device_pixel_ratio); | |
| 114 | |
| 115 // ui::PlatformWindowDelegate: | |
| 116 void OnBoundsChanged(const gfx::Rect& new_bounds) override; | |
| 117 void OnDamageRect(const gfx::Rect& damaged_region) override; | |
| 118 void DispatchEvent(ui::Event* event) override; | |
| 119 void OnCloseRequest() override; | |
| 120 void OnClosed() override; | |
| 121 void OnWindowStateChanged(ui::PlatformWindowState new_state) override; | |
| 122 void OnLostCapture() override; | |
| 123 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, | |
| 124 float device_pixel_ratio) override; | |
| 125 void OnActivationChanged(bool active) override; | |
| 126 | |
| 127 bool is_headless_; | |
| 128 mojo::ApplicationImpl* app_impl_; | |
| 129 scoped_refptr<gles2::GpuState> gpu_state_; | |
| 130 scoped_refptr<surfaces::SurfacesState> surfaces_state_; | |
| 131 DisplayManagerDelegate* delegate_; | |
| 132 | |
| 133 mojo::ViewportMetrics metrics_; | |
| 134 gfx::Rect dirty_rect_; | |
| 135 base::Timer draw_timer_; | |
| 136 bool frame_pending_; | |
| 137 | |
| 138 scoped_ptr<surfaces::TopLevelDisplayClient> top_level_display_client_; | |
| 139 scoped_ptr<ui::PlatformWindow> platform_window_; | |
| 140 | |
| 141 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; | |
| 142 | |
| 143 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); | |
| 144 }; | |
| 145 | |
| 146 } // namespace view_manager | |
| 147 | |
| 148 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | |
| OLD | NEW |