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