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