Index: mojo/services/native_viewport/native_viewport_service.cc |
diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc |
index 2903de0b441fa19a33937faa6836227f028ae2bd..3e53bd3520d29c5fb6744f36a080d9073de3bd2f 100644 |
--- a/mojo/services/native_viewport/native_viewport_service.cc |
+++ b/mojo/services/native_viewport/native_viewport_service.cc |
@@ -8,6 +8,7 @@ |
#include "base/memory/weak_ptr.h" |
#include "base/message_loop/message_loop.h" |
#include "base/time/time.h" |
+#include "gpu/command_buffer/service/mailbox_manager.h" |
#include "mojo/public/cpp/application/application_delegate.h" |
#include "mojo/public/cpp/application/interface_factory.h" |
#include "mojo/services/gles2/command_buffer_impl.h" |
@@ -16,6 +17,7 @@ |
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" |
#include "ui/events/event.h" |
+#include "ui/gl/gl_share_group.h" |
namespace mojo { |
namespace services { |
@@ -32,9 +34,13 @@ bool IsRateLimitedEventType(ui::Event* event) { |
class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, |
public NativeViewportDelegate { |
public: |
- NativeViewportImpl() |
+ NativeViewportImpl( |
+ const scoped_refptr<gfx::GLShareGroup>& share_group, |
+ const scoped_refptr<gpu::gles2::MailboxManager>& mailbox_manager) |
: widget_(gfx::kNullAcceleratedWidget), |
waiting_for_event_ack_(false), |
+ share_group_(share_group), |
+ mailbox_manager_(mailbox_manager), |
weak_factory_(this) {} |
virtual ~NativeViewportImpl() { |
// Destroy the NativeViewport early on as it may call us back during |
@@ -77,6 +83,13 @@ class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, |
CreateCommandBufferIfNeeded(); |
} |
+ virtual void CreateOffscreenGLES2Context( |
+ InterfaceRequest<CommandBuffer> command_buffer_request) OVERRIDE { |
+ BindToRequest( |
+ new CommandBufferImpl(share_group_.get(), mailbox_manager_.get()), |
+ &command_buffer_request); |
+ } |
+ |
void AckEvent() { |
waiting_for_event_ack_ = false; |
} |
@@ -90,8 +103,10 @@ class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, |
gfx::Size size = native_viewport_->GetSize(); |
if (size.IsEmpty()) |
return; |
- command_buffer_.reset( |
- new CommandBufferImpl(widget_, native_viewport_->GetSize())); |
+ command_buffer_.reset(new CommandBufferImpl(widget_, |
+ native_viewport_->GetSize(), |
+ share_group_.get(), |
+ mailbox_manager_.get())); |
WeakBindToRequest(command_buffer_.get(), &command_buffer_request_); |
} |
@@ -147,13 +162,17 @@ class NativeViewportImpl : public InterfaceImpl<mojo::NativeViewport>, |
InterfaceRequest<CommandBuffer> command_buffer_request_; |
scoped_ptr<CommandBufferImpl> command_buffer_; |
bool waiting_for_event_ack_; |
+ scoped_refptr<gfx::GLShareGroup> share_group_; |
+ scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
}; |
class NVSDelegate : public ApplicationDelegate, |
public InterfaceFactory<mojo::NativeViewport> { |
public: |
- NVSDelegate() {} |
+ NVSDelegate() |
+ : share_group_(new gfx::GLShareGroup), |
+ mailbox_manager_(new gpu::gles2::MailboxManager) {} |
virtual ~NVSDelegate() {} |
// ApplicationDelegate implementation. |
@@ -166,8 +185,16 @@ class NVSDelegate : public ApplicationDelegate, |
// ServiceFactory<mojo::NativeViewport> implementation. |
virtual void Create(ApplicationConnection* connection, |
InterfaceRequest<mojo::NativeViewport> request) OVERRIDE { |
- BindToRequest(new NativeViewportImpl, &request); |
+ BindToRequest( |
+ new NativeViewportImpl(share_group_.get(), mailbox_manager_.get()), |
+ &request); |
} |
+ |
+ private: |
+ // We need to share these across all NativeViewport instances so that contexts |
+ // they create can share resources with each other via mailboxes. |
+ scoped_refptr<gfx::GLShareGroup> share_group_; |
+ scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
}; |
MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* |