| 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 22 matching lines...) Expand all Loading... |
| 33 ack_pending_for_crashed_guest_(false), | 33 ack_pending_for_crashed_guest_(false), |
| 34 container_(container), | 34 container_(container), |
| 35 browser_plugin_manager_(manager) { | 35 browser_plugin_manager_(manager) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { | 38 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { | 41 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { |
| 42 if (enable && !texture_layer_) { | 42 if (enable && !texture_layer_) { |
| 43 texture_layer_ = cc::TextureLayer::createForMailbox(); | 43 texture_layer_ = cc::TextureLayer::CreateForMailbox(); |
| 44 texture_layer_->setIsDrawable(true); | 44 texture_layer_->SetIsDrawable(true); |
| 45 texture_layer_->setContentsOpaque(true); | 45 texture_layer_->SetContentsOpaque(true); |
| 46 | 46 |
| 47 background_layer_ = cc::SolidColorLayer::Create(); | 47 background_layer_ = cc::SolidColorLayer::Create(); |
| 48 background_layer_->setMasksToBounds(true); | 48 background_layer_->SetMasksToBounds(true); |
| 49 background_layer_->setBackgroundColor( | 49 background_layer_->SetBackgroundColor( |
| 50 SkColorSetARGBInline(255, 255, 255, 255)); | 50 SkColorSetARGBInline(255, 255, 255, 255)); |
| 51 background_layer_->addChild(texture_layer_); | 51 background_layer_->AddChild(texture_layer_); |
| 52 web_layer_.reset(new WebKit::WebLayerImpl(background_layer_)); | 52 web_layer_.reset(new WebKit::WebLayerImpl(background_layer_)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 container_->setWebLayer(enable ? web_layer_.get() : NULL); | 55 container_->setWebLayer(enable ? web_layer_.get() : NULL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // If we have a mailbox that was freed up from the compositor, | 58 // If we have a mailbox that was freed up from the compositor, |
| 59 // but we are not expected to return it to the guest renderer | 59 // but we are not expected to return it to the guest renderer |
| 60 // via an ACK, we should free it because we now own it. | 60 // via an ACK, we should free it because we now own it. |
| 61 // To free the mailbox memory, we need a context to consume it | 61 // To free the mailbox memory, we need a context to consume it |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // when a new buffer arrives. | 193 // when a new buffer arrives. |
| 194 // Visually, this will either display a smaller part of the buffer | 194 // Visually, this will either display a smaller part of the buffer |
| 195 // or introduce a gutter around it. | 195 // or introduce a gutter around it. |
| 196 if (buffer_size_ != size) { | 196 if (buffer_size_ != size) { |
| 197 buffer_size_ = size; | 197 buffer_size_ = size; |
| 198 // The container size is in DIP, so is the layer size. | 198 // The container size is in DIP, so is the layer size. |
| 199 // Buffer size is in physical pixels, so we need to adjust | 199 // Buffer size is in physical pixels, so we need to adjust |
| 200 // it by the device scale factor. | 200 // it by the device scale factor. |
| 201 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( | 201 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( |
| 202 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); | 202 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); |
| 203 texture_layer_->setBounds(device_scale_adjusted_size); | 203 texture_layer_->SetBounds(device_scale_adjusted_size); |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool current_mailbox_valid = !mailbox_name.empty(); | 206 bool current_mailbox_valid = !mailbox_name.empty(); |
| 207 if (!last_mailbox_valid_) { | 207 if (!last_mailbox_valid_) { |
| 208 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); | 208 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); |
| 209 if (!current_mailbox_valid) | 209 if (!current_mailbox_valid) |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 | 212 |
| 213 cc::TextureMailbox::ReleaseCallback callback; | 213 cc::TextureMailbox::ReleaseCallback callback; |
| 214 if (current_mailbox_valid) { | 214 if (current_mailbox_valid) { |
| 215 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, | 215 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, |
| 216 scoped_refptr<BrowserPluginCompositingHelper>(this), | 216 scoped_refptr<BrowserPluginCompositingHelper>(this), |
| 217 mailbox_name, | 217 mailbox_name, |
| 218 gpu_route_id, | 218 gpu_route_id, |
| 219 gpu_host_id); | 219 gpu_host_id); |
| 220 } | 220 } |
| 221 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name, | 221 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name, |
| 222 callback)); | 222 callback)); |
| 223 texture_layer_->setNeedsDisplay(); | 223 texture_layer_->SetNeedsDisplay(); |
| 224 last_mailbox_valid_ = current_mailbox_valid; | 224 last_mailbox_valid_ = current_mailbox_valid; |
| 225 } | 225 } |
| 226 | 226 |
| 227 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { | 227 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { |
| 228 if (texture_layer_) | 228 if (texture_layer_) |
| 229 texture_layer_->setIsDrawable(visible); | 229 texture_layer_->SetIsDrawable(visible); |
| 230 } | 230 } |
| 231 | 231 |
| 232 } // namespace content | 232 } // namespace content |
| OLD | NEW |