OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 | 11 |
| 12 #include "base/auto_reset.h" |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
14 #include "base/containers/small_map.h" | 15 #include "base/containers/small_map.h" |
15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/trace_event/trace_event_argument.h" | 21 #include "base/trace_event/trace_event_argument.h" |
21 #include "cc/animation/animation_host.h" | 22 #include "cc/animation/animation_host.h" |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && | 1447 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && |
1447 actual_policy.priority_cutoff_when_visible == | 1448 actual_policy.priority_cutoff_when_visible == |
1448 old_policy.priority_cutoff_when_visible) { | 1449 old_policy.priority_cutoff_when_visible) { |
1449 needs_commit = false; | 1450 needs_commit = false; |
1450 } | 1451 } |
1451 | 1452 |
1452 if (needs_commit) | 1453 if (needs_commit) |
1453 client_->SetNeedsCommitOnImplThread(); | 1454 client_->SetNeedsCommitOnImplThread(); |
1454 } | 1455 } |
1455 | 1456 |
1456 void LayerTreeHostImpl::SetExternalDrawConstraints( | 1457 void LayerTreeHostImpl::SetExternalTilePriorityConstraints( |
1457 const gfx::Transform& transform, | 1458 const gfx::Rect& viewport_rect, |
1458 const gfx::Rect& viewport, | 1459 const gfx::Transform& transform) { |
1459 const gfx::Rect& clip, | |
1460 const gfx::Rect& viewport_rect_for_tile_priority, | |
1461 const gfx::Transform& transform_for_tile_priority, | |
1462 bool resourceless_software_draw) { | |
1463 gfx::Rect viewport_rect_for_tile_priority_in_view_space; | 1460 gfx::Rect viewport_rect_for_tile_priority_in_view_space; |
1464 if (!resourceless_software_draw) { | 1461 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); |
1465 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); | 1462 if (transform.GetInverse(&screen_to_view)) { |
1466 if (transform_for_tile_priority.GetInverse(&screen_to_view)) { | 1463 // Convert from screen space to view space. |
1467 // Convert from screen space to view space. | 1464 viewport_rect_for_tile_priority_in_view_space = |
1468 viewport_rect_for_tile_priority_in_view_space = | 1465 MathUtil::ProjectEnclosingClippedRect(screen_to_view, viewport_rect); |
1469 MathUtil::ProjectEnclosingClippedRect( | |
1470 screen_to_view, viewport_rect_for_tile_priority); | |
1471 } | |
1472 } | 1466 } |
1473 | 1467 |
1474 const bool transform_changed = external_transform_ != transform; | |
1475 const bool viewport_changed = external_viewport_ != viewport; | |
1476 const bool clip_changed = external_clip_ != clip; | |
1477 const bool resourceless_software_draw_changed = | |
1478 resourceless_software_draw_ != resourceless_software_draw; | |
1479 const bool tile_priority_params_changed = | 1468 const bool tile_priority_params_changed = |
1480 viewport_rect_for_tile_priority_ != | 1469 viewport_rect_for_tile_priority_ != |
1481 viewport_rect_for_tile_priority_in_view_space; | 1470 viewport_rect_for_tile_priority_in_view_space; |
1482 | 1471 |
1483 // UpdateDrawProperties does not depend on clip. | |
1484 if (transform_changed || viewport_changed || | |
1485 resourceless_software_draw_changed || tile_priority_params_changed) { | |
1486 active_tree_->set_needs_update_draw_properties(); | |
1487 } | |
1488 | |
1489 external_transform_ = transform; | |
1490 external_viewport_ = viewport; | |
1491 external_clip_ = clip; | |
1492 viewport_rect_for_tile_priority_ = | 1472 viewport_rect_for_tile_priority_ = |
1493 viewport_rect_for_tile_priority_in_view_space; | 1473 viewport_rect_for_tile_priority_in_view_space; |
1494 resourceless_software_draw_ = resourceless_software_draw; | |
1495 | 1474 |
1496 // When not toggling resourceless software draw, need to set redraw for | 1475 if (tile_priority_params_changed) { |
1497 // all changes to draw parameters. Damage will be set externally by Android | 1476 active_tree_->set_needs_update_draw_properties(); |
1498 // WebView for resourceless software draw toggles, so ignored here. | 1477 |
1499 const bool draw_params_changed = transform_changed || viewport_changed || | 1478 // Compositor, not OutputSurface, is responsible for setting damage and |
1500 clip_changed || tile_priority_params_changed; | 1479 // triggering redraw for constraint changes. |
1501 if (!resourceless_software_draw_changed && draw_params_changed) { | |
1502 SetFullRootLayerDamage(); | 1480 SetFullRootLayerDamage(); |
1503 SetNeedsRedraw(); | 1481 SetNeedsRedraw(); |
1504 } | 1482 } |
1505 | |
1506 if (resourceless_software_draw_changed) { | |
1507 client_->OnResourcelessSoftareDrawStateChanged(resourceless_software_draw); | |
1508 client_->OnCanDrawStateChanged(CanDraw()); | |
1509 } | |
1510 } | 1483 } |
1511 | 1484 |
1512 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 1485 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
1513 if (damage_rect.IsEmpty()) | 1486 if (damage_rect.IsEmpty()) |
1514 return; | 1487 return; |
1515 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1488 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
1516 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1489 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
1517 } | 1490 } |
1518 | 1491 |
1519 void LayerTreeHostImpl::DidSwapBuffers() { | 1492 void LayerTreeHostImpl::DidSwapBuffers() { |
(...skipping 29 matching lines...) Expand all Loading... |
1549 } | 1522 } |
1550 | 1523 |
1551 // If we're not visible, we likely released resources, so we want to | 1524 // If we're not visible, we likely released resources, so we want to |
1552 // aggressively flush here to make sure those DeleteTextures make it to the | 1525 // aggressively flush here to make sure those DeleteTextures make it to the |
1553 // GPU process to free up the memory. | 1526 // GPU process to free up the memory. |
1554 if (output_surface_->context_provider() && !visible_) { | 1527 if (output_surface_->context_provider() && !visible_) { |
1555 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); | 1528 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); |
1556 } | 1529 } |
1557 } | 1530 } |
1558 | 1531 |
1559 void LayerTreeHostImpl::OnDraw() { | 1532 void LayerTreeHostImpl::OnDraw(const gfx::Transform& transform, |
1560 client_->OnDrawForOutputSurface(); | 1533 const gfx::Rect& viewport, |
| 1534 const gfx::Rect& clip, |
| 1535 bool resourceless_software_draw) { |
| 1536 DCHECK(!resourceless_software_draw_); |
| 1537 const bool transform_changed = external_transform_ != transform; |
| 1538 const bool viewport_changed = external_viewport_ != viewport; |
| 1539 const bool clip_changed = external_clip_ != clip; |
| 1540 |
| 1541 external_transform_ = transform; |
| 1542 external_viewport_ = viewport; |
| 1543 external_clip_ = clip; |
| 1544 |
| 1545 { |
| 1546 base::AutoReset<bool> resourceless_software_draw_reset( |
| 1547 &resourceless_software_draw_, resourceless_software_draw); |
| 1548 |
| 1549 // For resourceless software draw, always set full damage to ensure they |
| 1550 // always swap. Otherwise, need to set redraw for any changes to draw |
| 1551 // parameters. |
| 1552 const bool draw_params_changed = |
| 1553 transform_changed || viewport_changed || clip_changed; |
| 1554 if (resourceless_software_draw_ || draw_params_changed) { |
| 1555 SetFullRootLayerDamage(); |
| 1556 SetNeedsRedraw(); |
| 1557 } |
| 1558 |
| 1559 // UpdateDrawProperties does not depend on clip. |
| 1560 if (transform_changed || viewport_changed || resourceless_software_draw_) { |
| 1561 active_tree_->set_needs_update_draw_properties(); |
| 1562 } |
| 1563 |
| 1564 if (resourceless_software_draw) { |
| 1565 client_->OnCanDrawStateChanged(CanDraw()); |
| 1566 } |
| 1567 |
| 1568 client_->OnDrawForOutputSurface(resourceless_software_draw_); |
| 1569 } |
| 1570 |
| 1571 if (resourceless_software_draw) { |
| 1572 active_tree_->set_needs_update_draw_properties(); |
| 1573 client_->OnCanDrawStateChanged(CanDraw()); |
| 1574 // This draw may have reset all damage, which would lead to subsequent |
| 1575 // incorrect hardware draw, so explicitly set damage for next hardware |
| 1576 // draw as well. |
| 1577 SetFullRootLayerDamage(); |
| 1578 } |
1561 } | 1579 } |
1562 | 1580 |
1563 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { | 1581 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { |
1564 client_->OnCanDrawStateChanged(CanDraw()); | 1582 client_->OnCanDrawStateChanged(CanDraw()); |
1565 } | 1583 } |
1566 | 1584 |
1567 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { | 1585 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { |
1568 CompositorFrameMetadata metadata; | 1586 CompositorFrameMetadata metadata; |
1569 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * | 1587 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * |
1570 active_tree_->device_scale_factor(); | 1588 active_tree_->device_scale_factor(); |
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 return task_runner_provider_->HasImplThread(); | 3775 return task_runner_provider_->HasImplThread(); |
3758 } | 3776 } |
3759 | 3777 |
3760 bool LayerTreeHostImpl::CommitToActiveTree() const { | 3778 bool LayerTreeHostImpl::CommitToActiveTree() const { |
3761 // In single threaded mode we skip the pending tree and commit directly to the | 3779 // In single threaded mode we skip the pending tree and commit directly to the |
3762 // active tree. | 3780 // active tree. |
3763 return !task_runner_provider_->HasImplThread(); | 3781 return !task_runner_provider_->HasImplThread(); |
3764 } | 3782 } |
3765 | 3783 |
3766 } // namespace cc | 3784 } // namespace cc |
OLD | NEW |