Home | History | Annotate | Download | only in resources
      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 base {
     14 namespace debug {
     15 class TracedValue;
     16 }
     17 }
     18 
     19 namespace cc {
     20 
     21 class CC_EXPORT PictureLayerTilingSet {
     22  public:
     23   enum TilingRangeType {
     24     HIGHER_THAN_HIGH_RES,
     25     HIGH_RES,
     26     BETWEEN_HIGH_AND_LOW_RES,
     27     LOW_RES,
     28     LOWER_THAN_LOW_RES
     29   };
     30   struct TilingRange {
     31     TilingRange(size_t start, size_t end) : start(start), end(end) {}
     32 
     33     size_t start;
     34     size_t end;
     35   };
     36 
     37   PictureLayerTilingSet(PictureLayerTilingClient* client,
     38                         const gfx::Size& layer_bounds);
     39   ~PictureLayerTilingSet();
     40 
     41   void SetClient(PictureLayerTilingClient* client);
     42   const PictureLayerTilingClient* client() const { return client_; }
     43 
     44   void RemoveTilesInRegion(const Region& region);
     45 
     46   // Make this set of tilings match the same set of content scales from |other|.
     47   // Delete any tilings that don't meet |minimum_contents_scale|.  Recreate
     48   // any tiles that intersect |layer_invalidation|.  Update the size of all
     49   // tilings to |new_layer_bounds|.
     50   // Returns true if we had at least one high res tiling synced.
     51   bool SyncTilings(const PictureLayerTilingSet& other,
     52                    const gfx::Size& new_layer_bounds,
     53                    const Region& layer_invalidation,
     54                    float minimum_contents_scale);
     55 
     56   gfx::Size layer_bounds() const { return layer_bounds_; }
     57 
     58   PictureLayerTiling* AddTiling(float contents_scale);
     59   size_t num_tilings() const { return tilings_.size(); }
     60   int NumHighResTilings() const;
     61   PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
     62   const PictureLayerTiling* tiling_at(size_t idx) const {
     63     return tilings_[idx];
     64   }
     65 
     66   PictureLayerTiling* TilingAtScale(float scale) const;
     67 
     68   // Remove all tilings.
     69   void RemoveAllTilings();
     70 
     71   // Remove one tiling.
     72   void Remove(PictureLayerTiling* tiling);
     73 
     74   // Remove all tiles; keep all tilings.
     75   void RemoveAllTiles();
     76 
     77   void DidBecomeActive();
     78   void DidBecomeRecycled();
     79 
     80   // For a given rect, iterates through tiles that can fill it.  If no
     81   // set of tiles with resources can fill the rect, then it will iterate
     82   // through null tiles with valid geometry_rect() until the rect is full.
     83   // If all tiles have resources, the union of all geometry_rects will
     84   // exactly fill rect with no overlap.
     85   class CC_EXPORT CoverageIterator {
     86    public:
     87     CoverageIterator(const PictureLayerTilingSet* set,
     88       float contents_scale,
     89       const gfx::Rect& content_rect,
     90       float ideal_contents_scale);
     91     ~CoverageIterator();
     92 
     93     // Visible rect (no borders), always in the space of rect,
     94     // regardless of the relative contents scale of the tiling.
     95     gfx::Rect geometry_rect() const;
     96     // Texture rect (in texels) for geometry_rect
     97     gfx::RectF texture_rect() const;
     98     // Texture size in texels
     99     gfx::Size texture_size() const;
    100 
    101     Tile* operator->() const;
    102     Tile* operator*() const;
    103 
    104     CoverageIterator& operator++();
    105     operator bool() const;
    106 
    107     PictureLayerTiling* CurrentTiling();
    108 
    109    private:
    110     int NextTiling() const;
    111 
    112     const PictureLayerTilingSet* set_;
    113     float contents_scale_;
    114     float ideal_contents_scale_;
    115     PictureLayerTiling::CoverageIterator tiling_iter_;
    116     int current_tiling_;
    117     int ideal_tiling_;
    118 
    119     Region current_region_;
    120     Region missing_region_;
    121     Region::Iterator region_iter_;
    122   };
    123 
    124   void AsValueInto(base::debug::TracedValue* array) const;
    125   size_t GPUMemoryUsageInBytes() const;
    126 
    127   TilingRange GetTilingRange(TilingRangeType type) const;
    128 
    129  private:
    130   PictureLayerTilingClient* client_;
    131   gfx::Size layer_bounds_;
    132   ScopedPtrVector<PictureLayerTiling> tilings_;
    133 
    134   friend class Iterator;
    135   DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
    136 };
    137 
    138 }  // namespace cc
    139 
    140 #endif  // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
    141