| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 GLInProcessContext* share_context, | 97 GLInProcessContext* share_context, |
| 97 gfx::AcceleratedWidget window, | 98 gfx::AcceleratedWidget window, |
| 98 const gles2::ContextCreationAttribHelper& attribs, | 99 const gles2::ContextCreationAttribHelper& attribs, |
| 99 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 100 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 100 const SharedMemoryLimits& mem_limits, | 101 const SharedMemoryLimits& mem_limits, |
| 101 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 102 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 102 ImageFactory* image_factory) { | 103 ImageFactory* image_factory) { |
| 103 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0); | 104 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0); |
| 104 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0); | 105 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0); |
| 105 | 106 |
| 107 // Setup the task runner which will be used by both the CommandBuffer and |
| 108 // GLES2Implementation. |
| 109 scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
| 110 // If a surface is provided, we are running in a webview and do not have a |
| 111 // task runner. |
| 112 if (!surface) { |
| 113 task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 114 } |
| 115 |
| 106 command_buffer_.reset(new InProcessCommandBuffer(service)); | 116 command_buffer_.reset(new InProcessCommandBuffer(service)); |
| 107 | 117 |
| 108 scoped_refptr<gles2::ShareGroup> share_group; | 118 scoped_refptr<gles2::ShareGroup> share_group; |
| 109 InProcessCommandBuffer* share_command_buffer = nullptr; | 119 InProcessCommandBuffer* share_command_buffer = nullptr; |
| 110 if (share_context) { | 120 if (share_context) { |
| 111 GLInProcessContextImpl* impl = | 121 GLInProcessContextImpl* impl = |
| 112 static_cast<GLInProcessContextImpl*>(share_context); | 122 static_cast<GLInProcessContextImpl*>(share_context); |
| 113 share_group = impl->gles2_implementation_->share_group(); | 123 share_group = impl->gles2_implementation_->share_group(); |
| 114 share_command_buffer = impl->command_buffer_.get(); | 124 share_command_buffer = impl->command_buffer_.get(); |
| 115 DCHECK(share_group); | 125 DCHECK(share_group); |
| 116 DCHECK(share_command_buffer); | 126 DCHECK(share_command_buffer); |
| 117 } | 127 } |
| 118 | 128 |
| 119 if (!command_buffer_->Initialize(surface, | 129 if (!command_buffer_->Initialize( |
| 120 is_offscreen, | 130 surface, is_offscreen, window, attribs, share_command_buffer, |
| 121 window, | 131 gpu_memory_buffer_manager, image_factory, task_runner)) { |
| 122 attribs, | |
| 123 share_command_buffer, | |
| 124 gpu_memory_buffer_manager, | |
| 125 image_factory)) { | |
| 126 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; | 132 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; |
| 127 return false; | 133 return false; |
| 128 } | 134 } |
| 129 | 135 |
| 130 // Create the GLES2 helper, which writes the command buffer protocol. | 136 // Create the GLES2 helper, which writes the command buffer protocol. |
| 131 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 137 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
| 132 if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) { | 138 if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) { |
| 133 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; | 139 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; |
| 134 Destroy(); | 140 Destroy(); |
| 135 return false; | 141 return false; |
| 136 } | 142 } |
| 137 | 143 |
| 138 // Create a transfer buffer. | 144 // Create a transfer buffer. |
| 139 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 145 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
| 140 | 146 |
| 141 // Check for consistency. | 147 // Check for consistency. |
| 142 DCHECK(!attribs.bind_generates_resource); | 148 DCHECK(!attribs.bind_generates_resource); |
| 143 const bool bind_generates_resource = false; | 149 const bool bind_generates_resource = false; |
| 144 const bool support_client_side_arrays = false; | 150 const bool support_client_side_arrays = false; |
| 145 | 151 |
| 146 // Create the object exposing the OpenGL API. | 152 // Create the object exposing the OpenGL API. |
| 147 gles2_implementation_.reset( | 153 gles2_implementation_.reset(new gles2::GLES2Implementation( |
| 148 new gles2::GLES2Implementation(gles2_helper_.get(), | 154 gles2_helper_.get(), share_group.get(), transfer_buffer_.get(), |
| 149 share_group.get(), | 155 bind_generates_resource, attribs.lose_context_when_out_of_memory, |
| 150 transfer_buffer_.get(), | 156 support_client_side_arrays, command_buffer_.get(), |
| 151 bind_generates_resource, | 157 std::move(task_runner))); |
| 152 attribs.lose_context_when_out_of_memory, | |
| 153 support_client_side_arrays, | |
| 154 command_buffer_.get())); | |
| 155 | 158 |
| 156 if (!gles2_implementation_->Initialize( | 159 if (!gles2_implementation_->Initialize( |
| 157 mem_limits.start_transfer_buffer_size, | 160 mem_limits.start_transfer_buffer_size, |
| 158 mem_limits.min_transfer_buffer_size, | 161 mem_limits.min_transfer_buffer_size, |
| 159 mem_limits.max_transfer_buffer_size, | 162 mem_limits.max_transfer_buffer_size, |
| 160 mem_limits.mapped_memory_reclaim_limit)) { | 163 mem_limits.mapped_memory_reclaim_limit)) { |
| 161 return false; | 164 return false; |
| 162 } | 165 } |
| 163 | 166 |
| 164 return true; | 167 return true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); | 205 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); |
| 203 if (!context->Initialize(surface, is_offscreen, share_context, window, | 206 if (!context->Initialize(surface, is_offscreen, share_context, window, |
| 204 attribs, service, memory_limits, | 207 attribs, service, memory_limits, |
| 205 gpu_memory_buffer_manager, image_factory)) | 208 gpu_memory_buffer_manager, image_factory)) |
| 206 return NULL; | 209 return NULL; |
| 207 | 210 |
| 208 return context.release(); | 211 return context.release(); |
| 209 } | 212 } |
| 210 | 213 |
| 211 } // namespace gpu | 214 } // namespace gpu |
| OLD | NEW |