Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser_plugin/browser_plugin_compositing_helper.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
| 6 | 6 |
| 7 #include "cc/context_provider.h" | 7 #include "cc/context_provider.h" |
| 8 #include "cc/solid_color_layer.h" | 8 #include "cc/solid_color_layer.h" |
| 9 #include "cc/texture_layer.h" | 9 #include "cc/texture_layer.h" |
| 10 #include "content/common/browser_plugin/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 } | 55 } |
| 56 | 56 |
| 57 // If we have a mailbox that was freed up from the compositor, | 57 // If we have a mailbox that was freed up from the compositor, |
| 58 // but we are not expected to return it to the guest renderer | 58 // but we are not expected to return it to the guest renderer |
| 59 // via an ACK, we should free it because we now own it. | 59 // via an ACK, we should free it because we now own it. |
| 60 // To free the mailbox memory, we need a context to consume it | 60 // To free the mailbox memory, we need a context to consume it |
| 61 // into a texture ID and then delete this texture ID. | 61 // into a texture ID and then delete this texture ID. |
| 62 // We use a shared graphics context accessible from the main | 62 // We use a shared graphics context accessible from the main |
| 63 // thread to do it. | 63 // thread to do it. |
| 64 void BrowserPluginCompositingHelper::FreeMailboxMemory( | 64 void BrowserPluginCompositingHelper::FreeMailboxMemory( |
| 65 const std::string& mailbox_name, | 65 const gpu::Mailbox& mailbox_name, |
| 66 unsigned sync_point) { | 66 unsigned sync_point) { |
| 67 if (mailbox_name.empty()) | 67 if (mailbox_name.IsZero()) |
| 68 return; | 68 return; |
| 69 | 69 |
| 70 scoped_refptr<cc::ContextProvider> context_provider = | 70 scoped_refptr<cc::ContextProvider> context_provider = |
| 71 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); | 71 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
| 72 if (!context_provider->InitializeOnMainThread()) | 72 if (!context_provider->InitializeOnMainThread()) |
| 73 return; | 73 return; |
| 74 if (!context_provider->BindToCurrentThread()) | 74 if (!context_provider->BindToCurrentThread()) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); | 77 WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); |
| 78 // When a buffer is released from the compositor, we also get a | 78 // When a buffer is released from the compositor, we also get a |
| 79 // sync point that specifies when in the command buffer | 79 // sync point that specifies when in the command buffer |
| 80 // it's safe to use it again. | 80 // it's safe to use it again. |
| 81 // If the sync point is non-zero, we need to tell our context | 81 // If the sync point is non-zero, we need to tell our context |
| 82 // to wait until this sync point is reached before we can safely | 82 // to wait until this sync point is reached before we can safely |
| 83 // delete the buffer. | 83 // delete the buffer. |
| 84 if (sync_point) | 84 if (sync_point) |
| 85 context->waitSyncPoint(sync_point); | 85 context->waitSyncPoint(sync_point); |
| 86 | 86 |
| 87 unsigned texture_id = context->createTexture(); | 87 unsigned texture_id = context->createTexture(); |
| 88 context->bindTexture(GL_TEXTURE_2D, texture_id); | 88 context->bindTexture(GL_TEXTURE_2D, texture_id); |
| 89 context->consumeTextureCHROMIUM( | 89 context->consumeTextureCHROMIUM( GL_TEXTURE_2D, mailbox_name.name); |
|
alexst (slow to review)
2013/03/06 21:54:27
There is an extra space here
piman
2013/03/07 01:48:02
Done.
| |
| 90 GL_TEXTURE_2D, | |
| 91 reinterpret_cast<const int8*>(mailbox_name.data())); | |
| 92 context->deleteTexture(texture_id); | 90 context->deleteTexture(texture_id); |
| 93 } | 91 } |
| 94 | 92 |
| 95 void BrowserPluginCompositingHelper::MailboxReleased( | 93 void BrowserPluginCompositingHelper::MailboxReleased( |
| 96 const std::string& mailbox_name, | 94 const gpu::Mailbox& mailbox_name, |
| 97 int gpu_route_id, | 95 int gpu_route_id, |
| 98 int gpu_host_id, | 96 int gpu_host_id, |
| 99 unsigned sync_point) { | 97 unsigned sync_point) { |
| 100 // This means the GPU process crashed and we have nothing further to do. | 98 // This means the GPU process crashed and we have nothing further to do. |
| 101 // Nobody is expecting an ACK and the buffer doesn't need to be deleted | 99 // Nobody is expecting an ACK and the buffer doesn't need to be deleted |
| 102 // because it went away with the GPU process. | 100 // because it went away with the GPU process. |
| 103 if (last_gpu_host_id_ != gpu_host_id) | 101 if (last_gpu_host_id_ != gpu_host_id) |
| 104 return; | 102 return; |
| 105 | 103 |
| 106 // This means the guest crashed. | 104 // This means the guest crashed. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 container_->setWebLayer(NULL); | 146 container_->setWebLayer(NULL); |
| 149 container_ = NULL; | 147 container_ = NULL; |
| 150 | 148 |
| 151 texture_layer_ = NULL; | 149 texture_layer_ = NULL; |
| 152 background_layer_ = NULL; | 150 background_layer_ = NULL; |
| 153 web_layer_.reset(); | 151 web_layer_.reset(); |
| 154 } | 152 } |
| 155 | 153 |
| 156 void BrowserPluginCompositingHelper::OnBuffersSwapped( | 154 void BrowserPluginCompositingHelper::OnBuffersSwapped( |
| 157 const gfx::Size& size, | 155 const gfx::Size& size, |
| 158 const std::string& mailbox_name, | 156 const gpu::Mailbox& mailbox_name, |
| 159 int gpu_route_id, | 157 int gpu_route_id, |
| 160 int gpu_host_id, | 158 int gpu_host_id, |
| 161 float device_scale_factor) { | 159 float device_scale_factor) { |
| 162 // If the guest crashed but the GPU process didn't, we may still have | 160 // If the guest crashed but the GPU process didn't, we may still have |
| 163 // a transport surface waiting on an ACK, which we must send to | 161 // a transport surface waiting on an ACK, which we must send to |
| 164 // avoid leaking. | 162 // avoid leaking. |
| 165 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id) | 163 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id) |
| 166 ack_pending_for_crashed_guest_ = ack_pending_; | 164 ack_pending_for_crashed_guest_ = ack_pending_; |
| 167 | 165 |
| 168 // If these mismatch, we are either just starting up, GPU process crashed or | 166 // If these mismatch, we are either just starting up, GPU process crashed or |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 195 if (buffer_size_ != size) { | 193 if (buffer_size_ != size) { |
| 196 buffer_size_ = size; | 194 buffer_size_ = size; |
| 197 // The container size is in DIP, so is the layer size. | 195 // The container size is in DIP, so is the layer size. |
| 198 // Buffer size is in physical pixels, so we need to adjust | 196 // Buffer size is in physical pixels, so we need to adjust |
| 199 // it by the device scale factor. | 197 // it by the device scale factor. |
| 200 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( | 198 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( |
| 201 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); | 199 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); |
| 202 texture_layer_->setBounds(device_scale_adjusted_size); | 200 texture_layer_->setBounds(device_scale_adjusted_size); |
| 203 } | 201 } |
| 204 | 202 |
| 205 bool current_mailbox_valid = !mailbox_name.empty(); | 203 bool current_mailbox_valid = !mailbox_name.IsZero(); |
| 206 if (!last_mailbox_valid_) { | 204 if (!last_mailbox_valid_) { |
| 207 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); | 205 MailboxReleased(gpu::Mailbox(), gpu_route_id, gpu_host_id, 0); |
| 208 if (!current_mailbox_valid) | 206 if (!current_mailbox_valid) |
| 209 return; | 207 return; |
| 210 } | 208 } |
| 211 | 209 |
| 212 cc::TextureMailbox::ReleaseCallback callback; | 210 cc::TextureMailbox::ReleaseCallback callback; |
| 213 if (current_mailbox_valid) { | 211 if (current_mailbox_valid) { |
| 214 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, | 212 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, |
| 215 scoped_refptr<BrowserPluginCompositingHelper>(this), | 213 scoped_refptr<BrowserPluginCompositingHelper>(this), |
| 216 mailbox_name, | 214 mailbox_name, |
| 217 gpu_route_id, | 215 gpu_route_id, |
| 218 gpu_host_id); | 216 gpu_host_id); |
| 219 } | 217 } |
| 220 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name, | 218 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name, |
| 221 callback)); | 219 callback)); |
| 222 last_mailbox_valid_ = current_mailbox_valid; | 220 last_mailbox_valid_ = current_mailbox_valid; |
| 223 } | 221 } |
| 224 | 222 |
| 225 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { | 223 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { |
| 226 if (texture_layer_) | 224 if (texture_layer_) |
| 227 texture_layer_->setIsDrawable(visible); | 225 texture_layer_->setIsDrawable(visible); |
| 228 } | 226 } |
| 229 | 227 |
| 230 } // namespace content | 228 } // namespace content |
| OLD | NEW |