| 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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 if (!compositor) { |
| 1457 SendSoftwareFrameAck(last_dib_id); |
| 1458 return; |
| 1459 } |
| 1460 |
| 1461 gfx::Size frame_size_in_dip = gfx::ToFlooredSize( |
| 1462 gfx::ScaleSize(frame_size, 1.0f / frame_device_scale_factor)); |
| 1463 if (ShouldSkipFrame(frame_size_in_dip)) { |
| 1464 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 1465 SendSoftwareFrameAck(last_dib_id); |
| 1466 } else { |
| 1467 AddOnCommitCallbackAndDisableLocks( |
| 1468 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
| 1469 AsWeakPtr(), last_dib_id)); |
| 1470 } |
| 1471 |
| 1472 CheckResizeLocks(frame_size_in_dip); |
| 1473 released_front_lock_ = NULL; |
| 1474 window_->SetExternalTexture(NULL); |
| 1475 window_->SchedulePaintInRect(ConvertRectToDIP(this, damage_rect)); |
| 1476 |
| 1477 if (paint_observer_) |
| 1478 paint_observer_->OnUpdateCompositorContent(); |
| 1479 } |
| 1480 |
| 1481 void RenderWidgetHostViewAura::SendSoftwareFrameAck( |
| 1482 const TransportDIB::Id& id) { |
| 1483 cc::CompositorFrameAck ack; |
| 1484 ack.last_dib_id = id; |
| 1485 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1486 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
| 1487 } |
| 1488 |
| 1419 void RenderWidgetHostViewAura::OnSwapCompositorFrame( | 1489 void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
| 1420 scoped_ptr<cc::CompositorFrame> frame) { | 1490 scoped_ptr<cc::CompositorFrame> frame) { |
| 1421 if (frame->delegated_frame_data) { | 1491 if (frame->delegated_frame_data) { |
| 1422 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), | 1492 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), |
| 1423 frame->metadata.device_scale_factor); | 1493 frame->metadata.device_scale_factor); |
| 1424 return; | 1494 return; |
| 1425 } | 1495 } |
| 1496 |
| 1497 if (frame->software_frame_data) { |
| 1498 SwapSoftwareFrame(frame->software_frame_data.Pass(), |
| 1499 frame->metadata.device_scale_factor); |
| 1500 return; |
| 1501 } |
| 1502 |
| 1426 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) | 1503 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) |
| 1427 return; | 1504 return; |
| 1428 | 1505 |
| 1429 BufferPresentedCallback ack_callback = base::Bind( | 1506 BufferPresentedCallback ack_callback = base::Bind( |
| 1430 &SendCompositorFrameAck, | 1507 &SendCompositorFrameAck, |
| 1431 host_->GetRoutingID(), host_->GetProcess()->GetID(), | 1508 host_->GetRoutingID(), host_->GetProcess()->GetID(), |
| 1432 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); | 1509 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); |
| 1433 | 1510 |
| 1434 if (!frame->gl_frame_data->sync_point) { | 1511 if (!frame->gl_frame_data->sync_point) { |
| 1435 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; | 1512 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; |
| 1436 ack_callback.Run(true, scoped_refptr<ui::Texture>()); | 1513 ack_callback.Run(true, scoped_refptr<ui::Texture>()); |
| 1437 return; | 1514 return; |
| 1438 } | 1515 } |
| 1439 | 1516 |
| 1440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1517 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1441 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); | 1518 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); |
| 1442 | 1519 |
| 1443 std::string mailbox_name( | 1520 std::string mailbox_name( |
| 1444 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), | 1521 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), |
| 1445 sizeof(frame->gl_frame_data->mailbox.name)); | 1522 sizeof(frame->gl_frame_data->mailbox.name)); |
| 1446 BuffersSwapped( | 1523 BuffersSwapped( |
| 1447 frame->gl_frame_data->size, mailbox_name, ack_callback); | 1524 frame->gl_frame_data->size, mailbox_name, ack_callback); |
| 1448 } | 1525 } |
| 1449 | 1526 |
| 1450 void RenderWidgetHostViewAura::BuffersSwapped( | 1527 void RenderWidgetHostViewAura::BuffersSwapped( |
| 1451 const gfx::Size& size, | 1528 const gfx::Size& size, |
| 1452 const std::string& mailbox_name, | 1529 const std::string& mailbox_name, |
| 1453 const BufferPresentedCallback& ack_callback) { | 1530 const BufferPresentedCallback& ack_callback) { |
| 1454 scoped_refptr<ui::Texture> texture_to_return(current_surface_); | 1531 scoped_refptr<ui::Texture> texture_to_return(current_surface_); |
| 1455 const gfx::Rect surface_rect = gfx::Rect(gfx::Point(), size); | 1532 const gfx::Rect surface_rect = gfx::Rect(size); |
| 1456 if (!SwapBuffersPrepare( | 1533 if (!SwapBuffersPrepare( |
| 1457 surface_rect, surface_rect, mailbox_name, ack_callback)) { | 1534 surface_rect, surface_rect, mailbox_name, ack_callback)) { |
| 1458 return; | 1535 return; |
| 1459 } | 1536 } |
| 1460 | 1537 |
| 1461 previous_damage_.setRect(RectToSkIRect(surface_rect)); | 1538 previous_damage_.setRect(RectToSkIRect(surface_rect)); |
| 1462 skipped_damage_.setEmpty(); | 1539 skipped_damage_.setEmpty(); |
| 1463 | 1540 |
| 1464 ui::Compositor* compositor = GetCompositor(); | 1541 ui::Compositor* compositor = GetCompositor(); |
| 1465 if (compositor) { | 1542 if (compositor) { |
| 1466 gfx::Size surface_size = ConvertSizeToDIP(this, size); | 1543 gfx::Size surface_size = ConvertSizeToDIP(this, size); |
| 1467 window_->SchedulePaintInRect(gfx::Rect(surface_size)); | 1544 window_->SchedulePaintInRect(gfx::Rect(surface_size)); |
| 1468 } | 1545 } |
| 1469 | 1546 |
| 1470 if (paint_observer_) | 1547 if (paint_observer_) |
| 1471 paint_observer_->OnUpdateCompositorContent(); | 1548 paint_observer_->OnUpdateCompositorContent(); |
| 1472 | 1549 |
| 1473 SwapBuffersCompleted(ack_callback, texture_to_return); | 1550 SwapBuffersCompleted(ack_callback, texture_to_return); |
| 1474 } | 1551 } |
| 1475 | 1552 |
| 1476 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( | 1553 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
| 1477 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 1554 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
| 1478 int gpu_host_id) { | 1555 int gpu_host_id) { |
| 1479 scoped_refptr<ui::Texture> previous_texture(current_surface_); | 1556 scoped_refptr<ui::Texture> previous_texture(current_surface_); |
| 1480 const gfx::Rect surface_rect = | 1557 const gfx::Rect surface_rect = |
| 1481 gfx::Rect(gfx::Point(), params_in_pixel.surface_size); | 1558 gfx::Rect(params_in_pixel.surface_size); |
| 1482 gfx::Rect damage_rect(params_in_pixel.x, | 1559 gfx::Rect damage_rect(params_in_pixel.x, |
| 1483 params_in_pixel.y, | 1560 params_in_pixel.y, |
| 1484 params_in_pixel.width, | 1561 params_in_pixel.width, |
| 1485 params_in_pixel.height); | 1562 params_in_pixel.height); |
| 1486 BufferPresentedCallback ack_callback = base::Bind( | 1563 BufferPresentedCallback ack_callback = base::Bind( |
| 1487 &AcknowledgeBufferForGpu, params_in_pixel.route_id, gpu_host_id, | 1564 &AcknowledgeBufferForGpu, params_in_pixel.route_id, gpu_host_id, |
| 1488 params_in_pixel.mailbox_name); | 1565 params_in_pixel.mailbox_name); |
| 1489 | 1566 |
| 1490 if (!SwapBuffersPrepare( | 1567 if (!SwapBuffersPrepare( |
| 1491 surface_rect, damage_rect, params_in_pixel.mailbox_name, ack_callback)) { | 1568 surface_rect, damage_rect, params_in_pixel.mailbox_name, ack_callback)) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1545 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { | 1622 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
| 1546 } | 1623 } |
| 1547 | 1624 |
| 1548 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { | 1625 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { |
| 1549 // This really tells us to release the frontbuffer. | 1626 // This really tells us to release the frontbuffer. |
| 1550 if (current_surface_) { | 1627 if (current_surface_) { |
| 1551 ui::Compositor* compositor = GetCompositor(); | 1628 ui::Compositor* compositor = GetCompositor(); |
| 1552 if (compositor) { | 1629 if (compositor) { |
| 1553 // We need to wait for a commit to clear to guarantee that all we | 1630 // 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. | 1631 // will not issue any more GL referencing the previous surface. |
| 1555 can_lock_compositor_ = NO_PENDING_COMMIT; | 1632 AddOnCommitCallbackAndDisableLocks( |
| 1556 on_compositing_did_commit_callbacks_.push_back( | |
| 1557 base::Bind(&RenderWidgetHostViewAura:: | 1633 base::Bind(&RenderWidgetHostViewAura:: |
| 1558 SetSurfaceNotInUseByCompositor, | 1634 SetSurfaceNotInUseByCompositor, |
| 1559 AsWeakPtr(), | 1635 AsWeakPtr(), |
| 1560 current_surface_)); // Hold a ref so the texture will not | 1636 current_surface_)); // Hold a ref so the texture will not |
| 1561 // get deleted until after commit. | 1637 // get deleted until after commit. |
| 1562 if (!compositor->HasObserver(this)) | |
| 1563 compositor->AddObserver(this); | |
| 1564 } | 1638 } |
| 1565 current_surface_ = NULL; | 1639 current_surface_ = NULL; |
| 1566 UpdateExternalTexture(); | 1640 UpdateExternalTexture(); |
| 1567 } | 1641 } |
| 1568 } | 1642 } |
| 1569 | 1643 |
| 1570 bool RenderWidgetHostViewAura::HasAcceleratedSurface( | 1644 bool RenderWidgetHostViewAura::HasAcceleratedSurface( |
| 1571 const gfx::Size& desired_size) { | 1645 const gfx::Size& desired_size) { |
| 1572 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't | 1646 // 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 | 1647 // 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 Loading... |
| 1936 | 2010 |
| 1937 bool RenderWidgetHostViewAura::CanFocus() { | 2011 bool RenderWidgetHostViewAura::CanFocus() { |
| 1938 return popup_type_ == WebKit::WebPopupTypeNone; | 2012 return popup_type_ == WebKit::WebPopupTypeNone; |
| 1939 } | 2013 } |
| 1940 | 2014 |
| 1941 void RenderWidgetHostViewAura::OnCaptureLost() { | 2015 void RenderWidgetHostViewAura::OnCaptureLost() { |
| 1942 host_->LostCapture(); | 2016 host_->LostCapture(); |
| 1943 } | 2017 } |
| 1944 | 2018 |
| 1945 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { | 2019 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { |
| 1946 paint_canvas_ = canvas; | 2020 bool is_compositing_active = host_->is_accelerated_compositing_active(); |
| 1947 BackingStore* backing_store = host_->GetBackingStore(true); | 2021 bool has_backing_store = !!host_->GetBackingStore(false); |
| 1948 paint_canvas_ = NULL; | 2022 if (is_compositing_active && current_dib_) { |
| 1949 if (backing_store) { | 2023 const gfx::Size window_size = window_->bounds().size(); |
| 1950 static_cast<BackingStoreAura*>(backing_store)->SkiaShowRect(gfx::Point(), | 2024 const gfx::Size& frame_size = last_swapped_surface_size_; |
| 1951 canvas); | 2025 |
| 2026 SkBitmap bitmap; |
| 2027 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 2028 frame_size.width(), |
| 2029 frame_size.height()); |
| 2030 bitmap.setPixels(current_dib_->memory()); |
| 2031 |
| 2032 SkCanvas* sk_canvas = canvas->sk_canvas(); |
| 2033 for (SkRegion::Iterator it(previous_damage_); !it.done(); it.next()) { |
| 2034 const SkIRect& src_rect = it.rect(); |
| 2035 SkRect dst_rect = SkRect::Make(src_rect); |
| 2036 sk_canvas->drawBitmapRect(bitmap, &src_rect, dst_rect, NULL); |
| 2037 } |
| 2038 previous_damage_.setEmpty(); |
| 2039 |
| 2040 if (frame_size != window_size) { |
| 2041 SkRegion region; |
| 2042 region.op(0, 0, window_size.width(), window_size.height(), |
| 2043 SkRegion::kUnion_Op); |
| 2044 region.op(0, 0, frame_size.width(), frame_size.height(), |
| 2045 SkRegion::kDifference_Op); |
| 2046 SkPaint paint; |
| 2047 paint.setColor(SK_ColorWHITE); |
| 2048 for (SkRegion::Iterator it(region); !it.done(); it.next()) |
| 2049 sk_canvas->drawIRect(it.rect(), paint); |
| 2050 } |
| 2051 |
| 2052 if (paint_observer_) |
| 2053 paint_observer_->OnPaintComplete(); |
| 2054 } else if (!is_compositing_active && has_backing_store) { |
| 2055 paint_canvas_ = canvas; |
| 2056 BackingStoreAura* backing_store = static_cast<BackingStoreAura*>( |
| 2057 host_->GetBackingStore(true)); |
| 2058 paint_canvas_ = NULL; |
| 2059 backing_store->SkiaShowRect(gfx::Point(), canvas); |
| 2060 |
| 1952 if (paint_observer_) | 2061 if (paint_observer_) |
| 1953 paint_observer_->OnPaintComplete(); | 2062 paint_observer_->OnPaintComplete(); |
| 1954 } else if (aura::Env::GetInstance()->render_white_bg()) { | 2063 } else if (aura::Env::GetInstance()->render_white_bg()) { |
| 1955 canvas->DrawColor(SK_ColorWHITE); | 2064 canvas->DrawColor(SK_ColorWHITE); |
| 1956 } | 2065 } |
| 1957 } | 2066 } |
| 1958 | 2067 |
| 1959 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( | 2068 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( |
| 1960 float device_scale_factor) { | 2069 float device_scale_factor) { |
| 1961 if (!host_) | 2070 if (!host_) |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2359 | 2468 |
| 2360 void RenderWidgetHostViewAura::OnCompositingDidCommit( | 2469 void RenderWidgetHostViewAura::OnCompositingDidCommit( |
| 2361 ui::Compositor* compositor) { | 2470 ui::Compositor* compositor) { |
| 2362 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 2471 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
| 2363 can_lock_compositor_ = YES; | 2472 can_lock_compositor_ = YES; |
| 2364 for (ResizeLockList::iterator it = resize_locks_.begin(); | 2473 for (ResizeLockList::iterator it = resize_locks_.begin(); |
| 2365 it != resize_locks_.end(); ++it) | 2474 it != resize_locks_.end(); ++it) |
| 2366 if ((*it)->GrabDeferredLock()) | 2475 if ((*it)->GrabDeferredLock()) |
| 2367 can_lock_compositor_ = YES_DID_LOCK; | 2476 can_lock_compositor_ = YES_DID_LOCK; |
| 2368 } | 2477 } |
| 2369 RunCompositingDidCommitCallbacks(); | 2478 RunOnCommitCallbacks(); |
| 2370 locks_pending_commit_.clear(); | 2479 locks_pending_commit_.clear(); |
| 2371 } | 2480 } |
| 2372 | 2481 |
| 2373 void RenderWidgetHostViewAura::OnCompositingStarted( | 2482 void RenderWidgetHostViewAura::OnCompositingStarted( |
| 2374 ui::Compositor* compositor, base::TimeTicks start_time) { | 2483 ui::Compositor* compositor, base::TimeTicks start_time) { |
| 2375 last_draw_ended_ = start_time; | 2484 last_draw_ended_ = start_time; |
| 2376 } | 2485 } |
| 2377 | 2486 |
| 2378 void RenderWidgetHostViewAura::OnCompositingEnded( | 2487 void RenderWidgetHostViewAura::OnCompositingEnded( |
| 2379 ui::Compositor* compositor) { | 2488 ui::Compositor* compositor) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2458 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: | 2567 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
| 2459 | 2568 |
| 2460 void RenderWidgetHostViewAura::OnLostResources() { | 2569 void RenderWidgetHostViewAura::OnLostResources() { |
| 2461 current_surface_ = NULL; | 2570 current_surface_ = NULL; |
| 2462 UpdateExternalTexture(); | 2571 UpdateExternalTexture(); |
| 2463 locks_pending_commit_.clear(); | 2572 locks_pending_commit_.clear(); |
| 2464 | 2573 |
| 2465 // Make sure all ImageTransportClients are deleted now that the context those | 2574 // 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 | 2575 // are using is becoming invalid. This sends pending ACKs and needs to happen |
| 2467 // after calling UpdateExternalTexture() which syncs with the impl thread. | 2576 // after calling UpdateExternalTexture() which syncs with the impl thread. |
| 2468 RunCompositingDidCommitCallbacks(); | 2577 RunOnCommitCallbacks(); |
| 2469 | 2578 |
| 2470 DCHECK(!shared_surface_handle_.is_null()); | 2579 DCHECK(!shared_surface_handle_.is_null()); |
| 2471 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 2580 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 2472 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 2581 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
| 2473 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 2582 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); |
| 2474 host_->CompositingSurfaceUpdated(); | 2583 host_->CompositingSurfaceUpdated(); |
| 2475 host_->ScheduleComposite(); | 2584 host_->ScheduleComposite(); |
| 2476 } | 2585 } |
| 2477 | 2586 |
| 2478 //////////////////////////////////////////////////////////////////////////////// | 2587 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2614 gfx::Rect rect = window_->bounds(); | 2723 gfx::Rect rect = window_->bounds(); |
| 2615 int border_x = rect.width() * kMouseLockBorderPercentage / 100; | 2724 int border_x = rect.width() * kMouseLockBorderPercentage / 100; |
| 2616 int border_y = rect.height() * kMouseLockBorderPercentage / 100; | 2725 int border_y = rect.height() * kMouseLockBorderPercentage / 100; |
| 2617 | 2726 |
| 2618 return global_mouse_position_.x() < rect.x() + border_x || | 2727 return global_mouse_position_.x() < rect.x() + border_x || |
| 2619 global_mouse_position_.x() > rect.right() - border_x || | 2728 global_mouse_position_.x() > rect.right() - border_x || |
| 2620 global_mouse_position_.y() < rect.y() + border_y || | 2729 global_mouse_position_.y() < rect.y() + border_y || |
| 2621 global_mouse_position_.y() > rect.bottom() - border_y; | 2730 global_mouse_position_.y() > rect.bottom() - border_y; |
| 2622 } | 2731 } |
| 2623 | 2732 |
| 2624 void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks() { | 2733 void RenderWidgetHostViewAura::RunOnCommitCallbacks() { |
| 2625 for (std::vector<base::Closure>::const_iterator | 2734 for (std::vector<base::Closure>::const_iterator |
| 2626 it = on_compositing_did_commit_callbacks_.begin(); | 2735 it = on_compositing_did_commit_callbacks_.begin(); |
| 2627 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 2736 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
| 2628 it->Run(); | 2737 it->Run(); |
| 2629 } | 2738 } |
| 2630 on_compositing_did_commit_callbacks_.clear(); | 2739 on_compositing_did_commit_callbacks_.clear(); |
| 2631 } | 2740 } |
| 2632 | 2741 |
| 2742 void RenderWidgetHostViewAura::AddOnCommitCallbackAndDisableLocks( |
| 2743 const base::Closure& callback) { |
| 2744 ui::Compositor* compositor = GetCompositor(); |
| 2745 DCHECK(compositor); |
| 2746 |
| 2747 if (!compositor->HasObserver(this)) |
| 2748 compositor->AddObserver(this); |
| 2749 |
| 2750 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 2751 on_compositing_did_commit_callbacks_.push_back(callback); |
| 2752 } |
| 2753 |
| 2633 void RenderWidgetHostViewAura::AddedToRootWindow() { | 2754 void RenderWidgetHostViewAura::AddedToRootWindow() { |
| 2634 window_->GetRootWindow()->AddRootWindowObserver(this); | 2755 window_->GetRootWindow()->AddRootWindowObserver(this); |
| 2635 host_->ParentChanged(GetNativeViewId()); | 2756 host_->ParentChanged(GetNativeViewId()); |
| 2636 UpdateScreenInfo(window_); | 2757 UpdateScreenInfo(window_); |
| 2637 if (popup_type_ != WebKit::WebPopupTypeNone) | 2758 if (popup_type_ != WebKit::WebPopupTypeNone) |
| 2638 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); | 2759 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); |
| 2639 } | 2760 } |
| 2640 | 2761 |
| 2641 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 2762 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| 2642 event_filter_for_popup_exit_.reset(); | 2763 event_filter_for_popup_exit_.reset(); |
| 2643 window_->GetRootWindow()->RemoveRootWindowObserver(this); | 2764 window_->GetRootWindow()->RemoveRootWindowObserver(this); |
| 2644 host_->ParentChanged(0); | 2765 host_->ParentChanged(0); |
| 2645 // We are about to disconnect ourselves from the compositor, we need to issue | 2766 // 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. | 2767 // 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 | 2768 // 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 | 2769 // 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 | 2770 // frame though, because we will reissue a new frame right away without that |
| 2650 // composited data. | 2771 // composited data. |
| 2651 ui::Compositor* compositor = GetCompositor(); | 2772 ui::Compositor* compositor = GetCompositor(); |
| 2652 RunCompositingDidCommitCallbacks(); | 2773 RunOnCommitCallbacks(); |
| 2653 locks_pending_commit_.clear(); | 2774 locks_pending_commit_.clear(); |
| 2654 if (compositor && compositor->HasObserver(this)) | 2775 if (compositor && compositor->HasObserver(this)) |
| 2655 compositor->RemoveObserver(this); | 2776 compositor->RemoveObserver(this); |
| 2656 } | 2777 } |
| 2657 | 2778 |
| 2658 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { | 2779 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() { |
| 2659 aura::RootWindow* root_window = window_->GetRootWindow(); | 2780 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 2660 return root_window ? root_window->compositor() : NULL; | 2781 return root_window ? root_window->compositor() : NULL; |
| 2661 } | 2782 } |
| 2662 | 2783 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2674 RenderWidgetHost* widget) { | 2795 RenderWidgetHost* widget) { |
| 2675 return new RenderWidgetHostViewAura(widget); | 2796 return new RenderWidgetHostViewAura(widget); |
| 2676 } | 2797 } |
| 2677 | 2798 |
| 2678 // static | 2799 // static |
| 2679 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 2800 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2680 GetScreenInfoForWindow(results, NULL); | 2801 GetScreenInfoForWindow(results, NULL); |
| 2681 } | 2802 } |
| 2682 | 2803 |
| 2683 } // namespace content | 2804 } // namespace content |
| OLD | NEW |