blob: 7e03c927a2302821c5264e57bedcc14989510098 [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]4cbadc882012-12-04 08:52:5899
[email protected]a3bca5f32013-02-02 01:51:58100 static inline float manhattanDistance(const gfx::RectF& a, const gfx::RectF& b) {
101 // Compute the union explicitly.
102 gfx::RectF c = gfx::RectF(
103 std::min(a.x(), b.x()),
104 std::min(a.y(), b.y()),
105 std::max(a.right(), b.right()) - std::min(a.x(), b.x()),
106 std::max(a.bottom(), b.bottom()) - std::min(a.y(), b.y()));
107
108 // Rects touching the edge of the screen should not be considered visible.
109 // So we add 1 pixel here to avoid that situation.
110 float x = std::max(0.0f, c.width() - a.width() - b.width() + 1.0f);
111 float y = std::max(0.0f, c.height() - a.height() - b.height() + 1.0f);
112 return (x + y);
113 }
[email protected]4cbadc882012-12-04 08:52:58114
115 // Calculate the time for the |current_bounds| to intersect with the
116 // |target_bounds| given its previous location and time delta.
117 // This function should work for both scaling and scrolling case.
[email protected]a3bca5f32013-02-02 01:51:58118 static float TimeForBoundsToIntersect(const gfx::RectF& previous_bounds,
119 const gfx::RectF& current_bounds,
120 float time_delta,
121 const gfx::RectF& target_bounds);
[email protected]4cbadc882012-12-04 08:52:58122
[email protected]63db9222013-01-29 22:13:47123 // If a tile is not live, then all other fields are invalid.
124 bool is_live;
[email protected]0f0609c2012-11-16 10:00:47125 TileResolution resolution;
126 float time_to_visible_in_seconds;
[email protected]0f0609c2012-11-16 10:00:47127 float distance_to_visible_in_pixels;
[email protected]131a0c22013-02-12 18:31:08128
129private:
130 gfx::QuadF current_screen_quad;
[email protected]18134fc2012-11-08 22:42:34131};
132
[email protected]76858dd382012-11-10 09:38:07133enum TileMemoryLimitPolicy {
134 // Nothing.
135 ALLOW_NOTHING,
136
[email protected]0f0609c2012-11-16 10:00:47137 // You might be made visible, but you're not being interacted with.
138 ALLOW_ABSOLUTE_MINIMUM, // Tall.
[email protected]76858dd382012-11-10 09:38:07139
[email protected]0f0609c2012-11-16 10:00:47140 // You're being interacted with, but we're low on memory.
141 ALLOW_PREPAINT_ONLY, // Grande.
[email protected]76858dd382012-11-10 09:38:07142
[email protected]0f0609c2012-11-16 10:00:47143 // You're the only thing in town. Go crazy.
144 ALLOW_ANYTHING, // Venti.
[email protected]4f0a5002013-01-28 13:02:27145
146 // Be sure to update TreePriorityAsValue when adding new fields.
[email protected]76858dd382012-11-10 09:38:07147};
[email protected]4f0a5002013-01-28 13:02:27148scoped_ptr<base::Value> TileMemoryLimitPolicyAsValue(
149 TileMemoryLimitPolicy policy);
[email protected]76858dd382012-11-10 09:38:07150
[email protected]362f1e8b2013-01-21 16:54:30151enum TreePriority {
152 SAME_PRIORITY_FOR_BOTH_TREES,
153 SMOOTHNESS_TAKES_PRIORITY,
154 NEW_CONTENT_TAKES_PRIORITY
[email protected]4f0a5002013-01-28 13:02:27155
156 // Be sure to update TreePriorityAsValue when adding new fields.
[email protected]362f1e8b2013-01-21 16:54:30157};
[email protected]4f0a5002013-01-28 13:02:27158scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio);
[email protected]362f1e8b2013-01-21 16:54:30159
[email protected]76858dd382012-11-10 09:38:07160class GlobalStateThatImpactsTilePriority {
[email protected]ffaa2a632012-11-11 14:47:50161 public:
[email protected]76858dd382012-11-10 09:38:07162 GlobalStateThatImpactsTilePriority()
163 : memory_limit_policy(ALLOW_NOTHING)
164 , memory_limit_in_bytes(0)
[email protected]362f1e8b2013-01-21 16:54:30165 , tree_priority(SAME_PRIORITY_FOR_BOTH_TREES) {
[email protected]76858dd382012-11-10 09:38:07166 }
167
168 TileMemoryLimitPolicy memory_limit_policy;
169
170 size_t memory_limit_in_bytes;
171
[email protected]362f1e8b2013-01-21 16:54:30172 TreePriority tree_priority;
[email protected]4f0a5002013-01-28 13:02:27173
174 scoped_ptr<base::Value> AsValue() const;
[email protected]18134fc2012-11-08 22:42:34175};
176
177} // namespace cc
[email protected]ffaa2a632012-11-11 14:47:50178
179#endif // CC_TILE_PRIORITY_H_