Chromium Code Reviews| 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/public/cpp/gles2_context.h" | 5 #include "components/mus/public/cpp/gles2_context.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "components/mus/public/cpp/gpu_service.h" | |
| 13 #include "components/mus/public/cpp/lib/command_buffer_client_impl.h" | |
| 12 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 14 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 13 #include "gpu/command_buffer/client/gles2_implementation.h" | |
| 14 #include "gpu/command_buffer/client/shared_memory_limits.h" | 15 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 15 #include "gpu/command_buffer/client/transfer_buffer.h" | 16 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 17 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | |
| 16 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 19 #include "url/gurl.h" | |
| 17 | 20 |
| 18 namespace mus { | 21 namespace mus { |
| 19 | 22 |
| 20 GLES2Context::GLES2Context(const std::vector<int32_t>& attribs, | 23 GLES2Context::GLES2Context(const std::vector<int32_t>& attribs, |
| 21 mojo::ScopedMessagePipeHandle command_buffer_handle, | 24 mojo::ScopedMessagePipeHandle command_buffer_handle, |
| 22 MojoGLES2ContextLost lost_callback, | 25 MojoGLES2ContextLost lost_callback, |
| 23 void* closure) | 26 void* closure) |
| 24 : command_buffer_(attribs, std::move(command_buffer_handle)), | 27 : lost_callback_(lost_callback), closure_(closure) { |
| 25 lost_callback_(lost_callback), | 28 // TODO(penghuang): Use type gpu::gles2::ContextCreationAttribHelper for |
| 26 closure_(closure) {} | 29 // attribs. |
| 30 if (!mus::GpuService::UseChromeGpuCommandBuffer()) { | |
| 31 command_buffer_client_impl_.reset( | |
| 32 new CommandBufferClientImpl(attribs, std::move(command_buffer_handle))); | |
| 33 } else { | |
| 34 // For using chrome gpu command buffer, the command_buffer_handle is not | |
| 35 // used. | |
| 36 DCHECK(!command_buffer_handle.is_valid()); | |
| 37 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = | |
| 38 GpuService::GetInstance()->gpu_channel_host(); | |
| 39 gpu::SurfaceHandle surface_handle = gfx::kNullAcceleratedWidget; | |
| 40 // TODO(penghuang): support shared group. | |
| 41 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr; | |
| 42 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT; | |
| 43 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL; | |
| 44 gfx::GpuPreference gpu_preference = gfx::PreferIntegratedGpu; | |
| 45 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 46 // TODO(penghuang): figure a useful active_url. | |
| 47 GURL active_url; | |
| 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
| 49 base::ThreadTaskRunnerHandle::Get(); | |
| 50 if (attributes.Parse(attribs)) { | |
| 51 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create( | |
| 52 std::move(gpu_channel_host), surface_handle, gfx::Size(), | |
| 53 shared_command_buffer, stream_id, stream_priority, attributes, | |
| 54 active_url, gpu_preference, std::move(task_runner)); | |
| 55 } else { | |
| 56 LOG(WARNING) << "Parse attribs failed!"; | |
|
piman
2016/05/24 22:46:54
nit: DLOG
Peng
2016/05/25 19:42:55
Done.
| |
| 57 } | |
| 58 } | |
| 59 } | |
| 27 | 60 |
| 28 GLES2Context::~GLES2Context() {} | 61 GLES2Context::~GLES2Context() {} |
| 29 | 62 |
| 30 bool GLES2Context::Initialize() { | 63 bool GLES2Context::Initialize() { |
| 31 if (!command_buffer_.Initialize()) | 64 gpu::CommandBuffer* command_buffer = nullptr; |
| 32 return false; | 65 gpu::GpuControl* gpu_control = nullptr; |
| 66 if (!mus::GpuService::UseChromeGpuCommandBuffer()) { | |
| 67 if (!command_buffer_client_impl_->Initialize()) | |
| 68 return false; | |
| 69 command_buffer = command_buffer_client_impl_.get(); | |
| 70 gpu_control = command_buffer_client_impl_.get(); | |
| 71 } else { | |
| 72 if (!command_buffer_proxy_impl_) | |
| 73 return false; | |
| 74 command_buffer = command_buffer_proxy_impl_.get(); | |
| 75 gpu_control = command_buffer_proxy_impl_.get(); | |
| 76 } | |
| 33 | 77 |
| 34 constexpr gpu::SharedMemoryLimits default_limits; | 78 constexpr gpu::SharedMemoryLimits default_limits; |
| 35 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(&command_buffer_)); | 79 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); |
| 36 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) | 80 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) |
| 37 return false; | 81 return false; |
| 38 gles2_helper_->SetAutomaticFlushes(false); | 82 gles2_helper_->SetAutomaticFlushes(false); |
| 39 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | 83 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
| 40 gpu::Capabilities capabilities = command_buffer_.GetCapabilities(); | 84 gpu::Capabilities capabilities = gpu_control->GetCapabilities(); |
| 41 bool bind_generates_resource = | 85 bool bind_generates_resource = |
| 42 !!capabilities.bind_generates_resource_chromium; | 86 !!capabilities.bind_generates_resource_chromium; |
| 43 // TODO(piman): Some contexts (such as compositor) want this to be true, so | 87 // TODO(piman): Some contexts (such as compositor) want this to be true, so |
| 44 // this needs to be a public parameter. | 88 // this needs to be a public parameter. |
| 45 bool lose_context_when_out_of_memory = false; | 89 bool lose_context_when_out_of_memory = false; |
| 46 bool support_client_side_arrays = false; | 90 bool support_client_side_arrays = false; |
| 47 implementation_.reset(new gpu::gles2::GLES2Implementation( | 91 implementation_.reset(new gpu::gles2::GLES2Implementation( |
| 48 gles2_helper_.get(), NULL, transfer_buffer_.get(), | 92 gles2_helper_.get(), NULL, transfer_buffer_.get(), |
| 49 bind_generates_resource, lose_context_when_out_of_memory, | 93 bind_generates_resource, lose_context_when_out_of_memory, |
| 50 support_client_side_arrays, &command_buffer_)); | 94 support_client_side_arrays, gpu_control)); |
| 51 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size, | 95 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size, |
| 52 default_limits.min_transfer_buffer_size, | 96 default_limits.min_transfer_buffer_size, |
| 53 default_limits.max_transfer_buffer_size, | 97 default_limits.max_transfer_buffer_size, |
| 54 default_limits.mapped_memory_reclaim_limit)) | 98 default_limits.mapped_memory_reclaim_limit)) |
| 55 return false; | 99 return false; |
| 56 implementation_->SetLostContextCallback( | 100 implementation_->SetLostContextCallback( |
| 57 base::Bind(&GLES2Context::OnLostContext, base::Unretained(this))); | 101 base::Bind(&GLES2Context::OnLostContext, base::Unretained(this))); |
| 58 return true; | 102 return true; |
| 59 } | 103 } |
| 60 | 104 |
| 61 void GLES2Context::OnLostContext() { | 105 void GLES2Context::OnLostContext() { |
| 62 lost_callback_(closure_); | 106 lost_callback_(closure_); |
| 63 } | 107 } |
| 64 | 108 |
| 65 } // namespace mus | 109 } // namespace mus |
| OLD | NEW |