OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/priority_calculator.h" | |
6 | |
7 #include "ui/gfx/rect.h" | |
8 | |
9 namespace cc { | |
10 | |
11 static const int kNothingPriorityCutoff = -3; | |
12 | |
13 static const int kMostHighPriority = -2; | |
14 | |
15 static const int kUIDrawsToRootSurfacePriority = -1; | |
16 static const int kVisibleDrawsToRootSurfacePriority = 0; | |
17 static const int kRenderSurfacesPriority = 1; | |
18 static const int kUIDoesNotDrawToRootSurfacePriority = 2; | |
19 static const int kVisibleDoesNotDrawToRootSurfacePriority = 3; | |
20 | |
21 static const int kVisibleOnlyPriorityCutoff = 4; | |
22 | |
23 // The lower digits are how far from being visible the texture is, | |
24 // in pixels. | |
25 static const int kNotVisibleBasePriority = 1000000; | |
26 static const int kNotVisibleLimitPriority = 1900000; | |
27 | |
28 // Arbitrarily define "nearby" to be 2000 pixels. A better estimate | |
29 // would be percent-of-viewport or percent-of-screen. | |
30 static const int kVisibleAndNearbyPriorityCutoff = | |
31 kNotVisibleBasePriority + 2000; | |
32 | |
33 // Small animated layers are treated as though they are 512 pixels | |
34 // from being visible. | |
35 static const int kSmallAnimatedLayerPriority = kNotVisibleBasePriority + 512; | |
36 | |
37 static const int kLingeringBasePriority = 2000000; | |
38 static const int kLingeringLimitPriority = 2900000; | |
39 | |
40 static const int kMostLowPriority = 3000000; | |
41 | |
42 static const int kEverythingPriorityCutoff = 3000001; | |
43 | |
44 // static | |
45 int PriorityCalculator::UIPriority(bool draws_to_root_surface) { | |
46 return draws_to_root_surface ? kUIDrawsToRootSurfacePriority | |
47 : kUIDoesNotDrawToRootSurfacePriority; | |
48 } | |
49 | |
50 // static | |
51 int PriorityCalculator::VisiblePriority(bool draws_to_root_surface) { | |
52 return draws_to_root_surface ? kVisibleDrawsToRootSurfacePriority | |
53 : kVisibleDoesNotDrawToRootSurfacePriority; | |
54 } | |
55 | |
56 // static | |
57 int PriorityCalculator::RenderSurfacePriority() { | |
58 return kRenderSurfacesPriority; | |
59 } | |
60 | |
61 // static | |
62 int PriorityCalculator::LingeringPriority(int previous_priority) { | |
63 // FIXME: We should remove this once we have priorities for all | |
64 // textures (we can't currently calculate distances for | |
65 // off-screen textures). | |
66 return std::min(kLingeringLimitPriority, | |
67 std::max(kLingeringBasePriority, previous_priority + 1)); | |
68 } | |
69 | |
70 namespace { | |
71 int ManhattanDistance(gfx::Rect a, gfx::Rect b) { | |
72 gfx::Rect c = gfx::UnionRects(a, b); | |
73 int x = std::max(0, c.width() - a.width() - b.width() + 1); | |
74 int y = std::max(0, c.height() - a.height() - b.height() + 1); | |
75 return (x + y); | |
76 } | |
77 } | |
78 | |
79 // static | |
80 int PriorityCalculator::PriorityFromDistance(gfx::Rect visible_rect, | |
81 gfx::Rect texture_rect, | |
82 bool draws_to_root_surface) { | |
83 int distance = ManhattanDistance(visible_rect, texture_rect); | |
84 if (!distance) | |
85 return VisiblePriority(draws_to_root_surface); | |
86 return std::min(kNotVisibleLimitPriority, kNotVisibleBasePriority + distance); | |
87 } | |
88 | |
89 // static | |
90 int PriorityCalculator::SmallAnimatedLayerMinPriority() { | |
91 return kSmallAnimatedLayerPriority; | |
92 } | |
93 | |
94 // static | |
95 int PriorityCalculator::HighestPriority() { | |
96 return kMostHighPriority; | |
97 } | |
98 | |
99 // static | |
100 int PriorityCalculator::LowestPriority() { | |
101 return kMostLowPriority; | |
102 } | |
103 | |
104 // static | |
105 int PriorityCalculator::AllowNothingCutoff() { | |
106 return kNothingPriorityCutoff; | |
107 } | |
108 | |
109 // static | |
110 int PriorityCalculator::AllowVisibleOnlyCutoff() { | |
111 return kVisibleOnlyPriorityCutoff; | |
112 } | |
113 | |
114 // static | |
115 int PriorityCalculator::AllowVisibleAndNearbyCutoff() { | |
116 return kVisibleAndNearbyPriorityCutoff; | |
117 } | |
118 | |
119 // static | |
120 int PriorityCalculator::AllowEverythingCutoff() { | |
121 return kEverythingPriorityCutoff; | |
122 } | |
123 | |
124 } // namespace cc | |
OLD | NEW |