Upstream version 7.36.149.0
[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/picture_pile_impl.h"
14 #include "cc/resources/raster_mode.h"
15 #include "cc/resources/tile_priority.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
18
19 namespace cc {
20
21 class CC_EXPORT Tile : public RefCountedManaged<Tile> {
22  public:
23   enum TileRasterFlags {
24     USE_LCD_TEXT = 1 << 0,
25     USE_GPU_RASTERIZATION = 1 << 1
26   };
27
28   typedef uint64 Id;
29
30   Id id() const {
31     return id_;
32   }
33
34   PicturePileImpl* picture_pile() {
35     return picture_pile_.get();
36   }
37
38   const PicturePileImpl* picture_pile() const {
39     return picture_pile_.get();
40   }
41
42   const TilePriority& priority(WhichTree tree) const {
43     return priority_[tree];
44   }
45
46   TilePriority priority_for_tree_priority(TreePriority tree_priority) const {
47     switch (tree_priority) {
48       case SMOOTHNESS_TAKES_PRIORITY:
49         return priority_[ACTIVE_TREE];
50       case NEW_CONTENT_TAKES_PRIORITY:
51         return priority_[PENDING_TREE];
52       case SAME_PRIORITY_FOR_BOTH_TREES:
53         return combined_priority();
54     }
55     NOTREACHED();
56     return TilePriority();
57   }
58
59   TilePriority combined_priority() const {
60     return TilePriority(priority_[ACTIVE_TREE],
61                         priority_[PENDING_TREE]);
62   }
63
64   void SetPriority(WhichTree tree, const TilePriority& priority);
65
66   void MarkRequiredForActivation();
67
68   bool required_for_activation() const {
69     return priority_[PENDING_TREE].required_for_activation;
70   }
71
72   void set_can_use_lcd_text(bool can_use_lcd_text) {
73     if (can_use_lcd_text)
74       flags_ |= USE_LCD_TEXT;
75     else
76       flags_ &= ~USE_LCD_TEXT;
77   }
78
79   bool can_use_lcd_text() const {
80     return !!(flags_ & USE_LCD_TEXT);
81   }
82
83   void set_use_gpu_rasterization(bool use_gpu_rasterization) {
84     if (use_gpu_rasterization)
85       flags_ |= USE_GPU_RASTERIZATION;
86     else
87       flags_ &= ~USE_GPU_RASTERIZATION;
88   }
89
90   bool use_gpu_rasterization() const {
91     return !!(flags_ & USE_GPU_RASTERIZATION);
92   }
93
94   bool NeedsRasterForMode(RasterMode mode) const {
95     return !managed_state_.tile_versions[mode].IsReadyToDraw();
96   }
97
98   bool HasResources() const {
99     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
100       if (managed_state_.tile_versions[mode].has_resource())
101         return true;
102     }
103     return false;
104   }
105
106   scoped_ptr<base::Value> AsValue() const;
107
108   inline bool IsReadyToDraw() const {
109     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
110       if (managed_state_.tile_versions[mode].IsReadyToDraw())
111         return true;
112     }
113     return false;
114   }
115
116   const ManagedTileState::TileVersion& GetTileVersionForDrawing() const {
117     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
118       if (managed_state_.tile_versions[mode].IsReadyToDraw())
119         return managed_state_.tile_versions[mode];
120     }
121     return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE];
122   }
123
124   gfx::Rect opaque_rect() const { return opaque_rect_; }
125   bool has_text(RasterMode mode) const {
126     return managed_state_.tile_versions[mode].has_text_;
127   }
128
129   float contents_scale() const { return contents_scale_; }
130   gfx::Rect content_rect() const { return content_rect_; }
131
132   int layer_id() const { return layer_id_; }
133
134   int source_frame_number() const { return source_frame_number_; }
135
136   void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
137     DCHECK(pile->CanRaster(contents_scale_, content_rect_));
138     picture_pile_ = pile;
139   }
140
141   size_t GPUMemoryUsageInBytes() const;
142
143   gfx::Size size() const { return tile_size_.size(); }
144
145   RasterMode DetermineRasterModeForTree(WhichTree tree) const;
146   RasterMode DetermineOverallRasterMode() const;
147
148   // Functionality used in tests.
149   RasterMode GetRasterModeForTesting() const {
150     return managed_state().raster_mode;
151   }
152   ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) {
153     return managed_state_.tile_versions[mode];
154   }
155
156  private:
157   friend class TileManager;
158   friend class PrioritizedTileSet;
159   friend class FakeTileManager;
160   friend class BinComparator;
161   friend class FakePictureLayerImpl;
162
163   // Methods called by by tile manager.
164   Tile(TileManager* tile_manager,
165        PicturePileImpl* picture_pile,
166        const gfx::Size& tile_size,
167        const gfx::Rect& content_rect,
168        const gfx::Rect& opaque_rect,
169        float contents_scale,
170        int layer_id,
171        int source_frame_number,
172        int flags);
173   ~Tile();
174
175   ManagedTileState& managed_state() { return managed_state_; }
176   const ManagedTileState& managed_state() const { return managed_state_; }
177   RasterMode DetermineRasterModeForResolution(TileResolution resolution) const;
178
179   TileManager* tile_manager_;
180   scoped_refptr<PicturePileImpl> picture_pile_;
181   gfx::Rect tile_size_;
182   gfx::Rect content_rect_;
183   float contents_scale_;
184   gfx::Rect opaque_rect_;
185
186   TilePriority priority_[NUM_TREES];
187   ManagedTileState managed_state_;
188   int layer_id_;
189   int source_frame_number_;
190   int flags_;
191
192   Id id_;
193   static Id s_next_id_;
194
195   DISALLOW_COPY_AND_ASSIGN(Tile);
196 };
197
198 }  // namespace cc
199
200 #endif  // CC_RESOURCES_TILE_H_