IndexedDB: fsync after transactions.
[chromium-blink-merge.git] / cc / base / tiling_data.h
blob96e6ae080384bb1472f2ecc56d09ef6348b76f07
1 // Copyright 2010 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_BASE_TILING_DATA_H_
6 #define CC_BASE_TILING_DATA_H_
8 #include <utility>
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "cc/base/cc_export.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
16 namespace gfx {
17 class Vector2d;
20 namespace cc {
22 class CC_EXPORT TilingData {
23 public:
24 TilingData();
25 TilingData(
26 gfx::Size max_texture_size,
27 gfx::Size total_size,
28 bool has_border_texels);
29 TilingData(
30 gfx::Size max_texture_size,
31 gfx::Size total_size,
32 int border_texels);
34 gfx::Size total_size() const { return total_size_; }
35 void SetTotalSize(const gfx::Size total_size);
37 gfx::Size max_texture_size() const { return max_texture_size_; }
38 void SetMaxTextureSize(gfx::Size max_texture_size);
40 int border_texels() const { return border_texels_; }
41 void SetHasBorderTexels(bool has_border_texels);
42 void SetBorderTexels(int border_texels);
44 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; }
45 int num_tiles_x() const { return num_tiles_x_; }
46 int num_tiles_y() const { return num_tiles_y_; }
47 // Return the tile index whose non-border texels include src_position.
48 int TileXIndexFromSrcCoord(int src_position) const;
49 int TileYIndexFromSrcCoord(int src_position) const;
50 // Return the lowest tile index whose border texels include src_position.
51 int FirstBorderTileXIndexFromSrcCoord(int src_position) const;
52 int FirstBorderTileYIndexFromSrcCoord(int src_position) const;
53 // Return the highest tile index whose border texels include src_position.
54 int LastBorderTileXIndexFromSrcCoord(int src_position) const;
55 int LastBorderTileYIndexFromSrcCoord(int src_position) const;
57 gfx::Rect TileBounds(int i, int j) const;
58 gfx::Rect TileBoundsWithBorder(int i, int j) const;
59 int TilePositionX(int x_index) const;
60 int TilePositionY(int y_index) const;
61 int TileSizeX(int x_index) const;
62 int TileSizeY(int y_index) const;
64 // Difference between TileBound's and TileBoundWithBorder's origin().
65 gfx::Vector2d TextureOffset(int x_index, int y_index) const;
67 class CC_EXPORT BaseIterator {
68 public:
69 operator bool() const { return index_x_ != -1 && index_y_ != -1; }
71 int index_x() const { return index_x_; }
72 int index_y() const { return index_y_; }
73 std::pair<int, int> index() const {
74 return std::make_pair(index_x_, index_y_);
77 protected:
78 explicit BaseIterator(const TilingData* tiling_data);
79 void done() {
80 index_x_ = -1;
81 index_y_ = -1;
84 const TilingData* tiling_data_;
85 int index_x_;
86 int index_y_;
89 // Iterate through all indices whose bounds + border intersect with |rect|.
90 class CC_EXPORT Iterator : public BaseIterator {
91 public:
92 Iterator(const TilingData* tiling_data, const gfx::Rect& tiling_rect);
93 Iterator& operator++();
95 private:
96 int left_;
97 int right_;
98 int bottom_;
101 // Iterate through all indices whose bounds + border intersect with
102 // |consider| but which also do not intersect with |ignore|.
103 class CC_EXPORT DifferenceIterator : public BaseIterator {
104 public:
105 DifferenceIterator(
106 const TilingData* tiling_data,
107 const gfx::Rect& consider_rect,
108 const gfx::Rect& ignore_rect);
109 DifferenceIterator& operator++();
111 private:
112 bool in_ignore_rect() const {
113 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ &&
114 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_;
117 int consider_left_;
118 int consider_top_;
119 int consider_right_;
120 int consider_bottom_;
121 int ignore_left_;
122 int ignore_top_;
123 int ignore_right_;
124 int ignore_bottom_;
127 private:
128 void AssertTile(int i, int j) const {
129 DCHECK_GE(i, 0);
130 DCHECK_LT(i, num_tiles_x_);
131 DCHECK_GE(j, 0);
132 DCHECK_LT(j, num_tiles_y_);
135 void RecomputeNumTiles();
137 gfx::Size max_texture_size_;
138 gfx::Size total_size_;
139 int border_texels_;
141 // These are computed values.
142 int num_tiles_x_;
143 int num_tiles_y_;
146 } // namespace cc
148 #endif // CC_BASE_TILING_DATA_H_