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