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 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 actual_policy.priority_cutoff_when_visible == | 1393 actual_policy.priority_cutoff_when_visible == |
1393 old_policy.priority_cutoff_when_visible) { | 1394 old_policy.priority_cutoff_when_visible) { |
1394 needs_commit = false; | 1395 needs_commit = false; |
1395 } | 1396 } |
1396 | 1397 |
1397 if (needs_commit) | 1398 if (needs_commit) |
1398 client_->SetNeedsCommitOnImplThread(); | 1399 client_->SetNeedsCommitOnImplThread(); |
1399 } | 1400 } |
1400 | 1401 |
1401 void LayerTreeHostImpl::SetExternalDrawConstraints( | 1402 void LayerTreeHostImpl::SetExternalDrawConstraints( |
1402 const gfx::Transform& transform, | |
1403 const gfx::Rect& viewport, | |
1404 const gfx::Rect& clip, | |
1405 const gfx::Rect& viewport_rect_for_tile_priority, | 1403 const gfx::Rect& viewport_rect_for_tile_priority, |
1406 const gfx::Transform& transform_for_tile_priority, | 1404 const gfx::Transform& transform_for_tile_priority) { |
1407 bool resourceless_software_draw) { | |
1408 gfx::Rect viewport_rect_for_tile_priority_in_view_space; | 1405 gfx::Rect viewport_rect_for_tile_priority_in_view_space; |
1409 if (!resourceless_software_draw) { | 1406 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); |
1410 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); | 1407 if (transform_for_tile_priority.GetInverse(&screen_to_view)) { |
1411 if (transform_for_tile_priority.GetInverse(&screen_to_view)) { | 1408 // Convert from screen space to view space. |
1412 // Convert from screen space to view space. | 1409 viewport_rect_for_tile_priority_in_view_space = |
1413 viewport_rect_for_tile_priority_in_view_space = | 1410 MathUtil::ProjectEnclosingClippedRect(screen_to_view, |
1414 MathUtil::ProjectEnclosingClippedRect( | 1411 viewport_rect_for_tile_priority); |
1415 screen_to_view, viewport_rect_for_tile_priority); | |
1416 } | |
1417 } | 1412 } |
1418 | 1413 |
1419 const bool transform_changed = external_transform_ != transform; | |
1420 const bool viewport_changed = external_viewport_ != viewport; | |
1421 const bool clip_changed = external_clip_ != clip; | |
1422 const bool resourceless_software_draw_changed = | |
1423 resourceless_software_draw_ != resourceless_software_draw; | |
1424 const bool tile_priority_params_changed = | 1414 const bool tile_priority_params_changed = |
1425 viewport_rect_for_tile_priority_ != | 1415 viewport_rect_for_tile_priority_ != |
1426 viewport_rect_for_tile_priority_in_view_space; | 1416 viewport_rect_for_tile_priority_in_view_space; |
1427 | 1417 |
1428 // UpdateDrawProperties does not depend on clip. | |
1429 if (transform_changed || viewport_changed || | |
1430 resourceless_software_draw_changed || tile_priority_params_changed) { | |
1431 active_tree_->set_needs_update_draw_properties(); | |
1432 } | |
1433 | |
1434 external_transform_ = transform; | |
1435 external_viewport_ = viewport; | |
1436 external_clip_ = clip; | |
1437 viewport_rect_for_tile_priority_ = | 1418 viewport_rect_for_tile_priority_ = |
1438 viewport_rect_for_tile_priority_in_view_space; | 1419 viewport_rect_for_tile_priority_in_view_space; |
1439 resourceless_software_draw_ = resourceless_software_draw; | |
1440 | 1420 |
1441 // When not toggling resourceless software draw, need to set redraw for | 1421 if (tile_priority_params_changed) { |
1442 // all changes to draw parameters. Damage will be set externally by Android | 1422 active_tree_->set_needs_update_draw_properties(); |
1443 // WebView for resourceless software draw toggles, so ignored here. | |
1444 const bool draw_params_changed = transform_changed || viewport_changed || | |
1445 clip_changed || tile_priority_params_changed; | |
1446 if (!resourceless_software_draw_changed && draw_params_changed) { | |
1447 SetFullRootLayerDamage(); | 1423 SetFullRootLayerDamage(); |
1448 SetNeedsRedraw(); | 1424 SetNeedsRedraw(); |
1449 } | 1425 } |
1450 | |
1451 if (resourceless_software_draw_changed) { | |
1452 client_->OnResourcelessSoftareDrawStateChanged(resourceless_software_draw); | |
1453 client_->OnCanDrawStateChanged(CanDraw()); | |
1454 } | |
1455 } | 1426 } |
1456 | 1427 |
1457 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 1428 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
1458 if (damage_rect.IsEmpty()) | 1429 if (damage_rect.IsEmpty()) |
1459 return; | 1430 return; |
1460 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1431 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
1461 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1432 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
1462 } | 1433 } |
1463 | 1434 |
1464 void LayerTreeHostImpl::DidSwapBuffers() { | 1435 void LayerTreeHostImpl::DidSwapBuffers() { |
(...skipping 29 matching lines...) Expand all Loading... | |
1494 } | 1465 } |
1495 | 1466 |
1496 // If we're not visible, we likely released resources, so we want to | 1467 // If we're not visible, we likely released resources, so we want to |
1497 // aggressively flush here to make sure those DeleteTextures make it to the | 1468 // aggressively flush here to make sure those DeleteTextures make it to the |
1498 // GPU process to free up the memory. | 1469 // GPU process to free up the memory. |
1499 if (output_surface_->context_provider() && !visible_) { | 1470 if (output_surface_->context_provider() && !visible_) { |
1500 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); | 1471 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); |
1501 } | 1472 } |
1502 } | 1473 } |
1503 | 1474 |
1504 void LayerTreeHostImpl::OnDraw() { | 1475 void LayerTreeHostImpl::OnDraw(const gfx::Transform& transform, |
1505 client_->OnDrawForOutputSurface(); | 1476 const gfx::Rect& viewport, |
1477 const gfx::Rect& clip, | |
1478 bool resourceless_software_draw) { | |
1479 DCHECK(!resourceless_software_draw_); | |
1480 const bool transform_changed = DrawTransform() != transform; | |
1481 const bool viewport_changed = DeviceViewport() != viewport; | |
1482 const bool clip_changed = DeviceClip() != clip; | |
1483 | |
1484 { | |
1485 base::AutoReset<gfx::Transform> transform_reset(&external_transform_, | |
1486 transform); | |
1487 base::AutoReset<gfx::Rect> viewport_reset(&external_viewport_, viewport); | |
1488 base::AutoReset<gfx::Rect> clip_reset(&external_clip_, clip); | |
1489 base::AutoReset<bool> resourceless_software_draw_reset( | |
1490 &resourceless_software_draw_, resourceless_software_draw); | |
1491 | |
1492 // For resourceless software draw, always set full damage to ensure they | |
1493 // always swap. Otherwise, need to set redraw for all changes to draw | |
1494 // parameters. | |
1495 const bool draw_params_changed = | |
1496 transform_changed || viewport_changed || clip_changed; | |
1497 if (resourceless_software_draw_ || draw_params_changed) { | |
1498 SetFullRootLayerDamage(); | |
1499 SetNeedsRedraw(); | |
1500 } | |
1501 | |
1502 // UpdateDrawProperties does not depend on clip. | |
1503 if (transform_changed || viewport_changed || resourceless_software_draw_) { | |
1504 active_tree_->set_needs_update_draw_properties(); | |
1505 } | |
1506 | |
1507 if (resourceless_software_draw) { | |
1508 client_->OnResourcelessSoftareDrawStateChanged( | |
1509 resourceless_software_draw_); | |
1510 client_->OnCanDrawStateChanged(CanDraw()); | |
1511 } | |
1512 | |
1513 client_->OnDrawForOutputSurface(); | |
danakj
2015/10/23 18:13:10
I was picturing resourcelessdraw being passed here
boliu
2015/10/23 18:18:20
Ahh, good point :)
| |
1514 } | |
1515 | |
1516 if (resourceless_software_draw) { | |
1517 client_->OnResourcelessSoftareDrawStateChanged(resourceless_software_draw_); | |
1518 client_->OnCanDrawStateChanged(CanDraw()); | |
1519 // This draw may have reset all damage, which would lead to subsequent | |
1520 // incorrect hardware draw, so explicitly set damage for next hardware | |
1521 // draw as well. | |
1522 SetFullRootLayerDamage(); | |
1523 } | |
1506 } | 1524 } |
1507 | 1525 |
1508 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { | 1526 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { |
1509 client_->OnCanDrawStateChanged(CanDraw()); | 1527 client_->OnCanDrawStateChanged(CanDraw()); |
1510 } | 1528 } |
1511 | 1529 |
1512 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { | 1530 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { |
1513 CompositorFrameMetadata metadata; | 1531 CompositorFrameMetadata metadata; |
1514 metadata.device_scale_factor = active_tree_->device_scale_factor(); | 1532 metadata.device_scale_factor = active_tree_->device_scale_factor(); |
1515 metadata.page_scale_factor = active_tree_->current_page_scale_factor(); | 1533 metadata.page_scale_factor = active_tree_->current_page_scale_factor(); |
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3656 return task_runner_provider_->HasImplThread(); | 3674 return task_runner_provider_->HasImplThread(); |
3657 } | 3675 } |
3658 | 3676 |
3659 bool LayerTreeHostImpl::CommitToActiveTree() const { | 3677 bool LayerTreeHostImpl::CommitToActiveTree() const { |
3660 // In single threaded mode we skip the pending tree and commit directly to the | 3678 // In single threaded mode we skip the pending tree and commit directly to the |
3661 // active tree. | 3679 // active tree. |
3662 return !task_runner_provider_->HasImplThread(); | 3680 return !task_runner_provider_->HasImplThread(); |
3663 } | 3681 } |
3664 | 3682 |
3665 } // namespace cc | 3683 } // namespace cc |
OLD | NEW |