1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/resources/priority_calculator.h"
9 #include "ui/gfx/geometry/rect.h"
13 static const int kNothingPriorityCutoff
= -3;
15 static const int kMostHighPriority
= -2;
17 static const int kUIDrawsToRootSurfacePriority
= -1;
18 static const int kVisibleDrawsToRootSurfacePriority
= 0;
19 static const int kRenderSurfacesPriority
= 1;
20 static const int kUIDoesNotDrawToRootSurfacePriority
= 2;
21 static const int kVisibleDoesNotDrawToRootSurfacePriority
= 3;
23 static const int kVisibleOnlyPriorityCutoff
= 4;
25 // The lower digits are how far from being visible the texture is,
27 static const int kNotVisibleBasePriority
= 1000000;
28 static const int kNotVisibleLimitPriority
= 1900000;
30 // Arbitrarily define "nearby" to be 2000 pixels. A better estimate
31 // would be percent-of-viewport or percent-of-screen.
32 static const int kVisibleAndNearbyPriorityCutoff
=
33 kNotVisibleBasePriority
+ 2000;
35 // Small animated layers are treated as though they are 512 pixels
36 // from being visible.
37 static const int kSmallAnimatedLayerPriority
= kNotVisibleBasePriority
+ 512;
39 static const int kLingeringBasePriority
= 2000000;
40 static const int kLingeringLimitPriority
= 2900000;
42 static const int kMostLowPriority
= 3000000;
44 static const int kEverythingPriorityCutoff
= 3000001;
47 int PriorityCalculator::UIPriority(bool draws_to_root_surface
) {
48 return draws_to_root_surface
? kUIDrawsToRootSurfacePriority
49 : kUIDoesNotDrawToRootSurfacePriority
;
53 int PriorityCalculator::VisiblePriority(bool draws_to_root_surface
) {
54 return draws_to_root_surface
? kVisibleDrawsToRootSurfacePriority
55 : kVisibleDoesNotDrawToRootSurfacePriority
;
59 int PriorityCalculator::RenderSurfacePriority() {
60 return kRenderSurfacesPriority
;
64 int PriorityCalculator::LingeringPriority(int previous_priority
) {
65 // TODO(reveman): We should remove this once we have priorities for all
66 // textures (we can't currently calculate distances for off-screen textures).
67 return std::min(kLingeringLimitPriority
,
68 std::max(kLingeringBasePriority
, previous_priority
+ 1));
72 int PriorityCalculator::PriorityFromDistance(const gfx::Rect
& visible_rect
,
73 const gfx::Rect
& texture_rect
,
74 bool draws_to_root_surface
) {
75 int distance
= visible_rect
.ManhattanInternalDistance(texture_rect
);
77 return VisiblePriority(draws_to_root_surface
);
78 return std::min(kNotVisibleLimitPriority
, kNotVisibleBasePriority
+ distance
);
82 int PriorityCalculator::SmallAnimatedLayerMinPriority() {
83 return kSmallAnimatedLayerPriority
;
87 int PriorityCalculator::HighestPriority() {
88 return kMostHighPriority
;
92 int PriorityCalculator::LowestPriority() {
93 return kMostLowPriority
;
97 int PriorityCalculator::AllowNothingCutoff() {
98 return kNothingPriorityCutoff
;
102 int PriorityCalculator::AllowVisibleOnlyCutoff() {
103 return kVisibleOnlyPriorityCutoff
;
107 int PriorityCalculator::AllowVisibleAndNearbyCutoff() {
108 return kVisibleAndNearbyPriorityCutoff
;
112 int PriorityCalculator::AllowEverythingCutoff() {
113 return kEverythingPriorityCutoff
;