Improve GL helpers. Use ApplicationConnector instead of Shell to obtain an offscreen GL context. This makes it easier to create GL contexts from separate threads since the Shell interface is usually owned by the main thread. Eagerly unbind GL textures from the context after creation to prevent spurious circularity warnings from the GPU Service caused by textures being bound while not actually in use. BUG= Review URL: https://codereview.chromium.org/1537783002 . R=viettrungluu@chromium.org, abarth, jamesr, viettrungluu Review URL: https://codereview.chromium.org/1532923003 .
diff --git a/mojo/gpu/gl_context.cc b/mojo/gpu/gl_context.cc index f12a323..eb6acdc 100644 --- a/mojo/gpu/gl_context.cc +++ b/mojo/gpu/gl_context.cc
@@ -5,7 +5,7 @@ #include "mojo/gpu/gl_context.h" #include "mojo/public/cpp/application/connect.h" -#include "mojo/public/interfaces/application/shell.mojom.h" +#include "mojo/public/interfaces/application/application_connector.mojom.h" #include "mojo/services/gpu/interfaces/gpu.mojom.h" namespace mojo { @@ -25,10 +25,11 @@ MGLDestroyContext(context_); } -base::WeakPtr<GLContext> GLContext::Create(Shell* shell) { +base::WeakPtr<GLContext> GLContext::CreateOffscreen( + ApplicationConnector* connector) { ServiceProviderPtr native_viewport; - shell->ConnectToApplication("mojo:native_viewport_service", - GetProxy(&native_viewport), nullptr); + connector->ConnectToApplication("mojo:native_viewport_service", + GetProxy(&native_viewport), nullptr); GpuPtr gpu_service; ConnectToService(native_viewport.get(), &gpu_service); CommandBufferPtr command_buffer;
diff --git a/mojo/gpu/gl_context.h b/mojo/gpu/gl_context.h index 2ccdaad..a557fdb 100644 --- a/mojo/gpu/gl_context.h +++ b/mojo/gpu/gl_context.h
@@ -12,6 +12,7 @@ #include "mojo/public/cpp/bindings/interface_ptr.h" namespace mojo { +class ApplicationConnector; class CommandBuffer; using CommandBufferPtr = InterfacePtr<CommandBuffer>; class Shell; @@ -26,7 +27,11 @@ virtual ~Observer(); }; - static base::WeakPtr<GLContext> Create(Shell* shell); + // Creates an offscreen GL context. + static base::WeakPtr<GLContext> CreateOffscreen( + ApplicationConnector* connector); + + // Creates a GL context from a command buffer. static base::WeakPtr<GLContext> CreateFromCommandBuffer( CommandBufferPtr command_buffer);
diff --git a/mojo/gpu/gl_context_owner.cc b/mojo/gpu/gl_context_owner.cc index 81d7d33..b909583 100644 --- a/mojo/gpu/gl_context_owner.cc +++ b/mojo/gpu/gl_context_owner.cc
@@ -8,9 +8,8 @@ namespace mojo { -GLContextOwner::GLContextOwner(mojo::Shell* shell) - : context_(mojo::GLContext::Create(shell)) { -} +GLContextOwner::GLContextOwner(ApplicationConnector* connector) + : context_(GLContext::CreateOffscreen(connector)) {} GLContextOwner::~GLContextOwner() { context_->Destroy();
diff --git a/mojo/gpu/gl_context_owner.h b/mojo/gpu/gl_context_owner.h index 872729a..b25bd69 100644 --- a/mojo/gpu/gl_context_owner.h +++ b/mojo/gpu/gl_context_owner.h
@@ -9,11 +9,13 @@ namespace mojo { class GLContext; +class ApplicationConnector; class Shell; class GLContextOwner { public: - explicit GLContextOwner(mojo::Shell* shell); + explicit GLContextOwner(ApplicationConnector* connector); + ~GLContextOwner(); const base::WeakPtr<mojo::GLContext>& context() const { return context_; }
diff --git a/mojo/gpu/gl_texture.cc b/mojo/gpu/gl_texture.cc index 3e2b2ce..aa41336 100644 --- a/mojo/gpu/gl_texture.cc +++ b/mojo/gpu/gl_texture.cc
@@ -17,6 +17,7 @@ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width, size_.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); } GLTexture::~GLTexture() {