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

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/lib/command_buffer_client_impl.h"
13 #include "components/mus/public/cpp/lib/gpu_service.h"
14 #include "components/mus/public/interfaces/command_buffer.mojom.h"
15 #include "components/mus/public/interfaces/gpu_service.mojom.h"
12 #include "gpu/command_buffer/client/gles2_cmd_helper.h" 16 #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" 17 #include "gpu/command_buffer/client/shared_memory_limits.h"
15 #include "gpu/command_buffer/client/transfer_buffer.h" 18 #include "gpu/command_buffer/client/transfer_buffer.h"
19 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
16 #include "mojo/public/cpp/system/core.h" 20 #include "mojo/public/cpp/system/core.h"
21 #include "services/shell/public/cpp/connector.h"
22 #include "url/gurl.h"
17 23
18 namespace mus { 24 namespace mus {
19 25
20 GLES2Context::GLES2Context(const std::vector<int32_t>& attribs, 26 GLES2Context::GLES2Context() {}
21 mus::mojom::CommandBufferPtr command_buffer_ptr)
22 : command_buffer_(attribs, std::move(command_buffer_ptr)) {}
23 27
24 GLES2Context::~GLES2Context() {} 28 GLES2Context::~GLES2Context() {}
25 29
26 bool GLES2Context::Initialize() { 30 bool GLES2Context::Initialize(const std::vector<int32_t>& attribs,
27 if (!command_buffer_.Initialize()) 31 shell::Connector* connector) {
28 return false; 32 gpu::CommandBuffer* command_buffer = nullptr;
33 gpu::GpuControl* gpu_control = nullptr;
34 // TODO(penghuang): Use type gpu::gles2::ContextCreationAttribHelper for
35 // attribs.
36 if (!mus::GpuService::UseChromeGpuCommandBuffer()) {
37 mojom::GpuPtr gpu;
38 connector->ConnectToInterface("mojo:mus", &gpu);
39 mojom::CommandBufferPtr command_buffer_ptr;
40 gpu->CreateOffscreenGLES2Context(GetProxy(&command_buffer_ptr));
41 command_buffer_client_impl_.reset(
42 new CommandBufferClientImpl(attribs, std::move(command_buffer_ptr)));
43 if (!command_buffer_client_impl_->Initialize())
44 return false;
45 command_buffer = command_buffer_client_impl_.get();
46 gpu_control = command_buffer_client_impl_.get();
47 } else {
48 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
49 GpuService::GetInstance()->EstablishGpuChannel(connector);
piman 2016/05/31 23:14:05 gpu_channel_host can be null, in which case you wa
Peng 2016/06/01 14:11:28 Done.
50 gpu::SurfaceHandle surface_handle = gfx::kNullAcceleratedWidget;
51 // TODO(penghuang): support shared group.
52 gpu::CommandBufferProxyImpl* shared_command_buffer = nullptr;
53 gpu::GpuStreamId stream_id = gpu::GpuStreamId::GPU_STREAM_DEFAULT;
54 gpu::GpuStreamPriority stream_priority = gpu::GpuStreamPriority::NORMAL;
55 gl::GpuPreference gpu_preference = gl::PreferIntegratedGpu;
56 gpu::gles2::ContextCreationAttribHelper attributes;
57 // TODO(penghuang): figure a useful active_url.
58 GURL active_url;
59 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
60 base::ThreadTaskRunnerHandle::Get();
61 if (!attributes.Parse(attribs))
62 return false;
63 command_buffer_proxy_impl_ = gpu::CommandBufferProxyImpl::Create(
64 std::move(gpu_channel_host), surface_handle, gfx::Size(),
65 shared_command_buffer, stream_id, stream_priority, attributes,
66 active_url, gpu_preference, std::move(task_runner));
67 if (!command_buffer_proxy_impl_)
68 return false;
69 command_buffer = command_buffer_proxy_impl_.get();
70 gpu_control = command_buffer_proxy_impl_.get();
71 }
29 72
30 constexpr gpu::SharedMemoryLimits default_limits; 73 constexpr gpu::SharedMemoryLimits default_limits;
31 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(&command_buffer_)); 74 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer));
32 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) 75 if (!gles2_helper_->Initialize(default_limits.command_buffer_size))
33 return false; 76 return false;
34 gles2_helper_->SetAutomaticFlushes(false); 77 gles2_helper_->SetAutomaticFlushes(false);
35 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); 78 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
36 gpu::Capabilities capabilities = command_buffer_.GetCapabilities(); 79 gpu::Capabilities capabilities = gpu_control->GetCapabilities();
37 bool bind_generates_resource = 80 bool bind_generates_resource =
38 !!capabilities.bind_generates_resource_chromium; 81 !!capabilities.bind_generates_resource_chromium;
39 // TODO(piman): Some contexts (such as compositor) want this to be true, so 82 // TODO(piman): Some contexts (such as compositor) want this to be true, so
40 // this needs to be a public parameter. 83 // this needs to be a public parameter.
41 bool lose_context_when_out_of_memory = false; 84 bool lose_context_when_out_of_memory = false;
42 bool support_client_side_arrays = false; 85 bool support_client_side_arrays = false;
43 implementation_.reset(new gpu::gles2::GLES2Implementation( 86 implementation_.reset(new gpu::gles2::GLES2Implementation(
44 gles2_helper_.get(), NULL, transfer_buffer_.get(), 87 gles2_helper_.get(), NULL, transfer_buffer_.get(),
45 bind_generates_resource, lose_context_when_out_of_memory, 88 bind_generates_resource, lose_context_when_out_of_memory,
46 support_client_side_arrays, &command_buffer_)); 89 support_client_side_arrays, gpu_control));
47 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size, 90 if (!implementation_->Initialize(default_limits.start_transfer_buffer_size,
48 default_limits.min_transfer_buffer_size, 91 default_limits.min_transfer_buffer_size,
49 default_limits.max_transfer_buffer_size, 92 default_limits.max_transfer_buffer_size,
50 default_limits.mapped_memory_reclaim_limit)) 93 default_limits.mapped_memory_reclaim_limit))
51 return false; 94 return false;
52 return true; 95 return true;
53 } 96 }
54 97
98 // static
99 std::unique_ptr<GLES2Context> GLES2Context::CreateOffscreenContext(
100 const std::vector<int32_t>& attribs,
101 shell::Connector* connector) {
102 std::unique_ptr<GLES2Context> gles2_context(new GLES2Context);
103 if (!gles2_context->Initialize(attribs, connector))
104 gles2_context.reset();
105 return gles2_context;
106 }
107
55 } // namespace mus 108 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/lib/context_provider.cc ('k') | components/mus/public/cpp/lib/gpu_memory_buffer_manager_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698