OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | |
6 | |
7 #include "third_party/khronos/GLES2/gl2.h" | |
8 #ifndef GL_GLEXT_PROTOTYPES | |
9 #define GL_GLEXT_PROTOTYPES 1 | |
10 #endif | |
11 #include "third_party/khronos/GLES2/gl2ext.h" | |
12 | |
13 #include <algorithm> | |
14 #include <map> | |
15 #include <memory> | |
16 | |
17 #include "base/atomicops.h" | |
18 #include "base/bind.h" | |
19 #include "base/command_line.h" | |
20 #include "base/lazy_instance.h" | |
21 #include "base/logging.h" | |
22 #include "base/message_loop/message_loop.h" | |
23 #include "base/metrics/field_trial.h" | |
24 #include "base/metrics/histogram.h" | |
25 #include "base/profiler/scoped_tracker.h" | |
26 #include "base/trace_event/trace_event.h" | |
27 #include "gpu/GLES2/gl2extchromium.h" | |
28 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | |
29 #include "gpu/command_buffer/client/gles2_implementation.h" | |
30 #include "gpu/command_buffer/client/gpu_switches.h" | |
31 #include "gpu/command_buffer/client/shared_memory_limits.h" | |
32 #include "gpu/command_buffer/client/transfer_buffer.h" | |
33 #include "gpu/command_buffer/common/constants.h" | |
34 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | |
35 #include "gpu/command_buffer/common/mailbox.h" | |
36 #include "gpu/ipc/client/gpu_channel_host.h" | |
37 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | |
38 #include "third_party/skia/include/core/SkTypes.h" | |
39 | |
40 namespace content { | |
41 | |
42 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() { | |
43 } | |
44 | |
45 WebGraphicsContext3DCommandBufferImpl:: | |
46 ~WebGraphicsContext3DCommandBufferImpl() {} | |
47 | |
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, | |
54 const gpu::SharedMemoryLimits& memory_limits, | |
55 gpu::CommandBufferProxyImpl* shared_command_buffer, | |
56 scoped_refptr<gpu::gles2::ShareGroup> share_group, | |
57 const gpu::gles2::ContextCreationAttribHelper& attributes, | |
58 command_buffer_metrics::ContextType context_type) { | |
59 DCHECK_EQ(!!shared_command_buffer, !!share_group); | |
60 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | |
61 | |
62 DCHECK(attributes.buffer_preserved); | |
63 std::vector<int32_t> serialized_attributes; | |
64 attributes.Serialize(&serialized_attributes); | |
65 | |
66 // Create a proxy to a command buffer in the GPU process. | |
67 command_buffer_ = host->CreateCommandBuffer( | |
68 surface_handle, gfx::Size(), shared_command_buffer, | |
69 gpu::GpuChannelHost::kDefaultStreamId, | |
70 gpu::GpuChannelHost::kDefaultStreamPriority, serialized_attributes, | |
71 active_url, gpu_preference); | |
72 | |
73 if (!command_buffer_) { | |
74 DLOG(ERROR) << "GpuChannelHost failed to create command buffer."; | |
75 command_buffer_metrics::UmaRecordContextInitFailed(context_type); | |
76 return false; | |
77 } | |
78 | |
79 // The GLES2 helper writes the command buffer protocol. | |
80 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | |
81 gles2_helper_->SetAutomaticFlushes(automatic_flushes); | |
82 if (!gles2_helper_->Initialize(memory_limits.command_buffer_size)) { | |
83 DLOG(ERROR) << "Failed to initialize GLES2CmdHelper."; | |
84 return false; | |
85 } | |
86 | |
87 // The transfer buffer is used to copy resources between the client | |
88 // process and the GPU process. | |
89 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); | |
90 | |
91 const bool bind_generates_resource = attributes.bind_generates_resource; | |
92 const bool lose_context_when_out_of_memory = | |
93 attributes.lose_context_when_out_of_memory; | |
94 const bool support_client_side_arrays = false; | |
95 | |
96 // The GLES2Implementation exposes the OpenGLES2 API, as well as the | |
97 // gpu::ContextSupport interface. | |
98 real_gl_.reset(new gpu::gles2::GLES2Implementation( | |
99 gles2_helper_.get(), std::move(share_group), transfer_buffer_.get(), | |
100 bind_generates_resource, lose_context_when_out_of_memory, | |
101 support_client_side_arrays, command_buffer_.get())); | |
102 if (!real_gl_->Initialize(memory_limits.start_transfer_buffer_size, | |
103 memory_limits.min_transfer_buffer_size, | |
104 memory_limits.max_transfer_buffer_size, | |
105 memory_limits.mapped_memory_reclaim_limit)) { | |
106 DLOG(ERROR) << "Failed to initialize GLES2Implementation."; | |
107 return false; | |
108 } | |
109 | |
110 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", "CommandBufferContext"); | |
111 return true; | |
112 } | |
113 | |
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, | |
120 const gpu::SharedMemoryLimits& memory_limits, | |
121 gpu::CommandBufferProxyImpl* shared_command_buffer, | |
122 scoped_refptr<gpu::gles2::ShareGroup> share_group, | |
123 const gpu::gles2::ContextCreationAttribHelper& attributes, | |
124 command_buffer_metrics::ContextType context_type) { | |
125 if (!MaybeInitializeGL(surface_handle, active_url, host, gpu_preference, | |
126 automatic_flushes, memory_limits, | |
127 shared_command_buffer, std::move(share_group), | |
128 attributes, context_type)) | |
129 return false; | |
130 if (gpu::error::IsError(command_buffer_->GetLastError())) { | |
131 DLOG(ERROR) << "Context dead on arrival. Last error: " | |
132 << command_buffer_->GetLastError(); | |
133 return false; | |
134 } | |
135 | |
136 return true; | |
137 } | |
138 | |
139 } // namespace content | |
OLD | NEW |