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