Chromium Code Reviews| 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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { | 136 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { |
| 137 return command_buffer_.get(); | 137 return command_buffer_.get(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { | 140 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { |
| 141 return command_buffer_.get(); | 141 return command_buffer_.get(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { | 144 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { |
| 145 DCHECK(command_buffer_); | 145 DCHECK(command_buffer_); |
| 146 if (sync_token.HasData()) | |
| 147 sync_token_ = sync_token; | |
| 148 | 146 |
| 149 if (bound_to_instance_) { | 147 if (bound_to_instance_) { |
| 150 // If we are bound to the instance, we need to ask the compositor | 148 // If we are bound to the instance, we need to ask the compositor |
| 151 // to commit our backing texture so that the graphics appears on the page. | 149 // to commit our backing texture so that the graphics appears on the page. |
| 152 // When the backing texture will be committed we get notified via | 150 // When the backing texture will be committed we get notified via |
| 153 // ViewFlushedPaint(). | 151 // ViewFlushedPaint(). |
| 154 // | 152 // |
| 155 // Don't need to check for NULL from GetPluginInstance since when we're | 153 // Don't need to check for NULL from GetPluginInstance since when we're |
| 156 // bound, we know our instance is valid. | 154 // bound, we know our instance is valid. |
| 157 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); | 155 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); |
| 158 commit_pending_ = true; | 156 commit_pending_ = true; |
| 159 } else { | 157 } else { |
| 160 // Wait for the command to complete on the GPU to allow for throttling. | 158 // Wait for the command to complete on the GPU to allow for throttling. |
| 161 command_buffer_->SignalSyncToken( | 159 command_buffer_->SignalSyncToken( |
| 162 sync_token_, | 160 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
| 163 base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 161 weak_ptr_factory_.GetWeakPtr())); |
| 164 weak_ptr_factory_.GetWeakPtr())); | |
| 165 } | 162 } |
| 166 | 163 |
| 167 return PP_OK_COMPLETIONPENDING; | 164 return PP_OK_COMPLETIONPENDING; |
| 168 } | 165 } |
| 169 | 166 |
| 170 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 167 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
| 171 const int32_t* attrib_list, | 168 const int32_t* attrib_list, |
| 172 gpu::Capabilities* capabilities, | 169 gpu::Capabilities* capabilities, |
| 173 base::SharedMemoryHandle* shared_state_handle, | 170 base::SharedMemoryHandle* shared_state_handle, |
| 174 gpu::CommandBufferId* command_buffer_id) { | 171 gpu::CommandBufferId* command_buffer_id) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 if (!command_buffer_->Initialize()) | 252 if (!command_buffer_->Initialize()) |
| 256 return false; | 253 return false; |
| 257 | 254 |
| 258 if (shared_state_handle) | 255 if (shared_state_handle) |
| 259 *shared_state_handle = command_buffer_->GetSharedStateHandle(); | 256 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
| 260 if (capabilities) | 257 if (capabilities) |
| 261 *capabilities = command_buffer_->GetCapabilities(); | 258 *capabilities = command_buffer_->GetCapabilities(); |
| 262 if (command_buffer_id) | 259 if (command_buffer_id) |
| 263 *command_buffer_id = command_buffer_->GetCommandBufferID(); | 260 *command_buffer_id = command_buffer_->GetCommandBufferID(); |
| 264 | 261 |
| 265 mailbox_ = gpu::Mailbox::Generate(); | 262 return true; |
| 266 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | 263 } |
| 267 return false; | |
| 268 | 264 |
| 265 bool PPB_Graphics3D_Impl::TakeBackingMailbox(gpu::Mailbox* mailbox, | |
| 266 gpu::SyncToken* sync_token) { | |
| 267 *mailbox = gpu::Mailbox::Generate(); | |
|
piman
2016/04/26 01:54:01
This is kind of costly (generate a crypto-secure n
erikchen
2016/04/27 16:31:23
Done.
| |
| 268 command_buffer_->TakeFrontBuffer(*mailbox, sync_token); | |
| 269 return true; | 269 return true; |
| 270 } | 270 } |
| 271 | 271 |
| 272 void PPB_Graphics3D_Impl::ReturnBackingMailbox(const gpu::Mailbox& mailbox, | |
| 273 const gpu::SyncToken& sync_token, | |
| 274 bool is_lost) { | |
| 275 command_buffer_->ReturnFrontBuffer(mailbox, sync_token, is_lost); | |
| 276 } | |
| 277 | |
| 272 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, | 278 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, |
| 273 int32_t id) { | 279 int32_t id) { |
| 274 if (!bound_to_instance_) | 280 if (!bound_to_instance_) |
| 275 return; | 281 return; |
| 276 WebPluginContainer* container = | 282 WebPluginContainer* container = |
| 277 HostGlobals::Get()->GetInstance(pp_instance())->container(); | 283 HostGlobals::Get()->GetInstance(pp_instance())->container(); |
| 278 if (!container) | 284 if (!container) |
| 279 return; | 285 return; |
| 280 WebLocalFrame* frame = container->element().document().frame(); | 286 WebLocalFrame* frame = container->element().document().frame(); |
| 281 if (!frame) | 287 if (!frame) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 339 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
| 334 // We have to check *again* that the instance exists, because it could have | 340 // We have to check *again* that the instance exists, because it could have |
| 335 // been deleted during GetPluginInterface(). Even the PluginModule could be | 341 // been deleted during GetPluginInterface(). Even the PluginModule could be |
| 336 // deleted, but in that case, the instance should also be gone, so the | 342 // deleted, but in that case, the instance should also be gone, so the |
| 337 // GetInstance check covers both cases. | 343 // GetInstance check covers both cases. |
| 338 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 344 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
| 339 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 345 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
| 340 } | 346 } |
| 341 | 347 |
| 342 } // namespace content | 348 } // namespace content |
| OLD | NEW |