| 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 "components/mus/surfaces/surfaces_context_provider.h" | 5 #include "components/mus/surfaces/surfaces_context_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 SurfacesContextProvider::SurfacesContextProvider( | 30 SurfacesContextProvider::SurfacesContextProvider( |
| 31 SurfacesContextProviderDelegate* delegate, | 31 SurfacesContextProviderDelegate* delegate, |
| 32 gfx::AcceleratedWidget widget, | 32 gfx::AcceleratedWidget widget, |
| 33 const scoped_refptr<GpuState>& state) | 33 const scoped_refptr<GpuState>& state) |
| 34 : delegate_(delegate), widget_(widget), command_buffer_local_(nullptr) { | 34 : delegate_(delegate), widget_(widget), command_buffer_local_(nullptr) { |
| 35 capabilities_.gpu.image = true; | 35 capabilities_.gpu.image = true; |
| 36 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); | 36 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // This routine needs to be safe to call more than once. |
| 39 // This is called when we have an accelerated widget. | 40 // This is called when we have an accelerated widget. |
| 40 bool SurfacesContextProvider::BindToCurrentThread() { | 41 bool SurfacesContextProvider::BindToCurrentThread() { |
| 42 if (implementation_) |
| 43 return true; |
| 44 |
| 41 // SurfacesContextProvider should always live on the same thread as the | 45 // SurfacesContextProvider should always live on the same thread as the |
| 42 // Window Manager. | 46 // Window Manager. |
| 43 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
| 44 if (!command_buffer_local_->Initialize()) | 48 if (!command_buffer_local_->Initialize()) |
| 45 return false; | 49 return false; |
| 46 gles2_helper_.reset( | 50 gles2_helper_.reset( |
| 47 new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); | 51 new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); |
| 48 if (!gles2_helper_->Initialize(kDefaultCommandBufferSize)) | 52 if (!gles2_helper_->Initialize(kDefaultCommandBufferSize)) |
| 49 return false; | 53 return false; |
| 50 gles2_helper_->SetAutomaticFlushes(false); | 54 gles2_helper_->SetAutomaticFlushes(false); |
| 51 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | 55 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
| 52 capabilities_.gpu = command_buffer_local_->GetCapabilities(); | 56 capabilities_.gpu = command_buffer_local_->GetCapabilities(); |
| 53 bool bind_generates_resource = | 57 bool bind_generates_resource = |
| 54 !!capabilities_.gpu.bind_generates_resource_chromium; | 58 !!capabilities_.gpu.bind_generates_resource_chromium; |
| 55 // TODO(piman): Some contexts (such as compositor) want this to be true, so | 59 // TODO(piman): Some contexts (such as compositor) want this to be true, so |
| 56 // this needs to be a public parameter. | 60 // this needs to be a public parameter. |
| 57 bool lose_context_when_out_of_memory = false; | 61 bool lose_context_when_out_of_memory = false; |
| 58 bool support_client_side_arrays = false; | 62 bool support_client_side_arrays = false; |
| 59 implementation_.reset(new gpu::gles2::GLES2Implementation( | 63 implementation_.reset(new gpu::gles2::GLES2Implementation( |
| 60 gles2_helper_.get(), NULL, transfer_buffer_.get(), | 64 gles2_helper_.get(), NULL, transfer_buffer_.get(), |
| 61 bind_generates_resource, lose_context_when_out_of_memory, | 65 bind_generates_resource, lose_context_when_out_of_memory, |
| 62 support_client_side_arrays, command_buffer_local_)); | 66 support_client_side_arrays, command_buffer_local_)); |
| 63 return implementation_->Initialize( | 67 return implementation_->Initialize( |
| 64 kDefaultStartTransferBufferSize, kDefaultMinTransferBufferSize, | 68 kDefaultStartTransferBufferSize, kDefaultMinTransferBufferSize, |
| 65 kDefaultMaxTransferBufferSize, gpu::gles2::GLES2Implementation::kNoLimit); | 69 kDefaultMaxTransferBufferSize, gpu::gles2::GLES2Implementation::kNoLimit); |
| 66 } | 70 } |
| 67 | 71 |
| 68 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { | 72 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { |
| 73 DCHECK(implementation_); |
| 69 return implementation_.get(); | 74 return implementation_.get(); |
| 70 } | 75 } |
| 71 | 76 |
| 72 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() { | 77 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() { |
| 73 return implementation_.get(); | 78 return implementation_.get(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 class GrContext* SurfacesContextProvider::GrContext() { | 81 class GrContext* SurfacesContextProvider::GrContext() { |
| 77 return NULL; | 82 return NULL; |
| 78 } | 83 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 swap_buffers_completion_callback_.Run(result); | 124 swap_buffers_completion_callback_.Run(result); |
| 120 } | 125 } |
| 121 } | 126 } |
| 122 | 127 |
| 123 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( | 128 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( |
| 124 gfx::GLSurface::SwapCompletionCallback callback) { | 129 gfx::GLSurface::SwapCompletionCallback callback) { |
| 125 swap_buffers_completion_callback_ = callback; | 130 swap_buffers_completion_callback_ = callback; |
| 126 } | 131 } |
| 127 | 132 |
| 128 } // namespace mus | 133 } // namespace mus |
| OLD | NEW |