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

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 1418273002: cc: Move draw params from SetExternalDrawConstraints to OnDraw (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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
OLDNEW
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 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 pending_tree_ = nullptr; 1251 pending_tree_ = nullptr;
1251 if (recycle_tree_) 1252 if (recycle_tree_)
1252 recycle_tree_->DetachLayerTree(); 1253 recycle_tree_->DetachLayerTree();
1253 recycle_tree_ = nullptr; 1254 recycle_tree_ = nullptr;
1254 } 1255 }
1255 1256
1256 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const { 1257 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const {
1257 return fps_counter_->current_frame_number(); 1258 return fps_counter_->current_frame_number();
1258 } 1259 }
1259 1260
1261 void LayerTreeHostImpl::SetExternalViewportForTesting(
1262 const gfx::Rect& external_viewport) {
1263 external_viewport_ = external_viewport;
1264 }
1265
1266 void LayerTreeHostImpl::SetResourcelessSoftwareDrawForTesting(
1267 bool resourceless_software_draw) {
1268 resourceless_software_draw_ = resourceless_software_draw;
1269 active_tree_->set_needs_update_draw_properties();
1270 }
1271
1260 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( 1272 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy(
1261 const ManagedMemoryPolicy& policy) { 1273 const ManagedMemoryPolicy& policy) {
1262 if (!resource_pool_) 1274 if (!resource_pool_)
1263 return; 1275 return;
1264 1276
1265 global_tile_state_.hard_memory_limit_in_bytes = 0; 1277 global_tile_state_.hard_memory_limit_in_bytes = 0;
1266 global_tile_state_.soft_memory_limit_in_bytes = 0; 1278 global_tile_state_.soft_memory_limit_in_bytes = 0;
1267 if (visible_ && policy.bytes_limit_when_visible > 0) { 1279 if (visible_ && policy.bytes_limit_when_visible > 0) {
1268 global_tile_state_.hard_memory_limit_in_bytes = 1280 global_tile_state_.hard_memory_limit_in_bytes =
1269 policy.bytes_limit_when_visible; 1281 policy.bytes_limit_when_visible;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ && 1458 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ &&
1447 actual_policy.priority_cutoff_when_visible == 1459 actual_policy.priority_cutoff_when_visible ==
1448 old_policy.priority_cutoff_when_visible) { 1460 old_policy.priority_cutoff_when_visible) {
1449 needs_commit = false; 1461 needs_commit = false;
1450 } 1462 }
1451 1463
1452 if (needs_commit) 1464 if (needs_commit)
1453 client_->SetNeedsCommitOnImplThread(); 1465 client_->SetNeedsCommitOnImplThread();
1454 } 1466 }
1455 1467
1456 void LayerTreeHostImpl::SetExternalDrawConstraints( 1468 void LayerTreeHostImpl::SetExternalTilePriorityConstraints(
1457 const gfx::Transform& transform, 1469 const gfx::Rect& viewport_rect,
1458 const gfx::Rect& viewport, 1470 const gfx::Transform& transform) {
brianderson 2015/12/14 20:51:26 Would it make sense to DCHECK(using_synchronous_re
boliu 2015/12/16 19:06:41 This works in production, and so probably good ide
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; 1471 gfx::Rect viewport_rect_for_tile_priority_in_view_space;
1464 if (!resourceless_software_draw) { 1472 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
1465 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); 1473 if (transform.GetInverse(&screen_to_view)) {
1466 if (transform_for_tile_priority.GetInverse(&screen_to_view)) { 1474 // Convert from screen space to view space.
1467 // Convert from screen space to view space. 1475 viewport_rect_for_tile_priority_in_view_space =
1468 viewport_rect_for_tile_priority_in_view_space = 1476 MathUtil::ProjectEnclosingClippedRect(screen_to_view, viewport_rect);
1469 MathUtil::ProjectEnclosingClippedRect(
1470 screen_to_view, viewport_rect_for_tile_priority);
1471 }
1472 } 1477 }
1473 1478
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 = 1479 const bool tile_priority_params_changed =
1480 viewport_rect_for_tile_priority_ != 1480 viewport_rect_for_tile_priority_ !=
1481 viewport_rect_for_tile_priority_in_view_space; 1481 viewport_rect_for_tile_priority_in_view_space;
1482 1482
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_ = 1483 viewport_rect_for_tile_priority_ =
1493 viewport_rect_for_tile_priority_in_view_space; 1484 viewport_rect_for_tile_priority_in_view_space;
1494 resourceless_software_draw_ = resourceless_software_draw;
1495 1485
1496 // When not toggling resourceless software draw, need to set redraw for 1486 if (tile_priority_params_changed) {
1497 // all changes to draw parameters. Damage will be set externally by Android 1487 active_tree_->set_needs_update_draw_properties();
1498 // WebView for resourceless software draw toggles, so ignored here. 1488
1499 const bool draw_params_changed = transform_changed || viewport_changed || 1489 // Compositor, not OutputSurface, is responsible for setting damage and
1500 clip_changed || tile_priority_params_changed; 1490 // triggering redraw for constraint changes.
1501 if (!resourceless_software_draw_changed && draw_params_changed) {
1502 SetFullRootLayerDamage(); 1491 SetFullRootLayerDamage();
1503 SetNeedsRedraw(); 1492 SetNeedsRedraw();
1504 } 1493 }
1505
1506 if (resourceless_software_draw_changed) {
1507 client_->OnResourcelessSoftareDrawStateChanged(resourceless_software_draw);
1508 client_->OnCanDrawStateChanged(CanDraw());
1509 }
1510 } 1494 }
1511 1495
1512 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 1496 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
1513 if (damage_rect.IsEmpty()) 1497 if (damage_rect.IsEmpty())
1514 return; 1498 return;
1515 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 1499 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1516 client_->SetNeedsRedrawRectOnImplThread(damage_rect); 1500 client_->SetNeedsRedrawRectOnImplThread(damage_rect);
1517 } 1501 }
1518 1502
1519 void LayerTreeHostImpl::DidSwapBuffers() { 1503 void LayerTreeHostImpl::DidSwapBuffers() {
(...skipping 29 matching lines...) Expand all
1549 } 1533 }
1550 1534
1551 // If we're not visible, we likely released resources, so we want to 1535 // 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 1536 // aggressively flush here to make sure those DeleteTextures make it to the
1553 // GPU process to free up the memory. 1537 // GPU process to free up the memory.
1554 if (output_surface_->context_provider() && !visible_) { 1538 if (output_surface_->context_provider() && !visible_) {
1555 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); 1539 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1556 } 1540 }
1557 } 1541 }
1558 1542
1559 void LayerTreeHostImpl::OnDraw() { 1543 void LayerTreeHostImpl::OnDraw(const gfx::Transform& transform,
1560 client_->OnDrawForOutputSurface(); 1544 const gfx::Rect& viewport,
1545 const gfx::Rect& clip,
1546 bool resourceless_software_draw) {
1547 DCHECK(!resourceless_software_draw_);
1548 const bool transform_changed = external_transform_ != transform;
1549 const bool viewport_changed = external_viewport_ != viewport;
1550 const bool clip_changed = external_clip_ != clip;
1551
1552 external_transform_ = transform;
1553 external_viewport_ = viewport;
1554 external_clip_ = clip;
1555
1556 {
1557 base::AutoReset<bool> resourceless_software_draw_reset(
1558 &resourceless_software_draw_, resourceless_software_draw);
1559
1560 // For resourceless software draw, always set full damage to ensure they
1561 // always swap. Otherwise, need to set redraw for any changes to draw
1562 // parameters.
1563 const bool draw_params_changed =
1564 transform_changed || viewport_changed || clip_changed;
1565 if (resourceless_software_draw_ || draw_params_changed) {
1566 SetFullRootLayerDamage();
1567 SetNeedsRedraw();
1568 }
1569
1570 // UpdateDrawProperties does not depend on clip.
1571 if (transform_changed || viewport_changed || resourceless_software_draw_) {
1572 active_tree_->set_needs_update_draw_properties();
1573 }
1574
1575 if (resourceless_software_draw) {
1576 client_->OnCanDrawStateChanged(CanDraw());
1577 }
1578
1579 client_->OnDrawForOutputSurface(resourceless_software_draw_);
1580 }
1581
1582 if (resourceless_software_draw) {
brianderson 2015/12/14 20:51:26 I think it would be easier to understand the flow
boliu 2015/12/16 19:06:41 Tried this, result below in this comment. Really d
1583 active_tree_->set_needs_update_draw_properties();
1584 client_->OnCanDrawStateChanged(CanDraw());
1585 // This draw may have reset all damage, which would lead to subsequent
1586 // incorrect hardware draw, so explicitly set damage for next hardware
1587 // draw as well.
1588 SetFullRootLayerDamage();
1589 }
1561 } 1590 }
1562 1591
1563 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { 1592 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() {
1564 client_->OnCanDrawStateChanged(CanDraw()); 1593 client_->OnCanDrawStateChanged(CanDraw());
1565 } 1594 }
1566 1595
1567 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { 1596 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const {
1568 CompositorFrameMetadata metadata; 1597 CompositorFrameMetadata metadata;
1569 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * 1598 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() *
1570 active_tree_->device_scale_factor(); 1599 active_tree_->device_scale_factor();
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 return task_runner_provider_->HasImplThread(); 3786 return task_runner_provider_->HasImplThread();
3758 } 3787 }
3759 3788
3760 bool LayerTreeHostImpl::CommitToActiveTree() const { 3789 bool LayerTreeHostImpl::CommitToActiveTree() const {
3761 // In single threaded mode we skip the pending tree and commit directly to the 3790 // In single threaded mode we skip the pending tree and commit directly to the
3762 // active tree. 3791 // active tree.
3763 return !task_runner_provider_->HasImplThread(); 3792 return !task_runner_provider_->HasImplThread();
3764 } 3793 }
3765 3794
3766 } // namespace cc 3795 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698