OLD | NEW |
---|---|
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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 545 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
546 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 546 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
547 int gpu_host_id) { | 547 int gpu_host_id) { |
548 current_surface_ = params_in_pixel.surface_handle; | 548 current_surface_ = params_in_pixel.surface_handle; |
549 UpdateExternalTexture(); | 549 UpdateExternalTexture(); |
550 | 550 |
551 ui::Compositor* compositor = GetCompositor(); | 551 ui::Compositor* compositor = GetCompositor(); |
552 if (!compositor) { | 552 if (!compositor) { |
553 // We have no compositor, so we have no way to display the surface. | 553 // We have no compositor, so we have no way to display the surface. |
554 // Must still send the ACK. | 554 // Must still send the ACK. |
555 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id); | 555 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, compositor); |
piman
2012/07/09 22:40:01
compositor is NULL here. I don't think this works
jonathan.backer
2012/07/11 21:02:03
Good catch. The right thing to do here is to retur
| |
556 } else { | 556 } else { |
557 gfx::Size surface_size_in_pixel = | 557 gfx::Size surface_size_in_pixel = |
558 image_transport_clients_[params_in_pixel.surface_handle]->size(); | 558 image_transport_clients_[params_in_pixel.surface_handle]->size(); |
559 gfx::Size surface_size = content::ConvertSizeToDIP(this, | 559 gfx::Size surface_size = content::ConvertSizeToDIP(this, |
560 surface_size_in_pixel); | 560 surface_size_in_pixel); |
561 window_->SchedulePaintInRect(gfx::Rect(surface_size)); | 561 window_->SchedulePaintInRect(gfx::Rect(surface_size)); |
562 | 562 |
563 if (!resize_locks_.empty()) { | 563 if (!resize_locks_.empty()) { |
564 // If we are waiting for the resize, fast-track the ACK. | 564 // If we are waiting for the resize, fast-track the ACK. |
565 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id); | 565 compositor->AddDidCommitCallback( |
566 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | |
567 params_in_pixel.route_id, | |
568 gpu_host_id)); | |
566 } else { | 569 } else { |
567 // Add sending an ACK to the list of things to do OnCompositingWillStart | 570 // Add sending an ACK to the list of things to do OnCompositingWillStart |
568 on_compositing_will_start_callbacks_.push_back( | 571 on_compositing_will_start_callbacks_.push_back( |
569 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | 572 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, |
570 base::Unretained(this), | |
571 params_in_pixel.route_id, | 573 params_in_pixel.route_id, |
572 gpu_host_id)); | 574 gpu_host_id)); |
573 if (!compositor->HasObserver(this)) | 575 if (!compositor->HasObserver(this)) |
574 compositor->AddObserver(this); | 576 compositor->AddObserver(this); |
575 } | 577 } |
576 } | 578 } |
577 } | 579 } |
578 | 580 |
579 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( | 581 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
580 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 582 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
581 int gpu_host_id) { | 583 int gpu_host_id) { |
582 current_surface_ = params_in_pixel.surface_handle; | 584 current_surface_ = params_in_pixel.surface_handle; |
583 UpdateExternalTexture(); | 585 UpdateExternalTexture(); |
584 | 586 |
585 ui::Compositor* compositor = GetCompositor(); | 587 ui::Compositor* compositor = GetCompositor(); |
586 if (!compositor) { | 588 if (!compositor) { |
587 // We have no compositor, so we have no way to display the surface | 589 // We have no compositor, so we have no way to display the surface |
588 // Must still send the ACK | 590 // Must still send the ACK |
589 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id); | 591 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, compositor); |
590 } else { | 592 } else { |
591 gfx::Size surface_size_in_pixel = | 593 gfx::Size surface_size_in_pixel = |
592 image_transport_clients_[params_in_pixel.surface_handle]->size(); | 594 image_transport_clients_[params_in_pixel.surface_handle]->size(); |
593 | 595 |
594 // Co-ordinates come in OpenGL co-ordinate space. | 596 // Co-ordinates come in OpenGL co-ordinate space. |
595 // We need to convert to layer space. | 597 // We need to convert to layer space. |
596 gfx::Rect rect_to_paint = content::ConvertRectToDIP(this, gfx::Rect( | 598 gfx::Rect rect_to_paint = content::ConvertRectToDIP(this, gfx::Rect( |
597 params_in_pixel.x, | 599 params_in_pixel.x, |
598 surface_size_in_pixel.height() - params_in_pixel.y - | 600 surface_size_in_pixel.height() - params_in_pixel.y - |
599 params_in_pixel.height, | 601 params_in_pixel.height, |
600 params_in_pixel.width, | 602 params_in_pixel.width, |
601 params_in_pixel.height)); | 603 params_in_pixel.height)); |
602 window_->SchedulePaintInRect(rect_to_paint); | 604 window_->SchedulePaintInRect(rect_to_paint); |
603 | 605 |
604 if (!resize_locks_.empty()) { | 606 if (!resize_locks_.empty()) { |
605 // If we are waiting for the resize, fast-track the ACK. | 607 // If we are waiting for the resize, fast-track the ACK. |
606 InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id); | 608 compositor->AddDidCommitCallback( |
609 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | |
610 params_in_pixel.route_id, | |
611 gpu_host_id)); | |
607 } else { | 612 } else { |
608 // Add sending an ACK to the list of things to do OnCompositingWillStart | 613 // Add sending an ACK to the list of things to do OnCompositingWillStart |
609 on_compositing_will_start_callbacks_.push_back( | 614 on_compositing_will_start_callbacks_.push_back( |
610 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, | 615 base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK, |
611 base::Unretained(this), | |
612 params_in_pixel.route_id, | 616 params_in_pixel.route_id, |
613 gpu_host_id)); | 617 gpu_host_id)); |
614 if (!compositor->HasObserver(this)) | 618 if (!compositor->HasObserver(this)) |
615 compositor->AddObserver(this); | 619 compositor->AddObserver(this); |
616 } | 620 } |
617 } | 621 } |
618 } | 622 } |
619 | 623 |
620 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { | 624 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
621 } | 625 } |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 | 1213 |
1210 void RenderWidgetHostViewAura::OnLostActive() { | 1214 void RenderWidgetHostViewAura::OnLostActive() { |
1211 } | 1215 } |
1212 | 1216 |
1213 //////////////////////////////////////////////////////////////////////////////// | 1217 //////////////////////////////////////////////////////////////////////////////// |
1214 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: | 1218 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: |
1215 | 1219 |
1216 | 1220 |
1217 void RenderWidgetHostViewAura::OnCompositingWillStart( | 1221 void RenderWidgetHostViewAura::OnCompositingWillStart( |
1218 ui::Compositor* compositor) { | 1222 ui::Compositor* compositor) { |
1219 RunCompositingCallbacks(); | 1223 RunCompositingCallbacks(compositor); |
1220 } | 1224 } |
1221 | 1225 |
1222 void RenderWidgetHostViewAura::OnCompositingStarted( | 1226 void RenderWidgetHostViewAura::OnCompositingStarted( |
1223 ui::Compositor* compositor) { | 1227 ui::Compositor* compositor) { |
1224 locks_pending_draw_.clear(); | 1228 locks_pending_draw_.clear(); |
1225 compositor->RemoveObserver(this); | 1229 compositor->RemoveObserver(this); |
1226 } | 1230 } |
1227 | 1231 |
1228 void RenderWidgetHostViewAura::OnCompositingEnded(ui::Compositor* compositor) { | 1232 void RenderWidgetHostViewAura::OnCompositingEnded(ui::Compositor* compositor) { |
1229 } | 1233 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 gfx::Rect rect = window_->bounds(); | 1361 gfx::Rect rect = window_->bounds(); |
1358 int border_x = rect.width() * kMouseLockBorderPercentage / 100; | 1362 int border_x = rect.width() * kMouseLockBorderPercentage / 100; |
1359 int border_y = rect.height() * kMouseLockBorderPercentage / 100; | 1363 int border_y = rect.height() * kMouseLockBorderPercentage / 100; |
1360 | 1364 |
1361 return global_mouse_position_.x() < rect.x() + border_x || | 1365 return global_mouse_position_.x() < rect.x() + border_x || |
1362 global_mouse_position_.x() > rect.right() - border_x || | 1366 global_mouse_position_.x() > rect.right() - border_x || |
1363 global_mouse_position_.y() < rect.y() + border_y || | 1367 global_mouse_position_.y() < rect.y() + border_y || |
1364 global_mouse_position_.y() > rect.bottom() - border_y; | 1368 global_mouse_position_.y() > rect.bottom() - border_y; |
1365 } | 1369 } |
1366 | 1370 |
1367 void RenderWidgetHostViewAura::RunCompositingCallbacks() { | 1371 void RenderWidgetHostViewAura::RunCompositingCallbacks( |
1368 for (std::vector< base::Callback<void(void)> >::const_iterator | 1372 ui::Compositor* compositor) { |
1373 for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator | |
1369 it = on_compositing_will_start_callbacks_.begin(); | 1374 it = on_compositing_will_start_callbacks_.begin(); |
1370 it != on_compositing_will_start_callbacks_.end(); ++it) { | 1375 it != on_compositing_will_start_callbacks_.end(); ++it) { |
1371 it->Run(); | 1376 it->Run(compositor); |
1372 } | 1377 } |
1373 on_compositing_will_start_callbacks_.clear(); | 1378 on_compositing_will_start_callbacks_.clear(); |
1374 } | 1379 } |
1375 | 1380 |
1376 void RenderWidgetHostViewAura::InsertSyncPointAndACK(int32 route_id, | 1381 // static |
1377 int gpu_host_id) { | 1382 void RenderWidgetHostViewAura::InsertSyncPointAndACK( |
1383 int32 route_id, int gpu_host_id, ui::Compositor* compositor) { | |
1378 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1384 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
1379 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 1385 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
1380 route_id, gpu_host_id, factory->InsertSyncPoint(GetCompositor())); | 1386 route_id, gpu_host_id, factory->InsertSyncPoint(compositor)); |
1381 } | 1387 } |
1382 | 1388 |
1383 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 1389 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
1384 // We are about to disconnect ourselves from the compositor, we need to issue | 1390 // We are about to disconnect ourselves from the compositor, we need to issue |
1385 // the callbacks now, because we won't get notified when the frame is done. | 1391 // the callbacks now, because we won't get notified when the frame is done. |
1386 // TODO(piman): this might in theory cause a race where the GPU process starts | 1392 // TODO(piman): this might in theory cause a race where the GPU process starts |
1387 // drawing to the buffer we haven't yet displayed. This will only show for 1 | 1393 // drawing to the buffer we haven't yet displayed. This will only show for 1 |
1388 // frame though, because we will reissue a new frame right away without that | 1394 // frame though, because we will reissue a new frame right away without that |
1389 // composited data. | 1395 // composited data. |
1390 RunCompositingCallbacks(); | 1396 ui::Compositor* compositor = GetCompositor(); |
1397 RunCompositingCallbacks(compositor); | |
1391 locks_pending_draw_.clear(); | 1398 locks_pending_draw_.clear(); |
1392 ui::Compositor* compositor = GetCompositor(); | |
1393 if (compositor && compositor->HasObserver(this)) | 1399 if (compositor && compositor->HasObserver(this)) |
1394 compositor->RemoveObserver(this); | 1400 compositor->RemoveObserver(this); |
1395 DetachFromInputMethod(); | 1401 DetachFromInputMethod(); |
1396 } | 1402 } |
1397 | 1403 |
1398 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { | 1404 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { |
1399 aura::RootWindow* root_window = window_->GetRootWindow(); | 1405 aura::RootWindow* root_window = window_->GetRootWindow(); |
1400 return root_window ? root_window->compositor() : NULL; | 1406 return root_window ? root_window->compositor() : NULL; |
1401 } | 1407 } |
1402 | 1408 |
(...skipping 10 matching lines...) Expand all Loading... | |
1413 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 1419 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
1414 RenderWidgetHost* widget) { | 1420 RenderWidgetHost* widget) { |
1415 return new RenderWidgetHostViewAura(widget); | 1421 return new RenderWidgetHostViewAura(widget); |
1416 } | 1422 } |
1417 | 1423 |
1418 // static | 1424 // static |
1419 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1425 void content::RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1420 WebKit::WebScreenInfo* results) { | 1426 WebKit::WebScreenInfo* results) { |
1421 GetScreenInfoForWindow(results, NULL); | 1427 GetScreenInfoForWindow(results, NULL); |
1422 } | 1428 } |
OLD | NEW |