OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
6 | 6 |
7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
10 #endif | 10 #endif |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "gpu/command_buffer/client/transfer_buffer.h" | 32 #include "gpu/command_buffer/client/transfer_buffer.h" |
33 #include "gpu/command_buffer/common/constants.h" | 33 #include "gpu/command_buffer/common/constants.h" |
34 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 34 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
35 #include "gpu/command_buffer/common/mailbox.h" | 35 #include "gpu/command_buffer/common/mailbox.h" |
36 #include "gpu/ipc/client/gpu_channel_host.h" | 36 #include "gpu/ipc/client/gpu_channel_host.h" |
37 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 37 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
38 #include "third_party/skia/include/core/SkTypes.h" | 38 #include "third_party/skia/include/core/SkTypes.h" |
39 | 39 |
40 namespace content { | 40 namespace content { |
41 | 41 |
42 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 42 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() { |
43 gpu::SurfaceHandle surface_handle, | |
44 const GURL& active_url, | |
45 scoped_refptr<gpu::GpuChannelHost> host, | |
46 gfx::GpuPreference gpu_preference, | |
47 bool automatic_flushes) | |
48 : automatic_flushes_(automatic_flushes), | |
49 surface_handle_(surface_handle), | |
50 active_url_(active_url), | |
51 gpu_preference_(gpu_preference), | |
52 host_(std::move(host)) { | |
53 DCHECK(host_); | |
54 } | 43 } |
55 | 44 |
56 WebGraphicsContext3DCommandBufferImpl:: | 45 WebGraphicsContext3DCommandBufferImpl:: |
57 ~WebGraphicsContext3DCommandBufferImpl() {} | 46 ~WebGraphicsContext3DCommandBufferImpl() {} |
58 | 47 |
59 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( | 48 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( |
| 49 gpu::SurfaceHandle surface_handle, |
| 50 const GURL& active_url, |
| 51 gpu::GpuChannelHost* host, |
| 52 gfx::GpuPreference gpu_preference, |
| 53 bool automatic_flushes, |
60 const gpu::SharedMemoryLimits& memory_limits, | 54 const gpu::SharedMemoryLimits& memory_limits, |
61 gpu::CommandBufferProxyImpl* shared_command_buffer, | 55 gpu::CommandBufferProxyImpl* shared_command_buffer, |
62 scoped_refptr<gpu::gles2::ShareGroup> share_group, | 56 scoped_refptr<gpu::gles2::ShareGroup> share_group, |
63 const gpu::gles2::ContextCreationAttribHelper& attributes, | 57 const gpu::gles2::ContextCreationAttribHelper& attributes, |
64 command_buffer_metrics::ContextType context_type) { | 58 command_buffer_metrics::ContextType context_type) { |
65 DCHECK_EQ(!!shared_command_buffer, !!share_group); | 59 DCHECK_EQ(!!shared_command_buffer, !!share_group); |
66 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 60 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
67 | 61 |
68 DCHECK(attributes.buffer_preserved); | 62 DCHECK(attributes.buffer_preserved); |
69 std::vector<int32_t> serialized_attributes; | 63 std::vector<int32_t> serialized_attributes; |
70 attributes.Serialize(&serialized_attributes); | 64 attributes.Serialize(&serialized_attributes); |
71 | 65 |
72 // Create a proxy to a command buffer in the GPU process. | 66 // Create a proxy to a command buffer in the GPU process. |
73 command_buffer_ = host_->CreateCommandBuffer( | 67 command_buffer_ = host->CreateCommandBuffer( |
74 surface_handle_, gfx::Size(), shared_command_buffer, | 68 surface_handle, gfx::Size(), shared_command_buffer, |
75 gpu::GpuChannelHost::kDefaultStreamId, | 69 gpu::GpuChannelHost::kDefaultStreamId, |
76 gpu::GpuChannelHost::kDefaultStreamPriority, serialized_attributes, | 70 gpu::GpuChannelHost::kDefaultStreamPriority, serialized_attributes, |
77 active_url_, gpu_preference_); | 71 active_url, gpu_preference); |
78 | 72 |
79 if (!command_buffer_) { | 73 if (!command_buffer_) { |
80 DLOG(ERROR) << "GpuChannelHost failed to create command buffer."; | 74 DLOG(ERROR) << "GpuChannelHost failed to create command buffer."; |
81 command_buffer_metrics::UmaRecordContextInitFailed(context_type); | 75 command_buffer_metrics::UmaRecordContextInitFailed(context_type); |
82 return false; | 76 return false; |
83 } | 77 } |
84 | 78 |
85 // The GLES2 helper writes the command buffer protocol. | 79 // The GLES2 helper writes the command buffer protocol. |
86 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 80 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
87 gles2_helper_->SetAutomaticFlushes(automatic_flushes_); | 81 gles2_helper_->SetAutomaticFlushes(automatic_flushes); |
88 if (!gles2_helper_->Initialize(memory_limits.command_buffer_size)) { | 82 if (!gles2_helper_->Initialize(memory_limits.command_buffer_size)) { |
89 DLOG(ERROR) << "Failed to initialize GLES2CmdHelper."; | 83 DLOG(ERROR) << "Failed to initialize GLES2CmdHelper."; |
90 return false; | 84 return false; |
91 } | 85 } |
92 | 86 |
93 // The transfer buffer is used to copy resources between the client | 87 // The transfer buffer is used to copy resources between the client |
94 // process and the GPU process. | 88 // process and the GPU process. |
95 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); | 89 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); |
96 | 90 |
97 const bool bind_generates_resource = attributes.bind_generates_resource; | 91 const bool bind_generates_resource = attributes.bind_generates_resource; |
(...skipping 13 matching lines...) Expand all Loading... |
111 memory_limits.mapped_memory_reclaim_limit)) { | 105 memory_limits.mapped_memory_reclaim_limit)) { |
112 DLOG(ERROR) << "Failed to initialize GLES2Implementation."; | 106 DLOG(ERROR) << "Failed to initialize GLES2Implementation."; |
113 return false; | 107 return false; |
114 } | 108 } |
115 | 109 |
116 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", "CommandBufferContext"); | 110 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", "CommandBufferContext"); |
117 return true; | 111 return true; |
118 } | 112 } |
119 | 113 |
120 bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread( | 114 bool WebGraphicsContext3DCommandBufferImpl::InitializeOnCurrentThread( |
| 115 gpu::SurfaceHandle surface_handle, |
| 116 const GURL& active_url, |
| 117 gpu::GpuChannelHost* host, |
| 118 gfx::GpuPreference gpu_preference, |
| 119 bool automatic_flushes, |
121 const gpu::SharedMemoryLimits& memory_limits, | 120 const gpu::SharedMemoryLimits& memory_limits, |
122 gpu::CommandBufferProxyImpl* shared_command_buffer, | 121 gpu::CommandBufferProxyImpl* shared_command_buffer, |
123 scoped_refptr<gpu::gles2::ShareGroup> share_group, | 122 scoped_refptr<gpu::gles2::ShareGroup> share_group, |
124 const gpu::gles2::ContextCreationAttribHelper& attributes, | 123 const gpu::gles2::ContextCreationAttribHelper& attributes, |
125 command_buffer_metrics::ContextType context_type) { | 124 command_buffer_metrics::ContextType context_type) { |
126 if (!MaybeInitializeGL(memory_limits, shared_command_buffer, | 125 if (!MaybeInitializeGL(surface_handle, active_url, host, gpu_preference, |
127 std::move(share_group), attributes, context_type)) | 126 automatic_flushes, memory_limits, |
| 127 shared_command_buffer, std::move(share_group), |
| 128 attributes, context_type)) |
128 return false; | 129 return false; |
129 if (gpu::error::IsError(command_buffer_->GetLastError())) { | 130 if (gpu::error::IsError(command_buffer_->GetLastError())) { |
130 DLOG(ERROR) << "Context dead on arrival. Last error: " | 131 DLOG(ERROR) << "Context dead on arrival. Last error: " |
131 << command_buffer_->GetLastError(); | 132 << command_buffer_->GetLastError(); |
132 return false; | 133 return false; |
133 } | 134 } |
134 | 135 |
135 return true; | 136 return true; |
136 } | 137 } |
137 | 138 |
138 } // namespace content | 139 } // namespace content |
OLD | NEW |