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

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

Issue 13042012: Browser side changes for software compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 911
912 void RenderWidgetHostViewAura::Blur() { 912 void RenderWidgetHostViewAura::Blur() {
913 window_->Blur(); 913 window_->Blur();
914 } 914 }
915 915
916 bool RenderWidgetHostViewAura::HasFocus() const { 916 bool RenderWidgetHostViewAura::HasFocus() const {
917 return window_->HasFocus(); 917 return window_->HasFocus();
918 } 918 }
919 919
920 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { 920 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
921 return current_surface_ || !!host_->GetBackingStore(false); 921 return current_surface_ || current_dib_ || !!host_->GetBackingStore(false);
922 } 922 }
923 923
924 void RenderWidgetHostViewAura::Show() { 924 void RenderWidgetHostViewAura::Show() {
925 window_->Show(); 925 window_->Show();
926 } 926 }
927 927
928 void RenderWidgetHostViewAura::Hide() { 928 void RenderWidgetHostViewAura::Hide() {
929 window_->Hide(); 929 window_->Hide();
930 } 930 }
931 931
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 // switching to software mode or receive a buffers swapped notification 1212 // switching to software mode or receive a buffers swapped notification
1213 // if switching to accelerated mode. 1213 // if switching to accelerated mode.
1214 // Sometimes (e.g. on a page load) the renderer will spuriously disable then 1214 // Sometimes (e.g. on a page load) the renderer will spuriously disable then
1215 // re-enable accelerated compositing, causing us to flash. 1215 // re-enable accelerated compositing, causing us to flash.
1216 // TODO(piman): factor the enable/disable accelerated compositing message into 1216 // TODO(piman): factor the enable/disable accelerated compositing message into
1217 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have 1217 // the UpdateRect/AcceleratedSurfaceBuffersSwapped messages so that we have
1218 // fewer inconsistent temporary states. 1218 // fewer inconsistent temporary states.
1219 accelerated_compositing_state_changed_ = true; 1219 accelerated_compositing_state_changed_ = true;
1220 } 1220 }
1221 1221
1222 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) { 1222 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const {
1223 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 1223 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
1224 can_lock_compositor_ == NO_PENDING_COMMIT || 1224 can_lock_compositor_ == NO_PENDING_COMMIT ||
1225 resize_locks_.empty()) 1225 resize_locks_.empty())
1226 return false; 1226 return false;
1227 1227
1228 ResizeLockList::iterator it = resize_locks_.begin(); 1228 ResizeLockList::const_iterator it = resize_locks_.begin();
1229 while (it != resize_locks_.end()) { 1229 while (it != resize_locks_.end()) {
1230 if ((*it)->expected_size() == size_in_dip) 1230 if ((*it)->expected_size() == size_in_dip)
1231 break; 1231 break;
1232 ++it; 1232 ++it;
1233 } 1233 }
1234 1234
1235 // We could be getting an unexpected frame due to an animation 1235 // We could be getting an unexpected frame due to an animation
1236 // (i.e. we start resizing but we get an old size frame first). 1236 // (i.e. we start resizing but we get an old size frame first).
1237 return it == resize_locks_.end() || ++it != resize_locks_.end(); 1237 return it == resize_locks_.end() || ++it != resize_locks_.end();
1238 } 1238 }
(...skipping 27 matching lines...) Expand all
1266 } 1266 }
1267 } 1267 }
1268 1268
1269 void RenderWidgetHostViewAura::UpdateExternalTexture() { 1269 void RenderWidgetHostViewAura::UpdateExternalTexture() {
1270 // Delay processing accelerated compositing state change till here where we 1270 // Delay processing accelerated compositing state change till here where we
1271 // act upon the state change. (Clear the external texture if switching to 1271 // act upon the state change. (Clear the external texture if switching to
1272 // software mode or set the external texture if going to accelerated mode). 1272 // software mode or set the external texture if going to accelerated mode).
1273 if (accelerated_compositing_state_changed_) 1273 if (accelerated_compositing_state_changed_)
1274 accelerated_compositing_state_changed_ = false; 1274 accelerated_compositing_state_changed_ = false;
1275 1275
1276 if (current_surface_ && host_->is_accelerated_compositing_active()) { 1276 bool is_compositing_active = host_->is_accelerated_compositing_active();
1277 if (is_compositing_active && current_surface_) {
1277 window_->SetExternalTexture(current_surface_.get()); 1278 window_->SetExternalTexture(current_surface_.get());
1278 gfx::Size container_size = ConvertSizeToDIP(this, current_surface_->size()); 1279 gfx::Size container_size = ConvertSizeToDIP(this, current_surface_->size());
1279 CheckResizeLocks(container_size); 1280 CheckResizeLocks(container_size);
1281 } else if (is_compositing_active && current_dib_) {
1282 window_->SetExternalTexture(NULL);
1283 gfx::Size frame_size = ConvertSizeToDIP(this, last_swapped_surface_size_);
1284 CheckResizeLocks(frame_size);
1280 } else { 1285 } else {
1281 window_->SetExternalTexture(NULL); 1286 window_->SetExternalTexture(NULL);
1282 resize_locks_.clear(); 1287 resize_locks_.clear();
1283 } 1288 }
1284 } 1289 }
1285 1290
1286 bool RenderWidgetHostViewAura::SwapBuffersPrepare( 1291 bool RenderWidgetHostViewAura::SwapBuffersPrepare(
1287 const gfx::Rect& surface_rect, 1292 const gfx::Rect& surface_rect,
1288 const gfx::Rect& damage_rect, 1293 const gfx::Rect& damage_rect,
1289 const std::string& mailbox_name, 1294 const std::string& mailbox_name,
(...skipping 29 matching lines...) Expand all
1319 return true; 1324 return true;
1320 } 1325 }
1321 1326
1322 void RenderWidgetHostViewAura::SwapBuffersCompleted( 1327 void RenderWidgetHostViewAura::SwapBuffersCompleted(
1323 const BufferPresentedCallback& ack_callback, 1328 const BufferPresentedCallback& ack_callback,
1324 const scoped_refptr<ui::Texture>& texture_to_return) { 1329 const scoped_refptr<ui::Texture>& texture_to_return) {
1325 ui::Compositor* compositor = GetCompositor(); 1330 ui::Compositor* compositor = GetCompositor();
1326 if (!compositor) { 1331 if (!compositor) {
1327 ack_callback.Run(false, texture_to_return); 1332 ack_callback.Run(false, texture_to_return);
1328 } else { 1333 } else {
1329 // Add sending an ACK to the list of things to do OnCompositingDidCommit 1334 AddOnCommitCallbackAndDisableLocks(
1330 can_lock_compositor_ = NO_PENDING_COMMIT;
1331 on_compositing_did_commit_callbacks_.push_back(
1332 base::Bind(ack_callback, false, texture_to_return)); 1335 base::Bind(ack_callback, false, texture_to_return));
1333 if (!compositor->HasObserver(this))
1334 compositor->AddObserver(this);
1335 } 1336 }
1336 } 1337 }
1337 1338
1338 #if defined(OS_WIN) 1339 #if defined(OS_WIN)
1339 void RenderWidgetHostViewAura::UpdateTransientRects( 1340 void RenderWidgetHostViewAura::UpdateTransientRects(
1340 const std::vector<gfx::Rect>& rects) { 1341 const std::vector<gfx::Rect>& rects) {
1341 transient_rects_ = rects; 1342 transient_rects_ = rects;
1342 UpdateCutoutRects(); 1343 UpdateCutoutRects();
1343 } 1344 }
1344 1345
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 released_front_lock_ = NULL; 1394 released_front_lock_ = NULL;
1394 CheckResizeLocks(frame_size_in_dip); 1395 CheckResizeLocks(frame_size_in_dip);
1395 1396
1396 if (paint_observer_) 1397 if (paint_observer_)
1397 paint_observer_->OnUpdateCompositorContent(); 1398 paint_observer_->OnUpdateCompositorContent();
1398 1399
1399 ui::Compositor* compositor = GetCompositor(); 1400 ui::Compositor* compositor = GetCompositor();
1400 if (!compositor) { 1401 if (!compositor) {
1401 SendDelegatedFrameAck(); 1402 SendDelegatedFrameAck();
1402 } else { 1403 } else {
1403 can_lock_compositor_ = NO_PENDING_COMMIT; 1404 AddOnCommitCallbackAndDisableLocks(
1404 on_compositing_did_commit_callbacks_.push_back(
1405 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, 1405 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck,
1406 base::Unretained(this))); 1406 AsWeakPtr()));
1407 if (!compositor->HasObserver(this))
1408 compositor->AddObserver(this);
1409 } 1407 }
1410 } 1408 }
1411 1409
1412 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { 1410 void RenderWidgetHostViewAura::SendDelegatedFrameAck() {
1413 cc::CompositorFrameAck ack; 1411 cc::CompositorFrameAck ack;
1414 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); 1412 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources);
1415 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 1413 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1416 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); 1414 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1417 } 1415 }
1418 1416
1417 void RenderWidgetHostViewAura::SwapSoftwareFrame(
1418 scoped_ptr<cc::SoftwareFrameData> frame_data,
1419 float frame_device_scale_factor) {
1420 const gfx::Size& frame_size = frame_data->size;
1421 const gfx::Rect& damage_rect = frame_data->damage_rect;
1422 const TransportDIB::Id& dib_id = frame_data->dib_id;
1423
1424 scoped_ptr<TransportDIB> dib;
1425 #if defined(OS_WIN)
1426 TransportDIB::Handle my_handle = TransportDIB::DefaultHandleValue();
1427 ::DuplicateHandle(host_->GetProcess()->GetHandle(), dib_id.handle,
1428 ::GetCurrentProcess(), &my_handle,
1429 0, FALSE, DUPLICATE_SAME_ACCESS);
1430 dib.reset(TransportDIB::Map(my_handle));
1431 #elif defined(USE_X11)
1432 dib.reset(TransportDIB::Map(dib_id.shmkey));
1433 #else
1434 NOTIMPLEMENTED();
1435 #endif
1436
1437 // Validate the received DIB.
1438 size_t expected_size = 4 * frame_size.GetArea();
1439 if (!dib || dib->size() < expected_size) {
1440 host_->GetProcess()->ReceivedBadMessage();
1441 return;
1442 }
1443
1444 if (last_swapped_surface_size_ != frame_size) {
1445 DLOG_IF(ERROR, damage_rect != gfx::Rect(frame_size))
1446 << "Expected full damage rect";
1447 }
1448
1449 TransportDIB::Id last_dib_id = current_dib_id_;
1450 current_dib_.reset(dib.release());
1451 current_dib_id_ = dib_id;
1452 last_swapped_surface_size_ = frame_size;
1453 previous_damage_.op(RectToSkIRect(damage_rect), SkRegion::kUnion_Op);
1454
1455 ui::Compositor* compositor = GetCompositor();
1456 gfx::Size frame_size_in_dip = gfx::ToFlooredSize(
1457 gfx::ScaleSize(frame_size, 1.0f / frame_device_scale_factor));
1458 if (!compositor) {
1459 SendSoftwareFrameAck(last_dib_id);
1460 return;
1461 }
1462
1463 window_->SetExternalTexture(NULL);
1464 released_front_lock_ = NULL;
1465 CheckResizeLocks(frame_size_in_dip);
1466
1467 if (ShouldSkipFrame(frame_size_in_dip)) {
1468 can_lock_compositor_ = NO_PENDING_COMMIT;
1469 SendSoftwareFrameAck(last_dib_id);
1470 } else {
1471 AddOnCommitCallbackAndDisableLocks(
1472 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck,
1473 AsWeakPtr(), last_dib_id));
1474 }
1475
1476 if (paint_observer_)
1477 paint_observer_->OnUpdateCompositorContent();
1478 window_->SchedulePaintInRect(ConvertRectToDIP(this, damage_rect));
1479 }
1480
1481 void RenderWidgetHostViewAura::SendSoftwareFrameAck(
1482 const TransportDIB::Id& id) {
1483 if (!TransportDIB::is_valid_id(id))
1484 return;
1485 cc::CompositorFrameAck ack;
1486 ack.last_dib_id = id;
1487 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
1488 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack);
1489 }
1490
1419 void RenderWidgetHostViewAura::OnSwapCompositorFrame( 1491 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1420 scoped_ptr<cc::CompositorFrame> frame) { 1492 scoped_ptr<cc::CompositorFrame> frame) {
1421 if (frame->delegated_frame_data) { 1493 if (frame->delegated_frame_data) {
1422 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), 1494 SwapDelegatedFrame(frame->delegated_frame_data.Pass(),
1423 frame->metadata.device_scale_factor); 1495 frame->metadata.device_scale_factor);
1424 return; 1496 return;
1425 } 1497 }
1498
1499 if (frame->software_frame_data) {
1500 SwapSoftwareFrame(frame->software_frame_data.Pass(),
1501 frame->metadata.device_scale_factor);
1502 return;
1503 }
1504
1426 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) 1505 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero())
1427 return; 1506 return;
1428 1507
1429 BufferPresentedCallback ack_callback = base::Bind( 1508 BufferPresentedCallback ack_callback = base::Bind(
1430 &SendCompositorFrameAck, 1509 &SendCompositorFrameAck,
1431 host_->GetRoutingID(), host_->GetProcess()->GetID(), 1510 host_->GetRoutingID(), host_->GetProcess()->GetID(),
1432 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); 1511 frame->gl_frame_data->mailbox, frame->gl_frame_data->size);
1433 1512
1434 if (!frame->gl_frame_data->sync_point) { 1513 if (!frame->gl_frame_data->sync_point) {
1435 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; 1514 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame...";
1436 ack_callback.Run(true, scoped_refptr<ui::Texture>()); 1515 ack_callback.Run(true, scoped_refptr<ui::Texture>());
1437 return; 1516 return;
1438 } 1517 }
1439 1518
1440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1519 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1441 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); 1520 factory->WaitSyncPoint(frame->gl_frame_data->sync_point);
1442 1521
1443 std::string mailbox_name( 1522 std::string mailbox_name(
1444 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), 1523 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name),
1445 sizeof(frame->gl_frame_data->mailbox.name)); 1524 sizeof(frame->gl_frame_data->mailbox.name));
1446 BuffersSwapped( 1525 BuffersSwapped(
1447 frame->gl_frame_data->size, mailbox_name, ack_callback); 1526 frame->gl_frame_data->size, mailbox_name, ack_callback);
1448 } 1527 }
1449 1528
1450 void RenderWidgetHostViewAura::BuffersSwapped( 1529 void RenderWidgetHostViewAura::BuffersSwapped(
1451 const gfx::Size& size, 1530 const gfx::Size& size,
1452 const std::string& mailbox_name, 1531 const std::string& mailbox_name,
1453 const BufferPresentedCallback& ack_callback) { 1532 const BufferPresentedCallback& ack_callback) {
1454 scoped_refptr<ui::Texture> texture_to_return(current_surface_); 1533 scoped_refptr<ui::Texture> texture_to_return(current_surface_);
1455 const gfx::Rect surface_rect = gfx::Rect(gfx::Point(), size); 1534 const gfx::Rect surface_rect = gfx::Rect(size);
1456 if (!SwapBuffersPrepare( 1535 if (!SwapBuffersPrepare(
1457 surface_rect, surface_rect, mailbox_name, ack_callback)) { 1536 surface_rect, surface_rect, mailbox_name, ack_callback)) {
1458 return; 1537 return;
1459 } 1538 }
1460 1539
1461 previous_damage_.setRect(RectToSkIRect(surface_rect)); 1540 previous_damage_.setRect(RectToSkIRect(surface_rect));
1462 skipped_damage_.setEmpty(); 1541 skipped_damage_.setEmpty();
1463 1542
1464 ui::Compositor* compositor = GetCompositor(); 1543 ui::Compositor* compositor = GetCompositor();
1465 if (compositor) { 1544 if (compositor) {
1466 gfx::Size surface_size = ConvertSizeToDIP(this, size); 1545 gfx::Size surface_size = ConvertSizeToDIP(this, size);
1467 window_->SchedulePaintInRect(gfx::Rect(surface_size)); 1546 window_->SchedulePaintInRect(gfx::Rect(surface_size));
1468 } 1547 }
1469 1548
1470 if (paint_observer_) 1549 if (paint_observer_)
1471 paint_observer_->OnUpdateCompositorContent(); 1550 paint_observer_->OnUpdateCompositorContent();
1472 1551
1473 SwapBuffersCompleted(ack_callback, texture_to_return); 1552 SwapBuffersCompleted(ack_callback, texture_to_return);
1474 } 1553 }
1475 1554
1476 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( 1555 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
1477 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, 1556 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
1478 int gpu_host_id) { 1557 int gpu_host_id) {
1479 scoped_refptr<ui::Texture> previous_texture(current_surface_); 1558 scoped_refptr<ui::Texture> previous_texture(current_surface_);
1480 const gfx::Rect surface_rect = 1559 const gfx::Rect surface_rect =
1481 gfx::Rect(gfx::Point(), params_in_pixel.surface_size); 1560 gfx::Rect(params_in_pixel.surface_size);
1482 gfx::Rect damage_rect(params_in_pixel.x, 1561 gfx::Rect damage_rect(params_in_pixel.x,
1483 params_in_pixel.y, 1562 params_in_pixel.y,
1484 params_in_pixel.width, 1563 params_in_pixel.width,
1485 params_in_pixel.height); 1564 params_in_pixel.height);
1486 BufferPresentedCallback ack_callback = base::Bind( 1565 BufferPresentedCallback ack_callback = base::Bind(
1487 &AcknowledgeBufferForGpu, params_in_pixel.route_id, gpu_host_id, 1566 &AcknowledgeBufferForGpu, params_in_pixel.route_id, gpu_host_id,
1488 params_in_pixel.mailbox_name); 1567 params_in_pixel.mailbox_name);
1489 1568
1490 if (!SwapBuffersPrepare( 1569 if (!SwapBuffersPrepare(
1491 surface_rect, damage_rect, params_in_pixel.mailbox_name, ack_callback)) { 1570 surface_rect, damage_rect, params_in_pixel.mailbox_name, ack_callback)) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { 1624 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
1546 } 1625 }
1547 1626
1548 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { 1627 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() {
1549 // This really tells us to release the frontbuffer. 1628 // This really tells us to release the frontbuffer.
1550 if (current_surface_) { 1629 if (current_surface_) {
1551 ui::Compositor* compositor = GetCompositor(); 1630 ui::Compositor* compositor = GetCompositor();
1552 if (compositor) { 1631 if (compositor) {
1553 // We need to wait for a commit to clear to guarantee that all we 1632 // We need to wait for a commit to clear to guarantee that all we
1554 // will not issue any more GL referencing the previous surface. 1633 // will not issue any more GL referencing the previous surface.
1555 can_lock_compositor_ = NO_PENDING_COMMIT; 1634 AddOnCommitCallbackAndDisableLocks(
1556 on_compositing_did_commit_callbacks_.push_back(
1557 base::Bind(&RenderWidgetHostViewAura:: 1635 base::Bind(&RenderWidgetHostViewAura::
1558 SetSurfaceNotInUseByCompositor, 1636 SetSurfaceNotInUseByCompositor,
1559 AsWeakPtr(), 1637 AsWeakPtr(),
1560 current_surface_)); // Hold a ref so the texture will not 1638 current_surface_)); // Hold a ref so the texture will not
1561 // get deleted until after commit. 1639 // get deleted until after commit.
1562 if (!compositor->HasObserver(this))
1563 compositor->AddObserver(this);
1564 } 1640 }
1565 current_surface_ = NULL; 1641 current_surface_ = NULL;
1566 UpdateExternalTexture(); 1642 UpdateExternalTexture();
1567 } 1643 }
1568 } 1644 }
1569 1645
1570 bool RenderWidgetHostViewAura::HasAcceleratedSurface( 1646 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
1571 const gfx::Size& desired_size) { 1647 const gfx::Size& desired_size) {
1572 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't 1648 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
1573 // matter what is returned here as GetBackingStore is the only caller of this 1649 // matter what is returned here as GetBackingStore is the only caller of this
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 2012
1937 bool RenderWidgetHostViewAura::CanFocus() { 2013 bool RenderWidgetHostViewAura::CanFocus() {
1938 return popup_type_ == WebKit::WebPopupTypeNone; 2014 return popup_type_ == WebKit::WebPopupTypeNone;
1939 } 2015 }
1940 2016
1941 void RenderWidgetHostViewAura::OnCaptureLost() { 2017 void RenderWidgetHostViewAura::OnCaptureLost() {
1942 host_->LostCapture(); 2018 host_->LostCapture();
1943 } 2019 }
1944 2020
1945 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { 2021 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
1946 paint_canvas_ = canvas; 2022 bool is_compositing_active = host_->is_accelerated_compositing_active();
1947 BackingStore* backing_store = host_->GetBackingStore(true); 2023 bool has_backing_store = !!host_->GetBackingStore(false);
1948 paint_canvas_ = NULL; 2024 if (is_compositing_active && current_dib_) {
1949 if (backing_store) { 2025 const gfx::Size window_size = window_->bounds().size();
1950 static_cast<BackingStoreAura*>(backing_store)->SkiaShowRect(gfx::Point(), 2026 const gfx::Size& frame_size = last_swapped_surface_size_;
1951 canvas); 2027
2028 SkBitmap bitmap;
2029 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
2030 frame_size.width(),
2031 frame_size.height());
2032 bitmap.setPixels(current_dib_->memory());
2033
2034 SkCanvas* sk_canvas = canvas->sk_canvas();
2035 for (SkRegion::Iterator it(previous_damage_); !it.done(); it.next()) {
2036 const SkIRect& src_rect = it.rect();
2037 SkRect dst_rect = SkRect::Make(src_rect);
2038 sk_canvas->drawBitmapRect(bitmap, &src_rect, dst_rect, NULL);
2039 }
2040 previous_damage_.setEmpty();
2041
2042 if (frame_size != window_size) {
2043 SkRegion region;
2044 region.op(0, 0, window_size.width(), window_size.height(),
2045 SkRegion::kUnion_Op);
2046 region.op(0, 0, frame_size.width(), frame_size.height(),
2047 SkRegion::kDifference_Op);
2048 SkPaint paint;
2049 paint.setColor(SK_ColorWHITE);
2050 for (SkRegion::Iterator it(region); !it.done(); it.next())
2051 sk_canvas->drawIRect(it.rect(), paint);
2052 }
2053
2054 if (paint_observer_)
2055 paint_observer_->OnPaintComplete();
2056 } else if (!is_compositing_active && has_backing_store) {
2057 paint_canvas_ = canvas;
2058 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>(
2059 host_->GetBackingStore(true));
2060 paint_canvas_ = NULL;
2061 backing_store->SkiaShowRect(gfx::Point(), canvas);
2062
1952 if (paint_observer_) 2063 if (paint_observer_)
1953 paint_observer_->OnPaintComplete(); 2064 paint_observer_->OnPaintComplete();
1954 } else if (aura::Env::GetInstance()->render_white_bg()) { 2065 } else if (aura::Env::GetInstance()->render_white_bg()) {
1955 canvas->DrawColor(SK_ColorWHITE); 2066 canvas->DrawColor(SK_ColorWHITE);
1956 } 2067 }
1957 } 2068 }
1958 2069
1959 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( 2070 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1960 float device_scale_factor) { 2071 float device_scale_factor) {
1961 if (!host_) 2072 if (!host_)
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 2470
2360 void RenderWidgetHostViewAura::OnCompositingDidCommit( 2471 void RenderWidgetHostViewAura::OnCompositingDidCommit(
2361 ui::Compositor* compositor) { 2472 ui::Compositor* compositor) {
2362 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 2473 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
2363 can_lock_compositor_ = YES; 2474 can_lock_compositor_ = YES;
2364 for (ResizeLockList::iterator it = resize_locks_.begin(); 2475 for (ResizeLockList::iterator it = resize_locks_.begin();
2365 it != resize_locks_.end(); ++it) 2476 it != resize_locks_.end(); ++it)
2366 if ((*it)->GrabDeferredLock()) 2477 if ((*it)->GrabDeferredLock())
2367 can_lock_compositor_ = YES_DID_LOCK; 2478 can_lock_compositor_ = YES_DID_LOCK;
2368 } 2479 }
2369 RunCompositingDidCommitCallbacks(); 2480 RunOnCommitCallbacks();
2370 locks_pending_commit_.clear(); 2481 locks_pending_commit_.clear();
2371 } 2482 }
2372 2483
2373 void RenderWidgetHostViewAura::OnCompositingStarted( 2484 void RenderWidgetHostViewAura::OnCompositingStarted(
2374 ui::Compositor* compositor, base::TimeTicks start_time) { 2485 ui::Compositor* compositor, base::TimeTicks start_time) {
2375 last_draw_ended_ = start_time; 2486 last_draw_ended_ = start_time;
2376 } 2487 }
2377 2488
2378 void RenderWidgetHostViewAura::OnCompositingEnded( 2489 void RenderWidgetHostViewAura::OnCompositingEnded(
2379 ui::Compositor* compositor) { 2490 ui::Compositor* compositor) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 2569 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
2459 2570
2460 void RenderWidgetHostViewAura::OnLostResources() { 2571 void RenderWidgetHostViewAura::OnLostResources() {
2461 current_surface_ = NULL; 2572 current_surface_ = NULL;
2462 UpdateExternalTexture(); 2573 UpdateExternalTexture();
2463 locks_pending_commit_.clear(); 2574 locks_pending_commit_.clear();
2464 2575
2465 // Make sure all ImageTransportClients are deleted now that the context those 2576 // Make sure all ImageTransportClients are deleted now that the context those
2466 // are using is becoming invalid. This sends pending ACKs and needs to happen 2577 // are using is becoming invalid. This sends pending ACKs and needs to happen
2467 // after calling UpdateExternalTexture() which syncs with the impl thread. 2578 // after calling UpdateExternalTexture() which syncs with the impl thread.
2468 RunCompositingDidCommitCallbacks(); 2579 RunOnCommitCallbacks();
2469 2580
2470 DCHECK(!shared_surface_handle_.is_null()); 2581 DCHECK(!shared_surface_handle_.is_null());
2471 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 2582 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
2472 factory->DestroySharedSurfaceHandle(shared_surface_handle_); 2583 factory->DestroySharedSurfaceHandle(shared_surface_handle_);
2473 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); 2584 shared_surface_handle_ = factory->CreateSharedSurfaceHandle();
2474 host_->CompositingSurfaceUpdated(); 2585 host_->CompositingSurfaceUpdated();
2475 host_->ScheduleComposite(); 2586 host_->ScheduleComposite();
2476 } 2587 }
2477 2588
2478 //////////////////////////////////////////////////////////////////////////////// 2589 ////////////////////////////////////////////////////////////////////////////////
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 gfx::Rect rect = window_->bounds(); 2725 gfx::Rect rect = window_->bounds();
2615 int border_x = rect.width() * kMouseLockBorderPercentage / 100; 2726 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
2616 int border_y = rect.height() * kMouseLockBorderPercentage / 100; 2727 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
2617 2728
2618 return global_mouse_position_.x() < rect.x() + border_x || 2729 return global_mouse_position_.x() < rect.x() + border_x ||
2619 global_mouse_position_.x() > rect.right() - border_x || 2730 global_mouse_position_.x() > rect.right() - border_x ||
2620 global_mouse_position_.y() < rect.y() + border_y || 2731 global_mouse_position_.y() < rect.y() + border_y ||
2621 global_mouse_position_.y() > rect.bottom() - border_y; 2732 global_mouse_position_.y() > rect.bottom() - border_y;
2622 } 2733 }
2623 2734
2624 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks() { 2735 void RenderWidgetHostViewAura::RunOnCommitCallbacks() {
2625 for (std::vector<base::Closure>::const_iterator 2736 for (std::vector<base::Closure>::const_iterator
2626 it = on_compositing_did_commit_callbacks_.begin(); 2737 it = on_compositing_did_commit_callbacks_.begin();
2627 it != on_compositing_did_commit_callbacks_.end(); ++it) { 2738 it != on_compositing_did_commit_callbacks_.end(); ++it) {
2628 it->Run(); 2739 it->Run();
2629 } 2740 }
2630 on_compositing_did_commit_callbacks_.clear(); 2741 on_compositing_did_commit_callbacks_.clear();
2631 } 2742 }
2632 2743
2744 void RenderWidgetHostViewAura::AddOnCommitCallbackAndDisableLocks(
2745 const base::Closure& callback) {
2746 ui::Compositor* compositor = GetCompositor();
2747 DCHECK(compositor);
2748
2749 if (!compositor->HasObserver(this))
2750 compositor->AddObserver(this);
2751
2752 can_lock_compositor_ = NO_PENDING_COMMIT;
2753 on_compositing_did_commit_callbacks_.push_back(callback);
2754 }
2755
2633 void RenderWidgetHostViewAura::AddedToRootWindow() { 2756 void RenderWidgetHostViewAura::AddedToRootWindow() {
2634 window_->GetRootWindow()->AddRootWindowObserver(this); 2757 window_->GetRootWindow()->AddRootWindowObserver(this);
2635 host_->ParentChanged(GetNativeViewId()); 2758 host_->ParentChanged(GetNativeViewId());
2636 UpdateScreenInfo(window_); 2759 UpdateScreenInfo(window_);
2637 if (popup_type_ != WebKit::WebPopupTypeNone) 2760 if (popup_type_ != WebKit::WebPopupTypeNone)
2638 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); 2761 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this));
2639 } 2762 }
2640 2763
2641 void RenderWidgetHostViewAura::RemovingFromRootWindow() { 2764 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2642 event_filter_for_popup_exit_.reset(); 2765 event_filter_for_popup_exit_.reset();
2643 window_->GetRootWindow()->RemoveRootWindowObserver(this); 2766 window_->GetRootWindow()->RemoveRootWindowObserver(this);
2644 host_->ParentChanged(0); 2767 host_->ParentChanged(0);
2645 // We are about to disconnect ourselves from the compositor, we need to issue 2768 // We are about to disconnect ourselves from the compositor, we need to issue
2646 // the callbacks now, because we won't get notified when the frame is done. 2769 // the callbacks now, because we won't get notified when the frame is done.
2647 // TODO(piman): this might in theory cause a race where the GPU process starts 2770 // TODO(piman): this might in theory cause a race where the GPU process starts
2648 // drawing to the buffer we haven't yet displayed. This will only show for 1 2771 // drawing to the buffer we haven't yet displayed. This will only show for 1
2649 // frame though, because we will reissue a new frame right away without that 2772 // frame though, because we will reissue a new frame right away without that
2650 // composited data. 2773 // composited data.
2651 ui::Compositor* compositor = GetCompositor(); 2774 ui::Compositor* compositor = GetCompositor();
2652 RunCompositingDidCommitCallbacks(); 2775 RunOnCommitCallbacks();
2653 locks_pending_commit_.clear(); 2776 locks_pending_commit_.clear();
2654 if (compositor && compositor->HasObserver(this)) 2777 if (compositor && compositor->HasObserver(this))
2655 compositor->RemoveObserver(this); 2778 compositor->RemoveObserver(this);
2656 } 2779 }
2657 2780
2658 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { 2781 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
2659 aura::RootWindow* root_window = window_->GetRootWindow(); 2782 aura::RootWindow* root_window = window_->GetRootWindow();
2660 return root_window ? root_window->compositor() : NULL; 2783 return root_window ? root_window->compositor() : NULL;
2661 } 2784 }
2662 2785
(...skipping 11 matching lines...) Expand all
2674 RenderWidgetHost* widget) { 2797 RenderWidgetHost* widget) {
2675 return new RenderWidgetHostViewAura(widget); 2798 return new RenderWidgetHostViewAura(widget);
2676 } 2799 }
2677 2800
2678 // static 2801 // static
2679 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { 2802 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) {
2680 GetScreenInfoForWindow(results, NULL); 2803 GetScreenInfoForWindow(results, NULL);
2681 } 2804 }
2682 2805
2683 } // namespace content 2806 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698