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/resources/priority_calculator.h" 6 7 #include <algorithm> 8 9 #include "ui/gfx/rect.h" 10 11 namespace cc { 12 13 static const int kNothingPriorityCutoff = -3; 14 15 static const int kMostHighPriority = -2; 16 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; 22 23 static const int kVisibleOnlyPriorityCutoff = 4; 24 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; 29 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; 34 35 // Small animated layers are treated as though they are 512 pixels 36 // from being visible. 37 static const int kSmallAnimatedLayerPriority = kNotVisibleBasePriority + 512; 38 39 static const int kLingeringBasePriority = 2000000; 40 static const int kLingeringLimitPriority = 2900000; 41 42 static const int kMostLowPriority = 3000000; 43 44 static const int kEverythingPriorityCutoff = 3000001; 45 46 // static 47 int PriorityCalculator::UIPriority(bool draws_to_root_surface) { 48 return draws_to_root_surface ? kUIDrawsToRootSurfacePriority 49 : kUIDoesNotDrawToRootSurfacePriority; 50 } 51 52 // static 53 int PriorityCalculator::VisiblePriority(bool draws_to_root_surface) { 54 return draws_to_root_surface ? kVisibleDrawsToRootSurfacePriority 55 : kVisibleDoesNotDrawToRootSurfacePriority; 56 } 57 58 // static 59 int PriorityCalculator::RenderSurfacePriority() { 60 return kRenderSurfacesPriority; 61 } 62 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)); 69 } 70 71 // static 72 int PriorityCalculator::PriorityFromDistance(gfx::Rect visible_rect, 73 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); 79 } 80 81 // static 82 int PriorityCalculator::SmallAnimatedLayerMinPriority() { 83 return kSmallAnimatedLayerPriority; 84 } 85 86 // static 87 int PriorityCalculator::HighestPriority() { 88 return kMostHighPriority; 89 } 90 91 // static 92 int PriorityCalculator::LowestPriority() { 93 return kMostLowPriority; 94 } 95 96 // static 97 int PriorityCalculator::AllowNothingCutoff() { 98 return kNothingPriorityCutoff; 99 } 100 101 // static 102 int PriorityCalculator::AllowVisibleOnlyCutoff() { 103 return kVisibleOnlyPriorityCutoff; 104 } 105 106 // static 107 int PriorityCalculator::AllowVisibleAndNearbyCutoff() { 108 return kVisibleAndNearbyPriorityCutoff; 109 } 110 111 // static 112 int PriorityCalculator::AllowEverythingCutoff() { 113 return kEverythingPriorityCutoff; 114 } 115 116 } // namespace cc 117