Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/mus/public/cpp/lib/gles2_context.cc

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
21 mojo::ScopedMessagePipeHandle command_buffer_handle) 24 const std::vector<int32_t>& attribs,
22 : command_buffer_(attribs, std::move(command_buffer_handle)) {} 25 mojo::ScopedMessagePipeHandle command_buffer_handle) {
26 // TODO(penghuang): Use type gpu::gles2::ContextCreationAttribHelper for
27 // attribs.
28 if (!mus::GpuService::UseChromeGpuCommandBuffer()) {
29 command_buffer_client_impl_.reset(
30 new CommandBufferClientImpl(attribs, std::move(command_buffer_handle)));
31 } else {
32 // For using chrome gpu command buffer, the command_buffer_handle is not
33 // used.
34 DCHECK(!command_buffer_handle.is_valid());
35 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
36 GpuService::GetInstance()->gpu_channel_host();
37 gpu::SurfaceHandle surface_handle = gfx::kNullAcceleratedWidget;
38 // TODO(penghuang): support shared group.
39 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
40 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT;
41 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL;
42 gfx::GpuPreference gpu_preference = gfx::PreferIntegratedGpu;
43 gpu::gles2::ContextCreationAttribHelper attributes;
44 // TODO(penghuang): figure a useful active_url.
45 GURL active_url;
46 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
47 base::ThreadTaskRunnerHandle::Get();
48 if (attributes.Parse(attribs)) {
49 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create(
50 std::move(gpu_channel_host), surface_handle, gfx::Size(),
51 shared_command_buffer, stream_id, stream_priority, attributes,
52 active_url, gpu_preference, std::move(task_runner));
53 } else {
54 DLOG(WARNING) << "Parse attribs failed!";
55 }
56 }
57 }
23 58
24 GLES2Context::~GLES2Context() {} 59 GLES2Context::~GLES2Context() {}
25 60
26 bool GLES2Context::Initialize() { 61 bool GLES2Context::Initialize() {
27 if (!command_buffer_.Initialize()) 62 gpu::CommandBuffer* command_buffer = nullptr;
28 return false; 63 gpu::GpuControl* gpu_control = nullptr;
64 if (!mus::GpuService::UseChromeGpuCommandBuffer()) {
65 if (!command_buffer_client_impl_->Initialize())
66 return false;
67 command_buffer = command_buffer_client_impl_.get();
68 gpu_control = command_buffer_client_impl_.get();
69 } else {
70 if (!command_buffer_proxy_impl_)
71 return false;
72 command_buffer = command_buffer_proxy_impl_.get();
73 gpu_control = command_buffer_proxy_impl_.get();
74 }
29 75
30 constexpr gpu::SharedMemoryLimits default_limits; 76 constexpr gpu::SharedMemoryLimits default_limits;
31 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(&command_buffer_)); 77 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer));
32 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) 78 if (!gles2_helper_->Initialize(default_limits.command_buffer_size))
33 return false; 79 return false;
34 gles2_helper_->SetAutomaticFlushes(false); 80 gles2_helper_->SetAutomaticFlushes(false);
35 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); 81 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
36 gpu::Capabilities capabilities = command_buffer_.GetCapabilities(); 82 gpu::Capabilities capabilities = gpu_control->GetCapabilities();
37 bool bind_generates_resource = 83 bool bind_generates_resource =
38 !!capabilities.bind_generates_resource_chromium; 84 !!capabilities.bind_generates_resource_chromium;
39 // TODO(piman): Some contexts (such as compositor) want this to be true, so 85 // TODO(piman): Some contexts (such as compositor) want this to be true, so
40 // this needs to be a public parameter. 86 // this needs to be a public parameter.
41 bool lose_context_when_out_of_memory = false; 87 bool lose_context_when_out_of_memory = false;
42 bool support_client_side_arrays = false; 88 bool support_client_side_arrays = false;
43 implementation_.reset(new gpu::gles2::GLES2Implementation( 89 implementation_.reset(new gpu::gles2::GLES2Implementation(
44 gles2_helper_.get(), NULL, transfer_buffer_.get(), 90 gles2_helper_.get(), NULL, transfer_buffer_.get(),
45 bind_generates_resource, lose_context_when_out_of_memory, 91 bind_generates_resource, lose_context_when_out_of_memory,
46 support_client_side_arrays, &command_buffer_)); 92 support_client_side_arrays, gpu_control));
47 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size, 93 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size,
48 default_limits.min_transfer_buffer_size, 94 default_limits.min_transfer_buffer_size,
49 default_limits.max_transfer_buffer_size, 95 default_limits.max_transfer_buffer_size,
50 default_limits.mapped_memory_reclaim_limit)) 96 default_limits.mapped_memory_reclaim_limit))
51 return false; 97 return false;
52 return true; 98 return true;
53 } 99 }
54 100
55 } // namespace mus 101 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698