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

Side by Side Diff: content/renderer/pepper/ppb_graphics_3d_impl.cc

Issue 1837833004: Remove in-process PPB_Graphics3D (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile errors Created 4 years, 8 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 (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/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 13 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
14 #include "content/common/gpu/client/gpu_channel_host.h" 14 #include "content/common/gpu/client/gpu_channel_host.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/common/web_preferences.h" 16 #include "content/public/common/web_preferences.h"
17 #include "content/renderer/pepper/host_globals.h" 17 #include "content/renderer/pepper/host_globals.h"
18 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 18 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
19 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" 19 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
20 #include "content/renderer/pepper/plugin_module.h" 20 #include "content/renderer/pepper/plugin_module.h"
21 #include "content/renderer/render_thread_impl.h" 21 #include "content/renderer/render_thread_impl.h"
22 #include "content/renderer/render_view_impl.h" 22 #include "content/renderer/render_view_impl.h"
23 #include "gpu/command_buffer/client/gles2_interface.h"
24 #include "ppapi/c/ppp_graphics_3d.h" 23 #include "ppapi/c/ppp_graphics_3d.h"
25 #include "ppapi/thunk/enter.h" 24 #include "ppapi/thunk/enter.h"
26 #include "third_party/WebKit/public/platform/WebString.h" 25 #include "third_party/WebKit/public/platform/WebString.h"
27 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 26 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
28 #include "third_party/WebKit/public/web/WebDocument.h" 27 #include "third_party/WebKit/public/web/WebDocument.h"
29 #include "third_party/WebKit/public/web/WebElement.h" 28 #include "third_party/WebKit/public/web/WebElement.h"
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" 29 #include "third_party/WebKit/public/web/WebLocalFrame.h"
31 #include "third_party/WebKit/public/web/WebPluginContainer.h" 30 #include "third_party/WebKit/public/web/WebPluginContainer.h"
32 31
33 using ppapi::thunk::EnterResourceNoLock; 32 using ppapi::thunk::EnterResourceNoLock;
34 using ppapi::thunk::PPB_Graphics3D_API; 33 using ppapi::thunk::PPB_Graphics3D_API;
35 using blink::WebConsoleMessage; 34 using blink::WebConsoleMessage;
36 using blink::WebLocalFrame; 35 using blink::WebLocalFrame;
37 using blink::WebPluginContainer; 36 using blink::WebPluginContainer;
38 using blink::WebString; 37 using blink::WebString;
39 38
40 namespace content { 39 namespace content {
41 40
42 namespace {
43
44 const int32_t kCommandBufferSize = 1024 * 1024;
45 const int32_t kTransferBufferSize = 1024 * 1024;
46
47 } // namespace
48
49 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) 41 PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance)
50 : PPB_Graphics3D_Shared(instance), 42 : PPB_Graphics3D_Shared(instance),
51 bound_to_instance_(false), 43 bound_to_instance_(false),
52 commit_pending_(false), 44 commit_pending_(false),
53 has_alpha_(false), 45 has_alpha_(false),
54 weak_ptr_factory_(this) {} 46 weak_ptr_factory_(this) {}
55 47
56 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {} 48 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {}
57 49
58 // static 50 // static
59 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance,
60 PP_Resource share_context,
61 const int32_t* attrib_list) {
62 PPB_Graphics3D_API* share_api = NULL;
63 if (share_context) {
64 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true);
65 if (enter.failed())
66 return 0;
67 share_api = enter.object();
68 }
69 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d(
70 new PPB_Graphics3D_Impl(instance));
71 if (!graphics_3d->Init(share_api, attrib_list))
72 return 0;
73 return graphics_3d->GetReference();
74 }
75
76 // static
77 PP_Resource PPB_Graphics3D_Impl::CreateRaw( 51 PP_Resource PPB_Graphics3D_Impl::CreateRaw(
78 PP_Instance instance, 52 PP_Instance instance,
79 PP_Resource share_context, 53 PP_Resource share_context,
80 const int32_t* attrib_list, 54 const int32_t* attrib_list,
81 gpu::Capabilities* capabilities, 55 gpu::Capabilities* capabilities,
82 base::SharedMemoryHandle* shared_state_handle, 56 base::SharedMemoryHandle* shared_state_handle,
83 gpu::CommandBufferId* command_buffer_id) { 57 gpu::CommandBufferId* command_buffer_id) {
84 PPB_Graphics3D_API* share_api = NULL; 58 PPB_Graphics3D_API* share_api = NULL;
85 if (share_context) { 59 if (share_context) {
86 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); 60 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 134
161 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { 135 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() {
162 return command_buffer_.get(); 136 return command_buffer_.get();
163 } 137 }
164 138
165 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { 139 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) {
166 DCHECK(command_buffer_); 140 DCHECK(command_buffer_);
167 if (sync_token.HasData()) 141 if (sync_token.HasData())
168 sync_token_ = sync_token; 142 sync_token_ = sync_token;
169 143
170 // We do not have a GLES2 implementation when using an OOP proxy.
171 // The plugin-side proxy is responsible for adding the SwapBuffers command
172 // to the command buffer in that case.
173 if (gpu::gles2::GLES2Interface* gl = gles2_interface()) {
174 // A valid sync token would indicate a swap buffer already happened somehow.
175 DCHECK(!sync_token.HasData());
176
177 gl->SwapBuffers();
178 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
179 gl->OrderingBarrierCHROMIUM();
180 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token_.GetData());
181 }
182
183 if (bound_to_instance_) { 144 if (bound_to_instance_) {
184 // If we are bound to the instance, we need to ask the compositor 145 // If we are bound to the instance, we need to ask the compositor
185 // to commit our backing texture so that the graphics appears on the page. 146 // to commit our backing texture so that the graphics appears on the page.
186 // When the backing texture will be committed we get notified via 147 // When the backing texture will be committed we get notified via
187 // ViewFlushedPaint(). 148 // ViewFlushedPaint().
188 // 149 //
189 // Don't need to check for NULL from GetPluginInstance since when we're 150 // Don't need to check for NULL from GetPluginInstance since when we're
190 // bound, we know our instance is valid. 151 // bound, we know our instance is valid.
191 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); 152 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture();
192 commit_pending_ = true; 153 commit_pending_ = true;
193 } else { 154 } else {
194 // Wait for the command to complete on the GPU to allow for throttling. 155 // Wait for the command to complete on the GPU to allow for throttling.
195 command_buffer_->SignalSyncToken( 156 command_buffer_->SignalSyncToken(
196 sync_token_, 157 sync_token_,
197 base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, 158 base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers,
198 weak_ptr_factory_.GetWeakPtr())); 159 weak_ptr_factory_.GetWeakPtr()));
199 } 160 }
200 161
201 return PP_OK_COMPLETIONPENDING; 162 return PP_OK_COMPLETIONPENDING;
202 } 163 }
203 164
204 bool PPB_Graphics3D_Impl::Init(PPB_Graphics3D_API* share_context,
205 const int32_t* attrib_list) {
206 if (!InitRaw(share_context, attrib_list, NULL, NULL, NULL))
207 return false;
208
209 gpu::gles2::GLES2Implementation* share_gles2 = NULL;
210 if (share_context) {
211 share_gles2 =
212 static_cast<PPB_Graphics3D_Shared*>(share_context)->gles2_impl();
213 }
214
215 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize, share_gles2);
216 }
217
218 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, 165 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context,
219 const int32_t* attrib_list, 166 const int32_t* attrib_list,
220 gpu::Capabilities* capabilities, 167 gpu::Capabilities* capabilities,
221 base::SharedMemoryHandle* shared_state_handle, 168 base::SharedMemoryHandle* shared_state_handle,
222 gpu::CommandBufferId* command_buffer_id) { 169 gpu::CommandBufferId* command_buffer_id) {
223 PepperPluginInstanceImpl* plugin_instance = 170 PepperPluginInstanceImpl* plugin_instance =
224 HostGlobals::Get()->GetInstance(pp_instance()); 171 HostGlobals::Get()->GetInstance(pp_instance());
225 if (!plugin_instance) 172 if (!plugin_instance)
226 return false; 173 return false;
227 174
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); 320 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE));
374 // We have to check *again* that the instance exists, because it could have 321 // We have to check *again* that the instance exists, because it could have
375 // been deleted during GetPluginInterface(). Even the PluginModule could be 322 // been deleted during GetPluginInterface(). Even the PluginModule could be
376 // deleted, but in that case, the instance should also be gone, so the 323 // deleted, but in that case, the instance should also be gone, so the
377 // GetInstance check covers both cases. 324 // GetInstance check covers both cases.
378 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) 325 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance))
379 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); 326 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance);
380 } 327 }
381 328
382 } // namespace content 329 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/ppb_graphics_3d_impl.h ('k') | content/renderer/pepper/resource_creation_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698