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/renderer/pepper/pepper_platform_context_3d_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
8 #include "content/common/gpu/client/gpu_channel_host.h" | 9 #include "content/common/gpu/client/gpu_channel_host.h" |
9 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
10 #include "content/renderer/pepper/pepper_parent_context_provider.h" | |
11 #include "content/renderer/render_thread_impl.h" | 11 #include "content/renderer/render_thread_impl.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 13 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
14 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
15 #include "gpu/ipc/command_buffer_proxy.h" | 15 #include "gpu/ipc/command_buffer_proxy.h" |
16 #include "ppapi/c/pp_graphics_3d.h" | 16 #include "ppapi/c/pp_graphics_3d.h" |
17 #include "ui/gl/gpu_preference.h" | 17 #include "ui/gl/gpu_preference.h" |
18 | 18 |
19 #ifdef ENABLE_GPU | 19 #ifdef ENABLE_GPU |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 PlatformContext3DImpl::PlatformContext3DImpl( | 23 PlatformContext3DImpl::PlatformContext3DImpl() |
24 PepperParentContextProvider* parent_context_provider) | 24 : parent_texture_id_(0), |
25 : parent_context_provider_(parent_context_provider), | 25 has_alpha_(false), |
26 parent_texture_id_(0), | 26 command_buffer_(NULL), |
27 has_alpha_(false), | 27 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
28 command_buffer_(NULL), | |
29 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
30 } | 28 } |
31 | 29 |
32 PlatformContext3DImpl::~PlatformContext3DImpl() { | 30 PlatformContext3DImpl::~PlatformContext3DImpl() { |
33 if (parent_context_.get() && parent_texture_id_ != 0) { | 31 if (parent_texture_id_) { |
34 // Flush any remaining commands in the parent context to make sure the | 32 // Flush any remaining commands in the parent context to make sure the |
35 // texture id accounting stays consistent. | 33 // texture id accounting stays consistent. |
36 gpu::gles2::GLES2Implementation* parent_gles2 = | 34 gpu::gles2::GLES2Implementation* parent_gles2 = |
37 parent_context_->GetImplementation(); | 35 parent_context_provider_->Context3d()->GetImplementation(); |
38 parent_gles2->helper()->CommandBufferHelper::Finish(); | 36 parent_gles2->helper()->CommandBufferHelper::Finish(); |
39 parent_gles2->FreeTextureId(parent_texture_id_); | 37 parent_gles2->FreeTextureId(parent_texture_id_); |
40 } | 38 } |
41 | 39 |
42 if (command_buffer_) { | 40 if (command_buffer_) { |
43 DCHECK(channel_.get()); | 41 DCHECK(channel_.get()); |
44 channel_->DestroyCommandBuffer(command_buffer_); | 42 channel_->DestroyCommandBuffer(command_buffer_); |
45 command_buffer_ = NULL; | 43 command_buffer_ = NULL; |
46 } | 44 } |
47 | 45 |
48 channel_ = NULL; | 46 channel_ = NULL; |
49 } | 47 } |
50 | 48 |
51 bool PlatformContext3DImpl::Init(const int32* attrib_list, | 49 bool PlatformContext3DImpl::Init(const int32* attrib_list, |
52 PlatformContext3D* share_context) { | 50 PlatformContext3D* share_context) { |
53 // Ignore initializing more than once. | 51 // Ignore initializing more than once. |
54 if (command_buffer_) | 52 if (command_buffer_) |
55 return true; | 53 return true; |
56 | 54 |
57 if (!parent_context_provider_) | |
58 return false; | |
59 | |
60 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 55 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
61 if (!render_thread) | 56 if (!render_thread) |
62 return false; | 57 return false; |
63 | 58 |
64 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 59 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
65 | 60 |
66 channel_ = render_thread->EstablishGpuChannelSync( | 61 channel_ = render_thread->EstablishGpuChannelSync( |
67 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); | 62 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); |
68 if (!channel_.get()) | 63 if (!channel_.get()) |
69 return false; | 64 return false; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 if (!command_buffer_) | 114 if (!command_buffer_) |
120 return false; | 115 return false; |
121 | 116 |
122 command_buffer_->SetChannelErrorCallback( | 117 command_buffer_->SetChannelErrorCallback( |
123 base::Bind(&PlatformContext3DImpl::OnContextLost, | 118 base::Bind(&PlatformContext3DImpl::OnContextLost, |
124 weak_ptr_factory_.GetWeakPtr())); | 119 weak_ptr_factory_.GetWeakPtr())); |
125 command_buffer_->SetOnConsoleMessageCallback( | 120 command_buffer_->SetOnConsoleMessageCallback( |
126 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, | 121 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, |
127 weak_ptr_factory_.GetWeakPtr())); | 122 weak_ptr_factory_.GetWeakPtr())); |
128 | 123 |
129 // Fetch the parent context now, after any potential shutdown of the | 124 parent_context_provider_ = |
130 // channel due to GPU switching, and creation of the Pepper 3D | 125 render_thread->OffscreenContextProviderForMainThread(); |
131 // context with the discrete GPU preference. | 126 if (!parent_context_provider_->InitializeOnMainThread() || |
132 WebGraphicsContext3DCommandBufferImpl* parent_context = | 127 !parent_context_provider_->BindToCurrentThread()) { |
piman
2013/03/08 04:43:16
Is it ok to do those every time? Should this be do
danakj
2013/03/08 18:13:34
Ya this is a noop if you already did it once. I li
piman
2013/03/08 18:27:08
It does have side effect in the sense that it crea
danakj
2013/03/08 18:40:28
It creates a context provider, which is just a wra
| |
133 parent_context_provider_->GetParentContextForPlatformContext3D(); | 128 parent_context_provider_ = NULL; |
134 if (!parent_context) | |
135 return false; | 129 return false; |
136 | 130 } |
137 parent_context_provider_ = NULL; | |
138 parent_context_ = parent_context->AsWeakPtr(); | |
139 | 131 |
140 // Flush any remaining commands in the parent context to make sure the | 132 // Flush any remaining commands in the parent context to make sure the |
141 // texture id accounting stays consistent. | 133 // texture id accounting stays consistent. |
142 gpu::gles2::GLES2Implementation* parent_gles2 = | 134 gpu::gles2::GLES2Implementation* parent_gles2 = |
143 parent_context_->GetImplementation(); | 135 parent_context_provider_->Context3d()->GetImplementation(); |
144 parent_gles2->helper()->CommandBufferHelper::Finish(); | 136 parent_gles2->helper()->CommandBufferHelper::Finish(); |
145 parent_texture_id_ = parent_gles2->MakeTextureId(); | 137 parent_texture_id_ = parent_gles2->MakeTextureId(); |
146 | 138 |
147 CommandBufferProxyImpl* parent_command_buffer = | 139 CommandBufferProxyImpl* parent_command_buffer = |
148 parent_context_->GetCommandBufferProxy(); | 140 parent_context_provider_->Context3d()->GetCommandBufferProxy(); |
149 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_)) | 141 command_buffer_->SetParent(parent_command_buffer, parent_texture_id_); |
150 return false; | |
151 | |
152 return true; | 142 return true; |
153 } | 143 } |
154 | 144 |
155 void PlatformContext3DImpl::SetParentContext( | |
156 PepperParentContextProvider* parent_context_provider) { | |
157 if (parent_context_.get() && parent_texture_id_ != 0) { | |
158 // Flush any remaining commands in the parent context to make sure the | |
159 // texture id accounting stays consistent. | |
160 gpu::gles2::GLES2Implementation* parent_gles2 = | |
161 parent_context_->GetImplementation(); | |
162 parent_gles2->helper()->CommandBufferHelper::Flush(); | |
163 parent_gles2->FreeTextureId(parent_texture_id_); | |
164 parent_context_.reset(); | |
165 parent_texture_id_ = 0; | |
166 } | |
167 | |
168 WebGraphicsContext3DCommandBufferImpl* parent_context = | |
169 parent_context_provider->GetParentContextForPlatformContext3D(); | |
170 if (!parent_context) | |
171 return; | |
172 | |
173 parent_context_ = parent_context->AsWeakPtr(); | |
174 // Flush any remaining commands in the parent context to make sure the | |
175 // texture id accounting stays consistent. | |
176 gpu::gles2::GLES2Implementation* parent_gles2 = | |
177 parent_context_->GetImplementation(); | |
178 parent_gles2->helper()->CommandBufferHelper::Flush(); | |
179 parent_texture_id_ = parent_gles2->MakeTextureId(); | |
180 | |
181 CommandBufferProxyImpl* parent_command_buffer = | |
182 parent_context_->GetCommandBufferProxy(); | |
183 command_buffer_->SetParent(parent_command_buffer, parent_texture_id_); | |
184 } | |
185 | |
186 unsigned PlatformContext3DImpl::GetBackingTextureId() { | 145 unsigned PlatformContext3DImpl::GetBackingTextureId() { |
187 DCHECK(command_buffer_); | 146 DCHECK(command_buffer_); |
188 return parent_texture_id_; | 147 return parent_texture_id_; |
189 } | 148 } |
190 | 149 |
191 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() { | 150 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() { |
192 return parent_context_.get(); | 151 return parent_context_provider_->Context3d(); |
193 } | 152 } |
194 | 153 |
195 bool PlatformContext3DImpl::IsOpaque() { | 154 bool PlatformContext3DImpl::IsOpaque() { |
196 DCHECK(command_buffer_); | 155 DCHECK(command_buffer_); |
197 return !has_alpha_; | 156 return !has_alpha_; |
198 } | 157 } |
199 | 158 |
200 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { | 159 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { |
201 return command_buffer_; | 160 return command_buffer_; |
202 } | 161 } |
(...skipping 26 matching lines...) Expand all Loading... | |
229 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { | 188 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { |
230 DCHECK(command_buffer_); | 189 DCHECK(command_buffer_); |
231 | 190 |
232 if (!console_message_callback_.is_null()) | 191 if (!console_message_callback_.is_null()) |
233 console_message_callback_.Run(msg, id); | 192 console_message_callback_.Run(msg, id); |
234 } | 193 } |
235 | 194 |
236 } // namespace content | 195 } // namespace content |
237 | 196 |
238 #endif // ENABLE_GPU | 197 #endif // ENABLE_GPU |
OLD | NEW |