Upstream version 6.35.121.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 combined_priority() const {
47     return TilePriority(priority_[ACTIVE_TREE],
48                         priority_[PENDING_TREE]);
49   }
50
51   void SetPriority(WhichTree tree, const TilePriority& priority);
52
53   void MarkRequiredForActivation();
54
55   bool required_for_activation() const {
56     return priority_[PENDING_TREE].required_for_activation;
57   }
58
59   void set_can_use_lcd_text(bool can_use_lcd_text) {
60     if (can_use_lcd_text)
61       flags_ |= USE_LCD_TEXT;
62     else
63       flags_ &= ~USE_LCD_TEXT;
64   }
65
66   bool can_use_lcd_text() const {
67     return !!(flags_ & USE_LCD_TEXT);
68   }
69
70   void set_use_gpu_rasterization(bool use_gpu_rasterization) {
71     if (use_gpu_rasterization)
72       flags_ |= USE_GPU_RASTERIZATION;
73     else
74       flags_ &= ~USE_GPU_RASTERIZATION;
75   }
76
77   bool use_gpu_rasterization() const {
78     return !!(flags_ & USE_GPU_RASTERIZATION);
79   }
80
81   bool NeedsRasterForMode(RasterMode mode) const {
82     return !managed_state_.tile_versions[mode].IsReadyToDraw();
83   }
84
85   bool HasResources() const {
86     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
87       if (managed_state_.tile_versions[mode].has_resource())
88         return true;
89     }
90     return false;
91   }
92
93   scoped_ptr<base::Value> AsValue() const;
94
95   inline bool IsReadyToDraw() const {
96     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
97       if (managed_state_.tile_versions[mode].IsReadyToDraw())
98         return true;
99     }
100     return false;
101   }
102
103   const ManagedTileState::TileVersion& GetTileVersionForDrawing() const {
104     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
105       if (managed_state_.tile_versions[mode].IsReadyToDraw())
106         return managed_state_.tile_versions[mode];
107     }
108     return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE];
109   }
110
111   gfx::Rect opaque_rect() const { return opaque_rect_; }
112   bool has_text(RasterMode mode) const {
113     return managed_state_.tile_versions[mode].has_text_;
114   }
115
116   float contents_scale() const { return contents_scale_; }
117   gfx::Rect content_rect() const { return content_rect_; }
118
119   int layer_id() const { return layer_id_; }
120
121   int source_frame_number() const { return source_frame_number_; }
122
123   void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
124     DCHECK(pile->CanRaster(contents_scale_, content_rect_));
125     picture_pile_ = pile;
126   }
127
128   size_t GPUMemoryUsageInBytes() const;
129
130   gfx::Size size() const { return tile_size_.size(); }
131
132   RasterMode DetermineRasterModeForTree(WhichTree tree) const;
133   RasterMode DetermineOverallRasterMode() const;
134
135   // Functionality used in tests.
136   RasterMode GetRasterModeForTesting() const {
137     return managed_state().raster_mode;
138   }
139   ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) {
140     return managed_state_.tile_versions[mode];
141   }
142
143  private:
144   friend class TileManager;
145   friend class PrioritizedTileSet;
146   friend class FakeTileManager;
147   friend class BinComparator;
148   friend class FakePictureLayerImpl;
149
150   // Methods called by by tile manager.
151   Tile(TileManager* tile_manager,
152        PicturePileImpl* picture_pile,
153        const gfx::Size& tile_size,
154        const gfx::Rect& content_rect,
155        const gfx::Rect& opaque_rect,
156        float contents_scale,
157        int layer_id,
158        int source_frame_number,
159        int flags);
160   ~Tile();
161
162   ManagedTileState& managed_state() { return managed_state_; }
163   const ManagedTileState& managed_state() const { return managed_state_; }
164   RasterMode DetermineRasterModeForResolution(TileResolution resolution) const;
165
166   TileManager* tile_manager_;
167   scoped_refptr<PicturePileImpl> picture_pile_;
168   gfx::Rect tile_size_;
169   gfx::Rect content_rect_;
170   float contents_scale_;
171   gfx::Rect opaque_rect_;
172
173   TilePriority priority_[NUM_TREES];
174   ManagedTileState managed_state_;
175   int layer_id_;
176   int source_frame_number_;
177   int flags_;
178
179   Id id_;
180   static Id s_next_id_;
181
182   DISALLOW_COPY_AND_ASSIGN(Tile);
183 };
184
185 }  // namespace cc
186
187 #endif  // CC_RESOURCES_TILE_H_