blob: ea23df4e95b92c5faec9e2e261ed8cce8f9e80aa [file] [log] [blame]
[email protected]18134fc2012-11-08 22:42:341// 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
[email protected]ffaa2a632012-11-11 14:47:505#ifndef CC_TILE_PRIORITY_H_
6#define CC_TILE_PRIORITY_H_
[email protected]18134fc2012-11-08 22:42:347
[email protected]4cbadc882012-12-04 08:52:588#include <limits>
9
[email protected]18134fc2012-11-08 22:42:3410#include "base/memory/ref_counted.h"
[email protected]4f0a5002013-01-28 13:02:2711#include "base/memory/scoped_ptr.h"
[email protected]18134fc2012-11-08 22:42:3412#include "cc/picture_pile.h"
[email protected]131a0c22013-02-12 18:31:0813#include "ui/gfx/quad_f.h"
[email protected]18134fc2012-11-08 22:42:3414#include "ui/gfx/rect.h"
15#include "ui/gfx/size.h"
16
[email protected]4f0a5002013-01-28 13:02:2717namespace base {
18class Value;
19}
20
[email protected]18134fc2012-11-08 22:42:3421namespace cc {
22
[email protected]8947cbe2012-11-28 05:27:4323enum WhichTree {
24 // Note: these must be 0 and 1 because we index with them in various places,
25 // e.g. in Tile::priority_.
26 ACTIVE_TREE = 0,
[email protected]ee371e02012-12-16 20:13:4427 PENDING_TREE = 1,
28 NUM_TREES = 2
[email protected]4f0a5002013-01-28 13:02:2729 // Be sure to update WhichTreeAsValue when adding new fields.
[email protected]8947cbe2012-11-28 05:27:4330};
[email protected]4f0a5002013-01-28 13:02:2731scoped_ptr<base::Value> WhichTreeAsValue(
32 WhichTree tree);
[email protected]8947cbe2012-11-28 05:27:4333
[email protected]0f0609c2012-11-16 10:00:4734enum TileResolution {
35 LOW_RESOLUTION = 0 ,
36 HIGH_RESOLUTION = 1,
[email protected]63db9222013-01-29 22:13:4737 NON_IDEAL_RESOLUTION = 2,
[email protected]0f0609c2012-11-16 10:00:4738};
[email protected]131a0c22013-02-12 18:31:0839scoped_ptr<base::Value> TileResolutionAsValue(
40 TileResolution resolution);
[email protected]0f0609c2012-11-16 10:00:4741
[email protected]4cbadc882012-12-04 08:52:5842struct CC_EXPORT TilePriority {
[email protected]0f0609c2012-11-16 10:00:4743 TilePriority()
[email protected]63db9222013-01-29 22:13:4744 : is_live(false),
45 resolution(NON_IDEAL_RESOLUTION),
[email protected]91735ee2013-02-12 05:17:4346 time_to_visible_in_seconds(std::numeric_limits<float>::infinity()),
47 distance_to_visible_in_pixels(std::numeric_limits<float>::infinity()) {}
[email protected]76858dd382012-11-10 09:38:0748
[email protected]63db9222013-01-29 22:13:4749 TilePriority(
50 TileResolution resolution,
51 float time_to_visible_in_seconds,
52 float distance_to_visible_in_pixels)
53 : is_live(true),
54 resolution(resolution),
55 time_to_visible_in_seconds(time_to_visible_in_seconds),
56 distance_to_visible_in_pixels(distance_to_visible_in_pixels) {}
57
[email protected]0f0609c2012-11-16 10:00:4758 TilePriority(const TilePriority& active, const TilePriority& pending) {
[email protected]63db9222013-01-29 22:13:4759 if (!pending.is_live) {
60 if (!active.is_live) {
61 is_live = false;
62 return;
63 }
64 is_live = true;
65 resolution = active.resolution;
66 time_to_visible_in_seconds = active.time_to_visible_in_seconds;
67 distance_to_visible_in_pixels = active.distance_to_visible_in_pixels;
68 return;
69 } else if (!active.is_live) {
70 is_live = true;
71 resolution = pending.resolution;
72 time_to_visible_in_seconds = pending.time_to_visible_in_seconds;
73 distance_to_visible_in_pixels = pending.distance_to_visible_in_pixels;
74 return;
75 }
76
77 is_live = true;
[email protected]0f0609c2012-11-16 10:00:4778 if (active.resolution == HIGH_RESOLUTION ||
79 pending.resolution == HIGH_RESOLUTION)
80 resolution = HIGH_RESOLUTION;
81 else if (active.resolution == LOW_RESOLUTION ||
82 pending.resolution == LOW_RESOLUTION)
83 resolution = LOW_RESOLUTION;
84 else
85 resolution = NON_IDEAL_RESOLUTION;
[email protected]18134fc2012-11-08 22:42:3486
[email protected]0f0609c2012-11-16 10:00:4787 time_to_visible_in_seconds =
88 std::min(active.time_to_visible_in_seconds,
89 pending.time_to_visible_in_seconds);
[email protected]0f0609c2012-11-16 10:00:4790 distance_to_visible_in_pixels =
91 std::min(active.distance_to_visible_in_pixels,
92 pending.distance_to_visible_in_pixels);
93 }
[email protected]131a0c22013-02-12 18:31:0894 void set_current_screen_quad(const gfx::QuadF& q) { current_screen_quad = q; }
95
96 scoped_ptr<base::Value> AsValue() const;
[email protected]18134fc2012-11-08 22:42:3497
[email protected]a3bca5f32013-02-02 01:51:5898 static const float kMaxDistanceInContentSpace;
[email protected]8b981a92013-02-20 02:47:3999 static const int64 kNumTilesToCoverWithInflatedViewportRectForPrioritization;
[email protected]4cbadc882012-12-04 08:52:58100
[email protected]a3bca5f32013-02-02 01:51:58101 static inline float manhattanDistance(const gfx::RectF& a, const gfx::RectF& b) {
102 // Compute the union explicitly.
103 gfx::RectF c = gfx::RectF(
104 std::min(a.x(), b.x()),
105 std::min(a.y(), b.y()),
106 std::max(a.right(), b.right()) - std::min(a.x(), b.x()),
107 std::max(a.bottom(), b.bottom()) - std::min(a.y(), b.y()));
108
109 // Rects touching the edge of the screen should not be considered visible.
110 // So we add 1 pixel here to avoid that situation.
111 float x = std::max(0.0f, c.width() - a.width() - b.width() + 1.0f);
112 float y = std::max(0.0f, c.height() - a.height() - b.height() + 1.0f);
113 return (x + y);
114 }
[email protected]4cbadc882012-12-04 08:52:58115
116 // Calculate the time for the |current_bounds| to intersect with the
117 // |target_bounds| given its previous location and time delta.
118 // This function should work for both scaling and scrolling case.
[email protected]a3bca5f32013-02-02 01:51:58119 static float TimeForBoundsToIntersect(const gfx::RectF& previous_bounds,
120 const gfx::RectF& current_bounds,
121 float time_delta,
122 const gfx::RectF& target_bounds);
[email protected]4cbadc882012-12-04 08:52:58123
[email protected]63db9222013-01-29 22:13:47124 // If a tile is not live, then all other fields are invalid.
125 bool is_live;
[email protected]0f0609c2012-11-16 10:00:47126 TileResolution resolution;
127 float time_to_visible_in_seconds;
[email protected]0f0609c2012-11-16 10:00:47128 float distance_to_visible_in_pixels;
[email protected]131a0c22013-02-12 18:31:08129
130private:
131 gfx::QuadF current_screen_quad;
[email protected]18134fc2012-11-08 22:42:34132};
133
[email protected]76858dd382012-11-10 09:38:07134enum TileMemoryLimitPolicy {
135 // Nothing.
136 ALLOW_NOTHING,
137
[email protected]0f0609c2012-11-16 10:00:47138 // You might be made visible, but you're not being interacted with.
139 ALLOW_ABSOLUTE_MINIMUM, // Tall.
[email protected]76858dd382012-11-10 09:38:07140
[email protected]0f0609c2012-11-16 10:00:47141 // You're being interacted with, but we're low on memory.
142 ALLOW_PREPAINT_ONLY, // Grande.
[email protected]76858dd382012-11-10 09:38:07143
[email protected]0f0609c2012-11-16 10:00:47144 // You're the only thing in town. Go crazy.
145 ALLOW_ANYTHING, // Venti.
[email protected]4f0a5002013-01-28 13:02:27146
147 // Be sure to update TreePriorityAsValue when adding new fields.
[email protected]76858dd382012-11-10 09:38:07148};
[email protected]4f0a5002013-01-28 13:02:27149scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue(
150 TileMemoryLimitPolicy policy);
[email protected]76858dd382012-11-10 09:38:07151
[email protected]362f1e8b2013-01-21 16:54:30152enum TreePriority {
153 SAME_PRIORITY_FOR_BOTH_TREES,
154 SMOOTHNESS_TAKES_PRIORITY,
155 NEW_CONTENT_TAKES_PRIORITY
[email protected]4f0a5002013-01-28 13:02:27156
157 // Be sure to update TreePriorityAsValue when adding new fields.
[email protected]362f1e8b2013-01-21 16:54:30158};
[email protected]4f0a5002013-01-28 13:02:27159scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio);
[email protected]362f1e8b2013-01-21 16:54:30160
[email protected]76858dd382012-11-10 09:38:07161class GlobalStateThatImpactsTilePriority {
[email protected]ffaa2a632012-11-11 14:47:50162 public:
[email protected]76858dd382012-11-10 09:38:07163 GlobalStateThatImpactsTilePriority()
164 : memory_limit_policy(ALLOW_NOTHING)
165 , memory_limit_in_bytes(0)
[email protected]362f1e8b2013-01-21 16:54:30166 , tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {
[email protected]76858dd382012-11-10 09:38:07167 }
168
169 TileMemoryLimitPolicy memory_limit_policy;
170
171 size_t memory_limit_in_bytes;
172
[email protected]362f1e8b2013-01-21 16:54:30173 TreePriority tree_priority;
[email protected]4f0a5002013-01-28 13:02:27174
175 scoped_ptr<base::Value> AsValue() const;
[email protected]18134fc2012-11-08 22:42:34176};
177
178} // namespace cc
[email protected]ffaa2a632012-11-11 14:47:50179
180#endif // CC_TILE_PRIORITY_H_