• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   enum TileRasterFlags {
25     USE_LCD_TEXT = 1 << 0,
26     USE_GPU_RASTERIZATION = 1 << 1
27   };
28 
29   typedef uint64 Id;
30 
id()31   Id id() const {
32     return id_;
33   }
34 
picture_pile()35   PicturePileImpl* picture_pile() {
36     return picture_pile_.get();
37   }
38 
picture_pile()39   const PicturePileImpl* picture_pile() const {
40     return picture_pile_.get();
41   }
42 
priority(WhichTree tree)43   const TilePriority& priority(WhichTree tree) const {
44     return priority_[tree];
45   }
46 
combined_priority()47   TilePriority combined_priority() const {
48     return TilePriority(priority_[ACTIVE_TREE],
49                         priority_[PENDING_TREE]);
50   }
51 
52   void SetPriority(WhichTree tree, const TilePriority& priority);
53 
54   void MarkRequiredForActivation();
55 
required_for_activation()56   bool required_for_activation() const {
57     return priority_[PENDING_TREE].required_for_activation;
58   }
59 
set_can_use_lcd_text(bool can_use_lcd_text)60   void set_can_use_lcd_text(bool can_use_lcd_text) {
61     if (can_use_lcd_text)
62       flags_ |= USE_LCD_TEXT;
63     else
64       flags_ &= ~USE_LCD_TEXT;
65   }
66 
can_use_lcd_text()67   bool can_use_lcd_text() const {
68     return !!(flags_ & USE_LCD_TEXT);
69   }
70 
set_use_gpu_rasterization(bool use_gpu_rasterization)71   void set_use_gpu_rasterization(bool use_gpu_rasterization) {
72     if (use_gpu_rasterization)
73       flags_ |= USE_GPU_RASTERIZATION;
74     else
75       flags_ &= ~USE_GPU_RASTERIZATION;
76   }
77 
use_gpu_rasterization()78   bool use_gpu_rasterization() const {
79     return !!(flags_ & USE_GPU_RASTERIZATION);
80   }
81 
82   scoped_ptr<base::Value> AsValue() const;
83 
IsReadyToDraw()84   inline bool IsReadyToDraw() const {
85     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
86       if (managed_state_.tile_versions[mode].IsReadyToDraw())
87         return true;
88     }
89     return false;
90   }
91 
GetTileVersionForDrawing()92   const ManagedTileState::TileVersion& GetTileVersionForDrawing() const {
93     for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
94       if (managed_state_.tile_versions[mode].IsReadyToDraw())
95         return managed_state_.tile_versions[mode];
96     }
97     return managed_state_.tile_versions[HIGH_QUALITY_RASTER_MODE];
98   }
99 
opaque_rect()100   gfx::Rect opaque_rect() const { return opaque_rect_; }
has_text(RasterMode mode)101   bool has_text(RasterMode mode) const {
102     return managed_state_.tile_versions[mode].has_text_;
103   }
104 
contents_scale()105   float contents_scale() const { return contents_scale_; }
content_rect()106   gfx::Rect content_rect() const { return content_rect_; }
107 
layer_id()108   int layer_id() const { return layer_id_; }
109 
source_frame_number()110   int source_frame_number() const { return source_frame_number_; }
111 
set_picture_pile(scoped_refptr<PicturePileImpl> pile)112   void set_picture_pile(scoped_refptr<PicturePileImpl> pile) {
113     DCHECK(pile->CanRaster(contents_scale_, content_rect_));
114     picture_pile_ = pile;
115   }
116 
117   size_t GPUMemoryUsageInBytes() const;
118 
GetRasterModeForTesting()119   RasterMode GetRasterModeForTesting() const {
120     return managed_state().raster_mode;
121   }
GetTileVersionForTesting(RasterMode mode)122   ManagedTileState::TileVersion& GetTileVersionForTesting(RasterMode mode) {
123     return managed_state_.tile_versions[mode];
124   }
125 
size()126   gfx::Size size() const { return tile_size_.size(); }
127 
128  private:
129   friend class TileManager;
130   friend class PrioritizedTileSet;
131   friend class FakeTileManager;
132   friend class BinComparator;
133   friend class FakePictureLayerImpl;
134 
135   // Methods called by by tile manager.
136   Tile(TileManager* tile_manager,
137        PicturePileImpl* picture_pile,
138        gfx::Size tile_size,
139        gfx::Rect content_rect,
140        gfx::Rect opaque_rect,
141        float contents_scale,
142        int layer_id,
143        int source_frame_number,
144        int flags);
145   ~Tile();
146 
managed_state()147   ManagedTileState& managed_state() { return managed_state_; }
managed_state()148   const ManagedTileState& managed_state() const { return managed_state_; }
149 
150   TileManager* tile_manager_;
151   scoped_refptr<PicturePileImpl> picture_pile_;
152   gfx::Rect tile_size_;
153   gfx::Rect content_rect_;
154   float contents_scale_;
155   gfx::Rect opaque_rect_;
156 
157   TilePriority priority_[NUM_TREES];
158   ManagedTileState managed_state_;
159   int layer_id_;
160   int source_frame_number_;
161   int flags_;
162 
163   Id id_;
164   static Id s_next_id_;
165 
166   DISALLOW_COPY_AND_ASSIGN(Tile);
167 };
168 
169 }  // namespace cc
170 
171 #endif  // CC_RESOURCES_TILE_H_
172