Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6095)

Unified Diff: cc/base/index_rect.h

Issue 2350563002: cc: Implement IndexRect for encapsulating tile indices. (Closed)
Patch Set: build break Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/base/index_rect.h
diff --git a/cc/base/index_rect.h b/cc/base/index_rect.h
new file mode 100644
index 0000000000000000000000000000000000000000..ccfc2031a1ee1396ff1cf322b512141353bc0913
--- /dev/null
+++ b/cc/base/index_rect.h
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
vmpstr 2016/09/19 18:01:11 What do you think about just using gfx::Rect inste
prashant.n 2016/09/20 02:04:58 Yes. This is almost same with following difference
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_BASE_INDEX_RECT_H_
+#define CC_BASE_INDEX_RECT_H_
+
+#include "base/logging.h"
+#include "cc/base/cc_export.h"
+
+namespace cc {
+
+class CC_EXPORT IndexRect {
vmpstr 2016/09/19 18:01:11 Add a comment about what this class is, please.
+ public:
+ constexpr IndexRect(int left, int right, int top, int bottom)
+ : left_(left), right_(right), top_(top), bottom_(bottom) {}
+
+ ~IndexRect() = default;
+
+ constexpr int left() const { return left_; }
+ constexpr int right() const { return right_; }
+ constexpr int top() const { return top_; }
+ constexpr int bottom() const { return bottom_; }
+
+ // Returns the number of indices from left to right, including both.
+ constexpr int width() const { return right_ - left_ + 1; }
+ // Returns the number of indices from top to bottom, including both.
+ constexpr int height() const { return bottom_ - top_ + 1; }
+
+ // Returns true if the index rect has valid indices.
+ constexpr bool is_valid() const { return left_ <= right_ && top_ <= bottom_; }
+
+ // Returns true if the index identified by index_x is valid column.
+ bool valid_column(int index_x) const {
+ return index_x >= left() && index_x <= right();
+ }
+ // Returns true if the index identified by index_y is a valid row.
+ bool valid_row(int index_y) const {
+ return index_y >= top() && index_y <= bottom();
+ }
+
+ // Clamp indices to the given IndexRect indices. For non-intersecting rects,
+ // it makes this index rect invalid.
+ void ClampTo(const IndexRect& other);
+
+ // Returns true if the given index identified by index_x and index_y falls
+ // inside this index rectangle, including edge indices.
+ bool Contains(int index_x, int index_y) const;
+
+ std::string ToString() const;
+
+ private:
+ int left_;
+ int right_;
+ int top_;
+ int bottom_;
+};
+
+inline bool operator==(const IndexRect& lhs, const IndexRect& rhs) {
+ return lhs.left() == rhs.left() && lhs.right() == rhs.right() &&
+ lhs.top() == rhs.top() && lhs.bottom() == rhs.bottom();
+}
+
+inline bool operator!=(const IndexRect& lhs, const IndexRect& rhs) {
+ return !(lhs == rhs);
+}
+
+} // namespace cc
+
+#endif // CC_BASE_INDEX_RECT_H_
« no previous file with comments | « cc/base/BUILD.gn ('k') | cc/base/index_rect.cc » ('j') | cc/base/tiling_data.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698