Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 19331002: Associate an id with the output surface to handle lost contexts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android, tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 static_cast<const ui::GestureEvent&>(event); 291 static_cast<const ui::GestureEvent&>(event);
292 return gesture.details().touch_points() == 1; 292 return gesture.details().touch_points() == 1;
293 } 293 }
294 294
295 return false; 295 return false;
296 } 296 }
297 297
298 // Swap ack for the renderer when kCompositeToMailbox is enabled. 298 // Swap ack for the renderer when kCompositeToMailbox is enabled.
299 void SendCompositorFrameAck( 299 void SendCompositorFrameAck(
300 int32 route_id, 300 int32 route_id,
301 uint32 output_surface_id,
301 int renderer_host_id, 302 int renderer_host_id,
302 const gpu::Mailbox& received_mailbox, 303 const gpu::Mailbox& received_mailbox,
303 const gfx::Size& received_size, 304 const gfx::Size& received_size,
304 bool skip_frame, 305 bool skip_frame,
305 const scoped_refptr<ui::Texture>& texture_to_produce) { 306 const scoped_refptr<ui::Texture>& texture_to_produce) {
306 cc::CompositorFrameAck ack; 307 cc::CompositorFrameAck ack;
307 ack.gl_frame_data.reset(new cc::GLFrameData()); 308 ack.gl_frame_data.reset(new cc::GLFrameData());
308 DCHECK(!texture_to_produce.get() || !skip_frame); 309 DCHECK(!texture_to_produce.get() || !skip_frame);
309 if (texture_to_produce.get()) { 310 if (texture_to_produce.get()) {
310 std::string mailbox_name = texture_to_produce->Produce(); 311 std::string mailbox_name = texture_to_produce->Produce();
311 std::copy(mailbox_name.data(), 312 std::copy(mailbox_name.data(),
312 mailbox_name.data() + mailbox_name.length(), 313 mailbox_name.data() + mailbox_name.length(),
313 reinterpret_cast<char*>(ack.gl_frame_data->mailbox.name)); 314 reinterpret_cast<char*>(ack.gl_frame_data->mailbox.name));
314 ack.gl_frame_data->size = texture_to_produce->size(); 315 ack.gl_frame_data->size = texture_to_produce->size();
315 ack.gl_frame_data->sync_point = 316 ack.gl_frame_data->sync_point =
316 content::ImageTransportFactory::GetInstance()->InsertSyncPoint(); 317 content::ImageTransportFactory::GetInstance()->InsertSyncPoint();
317 } else if (skip_frame) { 318 } else if (skip_frame) {
318 // Skip the frame, i.e. tell the producer to reuse the same buffer that 319 // Skip the frame, i.e. tell the producer to reuse the same buffer that
319 // we just received. 320 // we just received.
320 ack.gl_frame_data->size = received_size; 321 ack.gl_frame_data->size = received_size;
321 ack.gl_frame_data->mailbox = received_mailbox; 322 ack.gl_frame_data->mailbox = received_mailbox;
322 } 323 }
323 324
324 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 325 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
325 route_id, renderer_host_id, ack); 326 route_id, output_surface_id, renderer_host_id, ack);
326 } 327 }
327 328
328 void AcknowledgeBufferForGpu( 329 void AcknowledgeBufferForGpu(
329 int32 route_id, 330 int32 route_id,
330 int gpu_host_id, 331 int gpu_host_id,
331 const std::string& received_mailbox, 332 const std::string& received_mailbox,
332 bool skip_frame, 333 bool skip_frame,
333 const scoped_refptr<ui::Texture>& texture_to_produce) { 334 const scoped_refptr<ui::Texture>& texture_to_produce) {
334 AcceleratedSurfaceMsg_BufferPresented_Params ack; 335 AcceleratedSurfaceMsg_BufferPresented_Params ack;
335 uint32 sync_point = 0; 336 uint32 sync_point = 0;
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 params_in_pixel.mailbox_name); 1395 params_in_pixel.mailbox_name);
1395 BuffersSwapped(params_in_pixel.size, 1396 BuffersSwapped(params_in_pixel.size,
1396 gfx::Rect(params_in_pixel.size), 1397 gfx::Rect(params_in_pixel.size),
1397 params_in_pixel.scale_factor, 1398 params_in_pixel.scale_factor,
1398 params_in_pixel.mailbox_name, 1399 params_in_pixel.mailbox_name,
1399 params_in_pixel.latency_info, 1400 params_in_pixel.latency_info,
1400 ack_callback); 1401 ack_callback);
1401 } 1402 }
1402 1403
1403 void RenderWidgetHostViewAura::SwapDelegatedFrame( 1404 void RenderWidgetHostViewAura::SwapDelegatedFrame(
1405 uint32 output_surface_id,
1404 scoped_ptr<cc::DelegatedFrameData> frame_data, 1406 scoped_ptr<cc::DelegatedFrameData> frame_data,
1405 float frame_device_scale_factor, 1407 float frame_device_scale_factor,
1406 const ui::LatencyInfo& latency_info) { 1408 const ui::LatencyInfo& latency_info) {
1407 gfx::Size frame_size_in_dip; 1409 gfx::Size frame_size_in_dip;
1408 if (!frame_data->render_pass_list.empty()) { 1410 if (!frame_data->render_pass_list.empty()) {
1409 frame_size_in_dip = gfx::ToFlooredSize(gfx::ScaleSize( 1411 frame_size_in_dip = gfx::ToFlooredSize(gfx::ScaleSize(
1410 frame_data->render_pass_list.back()->output_rect.size(), 1412 frame_data->render_pass_list.back()->output_rect.size(),
1411 1.f/frame_device_scale_factor)); 1413 1.f/frame_device_scale_factor));
1412 } 1414 }
1413 if (ShouldSkipFrame(frame_size_in_dip)) { 1415 if (ShouldSkipFrame(frame_size_in_dip)) {
1414 cc::CompositorFrameAck ack; 1416 cc::CompositorFrameAck ack;
1415 ack.resources.swap(frame_data->resource_list); 1417 ack.resources.swap(frame_data->resource_list);
1416 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1418 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1417 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1419 host_->GetRoutingID(), output_surface_id,
1420 host_->GetProcess()->GetID(), ack);
1418 return; 1421 return;
1419 } 1422 }
1420 window_->layer()->SetDelegatedFrame(frame_data.Pass(), frame_size_in_dip); 1423 window_->layer()->SetDelegatedFrame(frame_data.Pass(), frame_size_in_dip);
1421 released_front_lock_ = NULL; 1424 released_front_lock_ = NULL;
1422 current_frame_size_ = frame_size_in_dip; 1425 current_frame_size_ = frame_size_in_dip;
1423 CheckResizeLock(); 1426 CheckResizeLock();
1424 1427
1425 if (paint_observer_) 1428 if (paint_observer_)
1426 paint_observer_->OnUpdateCompositorContent(); 1429 paint_observer_->OnUpdateCompositorContent();
1427 1430
1428 ui::Compositor* compositor = GetCompositor(); 1431 ui::Compositor* compositor = GetCompositor();
1429 if (!compositor) { 1432 if (!compositor) {
1430 SendDelegatedFrameAck(); 1433 SendDelegatedFrameAck(output_surface_id);
1431 } else { 1434 } else {
1432 compositor->SetLatencyInfo(latency_info); 1435 compositor->SetLatencyInfo(latency_info);
1433 AddOnCommitCallbackAndDisableLocks( 1436 AddOnCommitCallbackAndDisableLocks(
1434 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, 1437 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck,
1435 AsWeakPtr())); 1438 AsWeakPtr(),
1439 output_surface_id));
1436 } 1440 }
1437 } 1441 }
1438 1442
1439 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { 1443 void RenderWidgetHostViewAura::SendDelegatedFrameAck(uint32 output_surface_id) {
1440 cc::CompositorFrameAck ack; 1444 cc::CompositorFrameAck ack;
1441 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); 1445 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources);
1442 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1446 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1443 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1447 host_->GetRoutingID(), output_surface_id,
1448 host_->GetProcess()->GetID(), ack);
1444 } 1449 }
1445 1450
1446 void RenderWidgetHostViewAura::SwapSoftwareFrame( 1451 void RenderWidgetHostViewAura::SwapSoftwareFrame(
1452 uint32 output_surface_id,
1447 scoped_ptr<cc::SoftwareFrameData> frame_data, 1453 scoped_ptr<cc::SoftwareFrameData> frame_data,
1448 float frame_device_scale_factor, 1454 float frame_device_scale_factor,
1449 const ui::LatencyInfo& latency_info) { 1455 const ui::LatencyInfo& latency_info) {
1450 const gfx::Size& frame_size = frame_data->size; 1456 const gfx::Size& frame_size = frame_data->size;
1451 const gfx::Rect& damage_rect = frame_data->damage_rect; 1457 const gfx::Rect& damage_rect = frame_data->damage_rect;
1452 gfx::Size frame_size_in_dip = 1458 gfx::Size frame_size_in_dip =
1453 ConvertSizeToDIP(frame_device_scale_factor, frame_size); 1459 ConvertSizeToDIP(frame_device_scale_factor, frame_size);
1454 if (ShouldSkipFrame(frame_size_in_dip)) { 1460 if (ShouldSkipFrame(frame_size_in_dip)) {
1455 SendSoftwareFrameAck(frame_data->id); 1461 SendSoftwareFrameAck(output_surface_id, frame_data->id);
1456 return; 1462 return;
1457 } 1463 }
1458 1464
1459 const size_t size_in_bytes = 4 * frame_size.GetArea(); 1465 const size_t size_in_bytes = 4 * frame_size.GetArea();
1460 #ifdef OS_WIN 1466 #ifdef OS_WIN
1461 scoped_ptr<base::SharedMemory> shared_memory( 1467 scoped_ptr<base::SharedMemory> shared_memory(
1462 new base::SharedMemory(frame_data->handle, true, 1468 new base::SharedMemory(frame_data->handle, true,
1463 host_->GetProcess()->GetHandle())); 1469 host_->GetProcess()->GetHandle()));
1464 #else 1470 #else
1465 scoped_ptr<base::SharedMemory> shared_memory( 1471 scoped_ptr<base::SharedMemory> shared_memory(
1466 new base::SharedMemory(frame_data->handle, true)); 1472 new base::SharedMemory(frame_data->handle, true));
1467 #endif 1473 #endif
1468 1474
1469 if (!shared_memory->Map(size_in_bytes)) { 1475 if (!shared_memory->Map(size_in_bytes)) {
1470 host_->GetProcess()->ReceivedBadMessage(); 1476 host_->GetProcess()->ReceivedBadMessage();
1471 return; 1477 return;
1472 } 1478 }
1473 1479
1474 if (last_swapped_surface_size_ != frame_size) { 1480 if (last_swapped_surface_size_ != frame_size) {
1475 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size)) 1481 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size))
1476 << "Expected full damage rect"; 1482 << "Expected full damage rect";
1477 } 1483 }
1478 last_swapped_surface_size_ = frame_size; 1484 last_swapped_surface_size_ = frame_size;
1479 last_swapped_surface_scale_factor_ = frame_device_scale_factor; 1485 last_swapped_surface_scale_factor_ = frame_device_scale_factor;
1480 1486
1481 base::SharedMemory* shared_memory_raw_ptr = shared_memory.get(); 1487 base::SharedMemory* shared_memory_raw_ptr = shared_memory.get();
1482 cc::TextureMailbox::ReleaseCallback callback = 1488 cc::TextureMailbox::ReleaseCallback callback =
1483 base::Bind(ReleaseMailbox, Passed(&shared_memory), 1489 base::Bind(ReleaseMailbox, Passed(&shared_memory),
1484 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, 1490 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
1485 AsWeakPtr(), frame_data->id)); 1491 AsWeakPtr(), output_surface_id, frame_data->id));
1486 current_software_frame_ = 1492 current_software_frame_ =
1487 cc::TextureMailbox(shared_memory_raw_ptr, frame_size, callback); 1493 cc::TextureMailbox(shared_memory_raw_ptr, frame_size, callback);
1488 DCHECK(current_software_frame_.IsSharedMemory()); 1494 DCHECK(current_software_frame_.IsSharedMemory());
1489 current_frame_size_ = frame_size_in_dip; 1495 current_frame_size_ = frame_size_in_dip;
1490 1496
1491 released_front_lock_ = NULL; 1497 released_front_lock_ = NULL;
1492 CheckResizeLock(); 1498 CheckResizeLock();
1493 window_->layer()->SetTextureMailbox(current_software_frame_, 1499 window_->layer()->SetTextureMailbox(current_software_frame_,
1494 frame_device_scale_factor); 1500 frame_device_scale_factor);
1495 window_->SchedulePaintInRect( 1501 window_->SchedulePaintInRect(
1496 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); 1502 ConvertRectToDIP(frame_device_scale_factor, damage_rect));
1497 1503
1498 ui::Compositor* compositor = GetCompositor(); 1504 ui::Compositor* compositor = GetCompositor();
1499 if (compositor) 1505 if (compositor)
1500 compositor->SetLatencyInfo(latency_info); 1506 compositor->SetLatencyInfo(latency_info);
1501 if (paint_observer_) 1507 if (paint_observer_)
1502 paint_observer_->OnUpdateCompositorContent(); 1508 paint_observer_->OnUpdateCompositorContent();
1503 } 1509 }
1504 1510
1505 void RenderWidgetHostViewAura::SendSoftwareFrameAck( 1511 void RenderWidgetHostViewAura::SendSoftwareFrameAck(
1506 unsigned software_frame_id) { 1512 uint32 output_surface_id, unsigned software_frame_id) {
1507 cc::CompositorFrameAck ack; 1513 cc::CompositorFrameAck ack;
1508 ack.last_software_frame_id = software_frame_id; 1514 ack.last_software_frame_id = software_frame_id;
1509 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1515 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1510 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1516 host_->GetRoutingID(), output_surface_id,
1517 host_->GetProcess()->GetID(), ack);
1511 } 1518 }
1512 1519
1513 void RenderWidgetHostViewAura::OnSwapCompositorFrame( 1520 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1521 uint32 output_surface_id,
1514 scoped_ptr<cc::CompositorFrame> frame) { 1522 scoped_ptr<cc::CompositorFrame> frame) {
1515 if (frame->delegated_frame_data) { 1523 if (frame->delegated_frame_data) {
1516 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), 1524 SwapDelegatedFrame(output_surface_id,
1525 frame->delegated_frame_data.Pass(),
1517 frame->metadata.device_scale_factor, 1526 frame->metadata.device_scale_factor,
1518 frame->metadata.latency_info); 1527 frame->metadata.latency_info);
1519 return; 1528 return;
1520 } 1529 }
1521 1530
1522 if (frame->software_frame_data) { 1531 if (frame->software_frame_data) {
1523 SwapSoftwareFrame(frame->software_frame_data.Pass(), 1532 SwapSoftwareFrame(output_surface_id,
1533 frame->software_frame_data.Pass(),
1524 frame->metadata.device_scale_factor, 1534 frame->metadata.device_scale_factor,
1525 frame->metadata.latency_info); 1535 frame->metadata.latency_info);
1526 return; 1536 return;
1527 } 1537 }
1528 1538
1529 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) 1539 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero())
1530 return; 1540 return;
1531 1541
1532 BufferPresentedCallback ack_callback = base::Bind( 1542 BufferPresentedCallback ack_callback = base::Bind(
1533 &SendCompositorFrameAck, 1543 &SendCompositorFrameAck,
1534 host_->GetRoutingID(), host_->GetProcess()->GetID(), 1544 host_->GetRoutingID(), output_surface_id, host_->GetProcess()->GetID(),
1535 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); 1545 frame->gl_frame_data->mailbox, frame->gl_frame_data->size);
1536 1546
1537 if (!frame->gl_frame_data->sync_point) { 1547 if (!frame->gl_frame_data->sync_point) {
1538 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; 1548 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame...";
1539 ack_callback.Run(true, scoped_refptr<ui::Texture>()); 1549 ack_callback.Run(true, scoped_refptr<ui::Texture>());
1540 return; 1550 return;
1541 } 1551 }
1542 1552
1543 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1553 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1544 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); 1554 factory->WaitSyncPoint(frame->gl_frame_data->sync_point);
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 RenderWidgetHost* widget) { 3122 RenderWidgetHost* widget) {
3113 return new RenderWidgetHostViewAura(widget); 3123 return new RenderWidgetHostViewAura(widget);
3114 } 3124 }
3115 3125
3116 // static 3126 // static
3117 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 3127 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
3118 GetScreenInfoForWindow(results, NULL); 3128 GetScreenInfoForWindow(results, NULL);
3119 } 3129 }
3120 3130
3121 } // namespace content 3131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698