tile.h revision bb1529ce867d8845a77ec7cdf3e3003ef1771a40
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#ifndef CC_RESOURCES_TILE_H_
6#define CC_RESOURCES_TILE_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/memory/scoped_vector.h"
11#include "cc/resources/managed_tile_state.h"
12#include "cc/resources/raster_mode.h"
13#include "cc/resources/tile_priority.h"
14#include "ui/gfx/rect.h"
15#include "ui/gfx/size.h"
16
17namespace cc {
18
19class PicturePileImpl;
20
21class CC_EXPORT Tile : public base::RefCounted<Tile> {
22 public:
23  typedef uint64 Id;
24
25  Tile(TileManager* tile_manager,
26       PicturePileImpl* picture_pile,
27       gfx::Size tile_size,
28       gfx::Rect content_rect,
29       gfx::Rect opaque_rect,
30       float contents_scale,
31       int layer_id,
32       int source_frame_number,
33       bool can_use_lcd_text);
34
35  Id id() const {
36    return id_;
37  }
38
39  PicturePileImpl* picture_pile() {
40    return picture_pile_.get();
41  }
42
43  const PicturePileImpl* picture_pile() const {
44    return picture_pile_.get();
45  }
46
47  const TilePriority& priority(WhichTree tree) const {
48    return priority_[tree];
49  }
50
51  TilePriority combined_priority() const {
52    return TilePriority(priority_[ACTIVE_TREE],
53                        priority_[PENDING_TREE]);
54  }
55
56  void SetPriority(WhichTree tree, const TilePriority& priority) {
57    priority_[tree] = priority;
58  }
59
60  void mark_required_for_activation() {
61    priority_[PENDING_TREE].required_for_activation = true;
62  }
63
64  bool required_for_activation() const {
65    return priority_[PENDING_TREE].required_for_activation;
66  }
67
68  void set_can_use_lcd_text(bool can_use_lcd_text) {
69    can_use_lcd_text_ = can_use_lcd_text;
70  }
71
72  bool can_use_lcd_text() const {
73    return can_use_lcd_text_;
74  }
75
76  scoped_ptr<base::Value> AsValue() const;
77
78  bool IsReadyToDraw() const {
79    for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
80      if (managed_state_.tile_versions[mode].IsReadyToDraw())
81        return true;
82    }
83    return false;
84  }
85
86  const ManagedTileState::TileVersion& GetTileVersionForDrawing() const {
87    for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
88      if (managed_state_.tile_versions[mode].IsReadyToDraw())
89        return managed_state_.tile_versions[mode];
90    }
91    return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE];
92  }
93
94  gfx::Rect opaque_rect() const { return opaque_rect_; }
95  bool has_text(RasterMode mode) const {
96    return managed_state_.tile_versions[mode].has_text_;
97  }
98
99  float contents_scale() const { return contents_scale_; }
100  gfx::Rect content_rect() const { return content_rect_; }
101
102  int layer_id() const { return layer_id_; }
103
104  int source_frame_number() const { return source_frame_number_; }
105
106  void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
107    DCHECK(pile->CanRaster(contents_scale_, content_rect_));
108    picture_pile_ = pile;
109  }
110
111  size_t GPUMemoryUsageInBytes() const;
112
113  RasterMode GetRasterModeForTesting() const {
114    return managed_state().raster_mode;
115  }
116  ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) {
117    return managed_state_.tile_versions[mode];
118  }
119
120 private:
121  // Methods called by by tile manager.
122  friend class TileManager;
123  friend class PrioritizedTileSet;
124  friend class FakeTileManager;
125  friend class BinComparator;
126  ManagedTileState& managed_state() { return managed_state_; }
127  const ManagedTileState& managed_state() const { return managed_state_; }
128
129  inline size_t bytes_consumed_if_allocated() const {
130    return 4 * tile_size_.width() * tile_size_.height();
131  }
132
133  // Normal private methods.
134  friend class base::RefCounted<Tile>;
135  ~Tile();
136
137  TileManager* tile_manager_;
138  scoped_refptr<PicturePileImpl> picture_pile_;
139  gfx::Rect tile_size_;
140  gfx::Rect content_rect_;
141  float contents_scale_;
142  gfx::Rect opaque_rect_;
143
144  TilePriority priority_[NUM_BIN_PRIORITIES];
145  ManagedTileState managed_state_;
146  int layer_id_;
147  int source_frame_number_;
148  bool can_use_lcd_text_;
149
150  Id id_;
151  static Id s_next_id_;
152
153  DISALLOW_COPY_AND_ASSIGN(Tile);
154};
155
156}  // namespace cc
157
158#endif  // CC_RESOURCES_TILE_H_
159