OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "mojo/services/native_viewport/native_viewport_service.h" | 5 #include "mojo/services/native_viewport/native_viewport_service.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "gpu/command_buffer/service/mailbox_manager.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/interface_factory.h" | 13 #include "mojo/public/cpp/application/interface_factory.h" |
13 #include "mojo/services/gles2/command_buffer_impl.h" | 14 #include "mojo/services/gles2/command_buffer_impl.h" |
14 #include "mojo/services/native_viewport/native_viewport.h" | 15 #include "mojo/services/native_viewport/native_viewport.h" |
15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
16 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 17 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
17 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 18 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/gl/gl_share_group.h" |
19 | 21 |
20 namespace mojo { | 22 namespace mojo { |
21 namespace services { | 23 namespace services { |
22 namespace { | 24 namespace { |
23 | 25 |
24 bool IsRateLimitedEventType(ui::Event* event) { | 26 bool IsRateLimitedEventType(ui::Event* event) { |
25 return event->type() == ui::ET_MOUSE_MOVED || | 27 return event->type() == ui::ET_MOUSE_MOVED || |
26 event->type() == ui::ET_MOUSE_DRAGGED || | 28 event->type() == ui::ET_MOUSE_DRAGGED || |
27 event->type() == ui::ET_TOUCH_MOVED; | 29 event->type() == ui::ET_TOUCH_MOVED; |
28 } | 30 } |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, | 34 class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, |
33 public NativeViewportDelegate { | 35 public NativeViewportDelegate { |
34 public: | 36 public: |
35 NativeViewportImpl() | 37 NativeViewportImpl( |
| 38 const scoped_refptr<gfx::GLShareGroup>& share_group, |
| 39 const scoped_refptr<gpu::gles2::MailboxManager>& mailbox_manager) |
36 : widget_(gfx::kNullAcceleratedWidget), | 40 : widget_(gfx::kNullAcceleratedWidget), |
37 waiting_for_event_ack_(false), | 41 waiting_for_event_ack_(false), |
| 42 share_group_(share_group), |
| 43 mailbox_manager_(mailbox_manager), |
38 weak_factory_(this) {} | 44 weak_factory_(this) {} |
39 virtual ~NativeViewportImpl() { | 45 virtual ~NativeViewportImpl() { |
40 // Destroy the NativeViewport early on as it may call us back during | 46 // Destroy the NativeViewport early on as it may call us back during |
41 // destruction and we want to be in a known state. | 47 // destruction and we want to be in a known state. |
42 native_viewport_.reset(); | 48 native_viewport_.reset(); |
43 } | 49 } |
44 | 50 |
45 virtual void Create(RectPtr bounds) OVERRIDE { | 51 virtual void Create(RectPtr bounds) OVERRIDE { |
46 native_viewport_ = services::NativeViewport::Create(this); | 52 native_viewport_ = services::NativeViewport::Create(this); |
47 native_viewport_->Init(bounds.To<gfx::Rect>()); | 53 native_viewport_->Init(bounds.To<gfx::Rect>()); |
(...skipping 22 matching lines...) Expand all Loading... |
70 virtual void CreateGLES2Context( | 76 virtual void CreateGLES2Context( |
71 InterfaceRequest<CommandBuffer> command_buffer_request) OVERRIDE { | 77 InterfaceRequest<CommandBuffer> command_buffer_request) OVERRIDE { |
72 if (command_buffer_ || command_buffer_request_.is_pending()) { | 78 if (command_buffer_ || command_buffer_request_.is_pending()) { |
73 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; | 79 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; |
74 return; | 80 return; |
75 } | 81 } |
76 command_buffer_request_ = command_buffer_request.Pass(); | 82 command_buffer_request_ = command_buffer_request.Pass(); |
77 CreateCommandBufferIfNeeded(); | 83 CreateCommandBufferIfNeeded(); |
78 } | 84 } |
79 | 85 |
| 86 virtual void CreateOffscreenGLES2Context( |
| 87 InterfaceRequest<CommandBuffer> command_buffer_request) OVERRIDE { |
| 88 BindToRequest( |
| 89 new CommandBufferImpl(share_group_.get(), mailbox_manager_.get()), |
| 90 &command_buffer_request); |
| 91 } |
| 92 |
80 void AckEvent() { | 93 void AckEvent() { |
81 waiting_for_event_ack_ = false; | 94 waiting_for_event_ack_ = false; |
82 } | 95 } |
83 | 96 |
84 void CreateCommandBufferIfNeeded() { | 97 void CreateCommandBufferIfNeeded() { |
85 if (!command_buffer_request_.is_pending()) | 98 if (!command_buffer_request_.is_pending()) |
86 return; | 99 return; |
87 DCHECK(!command_buffer_.get()); | 100 DCHECK(!command_buffer_.get()); |
88 if (widget_ == gfx::kNullAcceleratedWidget) | 101 if (widget_ == gfx::kNullAcceleratedWidget) |
89 return; | 102 return; |
90 gfx::Size size = native_viewport_->GetSize(); | 103 gfx::Size size = native_viewport_->GetSize(); |
91 if (size.IsEmpty()) | 104 if (size.IsEmpty()) |
92 return; | 105 return; |
93 command_buffer_.reset( | 106 command_buffer_.reset(new CommandBufferImpl(widget_, |
94 new CommandBufferImpl(widget_, native_viewport_->GetSize())); | 107 native_viewport_->GetSize(), |
| 108 share_group_.get(), |
| 109 mailbox_manager_.get())); |
95 WeakBindToRequest(command_buffer_.get(), &command_buffer_request_); | 110 WeakBindToRequest(command_buffer_.get(), &command_buffer_request_); |
96 } | 111 } |
97 | 112 |
98 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE { | 113 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE { |
99 // Must not return early before updating capture. | 114 // Must not return early before updating capture. |
100 switch (ui_event->type()) { | 115 switch (ui_event->type()) { |
101 case ui::ET_MOUSE_PRESSED: | 116 case ui::ET_MOUSE_PRESSED: |
102 case ui::ET_TOUCH_PRESSED: | 117 case ui::ET_TOUCH_PRESSED: |
103 native_viewport_->SetCapture(); | 118 native_viewport_->SetCapture(); |
104 break; | 119 break; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 private: | 155 private: |
141 void AckDestroyed() { | 156 void AckDestroyed() { |
142 command_buffer_.reset(); | 157 command_buffer_.reset(); |
143 } | 158 } |
144 | 159 |
145 gfx::AcceleratedWidget widget_; | 160 gfx::AcceleratedWidget widget_; |
146 scoped_ptr<services::NativeViewport> native_viewport_; | 161 scoped_ptr<services::NativeViewport> native_viewport_; |
147 InterfaceRequest<CommandBuffer> command_buffer_request_; | 162 InterfaceRequest<CommandBuffer> command_buffer_request_; |
148 scoped_ptr<CommandBufferImpl> command_buffer_; | 163 scoped_ptr<CommandBufferImpl> command_buffer_; |
149 bool waiting_for_event_ack_; | 164 bool waiting_for_event_ack_; |
| 165 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 166 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
150 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | 167 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
151 }; | 168 }; |
152 | 169 |
153 class NVSDelegate : public ApplicationDelegate, | 170 class NVSDelegate : public ApplicationDelegate, |
154 public InterfaceFactory<mojo::NativeViewport> { | 171 public InterfaceFactory<mojo::NativeViewport> { |
155 public: | 172 public: |
156 NVSDelegate() {} | 173 NVSDelegate() |
| 174 : share_group_(new gfx::GLShareGroup), |
| 175 mailbox_manager_(new gpu::gles2::MailboxManager) {} |
157 virtual ~NVSDelegate() {} | 176 virtual ~NVSDelegate() {} |
158 | 177 |
159 // ApplicationDelegate implementation. | 178 // ApplicationDelegate implementation. |
160 virtual bool ConfigureIncomingConnection( | 179 virtual bool ConfigureIncomingConnection( |
161 mojo::ApplicationConnection* connection) OVERRIDE { | 180 mojo::ApplicationConnection* connection) OVERRIDE { |
162 connection->AddService(this); | 181 connection->AddService(this); |
163 return true; | 182 return true; |
164 } | 183 } |
165 | 184 |
166 // ServiceFactory<mojo::NativeViewport> implementation. | 185 // ServiceFactory<mojo::NativeViewport> implementation. |
167 virtual void Create(ApplicationConnection* connection, | 186 virtual void Create(ApplicationConnection* connection, |
168 InterfaceRequest<mojo::NativeViewport> request) OVERRIDE { | 187 InterfaceRequest<mojo::NativeViewport> request) OVERRIDE { |
169 BindToRequest(new NativeViewportImpl, &request); | 188 BindToRequest( |
| 189 new NativeViewportImpl(share_group_.get(), mailbox_manager_.get()), |
| 190 &request); |
170 } | 191 } |
| 192 |
| 193 private: |
| 194 // We need to share these across all NativeViewport instances so that contexts |
| 195 // they create can share resources with each other via mailboxes. |
| 196 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 197 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
171 }; | 198 }; |
172 | 199 |
173 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* | 200 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* |
174 CreateNativeViewportService( | 201 CreateNativeViewportService( |
175 ScopedMessagePipeHandle service_provider_handle) { | 202 ScopedMessagePipeHandle service_provider_handle) { |
176 ApplicationImpl* app = new ApplicationImpl( | 203 ApplicationImpl* app = new ApplicationImpl( |
177 new NVSDelegate(), service_provider_handle.Pass()); | 204 new NVSDelegate(), service_provider_handle.Pass()); |
178 return app; | 205 return app; |
179 } | 206 } |
180 | 207 |
181 } // namespace services | 208 } // namespace services |
182 } // namespace mojo | 209 } // namespace mojo |
183 | 210 |
OLD | NEW |