Reject XMLHTTPRequests Without HTTP Status Success
[chromium-blink-merge.git] / cc / resources / picture_pile_base.h
blobbe9955e3fd0f916c29d4449f602807b2a9b6cd85
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.
5 #ifndef CC_RESOURCES_PICTURE_PILE_BASE_H_
6 #define CC_RESOURCES_PICTURE_PILE_BASE_H_
8 #include <bitset>
9 #include <list>
10 #include <utility>
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"
20 namespace base {
21 class Value;
24 namespace cc {
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);
32 void Resize(const gfx::Size& size);
33 gfx::Size size() const { return tiling_.total_size(); }
34 void SetMinContentsScale(float min_contents_scale);
36 int num_tiles_x() const { return tiling_.num_tiles_x(); }
37 int num_tiles_y() const { return tiling_.num_tiles_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, const gfx::Rect& content_rect);
42 // If this pile contains any valid recordings. May have false positives.
43 bool HasRecordings() const { return has_any_recordings_; }
45 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
46 SkTileGridPicture::TileGridInfo* info);
48 void SetTileGridSize(const gfx::Size& tile_grid_size);
49 TilingData& tiling() { return tiling_; }
51 scoped_ptr<base::Value> AsValue() const;
53 protected:
54 class CC_EXPORT PictureInfo {
55 public:
56 enum {
57 INVALIDATION_FRAMES_TRACKED = 32
60 PictureInfo();
61 ~PictureInfo();
63 bool Invalidate(int frame_number);
64 bool NeedsRecording(int frame_number, int distance_to_visible);
65 PictureInfo CloneForThread(int thread_index) const;
66 void SetPicture(scoped_refptr<Picture> picture);
67 Picture* GetPicture() const;
69 float GetInvalidationFrequencyForTesting() const {
70 return GetInvalidationFrequency();
73 private:
74 void AdvanceInvalidationHistory(int frame_number);
75 float GetInvalidationFrequency() const;
77 int last_frame_number_;
78 scoped_refptr<Picture> picture_;
79 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
82 typedef std::pair<int, int> PictureMapKey;
83 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
85 virtual ~PicturePileBase();
87 int buffer_pixels() const { return tiling_.border_texels(); }
88 void Clear();
90 gfx::Rect PaddedRect(const PictureMapKey& key);
91 gfx::Rect PadRect(const gfx::Rect& rect);
93 // An internal CanRaster check that goes to the picture_map rather than
94 // using the recorded_viewport hint.
95 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
97 // A picture pile is a tiled set of pictures. The picture map is a map of tile
98 // indices to picture infos.
99 PictureMap picture_map_;
100 TilingData tiling_;
101 // If non-empty, all pictures tiles inside this rect are recorded.
102 gfx::Rect recorded_viewport_;
103 float min_contents_scale_;
104 SkTileGridPicture::TileGridInfo tile_grid_info_;
105 SkColor background_color_;
106 int slow_down_raster_scale_factor_for_debug_;
107 bool contents_opaque_;
108 bool contents_fill_bounds_completely_;
109 bool show_debug_picture_borders_;
110 bool clear_canvas_with_debug_color_;
111 // A hint about whether there are any recordings. This may be a false
112 // positive.
113 bool has_any_recordings_;
115 private:
116 void SetBufferPixels(int buffer_pixels);
118 friend class base::RefCounted<PicturePileBase>;
119 DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
122 } // namespace cc
124 #endif // CC_RESOURCES_PICTURE_PILE_BASE_H_