[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 5 | #include "content/renderer/child_frame_compositing_helper.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 6 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 7 | #include "cc/layers/delegated_frame_provider.h" |
| 8 | #include "cc/layers/delegated_frame_resource_collection.h" |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 9 | #include "cc/layers/delegated_renderer_layer.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 10 | #include "cc/layers/solid_color_layer.h" |
| 11 | #include "cc/layers/texture_layer.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 12 | #include "cc/output/context_provider.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 13 | #include "cc/output/copy_output_request.h" |
| 14 | #include "cc/output/copy_output_result.h" |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 15 | #include "cc/resources/single_release_callback.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 16 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 17 | #include "content/common/frame_messages.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 18 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 19 | #include "content/renderer/browser_plugin/browser_plugin.h" |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 20 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | e1c5295 | 2014-06-18 08:35:43 | [diff] [blame] | 21 | #include "content/renderer/compositor_bindings/web_layer_impl.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 22 | #include "content/renderer/render_frame_impl.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 23 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 24 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 25 | #include "skia/ext/image_operations.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 26 | #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 27 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 28 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 29 | #include "third_party/khronos/GLES2/gl2.h" |
[email protected] | 7e95a6d | 2013-03-04 23:31:34 | [diff] [blame] | 30 | #include "ui/gfx/size_conversions.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 31 | #include "ui/gfx/skia_util.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 32 | |
| 33 | namespace content { |
| 34 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 35 | ChildFrameCompositingHelper::SwapBuffersInfo::SwapBuffersInfo() |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 36 | : route_id(0), |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 37 | output_surface_id(0), |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 38 | host_id(0), |
| 39 | software_frame_id(0), |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 40 | shared_memory(NULL) {} |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 41 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 42 | ChildFrameCompositingHelper* |
| 43 | ChildFrameCompositingHelper::CreateCompositingHelperForBrowserPlugin( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 44 | const base::WeakPtr<BrowserPlugin>& browser_plugin) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 45 | return new ChildFrameCompositingHelper( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 46 | browser_plugin, NULL, NULL, browser_plugin->render_view_routing_id()); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | ChildFrameCompositingHelper* |
| 50 | ChildFrameCompositingHelper::CreateCompositingHelperForRenderFrame( |
| 51 | blink::WebFrame* frame, |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 52 | RenderFrameProxy* render_frame_proxy, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 53 | int host_routing_id) { |
| 54 | return new ChildFrameCompositingHelper( |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 55 | base::WeakPtr<BrowserPlugin>(), frame, render_frame_proxy, |
| 56 | host_routing_id); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | ChildFrameCompositingHelper::ChildFrameCompositingHelper( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 60 | const base::WeakPtr<BrowserPlugin>& browser_plugin, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 61 | blink::WebFrame* frame, |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 62 | RenderFrameProxy* render_frame_proxy, |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 63 | int host_routing_id) |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 64 | : host_routing_id_(host_routing_id), |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 65 | last_route_id_(0), |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 66 | last_output_surface_id_(0), |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 67 | last_host_id_(0), |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 68 | last_mailbox_valid_(false), |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 69 | ack_pending_(true), |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 70 | software_ack_pending_(false), |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 71 | opaque_(true), |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 72 | browser_plugin_(browser_plugin), |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 73 | render_frame_proxy_(render_frame_proxy), |
[email protected] | bdca9be2 | 2014-02-18 00:37:49 | [diff] [blame] | 74 | frame_(frame) {} |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 75 | |
| 76 | ChildFrameCompositingHelper::~ChildFrameCompositingHelper() {} |
| 77 | |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 78 | BrowserPluginManager* ChildFrameCompositingHelper::GetBrowserPluginManager() { |
| 79 | if (!browser_plugin_) |
| 80 | return NULL; |
| 81 | |
| 82 | return browser_plugin_->browser_plugin_manager(); |
| 83 | } |
| 84 | |
| 85 | blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { |
| 86 | if (!browser_plugin_) |
| 87 | return NULL; |
| 88 | |
| 89 | return browser_plugin_->container(); |
| 90 | } |
| 91 | |
| 92 | int ChildFrameCompositingHelper::GetInstanceID() { |
| 93 | if (!browser_plugin_) |
| 94 | return 0; |
| 95 | |
| 96 | return browser_plugin_->guest_instance_id(); |
| 97 | } |
| 98 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 99 | void ChildFrameCompositingHelper::SendCompositorFrameSwappedACKToBrowser( |
| 100 | FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
| 101 | // This function will be removed when BrowserPluginManager is removed and |
| 102 | // BrowserPlugin is modified to use a RenderFrame. |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 103 | if (GetBrowserPluginManager()) { |
| 104 | GetBrowserPluginManager()->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 105 | new BrowserPluginHostMsg_CompositorFrameSwappedACK( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 106 | host_routing_id_, GetInstanceID(), params)); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 107 | } else if (render_frame_proxy_) { |
| 108 | render_frame_proxy_->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 109 | new FrameHostMsg_CompositorFrameSwappedACK(host_routing_id_, params)); |
| 110 | } |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 111 | } |
| 112 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 113 | void ChildFrameCompositingHelper::SendBuffersSwappedACKToBrowser( |
| 114 | FrameHostMsg_BuffersSwappedACK_Params& params) { |
| 115 | // This function will be removed when BrowserPluginManager is removed and |
| 116 | // BrowserPlugin is modified to use a RenderFrame. |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 117 | if (GetBrowserPluginManager()) { |
| 118 | GetBrowserPluginManager()->Send(new BrowserPluginHostMsg_BuffersSwappedACK( |
[email protected] | eb455d38 | 2014-04-12 10:54:23 | [diff] [blame] | 119 | host_routing_id_, params)); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 120 | } else if (render_frame_proxy_) { |
| 121 | render_frame_proxy_->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 122 | new FrameHostMsg_BuffersSwappedACK(host_routing_id_, params)); |
| 123 | } |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 124 | } |
| 125 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 126 | void ChildFrameCompositingHelper::SendReclaimCompositorResourcesToBrowser( |
| 127 | FrameHostMsg_ReclaimCompositorResources_Params& params) { |
| 128 | // This function will be removed when BrowserPluginManager is removed and |
| 129 | // BrowserPlugin is modified to use a RenderFrame. |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 130 | if (GetBrowserPluginManager()) { |
| 131 | GetBrowserPluginManager()->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 132 | new BrowserPluginHostMsg_ReclaimCompositorResources( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 133 | host_routing_id_, GetInstanceID(), params)); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame^] | 134 | } else if (render_frame_proxy_) { |
| 135 | render_frame_proxy_->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 136 | new FrameHostMsg_ReclaimCompositorResources(host_routing_id_, params)); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void ChildFrameCompositingHelper::CopyFromCompositingSurface( |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 141 | int request_id, |
| 142 | gfx::Rect source_rect, |
| 143 | gfx::Size dest_size) { |
| 144 | CHECK(background_layer_); |
| 145 | scoped_ptr<cc::CopyOutputRequest> request = |
| 146 | cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 147 | &ChildFrameCompositingHelper::CopyFromCompositingSurfaceHasResult, |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 148 | this, |
| 149 | request_id, |
| 150 | dest_size)); |
| 151 | request->set_area(source_rect); |
| 152 | background_layer_->RequestCopyOfOutput(request.Pass()); |
| 153 | } |
| 154 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 155 | void ChildFrameCompositingHelper::DidCommitCompositorFrame() { |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 156 | if (software_ack_pending_) { |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 157 | FrameHostMsg_CompositorFrameSwappedACK_Params params; |
| 158 | params.producing_host_id = last_host_id_; |
| 159 | params.producing_route_id = last_route_id_; |
| 160 | params.output_surface_id = last_output_surface_id_; |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 161 | if (!unacked_software_frames_.empty()) { |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 162 | params.ack.last_software_frame_id = unacked_software_frames_.back(); |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 163 | unacked_software_frames_.pop_back(); |
| 164 | } |
| 165 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 166 | SendCompositorFrameSwappedACKToBrowser(params); |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 167 | |
| 168 | software_ack_pending_ = false; |
| 169 | } |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 170 | if (!resource_collection_.get() || !ack_pending_) |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 171 | return; |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 172 | |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 173 | FrameHostMsg_CompositorFrameSwappedACK_Params params; |
| 174 | params.producing_host_id = last_host_id_; |
| 175 | params.producing_route_id = last_route_id_; |
| 176 | params.output_surface_id = last_output_surface_id_; |
| 177 | resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 178 | ¶ms.ack.resources); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 179 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 180 | SendCompositorFrameSwappedACKToBrowser(params); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 181 | |
| 182 | ack_pending_ = false; |
| 183 | } |
| 184 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 185 | void ChildFrameCompositingHelper::EnableCompositing(bool enable) { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 186 | if (enable && !background_layer_.get()) { |
[email protected] | 67be9b1d | 2013-03-08 02:27:45 | [diff] [blame] | 187 | background_layer_ = cc::SolidColorLayer::Create(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 188 | background_layer_->SetMasksToBounds(true); |
| 189 | background_layer_->SetBackgroundColor( |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 190 | SkColorSetARGBInline(255, 255, 255, 255)); |
[email protected] | e1c5295 | 2014-06-18 08:35:43 | [diff] [blame] | 191 | web_layer_.reset(new WebLayerImpl(background_layer_)); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 194 | if (GetContainer()) { |
| 195 | GetContainer()->setWebLayer(enable ? web_layer_.get() : NULL); |
| 196 | } else if (frame_) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 197 | frame_->setRemoteWebLayer(enable ? web_layer_.get() : NULL); |
| 198 | } |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 201 | void ChildFrameCompositingHelper::CheckSizeAndAdjustLayerProperties( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 202 | const gfx::Size& new_size, |
| 203 | float device_scale_factor, |
| 204 | cc::Layer* layer) { |
| 205 | if (buffer_size_ != new_size) { |
| 206 | buffer_size_ = new_size; |
| 207 | // The container size is in DIP, so is the layer size. |
| 208 | // Buffer size is in physical pixels, so we need to adjust |
| 209 | // it by the device scale factor. |
| 210 | gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( |
| 211 | gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); |
| 212 | layer->SetBounds(device_scale_adjusted_size); |
| 213 | } |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 214 | |
| 215 | // Manually manage background layer for transparent webview. |
| 216 | if (!opaque_) |
| 217 | background_layer_->SetIsDrawable(false); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 220 | void ChildFrameCompositingHelper::MailboxReleased(SwapBuffersInfo mailbox, |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 221 | uint32 sync_point, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 222 | bool lost_resource) { |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 223 | if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) { |
| 224 | delete mailbox.shared_memory; |
| 225 | mailbox.shared_memory = NULL; |
| 226 | } else if (lost_resource) { |
| 227 | // Reset mailbox's name if the resource was lost. |
| 228 | mailbox.name.SetZero(); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 229 | } |
| 230 | |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 231 | // This means the GPU process crashed or guest crashed. |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 232 | if (last_host_id_ != mailbox.host_id || |
| 233 | last_output_surface_id_ != mailbox.output_surface_id || |
| 234 | last_route_id_ != mailbox.route_id) |
[email protected] | 4f7bbdc | 2013-01-29 02:31:39 | [diff] [blame] | 235 | return; |
| 236 | |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 237 | if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) |
| 238 | unacked_software_frames_.push_back(mailbox.software_frame_id); |
| 239 | |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 240 | // We need to send an ACK to for every buffer sent to us. |
| 241 | // However, if a buffer is freed up from |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 242 | // the compositor in cases like switching back to SW mode without a new |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 243 | // buffer arriving, no ACK is needed. |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 244 | if (!ack_pending_) { |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 245 | last_mailbox_valid_ = false; |
| 246 | return; |
| 247 | } |
| 248 | ack_pending_ = false; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 249 | switch (mailbox.type) { |
| 250 | case TEXTURE_IMAGE_TRANSPORT: { |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 251 | FrameHostMsg_BuffersSwappedACK_Params params; |
| 252 | params.gpu_host_id = mailbox.host_id; |
| 253 | params.gpu_route_id = mailbox.route_id; |
[email protected] | 7c6c09e | 2014-02-15 00:16:17 | [diff] [blame] | 254 | params.mailbox = mailbox.name; |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 255 | params.sync_point = sync_point; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 256 | SendBuffersSwappedACKToBrowser(params); |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 257 | break; |
| 258 | } |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 259 | case GL_COMPOSITOR_FRAME: { |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 260 | FrameHostMsg_CompositorFrameSwappedACK_Params params; |
| 261 | params.producing_host_id = mailbox.host_id; |
| 262 | params.producing_route_id = mailbox.route_id; |
| 263 | params.output_surface_id = mailbox.output_surface_id; |
| 264 | params.ack.gl_frame_data.reset(new cc::GLFrameData()); |
| 265 | params.ack.gl_frame_data->mailbox = mailbox.name; |
| 266 | params.ack.gl_frame_data->size = mailbox.size; |
| 267 | params.ack.gl_frame_data->sync_point = sync_point; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 268 | SendCompositorFrameSwappedACKToBrowser(params); |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 269 | break; |
| 270 | } |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 271 | case SOFTWARE_COMPOSITOR_FRAME: |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 272 | break; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 273 | } |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 276 | void ChildFrameCompositingHelper::OnContainerDestroy() { |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 277 | if (GetContainer()) |
| 278 | GetContainer()->setWebLayer(NULL); |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 279 | |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 280 | if (resource_collection_) |
| 281 | resource_collection_->SetClient(NULL); |
| 282 | |
[email protected] | 7873fe4e | 2013-11-14 18:35:22 | [diff] [blame] | 283 | ack_pending_ = false; |
| 284 | software_ack_pending_ = false; |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 285 | resource_collection_ = NULL; |
| 286 | frame_provider_ = NULL; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 287 | texture_layer_ = NULL; |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 288 | delegated_layer_ = NULL; |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 289 | background_layer_ = NULL; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 290 | web_layer_.reset(); |
| 291 | } |
| 292 | |
[email protected] | f49722f | 2014-01-30 17:54:50 | [diff] [blame] | 293 | void ChildFrameCompositingHelper::ChildFrameGone() { |
| 294 | background_layer_->SetBackgroundColor(SkColorSetARGBInline(255, 0, 128, 0)); |
| 295 | background_layer_->RemoveAllChildren(); |
| 296 | background_layer_->SetIsDrawable(true); |
| 297 | background_layer_->SetContentsOpaque(true); |
| 298 | } |
| 299 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 300 | void ChildFrameCompositingHelper::OnBuffersSwappedPrivate( |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 301 | const SwapBuffersInfo& mailbox, |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 302 | uint32 sync_point, |
[email protected] | 19fa81a0 | 2013-03-04 18:23:32 | [diff] [blame] | 303 | float device_scale_factor) { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 304 | DCHECK(!delegated_layer_.get()); |
[email protected] | 4f7bbdc | 2013-01-29 02:31:39 | [diff] [blame] | 305 | // If these mismatch, we are either just starting up, GPU process crashed or |
| 306 | // guest renderer crashed. |
| 307 | // In this case, we are communicating with a new image transport |
| 308 | // surface and must ACK with the new ID's and an empty mailbox. |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 309 | if (last_route_id_ != mailbox.route_id || |
| 310 | last_output_surface_id_ != mailbox.output_surface_id || |
| 311 | last_host_id_ != mailbox.host_id) |
[email protected] | 4f7bbdc | 2013-01-29 02:31:39 | [diff] [blame] | 312 | last_mailbox_valid_ = false; |
| 313 | |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 314 | last_route_id_ = mailbox.route_id; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 315 | last_output_surface_id_ = mailbox.output_surface_id; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 316 | last_host_id_ = mailbox.host_id; |
[email protected] | 4f7bbdc | 2013-01-29 02:31:39 | [diff] [blame] | 317 | |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 318 | ack_pending_ = true; |
| 319 | // Browser plugin getting destroyed, do a fast ACK. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 320 | if (!background_layer_.get()) { |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 321 | MailboxReleased(mailbox, sync_point, false); |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 325 | if (!texture_layer_.get()) { |
[email protected] | e8e4ae23 | 2013-04-12 00:26:01 | [diff] [blame] | 326 | texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 327 | texture_layer_->SetIsDrawable(true); |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 328 | SetContentsOpaque(opaque_); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 329 | |
| 330 | background_layer_->AddChild(texture_layer_); |
| 331 | } |
| 332 | |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 333 | // The size of browser plugin container is not always equal to the size |
| 334 | // of the buffer that arrives here. This could be for a number of reasons, |
| 335 | // including autosize and a resize in progress. |
| 336 | // During resize, the container size changes first and then some time |
| 337 | // later, a new buffer with updated size will arrive. During this process, |
| 338 | // we need to make sure that things are still displayed pixel perfect. |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 339 | // We accomplish this by modifying bounds of the texture layer only |
| 340 | // when a new buffer arrives. |
| 341 | // Visually, this will either display a smaller part of the buffer |
| 342 | // or introduce a gutter around it. |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 343 | CheckSizeAndAdjustLayerProperties( |
| 344 | mailbox.size, device_scale_factor, texture_layer_.get()); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 345 | |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 346 | bool is_software_frame = mailbox.type == SOFTWARE_COMPOSITOR_FRAME; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 347 | bool current_mailbox_valid = is_software_frame ? mailbox.shared_memory != NULL |
| 348 | : !mailbox.name.IsZero(); |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 349 | if (!is_software_frame && !last_mailbox_valid_) { |
| 350 | SwapBuffersInfo empty_info = mailbox; |
| 351 | empty_info.name.SetZero(); |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 352 | MailboxReleased(empty_info, 0, false); |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 353 | if (!current_mailbox_valid) |
| 354 | return; |
| 355 | } |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 356 | |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 357 | cc::TextureMailbox texture_mailbox; |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 358 | scoped_ptr<cc::SingleReleaseCallback> release_callback; |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 359 | if (current_mailbox_valid) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 360 | release_callback = |
| 361 | cc::SingleReleaseCallback::Create( |
| 362 | base::Bind(&ChildFrameCompositingHelper::MailboxReleased, |
| 363 | scoped_refptr<ChildFrameCompositingHelper>(this), |
| 364 | mailbox)).Pass(); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 365 | if (is_software_frame) { |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 366 | texture_mailbox = cc::TextureMailbox(mailbox.shared_memory, mailbox.size); |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 367 | } else { |
| 368 | texture_mailbox = |
| 369 | cc::TextureMailbox(mailbox.name, GL_TEXTURE_2D, sync_point); |
| 370 | } |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 371 | } |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 372 | |
| 373 | texture_layer_->SetFlipped(!is_software_frame); |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 374 | texture_layer_->SetTextureMailbox(texture_mailbox, release_callback.Pass()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 375 | texture_layer_->SetNeedsDisplay(); |
[email protected] | c2bfe4e | 2013-01-16 01:10:20 | [diff] [blame] | 376 | last_mailbox_valid_ = current_mailbox_valid; |
| 377 | } |
| 378 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 379 | void ChildFrameCompositingHelper::OnBuffersSwapped( |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 380 | const gfx::Size& size, |
[email protected] | 7c6c09e | 2014-02-15 00:16:17 | [diff] [blame] | 381 | const gpu::Mailbox& mailbox, |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 382 | int gpu_route_id, |
| 383 | int gpu_host_id, |
| 384 | float device_scale_factor) { |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 385 | SwapBuffersInfo swap_info; |
[email protected] | 7c6c09e | 2014-02-15 00:16:17 | [diff] [blame] | 386 | swap_info.name = mailbox; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 387 | swap_info.type = TEXTURE_IMAGE_TRANSPORT; |
| 388 | swap_info.size = size; |
| 389 | swap_info.route_id = gpu_route_id; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 390 | swap_info.output_surface_id = 0; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 391 | swap_info.host_id = gpu_host_id; |
| 392 | OnBuffersSwappedPrivate(swap_info, 0, device_scale_factor); |
| 393 | } |
| 394 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 395 | void ChildFrameCompositingHelper::OnCompositorFrameSwapped( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 396 | scoped_ptr<cc::CompositorFrame> frame, |
| 397 | int route_id, |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 398 | uint32 output_surface_id, |
[email protected] | f197008 | 2014-04-09 04:29:56 | [diff] [blame] | 399 | int host_id, |
| 400 | base::SharedMemoryHandle handle) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 401 | |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 402 | if (frame->gl_frame_data) { |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 403 | SwapBuffersInfo swap_info; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 404 | swap_info.name = frame->gl_frame_data->mailbox; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 405 | swap_info.type = GL_COMPOSITOR_FRAME; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 406 | swap_info.size = frame->gl_frame_data->size; |
| 407 | swap_info.route_id = route_id; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 408 | swap_info.output_surface_id = output_surface_id; |
[email protected] | c049b2e | 2013-06-11 04:39:30 | [diff] [blame] | 409 | swap_info.host_id = host_id; |
| 410 | OnBuffersSwappedPrivate(swap_info, |
| 411 | frame->gl_frame_data->sync_point, |
| 412 | frame->metadata.device_scale_factor); |
| 413 | return; |
| 414 | } |
| 415 | |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 416 | if (frame->software_frame_data) { |
| 417 | cc::SoftwareFrameData* frame_data = frame->software_frame_data.get(); |
| 418 | |
| 419 | SwapBuffersInfo swap_info; |
| 420 | swap_info.type = SOFTWARE_COMPOSITOR_FRAME; |
| 421 | swap_info.size = frame_data->size; |
| 422 | swap_info.route_id = route_id; |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 423 | swap_info.output_surface_id = output_surface_id; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 424 | swap_info.host_id = host_id; |
| 425 | swap_info.software_frame_id = frame_data->id; |
| 426 | |
| 427 | scoped_ptr<base::SharedMemory> shared_memory( |
[email protected] | f197008 | 2014-04-09 04:29:56 | [diff] [blame] | 428 | new base::SharedMemory(handle, true)); |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 429 | const size_t size_in_bytes = 4 * frame_data->size.GetArea(); |
| 430 | if (!shared_memory->Map(size_in_bytes)) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 431 | LOG(ERROR) << "Failed to map shared memory of size " << size_in_bytes; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 432 | // Send ACK right away. |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 433 | software_ack_pending_ = true; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 434 | MailboxReleased(swap_info, 0, false); |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 435 | DidCommitCompositorFrame(); |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | |
| 439 | swap_info.shared_memory = shared_memory.release(); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 440 | OnBuffersSwappedPrivate(swap_info, 0, frame->metadata.device_scale_factor); |
[email protected] | 9afdaef | 2013-09-26 07:24:37 | [diff] [blame] | 441 | software_ack_pending_ = true; |
| 442 | last_route_id_ = route_id; |
| 443 | last_output_surface_id_ = output_surface_id; |
| 444 | last_host_id_ = host_id; |
[email protected] | 9f39c20 | 2013-06-18 16:06:42 | [diff] [blame] | 445 | return; |
| 446 | } |
| 447 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 448 | DCHECK(!texture_layer_.get()); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 449 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 450 | cc::DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 451 | // Do nothing if we are getting destroyed or have no frame data. |
| 452 | if (!frame_data || !background_layer_) |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 453 | return; |
| 454 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 455 | DCHECK(!frame_data->render_pass_list.empty()); |
| 456 | cc::RenderPass* root_pass = frame_data->render_pass_list.back(); |
| 457 | gfx::Size frame_size = root_pass->output_rect.size(); |
| 458 | |
[email protected] | 317f17d | 2013-11-09 05:03:48 | [diff] [blame] | 459 | if (last_route_id_ != route_id || |
| 460 | last_output_surface_id_ != output_surface_id || |
| 461 | last_host_id_ != host_id) { |
| 462 | // Resource ids are scoped by the output surface. |
| 463 | // If the originating output surface doesn't match the last one, it |
| 464 | // indicates the guest's output surface may have been recreated, in which |
| 465 | // case we should recreate the DelegatedRendererLayer, to avoid matching |
| 466 | // resources from the old one with resources from the new one which would |
| 467 | // have the same id. |
| 468 | frame_provider_ = NULL; |
| 469 | |
| 470 | // Drop the cc::DelegatedFrameResourceCollection so that we will not return |
| 471 | // any resources from the old output surface with the new output surface id. |
| 472 | if (resource_collection_) { |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 473 | resource_collection_->SetClient(NULL); |
| 474 | |
| 475 | if (resource_collection_->LoseAllResources()) |
| 476 | SendReturnedDelegatedResources(); |
[email protected] | 317f17d | 2013-11-09 05:03:48 | [diff] [blame] | 477 | resource_collection_ = NULL; |
| 478 | } |
| 479 | last_output_surface_id_ = output_surface_id; |
| 480 | last_route_id_ = route_id; |
| 481 | last_host_id_ = host_id; |
| 482 | } |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 483 | if (!resource_collection_) { |
| 484 | resource_collection_ = new cc::DelegatedFrameResourceCollection; |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 485 | resource_collection_->SetClient(this); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 486 | } |
| 487 | if (!frame_provider_.get() || frame_provider_->frame_size() != frame_size) { |
| 488 | frame_provider_ = new cc::DelegatedFrameProvider( |
| 489 | resource_collection_.get(), frame->delegated_frame_data.Pass()); |
| 490 | if (delegated_layer_.get()) |
| 491 | delegated_layer_->RemoveFromParent(); |
| 492 | delegated_layer_ = |
[email protected] | b59c161 | 2013-12-04 00:56:49 | [diff] [blame] | 493 | cc::DelegatedRendererLayer::Create(frame_provider_.get()); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 494 | delegated_layer_->SetIsDrawable(true); |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 495 | SetContentsOpaque(opaque_); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 496 | background_layer_->AddChild(delegated_layer_); |
| 497 | } else { |
| 498 | frame_provider_->SetFrameData(frame->delegated_frame_data.Pass()); |
| 499 | } |
| 500 | |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 501 | CheckSizeAndAdjustLayerProperties( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 502 | frame_data->render_pass_list.back()->output_rect.size(), |
| 503 | frame->metadata.device_scale_factor, |
| 504 | delegated_layer_.get()); |
| 505 | |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 506 | ack_pending_ = true; |
| 507 | } |
| 508 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 509 | void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 510 | if (texture_layer_.get()) |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 511 | texture_layer_->SetIsDrawable(visible); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 512 | if (delegated_layer_.get()) |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 513 | delegated_layer_->SetIsDrawable(visible); |
[email protected] | 69b7912 | 2013-02-14 19:16:45 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 516 | void ChildFrameCompositingHelper::UnusedResourcesAreAvailable() { |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 517 | if (ack_pending_) |
| 518 | return; |
| 519 | |
| 520 | SendReturnedDelegatedResources(); |
| 521 | } |
| 522 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 523 | void ChildFrameCompositingHelper::SendReturnedDelegatedResources() { |
| 524 | FrameHostMsg_ReclaimCompositorResources_Params params; |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 525 | if (resource_collection_) |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 526 | resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 527 | ¶ms.ack.resources); |
| 528 | DCHECK(!params.ack.resources.empty()); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 529 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 530 | params.route_id = last_route_id_; |
| 531 | params.output_surface_id = last_output_surface_id_; |
| 532 | params.renderer_host_id = last_host_id_; |
| 533 | SendReclaimCompositorResourcesToBrowser(params); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 534 | } |
| 535 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 536 | void ChildFrameCompositingHelper::SetContentsOpaque(bool opaque) { |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 537 | opaque_ = opaque; |
| 538 | |
| 539 | if (texture_layer_.get()) |
| 540 | texture_layer_->SetContentsOpaque(opaque_); |
| 541 | if (delegated_layer_.get()) |
| 542 | delegated_layer_->SetContentsOpaque(opaque_); |
| 543 | } |
| 544 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 545 | void ChildFrameCompositingHelper::CopyFromCompositingSurfaceHasResult( |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 546 | int request_id, |
| 547 | gfx::Size dest_size, |
| 548 | scoped_ptr<cc::CopyOutputResult> result) { |
| 549 | scoped_ptr<SkBitmap> bitmap; |
| 550 | if (result && result->HasBitmap() && !result->size().IsEmpty()) |
| 551 | bitmap = result->TakeBitmap(); |
| 552 | |
| 553 | SkBitmap resized_bitmap; |
| 554 | if (bitmap) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 555 | resized_bitmap = |
| 556 | skia::ImageOperations::Resize(*bitmap, |
| 557 | skia::ImageOperations::RESIZE_BEST, |
| 558 | dest_size.width(), |
| 559 | dest_size.height()); |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 560 | } |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 561 | if (GetBrowserPluginManager()) { |
| 562 | GetBrowserPluginManager()->Send( |
| 563 | new BrowserPluginHostMsg_CopyFromCompositingSurfaceAck( |
| 564 | host_routing_id_, GetInstanceID(), request_id, resized_bitmap)); |
| 565 | } |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 568 | } // namespace content |