Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / cc / priority_calculator.cc
bloba780f7f660c43d58549d60c7ffe0f27fd043bcf3
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/priority_calculator.h"
7 #include "ui/gfx/rect.h"
9 namespace cc {
11 static const int nothingPriorityCutoff = -3;
13 static const int mostHighPriority = -2;
15 static const int uiDrawsToRootSurfacePriority = -1;
16 static const int visibleDrawsToRootSurfacePriority = 0;
17 static const int renderSurfacesPriority = 1;
18 static const int uiDoesNotDrawToRootSurfacePriority = 2;
19 static const int visibleDoesNotDrawToRootSurfacePriority = 3;
21 static const int visibleOnlyPriorityCutoff = 4;
23 // The lower digits are how far from being visible the texture is,
24 // in pixels.
25 static const int notVisibleBasePriority = 1000000;
26 static const int notVisibleLimitPriority = 1900000;
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 visibleAndNearbyPriorityCutoff = notVisibleBasePriority + 2000;
32 // Small animated layers are treated as though they are 512 pixels
33 // from being visible.
34 static const int smallAnimatedLayerPriority = notVisibleBasePriority + 512;
36 static const int lingeringBasePriority = 2000000;
37 static const int lingeringLimitPriority = 2900000;
39 static const int mostLowPriority = 3000000;
41 static const int everythingPriorityCutoff = 3000001;
43 // static
44 int PriorityCalculator::uiPriority(bool drawsToRootSurface)
46 return drawsToRootSurface ? uiDrawsToRootSurfacePriority : uiDoesNotDrawToRootSurfacePriority;
49 // static
50 int PriorityCalculator::visiblePriority(bool drawsToRootSurface)
52 return drawsToRootSurface ? visibleDrawsToRootSurfacePriority : visibleDoesNotDrawToRootSurfacePriority;
55 // static
56 int PriorityCalculator::renderSurfacePriority()
58 return renderSurfacesPriority;
61 // static
62 int PriorityCalculator::lingeringPriority(int previousPriority)
64 // FIXME: We should remove this once we have priorities for all
65 // textures (we can't currently calculate distances for
66 // off-screen textures).
67 return std::min(lingeringLimitPriority,
68 std::max(lingeringBasePriority, previousPriority + 1));
71 namespace {
72 int manhattanDistance(const gfx::Rect& a, const gfx::Rect& b)
74 gfx::Rect c = gfx::UnionRects(a, b);
75 int x = std::max(0, c.width() - a.width() - b.width() + 1);
76 int y = std::max(0, c.height() - a.height() - b.height() + 1);
77 return (x + y);
81 // static
82 int PriorityCalculator::priorityFromDistance(const gfx::Rect& visibleRect, const gfx::Rect& textureRect, bool drawsToRootSurface)
84 int distance = manhattanDistance(visibleRect, textureRect);
85 if (!distance)
86 return visiblePriority(drawsToRootSurface);
87 return std::min(notVisibleLimitPriority, notVisibleBasePriority + distance);
90 // static
91 int PriorityCalculator::smallAnimatedLayerMinPriority()
93 return smallAnimatedLayerPriority;
96 // static
97 int PriorityCalculator::highestPriority()
99 return mostHighPriority;
102 // static
103 int PriorityCalculator::lowestPriority()
105 return mostLowPriority;
108 // static
109 int PriorityCalculator::allowNothingCutoff()
111 return nothingPriorityCutoff;
114 // static
115 int PriorityCalculator::allowVisibleOnlyCutoff()
117 return visibleOnlyPriorityCutoff;
120 // static
121 int PriorityCalculator::allowVisibleAndNearbyCutoff()
123 return visibleAndNearbyPriorityCutoff;
126 // static
127 int PriorityCalculator::allowEverythingCutoff()
129 return everythingPriorityCutoff;
132 } // namespace cc