Sync: Avoid deadlock in SyncBackendRegistrar / ModelSafeWorker on sync backend shutdown.
[chromium-blink-merge.git] / cc / resources / priority_calculator.cc
blob2a0cd189da1e14cb8b348dc807ef3e02a286da54
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"
7 #include <algorithm>
9 #include "ui/gfx/rect.h"
11 namespace cc {
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,
26 // in pixels.
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;
46 // static
47 int PriorityCalculator::UIPriority(bool draws_to_root_surface) {
48 return draws_to_root_surface ? kUIDrawsToRootSurfacePriority
49 : kUIDoesNotDrawToRootSurfacePriority;
52 // static
53 int PriorityCalculator::VisiblePriority(bool draws_to_root_surface) {
54 return draws_to_root_surface ? kVisibleDrawsToRootSurfacePriority
55 : kVisibleDoesNotDrawToRootSurfacePriority;
58 // static
59 int PriorityCalculator::RenderSurfacePriority() {
60 return kRenderSurfacesPriority;
63 // static
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));
71 // static
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);
76 if (!distance)
77 return VisiblePriority(draws_to_root_surface);
78 return std::min(kNotVisibleLimitPriority, kNotVisibleBasePriority + distance);
81 // static
82 int PriorityCalculator::SmallAnimatedLayerMinPriority() {
83 return kSmallAnimatedLayerPriority;
86 // static
87 int PriorityCalculator::HighestPriority() {
88 return kMostHighPriority;
91 // static
92 int PriorityCalculator::LowestPriority() {
93 return kMostLowPriority;
96 // static
97 int PriorityCalculator::AllowNothingCutoff() {
98 return kNothingPriorityCutoff;
101 // static
102 int PriorityCalculator::AllowVisibleOnlyCutoff() {
103 return kVisibleOnlyPriorityCutoff;
106 // static
107 int PriorityCalculator::AllowVisibleAndNearbyCutoff() {
108 return kVisibleAndNearbyPriorityCutoff;
111 // static
112 int PriorityCalculator::AllowEverythingCutoff() {
113 return kEverythingPriorityCutoff;
116 } // namespace cc