| 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 #include "mojo/gpu/gl_context.h" | 5 #include "mojo/gpu/gl_context.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/application/connect.h" | 7 #include "mojo/public/cpp/application/connect.h" |
| 8 #include "mojo/public/interfaces/application/application_connector.mojom.h" | 8 #include "mojo/public/interfaces/application/application_connector.mojom.h" |
| 9 #include "mojo/services/gpu/interfaces/gpu.mojom.h" | 9 #include "mojo/services/gpu/interfaces/gpu.mojom.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 GLContext::Observer::~Observer() {} | 13 GLContext::Observer::~Observer() {} |
| 14 | 14 |
| 15 GLContext::GLContext(CommandBufferPtr command_buffer) : weak_factory_(this) { | 15 GLContext::GLContext(InterfaceHandle<CommandBuffer> command_buffer) |
| 16 context_ = MGLCreateContext( | 16 : weak_factory_(this) { |
| 17 MGL_API_VERSION_GLES2, | 17 context_ = MGLCreateContext(MGL_API_VERSION_GLES2, |
| 18 command_buffer.PassInterfaceHandle().PassHandle().release().value(), | 18 command_buffer.PassHandle().release().value(), |
| 19 MGL_NO_CONTEXT, &ContextLostThunk, this, | 19 MGL_NO_CONTEXT, &ContextLostThunk, this, |
| 20 Environment::GetDefaultAsyncWaiter()); | 20 Environment::GetDefaultAsyncWaiter()); |
| 21 DCHECK(context_ != MGL_NO_CONTEXT); | 21 DCHECK(context_ != MGL_NO_CONTEXT); |
| 22 } | 22 } |
| 23 | 23 |
| 24 GLContext::~GLContext() { | 24 GLContext::~GLContext() { |
| 25 MGLDestroyContext(context_); | 25 MGLDestroyContext(context_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 base::WeakPtr<GLContext> GLContext::CreateOffscreen( | 28 base::WeakPtr<GLContext> GLContext::CreateOffscreen( |
| 29 ApplicationConnector* connector) { | 29 ApplicationConnector* connector) { |
| 30 ServiceProviderPtr native_viewport; | 30 ServiceProviderPtr native_viewport; |
| 31 connector->ConnectToApplication("mojo:native_viewport_service", | 31 connector->ConnectToApplication("mojo:native_viewport_service", |
| 32 GetProxy(&native_viewport), nullptr); | 32 GetProxy(&native_viewport), nullptr); |
| 33 GpuPtr gpu_service; | 33 GpuPtr gpu_service; |
| 34 ConnectToService(native_viewport.get(), &gpu_service); | 34 ConnectToService(native_viewport.get(), &gpu_service); |
| 35 CommandBufferPtr command_buffer; | 35 InterfaceHandle<CommandBuffer> command_buffer; |
| 36 gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer)); | 36 gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer)); |
| 37 return CreateFromCommandBuffer(command_buffer.Pass()); | 37 return CreateFromCommandBuffer(command_buffer.Pass()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer( | 40 base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer( |
| 41 CommandBufferPtr command_buffer) { | 41 InterfaceHandle<CommandBuffer> command_buffer) { |
| 42 return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr(); | 42 return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void GLContext::MakeCurrent() { | 45 void GLContext::MakeCurrent() { |
| 46 MGLMakeCurrent(context_); | 46 MGLMakeCurrent(context_); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool GLContext::IsCurrent() { | 49 bool GLContext::IsCurrent() { |
| 50 return context_ == MGLGetCurrentContext(); | 50 return context_ == MGLGetCurrentContext(); |
| 51 } | 51 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 void GLContext::ContextLostThunk(void* self) { | 65 void GLContext::ContextLostThunk(void* self) { |
| 66 static_cast<GLContext*>(self)->OnContextLost(); | 66 static_cast<GLContext*>(self)->OnContextLost(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void GLContext::OnContextLost() { | 69 void GLContext::OnContextLost() { |
| 70 FOR_EACH_OBSERVER(Observer, observers_, OnContextLost()); | 70 FOR_EACH_OBSERVER(Observer, observers_, OnContextLost()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace mojo | 73 } // namespace mojo |
| OLD | NEW |