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/thread_task_runner_handle.h" | 12 #include "base/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/ipc/client/command_buffer_proxy_impl.h" | 21 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
22 #include "gpu/ipc/client/gpu_channel_host.h" | 22 #include "gpu/ipc/client/gpu_channel_host.h" |
23 #include "ppapi/c/ppp_graphics_3d.h" | 23 #include "ppapi/c/ppp_graphics_3d.h" |
24 #include "ppapi/thunk/enter.h" | 24 #include "ppapi/thunk/enter.h" |
25 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
26 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 26 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
27 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
29 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 29 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 30 #include "third_party/khronos/GLES2/gl2.h" |
30 | 31 |
31 using ppapi::thunk::EnterResourceNoLock; | 32 using ppapi::thunk::EnterResourceNoLock; |
32 using ppapi::thunk::PPB_Graphics3D_API; | 33 using ppapi::thunk::PPB_Graphics3D_API; |
33 using blink::WebConsoleMessage; | 34 using blink::WebConsoleMessage; |
34 using blink::WebLocalFrame; | 35 using blink::WebLocalFrame; |
35 using blink::WebPluginContainer; | 36 using blink::WebPluginContainer; |
36 using blink::WebString; | 37 using blink::WebString; |
37 | 38 |
38 namespace content { | 39 namespace content { |
39 | 40 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 int32_t start, | 107 int32_t start, |
107 int32_t end) { | 108 int32_t end) { |
108 GetCommandBuffer()->WaitForGetOffsetInRange(start, end); | 109 GetCommandBuffer()->WaitForGetOffsetInRange(start, end); |
109 return GetCommandBuffer()->GetLastState(); | 110 return GetCommandBuffer()->GetLastState(); |
110 } | 111 } |
111 | 112 |
112 void PPB_Graphics3D_Impl::EnsureWorkVisible() { | 113 void PPB_Graphics3D_Impl::EnsureWorkVisible() { |
113 command_buffer_->EnsureWorkVisible(); | 114 command_buffer_->EnsureWorkVisible(); |
114 } | 115 } |
115 | 116 |
| 117 void PPB_Graphics3D_Impl::TakeFrontBuffer() { |
| 118 if (!taken_front_buffer_.IsZero()) { |
| 119 DLOG(ERROR) |
| 120 << "TakeFrontBuffer should only be called once before DoSwapBuffers"; |
| 121 return; |
| 122 } |
| 123 taken_front_buffer_ = GenerateMailbox(); |
| 124 command_buffer_->TakeFrontBuffer(taken_front_buffer_); |
| 125 } |
| 126 |
| 127 void PPB_Graphics3D_Impl::ReturnFrontBuffer(const gpu::Mailbox& mailbox, |
| 128 const gpu::SyncToken& sync_token, |
| 129 bool is_lost) { |
| 130 command_buffer_->ReturnFrontBuffer(mailbox, sync_token, is_lost); |
| 131 } |
| 132 |
116 bool PPB_Graphics3D_Impl::BindToInstance(bool bind) { | 133 bool PPB_Graphics3D_Impl::BindToInstance(bool bind) { |
117 bound_to_instance_ = bind; | 134 bound_to_instance_ = bind; |
118 return true; | 135 return true; |
119 } | 136 } |
120 | 137 |
121 bool PPB_Graphics3D_Impl::IsOpaque() { return !has_alpha_; } | 138 bool PPB_Graphics3D_Impl::IsOpaque() { return !has_alpha_; } |
122 | 139 |
123 void PPB_Graphics3D_Impl::ViewInitiatedPaint() { | 140 void PPB_Graphics3D_Impl::ViewInitiatedPaint() { |
124 commit_pending_ = false; | 141 commit_pending_ = false; |
125 | 142 |
126 if (HasPendingSwap()) | 143 if (HasPendingSwap()) |
127 SwapBuffersACK(PP_OK); | 144 SwapBuffersACK(PP_OK); |
128 } | 145 } |
129 | 146 |
130 gpu::CommandBufferProxyImpl* PPB_Graphics3D_Impl::GetCommandBufferProxy() { | 147 gpu::CommandBufferProxyImpl* PPB_Graphics3D_Impl::GetCommandBufferProxy() { |
131 DCHECK(command_buffer_); | 148 DCHECK(command_buffer_); |
132 return command_buffer_.get(); | 149 return command_buffer_.get(); |
133 } | 150 } |
134 | 151 |
135 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { | 152 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { |
136 return command_buffer_.get(); | 153 return command_buffer_.get(); |
137 } | 154 } |
138 | 155 |
139 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { | 156 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { |
140 return command_buffer_.get(); | 157 return command_buffer_.get(); |
141 } | 158 } |
142 | 159 |
143 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { | 160 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { |
144 DCHECK(command_buffer_); | 161 DCHECK(command_buffer_); |
145 if (sync_token.HasData()) | 162 if (taken_front_buffer_.IsZero()) { |
146 sync_token_ = sync_token; | 163 DLOG(ERROR) << "TakeFrontBuffer should be called before DoSwapBuffers"; |
| 164 return PP_ERROR_FAILED; |
| 165 } |
147 | 166 |
148 if (bound_to_instance_) { | 167 if (bound_to_instance_) { |
149 // If we are bound to the instance, we need to ask the compositor | 168 // If we are bound to the instance, we need to ask the compositor |
150 // to commit our backing texture so that the graphics appears on the page. | 169 // to commit our backing texture so that the graphics appears on the page. |
151 // When the backing texture will be committed we get notified via | 170 // When the backing texture will be committed we get notified via |
152 // ViewFlushedPaint(). | 171 // ViewFlushedPaint(). |
153 // | 172 // |
154 // Don't need to check for NULL from GetPluginInstance since when we're | 173 // Don't need to check for NULL from GetPluginInstance since when we're |
155 // bound, we know our instance is valid. | 174 // bound, we know our instance is valid. |
156 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); | 175 cc::TextureMailbox texture_mailbox(taken_front_buffer_, sync_token, |
| 176 GL_TEXTURE_2D); |
| 177 taken_front_buffer_.SetZero(); |
| 178 HostGlobals::Get() |
| 179 ->GetInstance(pp_instance()) |
| 180 ->CommitTextureMailbox(texture_mailbox); |
157 commit_pending_ = true; | 181 commit_pending_ = true; |
158 } else { | 182 } else { |
159 // Wait for the command to complete on the GPU to allow for throttling. | 183 // Wait for the command to complete on the GPU to allow for throttling. |
160 command_buffer_->SignalSyncToken( | 184 command_buffer_->SignalSyncToken( |
161 sync_token_, | 185 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
162 base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 186 weak_ptr_factory_.GetWeakPtr())); |
163 weak_ptr_factory_.GetWeakPtr())); | |
164 } | 187 } |
165 | 188 |
166 return PP_OK_COMPLETIONPENDING; | 189 return PP_OK_COMPLETIONPENDING; |
167 } | 190 } |
168 | 191 |
169 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 192 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
170 const int32_t* attrib_list, | 193 const int32_t* attrib_list, |
171 gpu::Capabilities* capabilities, | 194 gpu::Capabilities* capabilities, |
172 base::SharedMemoryHandle* shared_state_handle, | 195 base::SharedMemoryHandle* shared_state_handle, |
173 gpu::CommandBufferId* command_buffer_id) { | 196 gpu::CommandBufferId* command_buffer_id) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 274 |
252 command_buffer_->SetGpuControlClient(this); | 275 command_buffer_->SetGpuControlClient(this); |
253 | 276 |
254 if (shared_state_handle) | 277 if (shared_state_handle) |
255 *shared_state_handle = command_buffer_->GetSharedStateHandle(); | 278 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
256 if (capabilities) | 279 if (capabilities) |
257 *capabilities = command_buffer_->GetCapabilities(); | 280 *capabilities = command_buffer_->GetCapabilities(); |
258 if (command_buffer_id) | 281 if (command_buffer_id) |
259 *command_buffer_id = command_buffer_->GetCommandBufferID(); | 282 *command_buffer_id = command_buffer_->GetCommandBufferID(); |
260 | 283 |
261 mailbox_ = gpu::Mailbox::Generate(); | |
262 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | |
263 return false; | |
264 | |
265 return true; | 284 return true; |
266 } | 285 } |
267 | 286 |
268 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, | 287 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, |
269 int32_t id) { | 288 int32_t id) { |
270 if (!bound_to_instance_) | 289 if (!bound_to_instance_) |
271 return; | 290 return; |
272 WebPluginContainer* container = | 291 WebPluginContainer* container = |
273 HostGlobals::Get()->GetInstance(pp_instance())->container(); | 292 HostGlobals::Get()->GetInstance(pp_instance())->container(); |
274 if (!container) | 293 if (!container) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( | 351 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( |
333 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 352 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
334 // We have to check *again* that the instance exists, because it could have | 353 // We have to check *again* that the instance exists, because it could have |
335 // been deleted during GetPluginInterface(). Even the PluginModule could be | 354 // been deleted during GetPluginInterface(). Even the PluginModule could be |
336 // deleted, but in that case, the instance should also be gone, so the | 355 // deleted, but in that case, the instance should also be gone, so the |
337 // GetInstance check covers both cases. | 356 // GetInstance check covers both cases. |
338 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 357 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
339 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 358 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
340 } | 359 } |
341 | 360 |
| 361 gpu::Mailbox PPB_Graphics3D_Impl::GenerateMailbox() { |
| 362 if (!mailboxes_to_reuse_.empty()) { |
| 363 gpu::Mailbox mailbox = mailboxes_to_reuse_.back(); |
| 364 mailboxes_to_reuse_.pop_back(); |
| 365 return mailbox; |
| 366 } |
| 367 |
| 368 return gpu::Mailbox::Generate(); |
| 369 } |
| 370 |
342 } // namespace content | 371 } // namespace content |
OLD | NEW |