| 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/native_viewport/platform_viewport.h" | |
| 15 #include "components/view_manager/public/interfaces/display.mojom.h" | 14 #include "components/view_manager/public/interfaces/display.mojom.h" |
| 15 #include "components/view_manager/public/interfaces/native_viewport.mojom.h" |
| 16 #include "components/view_manager/public/interfaces/view_manager.mojom.h" | 16 #include "components/view_manager/public/interfaces/view_manager.mojom.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 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 class SurfaceIdAllocator; | 21 class SurfaceIdAllocator; |
| 22 } // namespace cc | 22 } |
| 23 | |
| 24 namespace gles2 { | |
| 25 class GpuState; | |
| 26 } // namespace gles2 | |
| 27 | |
| 28 namespace native_viewport { | |
| 29 class OnscreenContextProvider; | |
| 30 } // namespace native_viewport | |
| 31 | 23 |
| 32 namespace mojo { | 24 namespace mojo { |
| 33 class ApplicationImpl; | 25 class ApplicationImpl; |
| 34 } // namespace mojo | 26 } |
| 35 | 27 |
| 36 namespace view_manager { | 28 namespace view_manager { |
| 37 | 29 |
| 38 class EventDispatcher; | |
| 39 class ConnectionManager; | 30 class ConnectionManager; |
| 40 class ServerView; | 31 class ServerView; |
| 41 | 32 |
| 42 // DisplayManager is used to connect the root ServerView to a display. | 33 // DisplayManager is used to connect the root ServerView to a display. |
| 43 class DisplayManager { | 34 class DisplayManager { |
| 44 public: | 35 public: |
| 45 virtual ~DisplayManager() {} | 36 virtual ~DisplayManager() {} |
| 46 | 37 |
| 47 virtual void Init( | 38 virtual void Init( |
| 48 ConnectionManager* connection_manager, | 39 ConnectionManager* connection_manager, |
| 49 EventDispatcher* event_dispatcher) = 0; | 40 mojo::NativeViewportEventDispatcherPtr event_dispatcher) = 0; |
| 50 | 41 |
| 51 // Schedules a paint for the specified region in the coordinates of |view|. | 42 // Schedules a paint for the specified region in the coordinates of |view|. |
| 52 virtual void SchedulePaint(const ServerView* view, | 43 virtual void SchedulePaint(const ServerView* view, |
| 53 const gfx::Rect& bounds) = 0; | 44 const gfx::Rect& bounds) = 0; |
| 54 | 45 |
| 55 virtual void SetViewportSize(const gfx::Size& size) = 0; | 46 virtual void SetViewportSize(const gfx::Size& size) = 0; |
| 56 | 47 |
| 57 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0; | 48 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0; |
| 58 }; | 49 }; |
| 59 | 50 |
| 60 // DisplayManager implementation that connects to the services necessary to | 51 // DisplayManager implementation that connects to the services necessary to |
| 61 // actually display. | 52 // actually display. |
| 62 class DefaultDisplayManager : | 53 class DefaultDisplayManager : public DisplayManager, |
| 63 public DisplayManager, | 54 public mojo::ErrorHandler { |
| 64 public native_viewport::PlatformViewport::Delegate { | |
| 65 public: | 55 public: |
| 66 DefaultDisplayManager( | 56 DefaultDisplayManager( |
| 67 bool is_headless, | |
| 68 mojo::ApplicationImpl* app_impl, | 57 mojo::ApplicationImpl* app_impl, |
| 69 const scoped_refptr<gles2::GpuState>& gpu_state, | 58 const mojo::Callback<void()>& native_viewport_closed_callback); |
| 70 const mojo::Callback<void()>& platform_viewport_closed_callback); | |
| 71 ~DefaultDisplayManager() override; | 59 ~DefaultDisplayManager() override; |
| 72 | 60 |
| 73 // DisplayManager: | 61 // DisplayManager: |
| 74 void Init(ConnectionManager* connection_manager, | 62 void Init(ConnectionManager* connection_manager, |
| 75 EventDispatcher* event_dispatcher) override; | 63 mojo::NativeViewportEventDispatcherPtr event_dispatcher) override; |
| 76 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; | 64 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; |
| 77 void SetViewportSize(const gfx::Size& size) override; | 65 void SetViewportSize(const gfx::Size& size) override; |
| 78 const mojo::ViewportMetrics& GetViewportMetrics() override; | 66 const mojo::ViewportMetrics& GetViewportMetrics() override; |
| 79 | 67 |
| 80 private: | 68 private: |
| 81 void WantToDraw(); | 69 void WantToDraw(); |
| 82 void Draw(); | 70 void Draw(); |
| 83 void DidDraw(); | 71 void DidDraw(); |
| 84 | 72 |
| 85 // PlatformViewport::Delegate implementation: | 73 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics); |
| 86 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, | |
| 87 float device_pixel_ratio) override; | |
| 88 void OnAcceleratedWidgetDestroyed() override; | |
| 89 void OnEvent(mojo::EventPtr event) override; | |
| 90 void OnMetricsChanged(const gfx::Size& size, | |
| 91 float device_scale_factor) override; | |
| 92 void OnDestroyed() override; | |
| 93 | 74 |
| 94 bool is_headless_; | 75 // ErrorHandler: |
| 76 void OnConnectionError() override; |
| 77 |
| 95 mojo::ApplicationImpl* app_impl_; | 78 mojo::ApplicationImpl* app_impl_; |
| 96 scoped_refptr<gles2::GpuState> gpu_state_; | |
| 97 ConnectionManager* connection_manager_; | 79 ConnectionManager* connection_manager_; |
| 98 EventDispatcher* event_dispatcher_; | |
| 99 | 80 |
| 100 mojo::ViewportMetrics metrics_; | 81 mojo::ViewportMetrics metrics_; |
| 101 gfx::Rect dirty_rect_; | 82 gfx::Rect dirty_rect_; |
| 102 base::Timer draw_timer_; | 83 base::Timer draw_timer_; |
| 103 bool frame_pending_; | 84 bool frame_pending_; |
| 104 | 85 |
| 105 mojo::DisplayPtr display_; | 86 mojo::DisplayPtr display_; |
| 106 scoped_ptr<native_viewport::OnscreenContextProvider> context_provider_; | 87 mojo::NativeViewportPtr native_viewport_; |
| 107 scoped_ptr<native_viewport::PlatformViewport> platform_viewport_; | 88 mojo::Callback<void()> native_viewport_closed_callback_; |
| 108 mojo::Callback<void()> platform_viewport_closed_callback_; | |
| 109 | |
| 110 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; | 89 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; |
| 111 | 90 |
| 112 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); | 91 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); |
| 113 }; | 92 }; |
| 114 | 93 |
| 115 } // namespace view_manager | 94 } // namespace view_manager |
| 116 | 95 |
| 117 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ | 96 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_ |
| OLD | NEW |