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/ppb_graphics_3d_impl.h" | 5 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
14 #include "content/public/common/web_preferences.h" | 14 #include "content/public/common/web_preferences.h" |
15 #include "content/renderer/pepper/host_globals.h" | 15 #include "content/renderer/pepper/host_globals.h" |
16 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 16 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
17 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 17 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
18 #include "content/renderer/pepper/plugin_module.h" | 18 #include "content/renderer/pepper/plugin_module.h" |
19 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
20 #include "content/renderer/render_view_impl.h" | 20 #include "content/renderer/render_view_impl.h" |
21 #include "gpu/GLES2/gl2extchromium.h" | |
21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
22 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 23 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
23 #include "gpu/ipc/client/gpu_channel_host.h" | 24 #include "gpu/ipc/client/gpu_channel_host.h" |
24 #include "ppapi/c/ppp_graphics_3d.h" | 25 #include "ppapi/c/ppp_graphics_3d.h" |
25 #include "ppapi/thunk/enter.h" | 26 #include "ppapi/thunk/enter.h" |
26 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
27 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 28 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
28 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
30 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 31 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
31 #include "third_party/khronos/GLES2/gl2.h" | 32 #include "third_party/khronos/GLES2/gl2.h" |
32 | 33 |
33 using ppapi::thunk::EnterResourceNoLock; | 34 using ppapi::thunk::EnterResourceNoLock; |
34 using ppapi::thunk::PPB_Graphics3D_API; | 35 using ppapi::thunk::PPB_Graphics3D_API; |
35 using blink::WebConsoleMessage; | 36 using blink::WebConsoleMessage; |
36 using blink::WebLocalFrame; | 37 using blink::WebLocalFrame; |
37 using blink::WebPluginContainer; | 38 using blink::WebPluginContainer; |
38 using blink::WebString; | 39 using blink::WebString; |
39 | 40 |
40 namespace content { | 41 namespace content { |
41 | 42 |
42 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) | 43 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) |
43 : PPB_Graphics3D_Shared(instance), | 44 : PPB_Graphics3D_Shared(instance), |
44 bound_to_instance_(false), | 45 bound_to_instance_(false), |
45 commit_pending_(false), | 46 commit_pending_(false), |
46 has_alpha_(false), | 47 has_alpha_(false), |
47 weak_ptr_factory_(this) {} | 48 use_image_chromium_(false), |
49 weak_ptr_factory_(this) { | |
50 #if defined(OS_MACOSX) | |
51 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
52 bool use_image_chromium = | |
53 !command_line->HasSwitch(switches::kDisablePepper3DImageChromium); | |
54 use_image_chromium_ = use_image_chromium; | |
55 | |
56 // TODO(erikchen): Remove this line to enable the feature. | |
57 use_image_chromium_ = false; | |
58 #endif | |
59 } | |
48 | 60 |
49 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 61 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
50 // Unset the client before the command_buffer_ is destroyed, similar to how | 62 // Unset the client before the command_buffer_ is destroyed, similar to how |
51 // WeakPtrFactory invalidates before it. | 63 // WeakPtrFactory invalidates before it. |
52 if (command_buffer_) | 64 if (command_buffer_) |
53 command_buffer_->SetGpuControlClient(nullptr); | 65 command_buffer_->SetGpuControlClient(nullptr); |
54 } | 66 } |
55 | 67 |
56 // static | 68 // static |
57 PP_Resource PPB_Graphics3D_Impl::CreateRaw( | 69 PP_Resource PPB_Graphics3D_Impl::CreateRaw( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 } | 178 } |
167 | 179 |
168 if (bound_to_instance_) { | 180 if (bound_to_instance_) { |
169 // If we are bound to the instance, we need to ask the compositor | 181 // If we are bound to the instance, we need to ask the compositor |
170 // to commit our backing texture so that the graphics appears on the page. | 182 // to commit our backing texture so that the graphics appears on the page. |
171 // When the backing texture will be committed we get notified via | 183 // When the backing texture will be committed we get notified via |
172 // ViewFlushedPaint(). | 184 // ViewFlushedPaint(). |
173 // | 185 // |
174 // Don't need to check for NULL from GetPluginInstance since when we're | 186 // Don't need to check for NULL from GetPluginInstance since when we're |
175 // bound, we know our instance is valid. | 187 // bound, we know our instance is valid. |
176 cc::TextureMailbox texture_mailbox(taken_front_buffer_, sync_token, | 188 bool is_overlay_candidate = use_image_chromium_; |
177 GL_TEXTURE_2D); | 189 GLenum target = |
190 is_overlay_candidate ? GL_TEXTURE_RECTANGLE_ARB : GL_TEXTURE_2D; | |
191 cc::TextureMailbox texture_mailbox(taken_front_buffer_, sync_token, target, | |
192 gfx::Size(width(), height()), | |
piman
2016/06/28 20:51:41
The size will be wrong here.
PPB_Graphics3D_Share
| |
193 is_overlay_candidate, false); | |
178 taken_front_buffer_.SetZero(); | 194 taken_front_buffer_.SetZero(); |
179 HostGlobals::Get() | 195 HostGlobals::Get() |
180 ->GetInstance(pp_instance()) | 196 ->GetInstance(pp_instance()) |
181 ->CommitTextureMailbox(texture_mailbox); | 197 ->CommitTextureMailbox(texture_mailbox); |
182 commit_pending_ = true; | 198 commit_pending_ = true; |
183 } else { | 199 } else { |
184 // Wait for the command to complete on the GPU to allow for throttling. | 200 // Wait for the command to complete on the GPU to allow for throttling. |
185 command_buffer_->SignalSyncToken( | 201 command_buffer_->SignalSyncToken( |
186 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 202 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
187 weak_ptr_factory_.GetWeakPtr())); | 203 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 attribs.push_back(attr[0]); | 270 attribs.push_back(attr[0]); |
255 attribs.push_back(attr[1]); | 271 attribs.push_back(attr[1]); |
256 break; | 272 break; |
257 } | 273 } |
258 } | 274 } |
259 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 275 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
260 } | 276 } |
261 gpu::gles2::ContextCreationAttribHelper attrib_helper; | 277 gpu::gles2::ContextCreationAttribHelper attrib_helper; |
262 if (!attrib_helper.Parse(attribs)) | 278 if (!attrib_helper.Parse(attribs)) |
263 return false; | 279 return false; |
280 attrib_helper.should_use_native_gmb_for_backbuffer = use_image_chromium_; | |
264 | 281 |
265 gpu::CommandBufferProxyImpl* share_buffer = NULL; | 282 gpu::CommandBufferProxyImpl* share_buffer = NULL; |
266 if (share_context) { | 283 if (share_context) { |
267 PPB_Graphics3D_Impl* share_graphics = | 284 PPB_Graphics3D_Impl* share_graphics = |
268 static_cast<PPB_Graphics3D_Impl*>(share_context); | 285 static_cast<PPB_Graphics3D_Impl*>(share_context); |
269 share_buffer = share_graphics->GetCommandBufferProxy(); | 286 share_buffer = share_graphics->GetCommandBufferProxy(); |
270 } | 287 } |
271 | 288 |
272 command_buffer_ = gpu::CommandBufferProxyImpl::Create( | 289 command_buffer_ = gpu::CommandBufferProxyImpl::Create( |
273 std::move(channel), gpu::kNullSurfaceHandle, surface_size, share_buffer, | 290 std::move(channel), gpu::kNullSurfaceHandle, surface_size, share_buffer, |
274 gpu::GPU_STREAM_DEFAULT, gpu::GpuStreamPriority::NORMAL, | 291 gpu::GPU_STREAM_DEFAULT, gpu::GpuStreamPriority::NORMAL, |
275 attrib_helper, GURL::EmptyGURL(), gpu_preference, | 292 attrib_helper, GURL::EmptyGURL(), gpu_preference, |
276 base::ThreadTaskRunnerHandle::Get()); | 293 base::ThreadTaskRunnerHandle::Get()); |
294 SetSize(surface_size.width(), surface_size.height()); | |
277 if (!command_buffer_) | 295 if (!command_buffer_) |
278 return false; | 296 return false; |
279 | 297 |
280 command_buffer_->SetGpuControlClient(this); | 298 command_buffer_->SetGpuControlClient(this); |
281 | 299 |
282 if (shared_state_handle) | 300 if (shared_state_handle) |
283 *shared_state_handle = command_buffer_->GetSharedStateHandle(); | 301 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
284 if (capabilities) | 302 if (capabilities) |
285 *capabilities = command_buffer_->GetCapabilities(); | 303 *capabilities = command_buffer_->GetCapabilities(); |
286 if (command_buffer_id) | 304 if (command_buffer_id) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 if (!mailboxes_to_reuse_.empty()) { | 385 if (!mailboxes_to_reuse_.empty()) { |
368 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); | 386 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); |
369 mailboxes_to_reuse_.pop_back(); | 387 mailboxes_to_reuse_.pop_back(); |
370 return mailbox; | 388 return mailbox; |
371 } | 389 } |
372 | 390 |
373 return gpu::Mailbox::Generate(); | 391 return gpu::Mailbox::Generate(); |
374 } | 392 } |
375 | 393 |
376 } // namespace content | 394 } // namespace content |
OLD | NEW |