• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_PICTURE_PILE_BASE_H_
6 #define CC_RESOURCES_PICTURE_PILE_BASE_H_
7 
8 #include <bitset>
9 #include <list>
10 #include <utility>
11 
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/ref_counted.h"
14 #include "cc/base/cc_export.h"
15 #include "cc/base/region.h"
16 #include "cc/base/tiling_data.h"
17 #include "cc/resources/picture.h"
18 #include "ui/gfx/size.h"
19 
20 namespace base {
21 class Value;
22 }
23 
24 namespace cc {
25 
26 class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
27  public:
28   PicturePileBase();
29   explicit PicturePileBase(const PicturePileBase* other);
30   PicturePileBase(const PicturePileBase* other, unsigned thread_index);
31 
32   void Resize(gfx::Size size);
size()33   gfx::Size size() const { return tiling_.total_size(); }
34   void SetMinContentsScale(float min_contents_scale);
35 
num_tiles_x()36   int num_tiles_x() const { return tiling_.num_tiles_x(); }
num_tiles_y()37   int num_tiles_y() const { return tiling_.num_tiles_y(); }
tile_bounds(int x,int y)38   gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); }
39   bool HasRecordingAt(int x, int y);
40   bool CanRaster(float contents_scale, gfx::Rect content_rect);
41 
42   // If this pile contains any valid recordings. May have false positives.
HasRecordings()43   bool HasRecordings() const { return has_any_recordings_; }
44 
45 
46   static void ComputeTileGridInfo(gfx::Size tile_grid_size,
47                                   SkTileGridPicture::TileGridInfo* info);
48 
49   void SetTileGridSize(gfx::Size tile_grid_size);
tiling()50   TilingData& tiling() { return tiling_; }
51 
52   scoped_ptr<base::Value> AsValue() const;
53 
54  protected:
55   class CC_EXPORT PictureInfo {
56    public:
57     enum {
58       INVALIDATION_FRAMES_TRACKED = 32
59     };
60 
61     PictureInfo();
62     ~PictureInfo();
63 
64     bool Invalidate(int frame_number);
65     bool NeedsRecording(int frame_number, int distance_to_visible);
66     PictureInfo CloneForThread(int thread_index) const;
67     void SetPicture(scoped_refptr<Picture> picture);
68     Picture* GetPicture() const;
69 
GetInvalidationFrequencyForTesting()70     float GetInvalidationFrequencyForTesting() const {
71       return GetInvalidationFrequency();
72     }
73 
74    private:
75     void AdvanceInvalidationHistory(int frame_number);
76     float GetInvalidationFrequency() const;
77 
78     int last_frame_number_;
79     scoped_refptr<Picture> picture_;
80     std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
81   };
82 
83   typedef std::pair<int, int> PictureMapKey;
84   typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
85 
86   virtual ~PicturePileBase();
87 
num_raster_threads()88   int num_raster_threads() { return num_raster_threads_; }
buffer_pixels()89   int buffer_pixels() const { return tiling_.border_texels(); }
90   void Clear();
91 
92   gfx::Rect PaddedRect(const PictureMapKey& key);
93   gfx::Rect PadRect(gfx::Rect rect);
94 
95   // An internal CanRaster check that goes to the picture_map rather than
96   // using the recorded_viewport hint.
97   bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
98 
99   // A picture pile is a tiled set of pictures. The picture map is a map of tile
100   // indices to picture infos.
101   PictureMap picture_map_;
102   TilingData tiling_;
103   // If non-empty, all pictures tiles inside this rect are recorded.
104   gfx::Rect recorded_viewport_;
105   float min_contents_scale_;
106   SkTileGridPicture::TileGridInfo tile_grid_info_;
107   SkColor background_color_;
108   int slow_down_raster_scale_factor_for_debug_;
109   bool contents_opaque_;
110   bool show_debug_picture_borders_;
111   bool clear_canvas_with_debug_color_;
112   int num_raster_threads_;
113   // A hint about whether there are any recordings. This may be a false
114   // positive.
115   bool has_any_recordings_;
116 
117  private:
118   void SetBufferPixels(int buffer_pixels);
119 
120   friend class base::RefCounted<PicturePileBase>;
121   DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
122 };
123 
124 }  // namespace cc
125 
126 #endif  // CC_RESOURCES_PICTURE_PILE_BASE_H_
127