[Do not revert] Roll-back V8 to version 4.4.63.
[chromium-blink-merge.git] / cc / resources / layer_tiling_data.h
blob526da6faf1e19d4f78b2d1f01cf4ccea21287e69
1 // Copyright 2011 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_LAYER_TILING_DATA_H_
6 #define CC_RESOURCES_LAYER_TILING_DATA_H_
8 #include <utility>
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "cc/base/cc_export.h"
15 #include "cc/base/simple_enclosed_region.h"
16 #include "cc/base/tiling_data.h"
17 #include "ui/gfx/geometry/rect.h"
19 namespace cc {
21 class CC_EXPORT LayerTilingData {
22 public:
23 enum BorderTexelOption {
24 HAS_BORDER_TEXELS,
25 NO_BORDER_TEXELS
28 ~LayerTilingData();
30 static scoped_ptr<LayerTilingData> Create(const gfx::Size& tile_size,
31 BorderTexelOption option);
33 bool has_empty_bounds() const { return tiling_data_.has_empty_bounds(); }
34 int num_tiles_x() const { return tiling_data_.num_tiles_x(); }
35 int num_tiles_y() const { return tiling_data_.num_tiles_y(); }
36 gfx::Rect tile_bounds(int i, int j) const {
37 return tiling_data_.TileBounds(i, j);
39 gfx::Vector2d texture_offset(int x_index, int y_index) const {
40 return tiling_data_.TextureOffset(x_index, y_index);
43 // Change the tile size. This may invalidate all the existing tiles.
44 void SetTileSize(const gfx::Size& size);
45 gfx::Size tile_size() const;
46 // Change the border texel setting. This may invalidate all existing tiles.
47 void SetBorderTexelOption(BorderTexelOption option);
48 bool has_border_texels() const { return !!tiling_data_.border_texels(); }
50 bool is_empty() const { return has_empty_bounds() || !tiles().size(); }
52 const LayerTilingData& operator=(const LayerTilingData&);
54 class Tile {
55 public:
56 Tile() : i_(-1), j_(-1) {}
57 virtual ~Tile() {}
59 int i() const { return i_; }
60 int j() const { return j_; }
61 void move_to(int i, int j) {
62 i_ = i;
63 j_ = j;
66 private:
67 int i_;
68 int j_;
69 DISALLOW_COPY_AND_ASSIGN(Tile);
71 typedef std::pair<int, int> TileMapKey;
72 typedef base::ScopedPtrHashMap<TileMapKey, scoped_ptr<Tile>> TileMap;
74 void AddTile(scoped_ptr<Tile> tile, int i, int j);
75 scoped_ptr<Tile> TakeTile(int i, int j);
76 Tile* TileAt(int i, int j) const;
77 const TileMap& tiles() const { return tiles_; }
79 void SetTilingSize(const gfx::Size& tiling_size);
80 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); }
82 void ContentRectToTileIndices(const gfx::Rect& rect,
83 int* left,
84 int* top,
85 int* right,
86 int* bottom) const;
87 gfx::Rect TileRect(const Tile* tile) const;
89 void reset() { tiles_.clear(); }
91 protected:
92 LayerTilingData(const gfx::Size& tile_size, BorderTexelOption option);
94 TileMap tiles_;
95 TilingData tiling_data_;
97 DISALLOW_COPY(LayerTilingData);
100 } // namespace cc
102 #endif // CC_RESOURCES_LAYER_TILING_DATA_H_