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" | |
31 | 32 |
32 using ppapi::thunk::EnterResourceNoLock; | 33 using ppapi::thunk::EnterResourceNoLock; |
33 using ppapi::thunk::PPB_Graphics3D_API; | 34 using ppapi::thunk::PPB_Graphics3D_API; |
34 using blink::WebConsoleMessage; | 35 using blink::WebConsoleMessage; |
35 using blink::WebLocalFrame; | 36 using blink::WebLocalFrame; |
36 using blink::WebPluginContainer; | 37 using blink::WebPluginContainer; |
37 using blink::WebString; | 38 using blink::WebString; |
38 | 39 |
39 namespace content { | 40 namespace content { |
40 | 41 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 int32_t start, | 108 int32_t start, |
108 int32_t end) { | 109 int32_t end) { |
109 GetCommandBuffer()->WaitForGetOffsetInRange(start, end); | 110 GetCommandBuffer()->WaitForGetOffsetInRange(start, end); |
110 return GetCommandBuffer()->GetLastState(); | 111 return GetCommandBuffer()->GetLastState(); |
111 } | 112 } |
112 | 113 |
113 void PPB_Graphics3D_Impl::EnsureWorkVisible() { | 114 void PPB_Graphics3D_Impl::EnsureWorkVisible() { |
114 command_buffer_->EnsureWorkVisible(); | 115 command_buffer_->EnsureWorkVisible(); |
115 } | 116 } |
116 | 117 |
118 void PPB_Graphics3D_Impl::TakeFrontBuffer() { | |
119 DCHECK(taken_front_buffer_.IsZero()); | |
piman
2016/04/27 23:00:58
This DCHECK is not valid. The plugin side may be u
erikchen
2016/04/27 23:59:24
Done.
| |
120 taken_front_buffer_ = GenerateMailbox(); | |
121 command_buffer_->TakeFrontBuffer(taken_front_buffer_); | |
122 } | |
123 | |
124 void PPB_Graphics3D_Impl::ReturnFrontBuffer(const gpu::Mailbox& mailbox, | |
125 const gpu::SyncToken& sync_token, | |
126 bool is_lost) { | |
127 command_buffer_->ReturnFrontBuffer(mailbox, sync_token, is_lost); | |
128 mailboxes_to_reuse_.push_back(mailbox); | |
129 } | |
130 | |
117 bool PPB_Graphics3D_Impl::BindToInstance(bool bind) { | 131 bool PPB_Graphics3D_Impl::BindToInstance(bool bind) { |
118 bound_to_instance_ = bind; | 132 bound_to_instance_ = bind; |
119 return true; | 133 return true; |
120 } | 134 } |
121 | 135 |
122 bool PPB_Graphics3D_Impl::IsOpaque() { return !has_alpha_; } | 136 bool PPB_Graphics3D_Impl::IsOpaque() { return !has_alpha_; } |
123 | 137 |
124 void PPB_Graphics3D_Impl::ViewInitiatedPaint() { | 138 void PPB_Graphics3D_Impl::ViewInitiatedPaint() { |
125 commit_pending_ = false; | 139 commit_pending_ = false; |
126 | 140 |
127 if (HasPendingSwap()) | 141 if (HasPendingSwap()) |
128 SwapBuffersACK(PP_OK); | 142 SwapBuffersACK(PP_OK); |
129 } | 143 } |
130 | 144 |
131 gpu::CommandBufferProxyImpl* PPB_Graphics3D_Impl::GetCommandBufferProxy() { | 145 gpu::CommandBufferProxyImpl* PPB_Graphics3D_Impl::GetCommandBufferProxy() { |
132 DCHECK(command_buffer_); | 146 DCHECK(command_buffer_); |
133 return command_buffer_.get(); | 147 return command_buffer_.get(); |
134 } | 148 } |
135 | 149 |
136 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { | 150 gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { |
137 return command_buffer_.get(); | 151 return command_buffer_.get(); |
138 } | 152 } |
139 | 153 |
140 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { | 154 gpu::GpuControl* PPB_Graphics3D_Impl::GetGpuControl() { |
141 return command_buffer_.get(); | 155 return command_buffer_.get(); |
142 } | 156 } |
143 | 157 |
144 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { | 158 int32_t PPB_Graphics3D_Impl::DoSwapBuffers(const gpu::SyncToken& sync_token) { |
145 DCHECK(command_buffer_); | 159 DCHECK(command_buffer_); |
146 if (sync_token.HasData()) | 160 DCHECK(!taken_front_buffer_.IsZero()); |
piman
2016/04/27 23:00:58
Here too, the DCHECK is invalid.
It's ok to retur
erikchen
2016/04/27 23:59:24
Done.
| |
147 sync_token_ = sync_token; | |
148 | 161 |
149 if (bound_to_instance_) { | 162 if (bound_to_instance_) { |
150 // If we are bound to the instance, we need to ask the compositor | 163 // 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. | 164 // 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 | 165 // When the backing texture will be committed we get notified via |
153 // ViewFlushedPaint(). | 166 // ViewFlushedPaint(). |
154 // | 167 // |
155 // Don't need to check for NULL from GetPluginInstance since when we're | 168 // Don't need to check for NULL from GetPluginInstance since when we're |
156 // bound, we know our instance is valid. | 169 // bound, we know our instance is valid. |
157 HostGlobals::Get()->GetInstance(pp_instance())->CommitBackingTexture(); | 170 cc::TextureMailbox texture_mailbox(taken_front_buffer_, sync_token, |
171 GL_TEXTURE_2D); | |
172 taken_front_buffer_.SetZero(); | |
173 HostGlobals::Get() | |
174 ->GetInstance(pp_instance()) | |
175 ->CommitTextureMailbox(texture_mailbox); | |
158 commit_pending_ = true; | 176 commit_pending_ = true; |
159 } else { | 177 } else { |
160 // Wait for the command to complete on the GPU to allow for throttling. | 178 // Wait for the command to complete on the GPU to allow for throttling. |
161 command_buffer_->SignalSyncToken( | 179 command_buffer_->SignalSyncToken( |
162 sync_token_, | 180 sync_token, base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, |
163 base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers, | 181 weak_ptr_factory_.GetWeakPtr())); |
164 weak_ptr_factory_.GetWeakPtr())); | |
165 } | 182 } |
166 | 183 |
167 return PP_OK_COMPLETIONPENDING; | 184 return PP_OK_COMPLETIONPENDING; |
168 } | 185 } |
169 | 186 |
170 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 187 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
171 const int32_t* attrib_list, | 188 const int32_t* attrib_list, |
172 gpu::Capabilities* capabilities, | 189 gpu::Capabilities* capabilities, |
173 base::SharedMemoryHandle* shared_state_handle, | 190 base::SharedMemoryHandle* shared_state_handle, |
174 gpu::CommandBufferId* command_buffer_id) { | 191 gpu::CommandBufferId* command_buffer_id) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 if (!command_buffer_->Initialize()) | 272 if (!command_buffer_->Initialize()) |
256 return false; | 273 return false; |
257 | 274 |
258 if (shared_state_handle) | 275 if (shared_state_handle) |
259 *shared_state_handle = command_buffer_->GetSharedStateHandle(); | 276 *shared_state_handle = command_buffer_->GetSharedStateHandle(); |
260 if (capabilities) | 277 if (capabilities) |
261 *capabilities = command_buffer_->GetCapabilities(); | 278 *capabilities = command_buffer_->GetCapabilities(); |
262 if (command_buffer_id) | 279 if (command_buffer_id) |
263 *command_buffer_id = command_buffer_->GetCommandBufferID(); | 280 *command_buffer_id = command_buffer_->GetCommandBufferID(); |
264 | 281 |
265 mailbox_ = gpu::Mailbox::Generate(); | |
266 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | |
267 return false; | |
268 | |
269 return true; | 282 return true; |
270 } | 283 } |
271 | 284 |
272 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, | 285 void PPB_Graphics3D_Impl::OnGpuControlErrorMessage(const char* message, |
273 int32_t id) { | 286 int32_t id) { |
274 if (!bound_to_instance_) | 287 if (!bound_to_instance_) |
275 return; | 288 return; |
276 WebPluginContainer* container = | 289 WebPluginContainer* container = |
277 HostGlobals::Get()->GetInstance(pp_instance())->container(); | 290 HostGlobals::Get()->GetInstance(pp_instance())->container(); |
278 if (!container) | 291 if (!container) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( | 345 const PPP_Graphics3D* ppp_graphics_3d = static_cast<const PPP_Graphics3D*>( |
333 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); | 346 instance->module()->GetPluginInterface(PPP_GRAPHICS_3D_INTERFACE)); |
334 // We have to check *again* that the instance exists, because it could have | 347 // We have to check *again* that the instance exists, because it could have |
335 // been deleted during GetPluginInterface(). Even the PluginModule could be | 348 // been deleted during GetPluginInterface(). Even the PluginModule could be |
336 // deleted, but in that case, the instance should also be gone, so the | 349 // deleted, but in that case, the instance should also be gone, so the |
337 // GetInstance check covers both cases. | 350 // GetInstance check covers both cases. |
338 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 351 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
339 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 352 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
340 } | 353 } |
341 | 354 |
355 gpu::Mailbox PPB_Graphics3D_Impl::GenerateMailbox() { | |
356 if (mailboxes_to_reuse_.size()) { | |
piman
2016/04/27 23:00:58
nit: !mailboxes_to_reuse_.empty()
erikchen
2016/04/27 23:59:24
Done.
| |
357 gpu::Mailbox mailbox = mailboxes_to_reuse_[0]; | |
358 mailboxes_to_reuse_.erase(mailboxes_to_reuse_.begin()); | |
359 return mailbox; | |
360 } | |
361 | |
362 return gpu::Mailbox::Generate(); | |
363 } | |
364 | |
342 } // namespace content | 365 } // namespace content |
OLD | NEW |