| 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/ipc/gl_in_process_context.h" | 5 #include "gpu/ipc/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> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 class GLInProcessContextImpl | 47 class GLInProcessContextImpl |
| 48 : public GLInProcessContext, | 48 : public GLInProcessContext, |
| 49 public base::SupportsWeakPtr<GLInProcessContextImpl> { | 49 public base::SupportsWeakPtr<GLInProcessContextImpl> { |
| 50 public: | 50 public: |
| 51 GLInProcessContextImpl(); | 51 GLInProcessContextImpl(); |
| 52 ~GLInProcessContextImpl() override; | 52 ~GLInProcessContextImpl() override; |
| 53 | 53 |
| 54 bool Initialize(scoped_refptr<gl::GLSurface> surface, | 54 bool Initialize(scoped_refptr<gl::GLSurface> surface, |
| 55 bool is_offscreen, | 55 bool is_offscreen, |
| 56 GLInProcessContext* share_context, | 56 GLInProcessContext* share_context, |
| 57 gfx::AcceleratedWidget window, | 57 SurfaceHandle window, |
| 58 const gpu::gles2::ContextCreationAttribHelper& attribs, | 58 const gpu::gles2::ContextCreationAttribHelper& attribs, |
| 59 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 59 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 60 const SharedMemoryLimits& mem_limits, | 60 const SharedMemoryLimits& mem_limits, |
| 61 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 61 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 62 ImageFactory* image_factory, | 62 ImageFactory* image_factory, |
| 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 64 | 64 |
| 65 // GLInProcessContext implementation: | 65 // GLInProcessContext implementation: |
| 66 gles2::GLES2Implementation* GetImplementation() override; | 66 gles2::GLES2Implementation* GetImplementation() override; |
| 67 void SetSwapBuffersCompletionCallback( |
| 68 const gpu::InProcessCommandBuffer::SwapBuffersCompletionCallback& |
| 69 callback) override; |
| 70 void SetUpdateVSyncParametersCallback( |
| 71 const gpu::InProcessCommandBuffer::UpdateVSyncParametersCallback& |
| 72 callback) override; |
| 67 void SetLock(base::Lock* lock) override; | 73 void SetLock(base::Lock* lock) override; |
| 68 | 74 |
| 69 private: | 75 private: |
| 70 void Destroy(); | 76 void Destroy(); |
| 71 void OnSignalSyncPoint(const base::Closure& callback); | 77 void OnSignalSyncPoint(const base::Closure& callback); |
| 72 | 78 |
| 73 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_; | 79 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
| 74 std::unique_ptr<TransferBuffer> transfer_buffer_; | 80 std::unique_ptr<TransferBuffer> transfer_buffer_; |
| 75 std::unique_ptr<gles2::GLES2Implementation> gles2_implementation_; | 81 std::unique_ptr<gles2::GLES2Implementation> gles2_implementation_; |
| 76 std::unique_ptr<InProcessCommandBuffer> command_buffer_; | 82 std::unique_ptr<InProcessCommandBuffer> command_buffer_; |
| 77 | 83 |
| 78 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); | 84 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); |
| 79 }; | 85 }; |
| 80 | 86 |
| 81 GLInProcessContextImpl::GLInProcessContextImpl() = default; | 87 GLInProcessContextImpl::GLInProcessContextImpl() = default; |
| 82 | 88 |
| 83 GLInProcessContextImpl::~GLInProcessContextImpl() { | 89 GLInProcessContextImpl::~GLInProcessContextImpl() { |
| 84 Destroy(); | 90 Destroy(); |
| 85 } | 91 } |
| 86 | 92 |
| 87 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { | 93 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { |
| 88 return gles2_implementation_.get(); | 94 return gles2_implementation_.get(); |
| 89 } | 95 } |
| 90 | 96 |
| 97 void GLInProcessContextImpl::SetSwapBuffersCompletionCallback( |
| 98 const gpu::InProcessCommandBuffer::SwapBuffersCompletionCallback& |
| 99 callback) { |
| 100 command_buffer_->SetSwapBuffersCompletionCallback(callback); |
| 101 } |
| 102 |
| 103 void GLInProcessContextImpl::SetUpdateVSyncParametersCallback( |
| 104 const gpu::InProcessCommandBuffer::UpdateVSyncParametersCallback& |
| 105 callback) { |
| 106 command_buffer_->SetUpdateVSyncParametersCallback(callback); |
| 107 } |
| 108 |
| 91 void GLInProcessContextImpl::SetLock(base::Lock* lock) { | 109 void GLInProcessContextImpl::SetLock(base::Lock* lock) { |
| 92 NOTREACHED(); | 110 NOTREACHED(); |
| 93 } | 111 } |
| 94 | 112 |
| 95 bool GLInProcessContextImpl::Initialize( | 113 bool GLInProcessContextImpl::Initialize( |
| 96 scoped_refptr<gl::GLSurface> surface, | 114 scoped_refptr<gl::GLSurface> surface, |
| 97 bool is_offscreen, | 115 bool is_offscreen, |
| 98 GLInProcessContext* share_context, | 116 GLInProcessContext* share_context, |
| 99 gfx::AcceleratedWidget window, | 117 SurfaceHandle window, |
| 100 const gles2::ContextCreationAttribHelper& attribs, | 118 const gles2::ContextCreationAttribHelper& attribs, |
| 101 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 119 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 102 const SharedMemoryLimits& mem_limits, | 120 const SharedMemoryLimits& mem_limits, |
| 103 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 121 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 104 ImageFactory* image_factory, | 122 ImageFactory* image_factory, |
| 105 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 123 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 106 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0); | 124 DCHECK_GE(attribs.offscreen_framebuffer_size.width(), 0); |
| 107 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0); | 125 DCHECK_GE(attribs.offscreen_framebuffer_size.height(), 0); |
| 108 | 126 |
| 109 command_buffer_.reset(new InProcessCommandBuffer(service)); | 127 command_buffer_.reset(new InProcessCommandBuffer(service)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 command_buffer_.reset(); | 194 command_buffer_.reset(); |
| 177 } | 195 } |
| 178 | 196 |
| 179 } // anonymous namespace | 197 } // anonymous namespace |
| 180 | 198 |
| 181 // static | 199 // static |
| 182 GLInProcessContext* GLInProcessContext::Create( | 200 GLInProcessContext* GLInProcessContext::Create( |
| 183 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | 201 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, |
| 184 scoped_refptr<gl::GLSurface> surface, | 202 scoped_refptr<gl::GLSurface> surface, |
| 185 bool is_offscreen, | 203 bool is_offscreen, |
| 186 gfx::AcceleratedWidget window, | 204 SurfaceHandle window, |
| 187 GLInProcessContext* share_context, | 205 GLInProcessContext* share_context, |
| 188 const ::gpu::gles2::ContextCreationAttribHelper& attribs, | 206 const ::gpu::gles2::ContextCreationAttribHelper& attribs, |
| 189 const SharedMemoryLimits& memory_limits, | 207 const SharedMemoryLimits& memory_limits, |
| 190 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 208 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 191 ImageFactory* image_factory, | 209 ImageFactory* image_factory, |
| 192 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 210 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 193 // If a surface is provided, we are running in a webview and should not have | 211 // 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. | 212 // a task runner. We must have a task runner in all other cases. |
| 195 DCHECK_EQ(!!surface, !task_runner); | 213 DCHECK_EQ(!!surface, !task_runner); |
| 196 | 214 |
| 197 if (surface) { | 215 if (surface) { |
| 198 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); | 216 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); |
| 199 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); | 217 DCHECK_EQ(kNullSurfaceHandle, window); |
| 200 } | 218 } |
| 201 | 219 |
| 202 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); | 220 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); |
| 203 if (!context->Initialize(surface, is_offscreen, share_context, window, | 221 if (!context->Initialize(surface, is_offscreen, share_context, window, |
| 204 attribs, service, memory_limits, | 222 attribs, service, memory_limits, |
| 205 gpu_memory_buffer_manager, image_factory, | 223 gpu_memory_buffer_manager, image_factory, |
| 206 std::move(task_runner))) | 224 std::move(task_runner))) |
| 207 return NULL; | 225 return NULL; |
| 208 | 226 |
| 209 return context.release(); | 227 return context.release(); |
| 210 } | 228 } |
| 211 | 229 |
| 212 } // namespace gpu | 230 } // namespace gpu |
| OLD | NEW |