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

Side by Side Diff: gpu/command_buffer/client/gl_in_process_context.cc

Issue 2286873003: Provide TaskRunner to ContextCacheController (Closed)
Patch Set: feedback Created 4 years, 3 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/client/gl_in_process_context.h" 5 #include "gpu/command_buffer/client/gl_in_process_context.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include <GLES2/gl2.h> 15 #include <GLES2/gl2.h>
16 #ifndef GL_GLEXT_PROTOTYPES 16 #ifndef GL_GLEXT_PROTOTYPES
17 #define GL_GLEXT_PROTOTYPES 1 17 #define GL_GLEXT_PROTOTYPES 1
18 #endif 18 #endif
19 #include <GLES2/gl2ext.h> 19 #include <GLES2/gl2ext.h>
20 #include <GLES2/gl2extchromium.h> 20 #include <GLES2/gl2extchromium.h>
21 21
22 #include "base/bind.h" 22 #include "base/bind.h"
23 #include "base/bind_helpers.h" 23 #include "base/bind_helpers.h"
24 #include "base/lazy_instance.h" 24 #include "base/lazy_instance.h"
25 #include "base/logging.h" 25 #include "base/logging.h"
26 #include "base/macros.h" 26 #include "base/macros.h"
27 #include "base/memory/weak_ptr.h" 27 #include "base/memory/weak_ptr.h"
28 #include "base/message_loop/message_loop.h" 28 #include "base/message_loop/message_loop.h"
29 #include "base/threading/thread_task_runner_handle.h"
29 #include "gpu/command_buffer/client/gles2_cmd_helper.h" 30 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
30 #include "gpu/command_buffer/client/gles2_implementation.h" 31 #include "gpu/command_buffer/client/gles2_implementation.h"
31 #include "gpu/command_buffer/client/shared_memory_limits.h" 32 #include "gpu/command_buffer/client/shared_memory_limits.h"
32 #include "gpu/command_buffer/client/transfer_buffer.h" 33 #include "gpu/command_buffer/client/transfer_buffer.h"
33 #include "gpu/command_buffer/common/command_buffer.h" 34 #include "gpu/command_buffer/common/command_buffer.h"
34 #include "gpu/command_buffer/common/constants.h" 35 #include "gpu/command_buffer/common/constants.h"
35 #include "ui/gfx/geometry/size.h" 36 #include "ui/gfx/geometry/size.h"
36 #include "ui/gl/gl_image.h" 37 #include "ui/gl/gl_image.h"
37 38
38 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
(...skipping 12 matching lines...) Expand all
51 ~GLInProcessContextImpl() override; 52 ~GLInProcessContextImpl() override;
52 53
53 bool Initialize(scoped_refptr<gl::GLSurface> surface, 54 bool Initialize(scoped_refptr<gl::GLSurface> surface,
54 bool is_offscreen, 55 bool is_offscreen,
55 GLInProcessContext* share_context, 56 GLInProcessContext* share_context,
56 gfx::AcceleratedWidget window, 57 gfx::AcceleratedWidget window,
57 const gpu::gles2::ContextCreationAttribHelper& attribs, 58 const gpu::gles2::ContextCreationAttribHelper& attribs,
58 const scoped_refptr<InProcessCommandBuffer::Service>& service, 59 const scoped_refptr<InProcessCommandBuffer::Service>& service,
59 const SharedMemoryLimits& mem_limits, 60 const SharedMemoryLimits& mem_limits,
60 GpuMemoryBufferManager* gpu_memory_buffer_manager, 61 GpuMemoryBufferManager* gpu_memory_buffer_manager,
61 ImageFactory* image_factory); 62 ImageFactory* image_factory,
63 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
62 64
63 // GLInProcessContext implementation: 65 // GLInProcessContext implementation:
64 gles2::GLES2Implementation* GetImplementation() override; 66 gles2::GLES2Implementation* GetImplementation() override;
65 void SetLock(base::Lock* lock) override; 67 void SetLock(base::Lock* lock) override;
66 68
67 private: 69 private:
68 void Destroy(); 70 void Destroy();
69 void OnSignalSyncPoint(const base::Closure& callback); 71 void OnSignalSyncPoint(const base::Closure& callback);
70 72
71 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_; 73 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_;
(...skipping 20 matching lines...) Expand all
92 94
93 bool GLInProcessContextImpl::Initialize( 95 bool GLInProcessContextImpl::Initialize(
94 scoped_refptr<gl::GLSurface> surface, 96 scoped_refptr<gl::GLSurface> surface,
95 bool is_offscreen, 97 bool is_offscreen,
96 GLInProcessContext* share_context, 98 GLInProcessContext* share_context,
97 gfx::AcceleratedWidget window, 99 gfx::AcceleratedWidget window,
98 const gles2::ContextCreationAttribHelper& attribs, 100 const gles2::ContextCreationAttribHelper& attribs,
99 const scoped_refptr<InProcessCommandBuffer::Service>& service, 101 const scoped_refptr<InProcessCommandBuffer::Service>& service,
100 const SharedMemoryLimits& mem_limits, 102 const SharedMemoryLimits& mem_limits,
101 GpuMemoryBufferManager* gpu_memory_buffer_manager, 103 GpuMemoryBufferManager* gpu_memory_buffer_manager,
102 ImageFactory* image_factory) { 104 ImageFactory* image_factory,
105 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
103 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0); 106 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0);
104 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0); 107 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0);
105 108
106 command_buffer_.reset(new InProcessCommandBuffer(service)); 109 command_buffer_.reset(new InProcessCommandBuffer(service));
107 110
108 scoped_refptr<gles2::ShareGroup> share_group; 111 scoped_refptr<gles2::ShareGroup> share_group;
109 InProcessCommandBuffer* share_command_buffer = nullptr; 112 InProcessCommandBuffer* share_command_buffer = nullptr;
110 if (share_context) { 113 if (share_context) {
111 GLInProcessContextImpl* impl = 114 GLInProcessContextImpl* impl =
112 static_cast<GLInProcessContextImpl*>(share_context); 115 static_cast<GLInProcessContextImpl*>(share_context);
113 share_group = impl->gles2_implementation_->share_group(); 116 share_group = impl->gles2_implementation_->share_group();
114 share_command_buffer = impl->command_buffer_.get(); 117 share_command_buffer = impl->command_buffer_.get();
115 DCHECK(share_group); 118 DCHECK(share_group);
116 DCHECK(share_command_buffer); 119 DCHECK(share_command_buffer);
117 } 120 }
118 121
119 if (!command_buffer_->Initialize(surface, 122 if (!command_buffer_->Initialize(
120 is_offscreen, 123 surface, is_offscreen, window, attribs, share_command_buffer,
121 window, 124 gpu_memory_buffer_manager, image_factory, std::move(task_runner))) {
122 attribs,
123 share_command_buffer,
124 gpu_memory_buffer_manager,
125 image_factory)) {
126 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; 125 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer";
127 return false; 126 return false;
128 } 127 }
129 128
130 // Create the GLES2 helper, which writes the command buffer protocol. 129 // Create the GLES2 helper, which writes the command buffer protocol.
131 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); 130 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get()));
132 if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) { 131 if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) {
133 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; 132 LOG(ERROR) << "Failed to initialize GLES2CmdHelper";
134 Destroy(); 133 Destroy();
135 return false; 134 return false;
136 } 135 }
137 136
138 // Create a transfer buffer. 137 // Create a transfer buffer.
139 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); 138 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get()));
140 139
141 // Check for consistency. 140 // Check for consistency.
142 DCHECK(!attribs.bind_generates_resource); 141 DCHECK(!attribs.bind_generates_resource);
143 const bool bind_generates_resource = false; 142 const bool bind_generates_resource = false;
144 const bool support_client_side_arrays = false; 143 const bool support_client_side_arrays = false;
145 144
146 // Create the object exposing the OpenGL API. 145 // Create the object exposing the OpenGL API.
147 gles2_implementation_.reset( 146 gles2_implementation_.reset(new gles2::GLES2Implementation(
148 new gles2::GLES2Implementation(gles2_helper_.get(), 147 gles2_helper_.get(), share_group.get(), transfer_buffer_.get(),
149 share_group.get(), 148 bind_generates_resource, attribs.lose_context_when_out_of_memory,
150 transfer_buffer_.get(), 149 support_client_side_arrays, command_buffer_.get()));
151 bind_generates_resource,
152 attribs.lose_context_when_out_of_memory,
153 support_client_side_arrays,
154 command_buffer_.get()));
155 150
156 if (!gles2_implementation_->Initialize( 151 if (!gles2_implementation_->Initialize(
157 mem_limits.start_transfer_buffer_size, 152 mem_limits.start_transfer_buffer_size,
158 mem_limits.min_transfer_buffer_size, 153 mem_limits.min_transfer_buffer_size,
159 mem_limits.max_transfer_buffer_size, 154 mem_limits.max_transfer_buffer_size,
160 mem_limits.mapped_memory_reclaim_limit)) { 155 mem_limits.mapped_memory_reclaim_limit)) {
161 return false; 156 return false;
162 } 157 }
163 158
164 return true; 159 return true;
(...skipping 21 matching lines...) Expand all
186 // static 181 // static
187 GLInProcessContext* GLInProcessContext::Create( 182 GLInProcessContext* GLInProcessContext::Create(
188 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, 183 scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
189 scoped_refptr<gl::GLSurface> surface, 184 scoped_refptr<gl::GLSurface> surface,
190 bool is_offscreen, 185 bool is_offscreen,
191 gfx::AcceleratedWidget window, 186 gfx::AcceleratedWidget window,
192 GLInProcessContext* share_context, 187 GLInProcessContext* share_context,
193 const ::gpu::gles2::ContextCreationAttribHelper& attribs, 188 const ::gpu::gles2::ContextCreationAttribHelper& attribs,
194 const SharedMemoryLimits& memory_limits, 189 const SharedMemoryLimits& memory_limits,
195 GpuMemoryBufferManager* gpu_memory_buffer_manager, 190 GpuMemoryBufferManager* gpu_memory_buffer_manager,
196 ImageFactory* image_factory) { 191 ImageFactory* image_factory,
197 if (surface.get()) { 192 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
193 // If a surface is provided, we are running in a webview and should not have
194 // a task runner. We must have a task runner in all other cases.
195 DCHECK_EQ(!!surface, !task_runner);
196
197 if (surface) {
198 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); 198 DCHECK_EQ(surface->IsOffscreen(), is_offscreen);
199 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); 199 DCHECK_EQ(gfx::kNullAcceleratedWidget, window);
200 } 200 }
201 201
202 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); 202 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl);
203 if (!context->Initialize(surface, is_offscreen, share_context, window, 203 if (!context->Initialize(surface, is_offscreen, share_context, window,
204 attribs, service, memory_limits, 204 attribs, service, memory_limits,
205 gpu_memory_buffer_manager, image_factory)) 205 gpu_memory_buffer_manager, image_factory,
206 std::move(task_runner)))
206 return NULL; 207 return NULL;
207 208
208 return context.release(); 209 return context.release();
209 } 210 }
210 211
211 } // namespace gpu 212 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gl_in_process_context.h ('k') | gpu/command_buffer/service/in_process_command_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698