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_PICTURE_LAYER_TILING_SET_H_ 6 #define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_ 7 8 #include "cc/base/region.h" 9 #include "cc/base/scoped_ptr_vector.h" 10 #include "cc/resources/picture_layer_tiling.h" 11 #include "ui/gfx/size.h" 12 13 namespace cc { 14 15 class CC_EXPORT PictureLayerTilingSet { 16 public: 17 PictureLayerTilingSet(PictureLayerTilingClient* client, 18 gfx::Size layer_bounds); 19 ~PictureLayerTilingSet(); 20 21 void SetClient(PictureLayerTilingClient* client); 22 const PictureLayerTilingClient* client() const { return client_; } 23 24 // Make this set of tilings match the same set of content scales from |other|. 25 // Delete any tilings that don't meet |minimum_contents_scale|. Recreate 26 // any tiles that intersect |layer_invalidation|. Update the size of all 27 // tilings to |new_layer_bounds|. 28 void SyncTilings( 29 const PictureLayerTilingSet& other, 30 gfx::Size new_layer_bounds, 31 const Region& layer_invalidation, 32 float minimum_contents_scale); 33 34 gfx::Size layer_bounds() const { return layer_bounds_; } 35 36 void SetCanUseLCDText(bool can_use_lcd_text); 37 38 PictureLayerTiling* AddTiling(float contents_scale); 39 size_t num_tilings() const { return tilings_.size(); } 40 PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; } 41 const PictureLayerTiling* tiling_at(size_t idx) const { 42 return tilings_[idx]; 43 } 44 45 PictureLayerTiling* TilingAtScale(float scale) const; 46 47 // Remove all tilings. 48 void RemoveAllTilings(); 49 50 // Remove one tiling. 51 void Remove(PictureLayerTiling* tiling); 52 53 // Remove all tiles; keep all tilings. 54 void RemoveAllTiles(); 55 56 void UpdateTilePriorities( 57 WhichTree tree, 58 gfx::Size device_viewport, 59 gfx::Rect viewport_in_content_space, 60 gfx::Rect visible_content_rect, 61 gfx::Size last_layer_bounds, 62 gfx::Size current_layer_bounds, 63 float last_layer_contents_scale, 64 float current_layer_contents_scale, 65 const gfx::Transform& last_screen_transform, 66 const gfx::Transform& current_screen_transform, 67 double current_frame_time_in_seconds, 68 size_t max_tiles_for_interest_area); 69 70 void DidBecomeActive(); 71 72 // For a given rect, iterates through tiles that can fill it. If no 73 // set of tiles with resources can fill the rect, then it will iterate 74 // through null tiles with valid geometry_rect() until the rect is full. 75 // If all tiles have resources, the union of all geometry_rects will 76 // exactly fill rect with no overlap. 77 class CC_EXPORT CoverageIterator { 78 public: 79 CoverageIterator(const PictureLayerTilingSet* set, 80 float contents_scale, 81 gfx::Rect content_rect, 82 float ideal_contents_scale); 83 ~CoverageIterator(); 84 85 // Visible rect (no borders), always in the space of rect, 86 // regardless of the relative contents scale of the tiling. 87 gfx::Rect geometry_rect() const; 88 // Texture rect (in texels) for geometry_rect 89 gfx::RectF texture_rect() const; 90 // Texture size in texels 91 gfx::Size texture_size() const; 92 93 Tile* operator->() const; 94 Tile* operator*() const; 95 96 CoverageIterator& operator++(); 97 operator bool() const; 98 99 PictureLayerTiling* CurrentTiling(); 100 101 private: 102 int NextTiling() const; 103 104 const PictureLayerTilingSet* set_; 105 float contents_scale_; 106 float ideal_contents_scale_; 107 PictureLayerTiling::CoverageIterator tiling_iter_; 108 int current_tiling_; 109 int ideal_tiling_; 110 111 Region current_region_; 112 Region missing_region_; 113 Region::Iterator region_iter_; 114 }; 115 116 scoped_ptr<base::Value> AsValue() const; 117 size_t GPUMemoryUsageInBytes() const; 118 119 private: 120 PictureLayerTilingClient* client_; 121 gfx::Size layer_bounds_; 122 ScopedPtrVector<PictureLayerTiling> tilings_; 123 124 friend class Iterator; 125 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet); 126 }; 127 128 } // namespace cc 129 130 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_ 131