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

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: tests fixed Created 5 years, 1 month 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 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 pending_tree_ = nullptr; 1221 pending_tree_ = nullptr;
1221 if (recycle_tree_) 1222 if (recycle_tree_)
1222 recycle_tree_->DetachLayerTree(); 1223 recycle_tree_->DetachLayerTree();
1223 recycle_tree_ = nullptr; 1224 recycle_tree_ = nullptr;
1224 } 1225 }
1225 1226
1226 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const { 1227 size_t LayerTreeHostImpl::SourceAnimationFrameNumberForTesting() const {
1227 return fps_counter_->current_frame_number(); 1228 return fps_counter_->current_frame_number();
1228 } 1229 }
1229 1230
1231 void LayerTreeHostImpl::SetExternalViewporForTesting(
danakj 2015/11/24 21:17:31 Why aren't callers of this just using SetExternalD
boliu 2015/11/24 23:27:38 external_viewport_ is set in OnDraw now, so this i
danakj 2015/12/10 22:33:54 If you call CalcDrawProps you can pass whatever vi
1232 const gfx::Rect& external_viewport) {
1233 external_viewport_ = external_viewport;
1234 }
1235
1236 void LayerTreeHostImpl::SetResourcelessSoftwareDrawForTesting(
1237 bool resourceless_software_draw) {
1238 resourceless_software_draw_ = resourceless_software_draw;
1239 active_tree_->set_needs_update_draw_properties();
1240 }
1241
1230 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( 1242 void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy(
1231 const ManagedMemoryPolicy& policy) { 1243 const ManagedMemoryPolicy& policy) {
1232 if (!resource_pool_) 1244 if (!resource_pool_)
1233 return; 1245 return;
1234 1246
1235 global_tile_state_.hard_memory_limit_in_bytes = 0; 1247 global_tile_state_.hard_memory_limit_in_bytes = 0;
1236 global_tile_state_.soft_memory_limit_in_bytes = 0; 1248 global_tile_state_.soft_memory_limit_in_bytes = 0;
1237 if (visible_ && policy.bytes_limit_when_visible > 0) { 1249 if (visible_ && policy.bytes_limit_when_visible > 0) {
1238 global_tile_state_.hard_memory_limit_in_bytes = 1250 global_tile_state_.hard_memory_limit_in_bytes =
1239 policy.bytes_limit_when_visible; 1251 policy.bytes_limit_when_visible;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 actual_policy.priority_cutoff_when_visible == 1429 actual_policy.priority_cutoff_when_visible ==
1418 old_policy.priority_cutoff_when_visible) { 1430 old_policy.priority_cutoff_when_visible) {
1419 needs_commit = false; 1431 needs_commit = false;
1420 } 1432 }
1421 1433
1422 if (needs_commit) 1434 if (needs_commit)
1423 client_->SetNeedsCommitOnImplThread(); 1435 client_->SetNeedsCommitOnImplThread();
1424 } 1436 }
1425 1437
1426 void LayerTreeHostImpl::SetExternalDrawConstraints( 1438 void LayerTreeHostImpl::SetExternalDrawConstraints(
1427 const gfx::Transform& transform,
1428 const gfx::Rect& viewport,
1429 const gfx::Rect& clip,
1430 const gfx::Rect& viewport_rect_for_tile_priority, 1439 const gfx::Rect& viewport_rect_for_tile_priority,
1431 const gfx::Transform& transform_for_tile_priority, 1440 const gfx::Transform& transform_for_tile_priority) {
1432 bool resourceless_software_draw) {
1433 gfx::Rect viewport_rect_for_tile_priority_in_view_space; 1441 gfx::Rect viewport_rect_for_tile_priority_in_view_space;
1434 if (!resourceless_software_draw) { 1442 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
1435 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); 1443 if (transform_for_tile_priority.GetInverse(&screen_to_view)) {
1436 if (transform_for_tile_priority.GetInverse(&screen_to_view)) { 1444 // Convert from screen space to view space.
1437 // Convert from screen space to view space. 1445 viewport_rect_for_tile_priority_in_view_space =
1438 viewport_rect_for_tile_priority_in_view_space = 1446 MathUtil::ProjectEnclosingClippedRect(screen_to_view,
1439 MathUtil::ProjectEnclosingClippedRect( 1447 viewport_rect_for_tile_priority);
1440 screen_to_view, viewport_rect_for_tile_priority);
1441 }
1442 } 1448 }
1443 1449
1444 const bool transform_changed = external_transform_ != transform;
1445 const bool viewport_changed = external_viewport_ != viewport;
1446 const bool clip_changed = external_clip_ != clip;
1447 const bool resourceless_software_draw_changed =
1448 resourceless_software_draw_ != resourceless_software_draw;
1449 const bool tile_priority_params_changed = 1450 const bool tile_priority_params_changed =
1450 viewport_rect_for_tile_priority_ != 1451 viewport_rect_for_tile_priority_ !=
1451 viewport_rect_for_tile_priority_in_view_space; 1452 viewport_rect_for_tile_priority_in_view_space;
1452 1453
1453 // UpdateDrawProperties does not depend on clip.
1454 if (transform_changed || viewport_changed ||
1455 resourceless_software_draw_changed || tile_priority_params_changed) {
1456 active_tree_->set_needs_update_draw_properties();
1457 }
1458
1459 external_transform_ = transform;
1460 external_viewport_ = viewport;
1461 external_clip_ = clip;
1462 viewport_rect_for_tile_priority_ = 1454 viewport_rect_for_tile_priority_ =
1463 viewport_rect_for_tile_priority_in_view_space; 1455 viewport_rect_for_tile_priority_in_view_space;
1464 resourceless_software_draw_ = resourceless_software_draw;
1465 1456
1466 // When not toggling resourceless software draw, need to set redraw for 1457 if (tile_priority_params_changed) {
1467 // all changes to draw parameters. Damage will be set externally by Android 1458 active_tree_->set_needs_update_draw_properties();
1468 // WebView for resourceless software draw toggles, so ignored here.
1469 const bool draw_params_changed = transform_changed || viewport_changed ||
1470 clip_changed || tile_priority_params_changed;
1471 if (!resourceless_software_draw_changed && draw_params_changed) {
1472 SetFullRootLayerDamage(); 1459 SetFullRootLayerDamage();
danakj 2015/11/24 21:17:31 Can you explain why this and SetNeedsRedraw() stil
boliu 2015/11/24 23:27:38 Essentially this replaces SetNeedsRedrawRect from
1473 SetNeedsRedraw(); 1460 SetNeedsRedraw();
1474 } 1461 }
1475
1476 if (resourceless_software_draw_changed) {
1477 client_->OnResourcelessSoftareDrawStateChanged(resourceless_software_draw);
1478 client_->OnCanDrawStateChanged(CanDraw());
1479 }
1480 } 1462 }
1481 1463
1482 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 1464 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
1483 if (damage_rect.IsEmpty()) 1465 if (damage_rect.IsEmpty())
1484 return; 1466 return;
1485 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 1467 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1486 client_->SetNeedsRedrawRectOnImplThread(damage_rect); 1468 client_->SetNeedsRedrawRectOnImplThread(damage_rect);
1487 } 1469 }
1488 1470
1489 void LayerTreeHostImpl::DidSwapBuffers() { 1471 void LayerTreeHostImpl::DidSwapBuffers() {
(...skipping 29 matching lines...) Expand all
1519 } 1501 }
1520 1502
1521 // If we're not visible, we likely released resources, so we want to 1503 // If we're not visible, we likely released resources, so we want to
1522 // aggressively flush here to make sure those DeleteTextures make it to the 1504 // aggressively flush here to make sure those DeleteTextures make it to the
1523 // GPU process to free up the memory. 1505 // GPU process to free up the memory.
1524 if (output_surface_->context_provider() && !visible_) { 1506 if (output_surface_->context_provider() && !visible_) {
1525 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM(); 1507 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1526 } 1508 }
1527 } 1509 }
1528 1510
1529 void LayerTreeHostImpl::OnDraw() { 1511 void LayerTreeHostImpl::OnDraw(const gfx::Transform& transform,
1530 client_->OnDrawForOutputSurface(); 1512 const gfx::Rect& viewport,
1513 const gfx::Rect& clip,
1514 bool resourceless_software_draw) {
1515 DCHECK(!resourceless_software_draw_);
1516 const bool transform_changed = external_transform_ != transform;
1517 const bool viewport_changed = external_viewport_ != viewport;
1518 const bool clip_changed = external_clip_ != clip;
1519
1520 external_transform_ = transform;
1521 external_viewport_ = viewport;
1522 external_clip_ = clip;
1523
1524 {
1525 base::AutoReset<bool> resourceless_software_draw_reset(
1526 &resourceless_software_draw_, resourceless_software_draw);
1527
1528 // For resourceless software draw, always set full damage to ensure they
1529 // always swap. Otherwise, need to set redraw for all changes to draw
danakj 2015/11/24 21:17:30 all changes => any changes
boliu 2015/11/24 23:27:38 Done.
1530 // parameters.
1531 const bool draw_params_changed =
1532 transform_changed || viewport_changed || clip_changed;
1533 if (resourceless_software_draw_ || draw_params_changed) {
1534 SetFullRootLayerDamage();
1535 SetNeedsRedraw();
1536 }
1537
1538 // UpdateDrawProperties does not depend on clip.
1539 if (transform_changed || viewport_changed || resourceless_software_draw_) {
1540 active_tree_->set_needs_update_draw_properties();
1541 }
1542
1543 if (resourceless_software_draw) {
1544 client_->OnCanDrawStateChanged(CanDraw());
1545 }
1546
1547 client_->OnDrawForOutputSurface(resourceless_software_draw_);
1548 }
1549
1550 if (resourceless_software_draw) {
1551 active_tree_->set_needs_update_draw_properties();
1552 client_->OnCanDrawStateChanged(CanDraw());
1553 // This draw may have reset all damage, which would lead to subsequent
1554 // incorrect hardware draw, so explicitly set damage for next hardware
1555 // draw as well.
1556 SetFullRootLayerDamage();
1557 }
1531 } 1558 }
1532 1559
1533 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { 1560 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() {
1534 client_->OnCanDrawStateChanged(CanDraw()); 1561 client_->OnCanDrawStateChanged(CanDraw());
1535 } 1562 }
1536 1563
1537 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { 1564 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const {
1538 CompositorFrameMetadata metadata; 1565 CompositorFrameMetadata metadata;
1539 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * 1566 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() *
1540 active_tree_->device_scale_factor(); 1567 active_tree_->device_scale_factor();
(...skipping 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after
3695 return task_runner_provider_->HasImplThread(); 3722 return task_runner_provider_->HasImplThread();
3696 } 3723 }
3697 3724
3698 bool LayerTreeHostImpl::CommitToActiveTree() const { 3725 bool LayerTreeHostImpl::CommitToActiveTree() const {
3699 // In single threaded mode we skip the pending tree and commit directly to the 3726 // In single threaded mode we skip the pending tree and commit directly to the
3700 // active tree. 3727 // active tree.
3701 return !task_runner_provider_->HasImplThread(); 3728 return !task_runner_provider_->HasImplThread();
3702 } 3729 }
3703 3730
3704 } // namespace cc 3731 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698