picture_pile_base.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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 <list> 9#include <utility> 10 11#include "base/containers/hash_tables.h" 12#include "base/memory/ref_counted.h" 13#include "cc/base/cc_export.h" 14#include "cc/base/region.h" 15#include "cc/base/tiling_data.h" 16#include "cc/resources/picture.h" 17#include "ui/gfx/size.h" 18 19namespace base { 20class Value; 21} 22 23namespace cc { 24 25class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> { 26 public: 27 PicturePileBase(); 28 explicit PicturePileBase(const PicturePileBase* other); 29 PicturePileBase(const PicturePileBase* other, unsigned thread_index); 30 31 void Resize(gfx::Size size); 32 gfx::Size size() const { return tiling_.total_size(); } 33 void SetMinContentsScale(float min_contents_scale); 34 35 void UpdateRecordedRegion(); 36 const Region& recorded_region() const { return recorded_region_; } 37 38 int num_tiles_x() const { return tiling_.num_tiles_x(); } 39 int num_tiles_y() const { return tiling_.num_tiles_y(); } 40 gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); } 41 bool HasRecordingAt(int x, int y); 42 bool CanRaster(float contents_scale, gfx::Rect content_rect); 43 44 void SetTileGridSize(gfx::Size tile_grid_size); 45 TilingData& tiling() { return tiling_; } 46 47 scoped_ptr<base::Value> AsValue() const; 48 49 protected: 50 struct CC_EXPORT PictureInfo { 51 PictureInfo(); 52 ~PictureInfo(); 53 54 bool Invalidate(); 55 PictureInfo CloneForThread(int thread_index) const; 56 57 scoped_refptr<Picture> picture; 58 }; 59 60 typedef std::pair<int, int> PictureMapKey; 61 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap; 62 63 virtual ~PicturePileBase(); 64 65 int num_raster_threads() { return num_raster_threads_; } 66 int buffer_pixels() const { return tiling_.border_texels(); } 67 void Clear(); 68 69 gfx::Rect PaddedRect(const PictureMapKey& key); 70 71 // A picture pile is a tiled set of pictures. The picture map is a map of tile 72 // indices to picture infos. 73 PictureMap picture_map_; 74 TilingData tiling_; 75 Region recorded_region_; 76 float min_contents_scale_; 77 SkTileGridPicture::TileGridInfo tile_grid_info_; 78 SkColor background_color_; 79 bool contents_opaque_; 80 int slow_down_raster_scale_factor_for_debug_; 81 bool show_debug_picture_borders_; 82 int num_raster_threads_; 83 84 private: 85 void SetBufferPixels(int buffer_pixels); 86 87 friend class base::RefCounted<PicturePileBase>; 88 DISALLOW_COPY_AND_ASSIGN(PicturePileBase); 89}; 90 91} // namespace cc 92 93#endif // CC_RESOURCES_PICTURE_PILE_BASE_H_ 94