| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/ui/public/cpp/gles2_context.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | |
| 13 #include "gpu/command_buffer/client/shared_memory_limits.h" | |
| 14 #include "gpu/command_buffer/client/transfer_buffer.h" | |
| 15 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | |
| 16 #include "gpu/ipc/client/gpu_channel_host.h" | |
| 17 #include "mojo/public/cpp/system/core.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace ui { | |
| 21 | |
| 22 GLES2Context::GLES2Context() {} | |
| 23 | |
| 24 GLES2Context::~GLES2Context() {} | |
| 25 | |
| 26 bool GLES2Context::Initialize( | |
| 27 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | |
| 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
| 29 DCHECK(gpu_channel_host); | |
| 30 gpu::SurfaceHandle surface_handle = gfx::kNullAcceleratedWidget; | |
| 31 // TODO(penghuang): support shared group. | |
| 32 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr; | |
| 33 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT; | |
| 34 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL; | |
| 35 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 36 // TODO(penghuang): figure a useful active_url. | |
| 37 GURL active_url; | |
| 38 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create( | |
| 39 std::move(gpu_channel_host), surface_handle, shared_command_buffer, | |
| 40 stream_id, stream_priority, attributes, active_url, | |
| 41 std::move(task_runner)); | |
| 42 if (!command_buffer_proxy_impl_) | |
| 43 return false; | |
| 44 gpu::CommandBuffer* command_buffer = command_buffer_proxy_impl_.get(); | |
| 45 gpu::GpuControl* gpu_control = command_buffer_proxy_impl_.get(); | |
| 46 | |
| 47 constexpr gpu::SharedMemoryLimits default_limits; | |
| 48 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); | |
| 49 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) | |
| 50 return false; | |
| 51 gles2_helper_->SetAutomaticFlushes(false); | |
| 52 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | |
| 53 gpu::Capabilities capabilities = gpu_control->GetCapabilities(); | |
| 54 bool bind_generates_resource = | |
| 55 !!capabilities.bind_generates_resource_chromium; | |
| 56 // TODO(piman): Some contexts (such as compositor) want this to be true, so | |
| 57 // this needs to be a public parameter. | |
| 58 bool lose_context_when_out_of_memory = false; | |
| 59 bool support_client_side_arrays = false; | |
| 60 implementation_.reset(new gpu::gles2::GLES2Implementation( | |
| 61 gles2_helper_.get(), NULL, transfer_buffer_.get(), | |
| 62 bind_generates_resource, lose_context_when_out_of_memory, | |
| 63 support_client_side_arrays, gpu_control)); | |
| 64 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size, | |
| 65 default_limits.min_transfer_buffer_size, | |
| 66 default_limits.max_transfer_buffer_size, | |
| 67 default_limits.mapped_memory_reclaim_limit)) | |
| 68 return false; | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 std::unique_ptr<GLES2Context> GLES2Context::CreateOffscreenContext( | |
| 74 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | |
| 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
| 76 if (!gpu_channel_host) | |
| 77 return nullptr; | |
| 78 | |
| 79 // Return the GLES2Context only if it is successfully initialized. If | |
| 80 // initialization fails, then return null. | |
| 81 std::unique_ptr<GLES2Context> gles2_context(new GLES2Context); | |
| 82 if (!gles2_context->Initialize(std::move(gpu_channel_host), | |
| 83 std::move(task_runner))) | |
| 84 gles2_context.reset(); | |
| 85 return gles2_context; | |
| 86 } | |
| 87 | |
| 88 } // namespace ui | |
| OLD | NEW |