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

Unified Diff: util.cc

Issue 6902072: wm: Update a lot of code to use structs from geometry.h. (Closed) Base URL: ssh://gitrw.chromium.org:9222/window_manager.git@master
Patch Set: move override-redirect stacking and visibility into Window Created 9 years, 8 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
« no previous file with comments | « util.h ('k') | util_test.cc » ('j') | window.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util.cc
diff --git a/util.cc b/util.cc
index 57bc05e21477c2f2ae112a690271c8bec790970a..efe669c321018e0e75d83ff330a1b0045e5ffde4 100644
--- a/util.cc
+++ b/util.cc
@@ -30,12 +30,9 @@ static int64_t current_time_ms_for_test = -1;
// GetMonotonicTimeMs().
static TimeTicks monotonic_time_for_test;
-ByteMap::ByteMap(int width, int height)
- : width_(width),
- height_(height) {
- CHECK(width > 0);
- CHECK(height > 0);
- bytes_ = new unsigned char[width * height];
+ByteMap::ByteMap(const Size& size) : size_(size) {
+ CHECK(!size_.empty());
+ bytes_ = new unsigned char[size_.area()];
Clear(0);
}
@@ -45,34 +42,34 @@ ByteMap::~ByteMap() {
}
void ByteMap::Copy(const ByteMap& other) {
- CHECK(width_ == other.width_);
- CHECK(height_ == other.height_);
- memcpy(bytes_, other.bytes_, width_ * height_);
+ CHECK(size_ == other.size_);
+ memcpy(bytes_, other.bytes_, size_.area());
}
void ByteMap::Clear(unsigned char value) {
- memset(bytes_, value, width_ * height_);
+ memset(bytes_, value, size_.width * size_.height);
}
-void ByteMap::SetRectangle(int rect_x, int rect_y,
- int rect_width, int rect_height,
- unsigned char value) {
- const int limit_x = min(rect_x + rect_width, width_);
- const int limit_y = min(rect_y + rect_height, height_);
- rect_x = max(rect_x, 0);
- rect_y = max(rect_y, 0);
+void ByteMap::SetRectangle(const Rect& rect, unsigned char value) {
+ if (rect.empty())
+ return;
+
+ const int limit_x = min(rect.x + rect.width, size_.width);
+ const int limit_y = min(rect.y + rect.height, size_.height);
+ const int capped_x = max(rect.x, 0);
+ const int capped_y = max(rect.y, 0);
- if (rect_x >= limit_x)
+ if (capped_x >= limit_x)
return;
- for (int y = rect_y; y < limit_y; ++y)
- memset(bytes_ + y * width_ + rect_x, value, limit_x - rect_x);
+ for (int y = capped_y; y < limit_y; ++y)
+ memset(bytes_ + y * size_.width + capped_x, value, limit_x - capped_x);
}
bool ByteMap::operator==(const ByteMap& other) {
- if (width_ != other.width_ || height_ != other.height_)
+ if (size_ != other.size_)
return false;
- return memcmp(bytes_, other.bytes_, width_ * height_) == 0;
+ return memcmp(bytes_, other.bytes_, size_.area()) == 0;
}
« no previous file with comments | « util.h ('k') | util_test.cc » ('j') | window.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698