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 MOJO_SERVICES_VIEW_MANAGER_DISPLAY_MANAGER_H_ 6 #define MOJO_SERVICES_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 "cc/surfaces/surface_id.h" 15 #include "mojo/public/cpp/bindings/callback.h" 16 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" 17 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h" 18 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" 19 #include "mojo/services/view_manager/view_manager_export.h" 20 #include "ui/gfx/rect.h" 21 22 namespace cc { 23 class SurfaceIdAllocator; 24 } 25 26 namespace mojo { 27 28 class ApplicationConnection; 29 30 namespace service { 31 32 class ConnectionManager; 33 class ServerView; 34 35 // DisplayManager binds the root node to an actual display. 36 class MOJO_VIEW_MANAGER_EXPORT DisplayManager NON_EXPORTED_BASE(public NativeViewportClient)37 : NON_EXPORTED_BASE(public NativeViewportClient), 38 NON_EXPORTED_BASE(public SurfaceClient) { 39 public: 40 DisplayManager(ApplicationConnection* app_connection, 41 ConnectionManager* connection_manager, 42 const Callback<void()>& native_viewport_closed_callback); 43 virtual ~DisplayManager(); 44 45 // Schedules a paint for the specified region of the specified view. 46 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds); 47 48 // See description above field for details. 49 bool in_setup() const { return in_setup_; } 50 51 private: 52 void OnSurfaceConnectionCreated(SurfacePtr surface, uint32_t id_namespace); 53 void Draw(); 54 55 // NativeViewportClient implementation. 56 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE; 57 virtual void OnDestroyed() OVERRIDE; 58 virtual void OnBoundsChanged(SizePtr bounds) OVERRIDE; 59 virtual void OnEvent(EventPtr event, 60 const mojo::Callback<void()>& callback) OVERRIDE; 61 62 // SurfaceClient implementation. 63 virtual void ReturnResources(Array<ReturnedResourcePtr> resources) OVERRIDE; 64 65 ConnectionManager* connection_manager_; 66 67 // Returns true if adding the root view's window to |window_tree_host_|. 68 bool in_setup_; 69 70 gfx::Size bounds_; 71 gfx::Rect dirty_rect_; 72 base::Timer draw_timer_; 73 74 SurfacesServicePtr surfaces_service_; 75 SurfacePtr surface_; 76 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; 77 cc::SurfaceId surface_id_; 78 NativeViewportPtr native_viewport_; 79 Callback<void()> native_viewport_closed_callback_; 80 base::WeakPtrFactory<DisplayManager> weak_factory_; 81 82 DISALLOW_COPY_AND_ASSIGN(DisplayManager); 83 }; 84 85 } // namespace service 86 } // namespace mojo 87 88 #endif // MOJO_SERVICES_VIEW_MANAGER_DISPLAY_MANAGER_H_ 89