b188df7d62f6f4b94b821f3ccffbd5346c6650d5
[platform/framework/web/crosswalk.git] / src / cc / resources / picture_pile_base.h
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 namespace debug {
22 class TracedValue;
23 }
24 class Value;
25 }
26
27 namespace cc {
28
29 class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
30  public:
31   PicturePileBase();
32   explicit PicturePileBase(const PicturePileBase* other);
33   PicturePileBase(const PicturePileBase* other, unsigned thread_index);
34
35   gfx::Size tiling_size() const { return tiling_.tiling_size(); }
36   void SetMinContentsScale(float min_contents_scale);
37
38   // If non-empty, all pictures tiles inside this rect are recorded. There may
39   // be recordings outside this rect, but everything inside the rect is
40   // recorded.
41   gfx::Rect recorded_viewport() const { return recorded_viewport_; }
42
43   int num_tiles_x() const { return tiling_.num_tiles_x(); }
44   int num_tiles_y() const { return tiling_.num_tiles_y(); }
45   gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); }
46   bool HasRecordingAt(int x, int y);
47   bool CanRaster(float contents_scale, const gfx::Rect& content_rect);
48
49   // If this pile contains any valid recordings. May have false positives.
50   bool HasRecordings() const { return has_any_recordings_; }
51
52   static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
53                                   SkTileGridFactory::TileGridInfo* info);
54
55   void SetTileGridSize(const gfx::Size& tile_grid_size);
56   TilingData& tiling() { return tiling_; }
57
58   void AsValueInto(base::debug::TracedValue* array) const;
59
60  protected:
61   class CC_EXPORT PictureInfo {
62    public:
63     enum {
64       INVALIDATION_FRAMES_TRACKED = 32
65     };
66
67     PictureInfo();
68     ~PictureInfo();
69
70     bool Invalidate(int frame_number);
71     bool NeedsRecording(int frame_number, int distance_to_visible);
72     PictureInfo CloneForThread(int thread_index) const;
73     void SetPicture(scoped_refptr<Picture> picture);
74     Picture* GetPicture() const;
75
76     float GetInvalidationFrequencyForTesting() const {
77       return GetInvalidationFrequency();
78     }
79
80    private:
81     void AdvanceInvalidationHistory(int frame_number);
82     float GetInvalidationFrequency() const;
83
84     int last_frame_number_;
85     scoped_refptr<Picture> picture_;
86     std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
87   };
88
89   typedef std::pair<int, int> PictureMapKey;
90   typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
91
92   virtual ~PicturePileBase();
93
94   int buffer_pixels() const { return tiling_.border_texels(); }
95   void Clear();
96
97   gfx::Rect PaddedRect(const PictureMapKey& key);
98   gfx::Rect PadRect(const gfx::Rect& rect);
99
100   // An internal CanRaster check that goes to the picture_map rather than
101   // using the recorded_viewport hint.
102   bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
103
104   // A picture pile is a tiled set of pictures. The picture map is a map of tile
105   // indices to picture infos.
106   PictureMap picture_map_;
107   TilingData tiling_;
108   gfx::Rect recorded_viewport_;
109   float min_contents_scale_;
110   SkTileGridFactory::TileGridInfo tile_grid_info_;
111   SkColor background_color_;
112   int slow_down_raster_scale_factor_for_debug_;
113   bool contents_opaque_;
114   bool contents_fill_bounds_completely_;
115   bool show_debug_picture_borders_;
116   bool clear_canvas_with_debug_color_;
117   // A hint about whether there are any recordings. This may be a false
118   // positive.
119   bool has_any_recordings_;
120
121  private:
122   void SetBufferPixels(int buffer_pixels);
123
124   friend class base::RefCounted<PicturePileBase>;
125   DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
126 };
127
128 }  // namespace cc
129
130 #endif  // CC_RESOURCES_PICTURE_PILE_BASE_H_