Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: mojo/gpu/gl_context.cc

Issue 1537783002: Improve GL helpers. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "mojo/public/cpp/application/connect.h" 6 #include "mojo/public/cpp/application/connect.h"
7 #include "mojo/public/interfaces/application/shell.mojom.h" 7 #include "mojo/public/interfaces/application/application_connector.mojom.h"
8 #include "mojo/services/gpu/interfaces/gpu.mojom.h" 8 #include "mojo/services/gpu/interfaces/gpu.mojom.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 11
12 GLContext::Observer::~Observer() {} 12 GLContext::Observer::~Observer() {}
13 13
14 GLContext::GLContext(CommandBufferPtr command_buffer) : weak_factory_(this) { 14 GLContext::GLContext(CommandBufferPtr command_buffer) : weak_factory_(this) {
15 context_ = MGLCreateContext( 15 context_ = MGLCreateContext(
16 MGL_API_VERSION_GLES2, 16 MGL_API_VERSION_GLES2,
17 command_buffer.PassInterface().PassHandle().release().value(), 17 command_buffer.PassInterface().PassHandle().release().value(),
18 MGL_NO_CONTEXT, &ContextLostThunk, this, 18 MGL_NO_CONTEXT, &ContextLostThunk, this,
19 Environment::GetDefaultAsyncWaiter()); 19 Environment::GetDefaultAsyncWaiter());
20 DCHECK(context_ != MGL_NO_CONTEXT); 20 DCHECK(context_ != MGL_NO_CONTEXT);
21 } 21 }
22 22
23 GLContext::~GLContext() { 23 GLContext::~GLContext() {
24 MGLDestroyContext(context_); 24 MGLDestroyContext(context_);
25 } 25 }
26 26
27 base::WeakPtr<GLContext> GLContext::Create(Shell* shell) { 27 base::WeakPtr<GLContext> GLContext::CreateOffscreen(
28 ApplicationConnector* connector) {
28 ServiceProviderPtr native_viewport; 29 ServiceProviderPtr native_viewport;
29 shell->ConnectToApplication("mojo:native_viewport_service", 30 connector->ConnectToApplication("mojo:native_viewport_service",
30 GetProxy(&native_viewport), nullptr); 31 GetProxy(&native_viewport), nullptr);
31 GpuPtr gpu_service; 32 GpuPtr gpu_service;
32 ConnectToService(native_viewport.get(), &gpu_service); 33 ConnectToService(native_viewport.get(), &gpu_service);
33 CommandBufferPtr command_buffer; 34 CommandBufferPtr command_buffer;
34 gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer)); 35 gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
35 return CreateFromCommandBuffer(command_buffer.Pass()); 36 return CreateFromCommandBuffer(command_buffer.Pass());
36 } 37 }
37 38
38 base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer( 39 base::WeakPtr<GLContext> GLContext::CreateFromCommandBuffer(
39 CommandBufferPtr command_buffer) { 40 CommandBufferPtr command_buffer) {
40 return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr(); 41 return (new GLContext(command_buffer.Pass()))->weak_factory_.GetWeakPtr();
(...skipping 21 matching lines...) Expand all
62 63
63 void GLContext::ContextLostThunk(void* self) { 64 void GLContext::ContextLostThunk(void* self) {
64 static_cast<GLContext*>(self)->OnContextLost(); 65 static_cast<GLContext*>(self)->OnContextLost();
65 } 66 }
66 67
67 void GLContext::OnContextLost() { 68 void GLContext::OnContextLost() {
68 FOR_EACH_OBSERVER(Observer, observers_, OnContextLost()); 69 FOR_EACH_OBSERVER(Observer, observers_, OnContextLost());
69 } 70 }
70 71
71 } // namespace mojo 72 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/gpu/gl_context.h ('k') | mojo/gpu/gl_context_owner.h » ('j') | mojo/gpu/gl_context_owner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698