Use WeakNSProtocol/WeakNSObject for WebControllerObserverBridge ivars.
[chromium-blink-merge.git] / cc / resources / tile.h
blob4d41ebff7844d0be6406f50daaa2b72555c5e825
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 #ifndef CC_RESOURCES_TILE_H_
6 #define CC_RESOURCES_TILE_H_
8 #include "base/memory/ref_counted.h"
9 #include "cc/resources/raster_source.h"
10 #include "cc/resources/tile_draw_info.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/size.h"
14 namespace cc {
16 class TileManager;
17 struct TilePriority;
19 class CC_EXPORT Tile {
20 public:
21 class CC_EXPORT Deleter {
22 public:
23 void operator()(Tile* tile) const;
26 enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0 };
28 typedef uint64 Id;
30 Id id() const {
31 return id_;
34 RasterSource* raster_source() { return raster_source_.get(); }
36 const RasterSource* raster_source() const { return raster_source_.get(); }
38 // TODO(vmpstr): Move this to the iterators.
39 bool required_for_activation() const { return required_for_activation_; }
40 void set_required_for_activation(bool is_required) {
41 required_for_activation_ = is_required;
43 bool required_for_draw() const { return required_for_draw_; }
44 void set_required_for_draw(bool is_required) {
45 required_for_draw_ = is_required;
48 bool use_picture_analysis() const {
49 return !!(flags_ & USE_PICTURE_ANALYSIS);
52 bool HasResource() const { return draw_info_.has_resource(); }
53 bool NeedsRaster() const {
54 return draw_info_.mode() == TileDrawInfo::OOM_MODE ||
55 !draw_info_.IsReadyToDraw();
58 void AsValueWithPriorityInto(const TilePriority& priority,
59 base::trace_event::TracedValue* dict) const;
61 inline bool IsReadyToDraw() const { return draw_info_.IsReadyToDraw(); }
63 const TileDrawInfo& draw_info() const { return draw_info_; }
65 TileDrawInfo& draw_info() { return draw_info_; }
67 float contents_scale() const { return contents_scale_; }
68 gfx::Rect content_rect() const { return content_rect_; }
70 int layer_id() const { return layer_id_; }
72 int source_frame_number() const { return source_frame_number_; }
74 void set_raster_source(RasterSource* raster_source) {
75 DCHECK(raster_source->CoversRect(content_rect_, contents_scale_))
76 << "Recording rect: "
77 << gfx::ScaleToEnclosingRect(content_rect_, 1.f / contents_scale_)
78 .ToString();
79 raster_source_ = raster_source;
82 size_t GPUMemoryUsageInBytes() const;
84 gfx::Size desired_texture_size() const { return desired_texture_size_; }
86 void set_tiling_index(int i, int j) {
87 tiling_i_index_ = i;
88 tiling_j_index_ = j;
90 int tiling_i_index() const { return tiling_i_index_; }
91 int tiling_j_index() const { return tiling_j_index_; }
93 private:
94 friend class TileManager;
95 friend class FakeTileManager;
96 friend class FakePictureLayerImpl;
98 // Methods called by by tile manager.
99 Tile(TileManager* tile_manager,
100 RasterSource* raster_source,
101 const gfx::Size& desired_texture_size,
102 const gfx::Rect& content_rect,
103 float contents_scale,
104 int layer_id,
105 int source_frame_number,
106 int flags);
107 ~Tile();
109 bool HasRasterTask() const { return !!raster_task_.get(); }
111 TileManager* tile_manager_;
112 scoped_refptr<RasterSource> raster_source_;
113 gfx::Size desired_texture_size_;
114 gfx::Rect content_rect_;
115 float contents_scale_;
117 TileDrawInfo draw_info_;
119 int layer_id_;
120 int source_frame_number_;
121 int flags_;
122 int tiling_i_index_;
123 int tiling_j_index_;
124 bool required_for_activation_ : 1;
125 bool required_for_draw_ : 1;
127 Id id_;
128 static Id s_next_id_;
130 unsigned scheduled_priority_;
132 scoped_refptr<RasterTask> raster_task_;
134 DISALLOW_COPY_AND_ASSIGN(Tile);
137 using ScopedTilePtr = scoped_ptr<Tile, Tile::Deleter>;
139 } // namespace cc
141 #endif // CC_RESOURCES_TILE_H_