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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « util.h ('k') | util_test.cc » ('j') | window.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "window_manager/util.h" 5 #include "window_manager/util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <ctime> 9 #include <ctime>
10 10
(...skipping 12 matching lines...) Expand all
23 namespace window_manager { 23 namespace window_manager {
24 24
25 // If non-negative, contains a hardcoded time to be returned by 25 // If non-negative, contains a hardcoded time to be returned by
26 // GetCurrentTimeSecs() and GetCurrentTimeMs(). 26 // GetCurrentTimeSecs() and GetCurrentTimeMs().
27 static int64_t current_time_ms_for_test = -1; 27 static int64_t current_time_ms_for_test = -1;
28 28
29 // If non-zero, contains a hardcoded time to be returned by 29 // If non-zero, contains a hardcoded time to be returned by
30 // GetMonotonicTimeMs(). 30 // GetMonotonicTimeMs().
31 static TimeTicks monotonic_time_for_test; 31 static TimeTicks monotonic_time_for_test;
32 32
33 ByteMap::ByteMap(int width, int height) 33 ByteMap::ByteMap(const Size& size) : size_(size) {
34 : width_(width), 34 CHECK(!size_.empty());
35 height_(height) { 35 bytes_ = new unsigned char[size_.area()];
36 CHECK(width > 0);
37 CHECK(height > 0);
38 bytes_ = new unsigned char[width * height];
39 Clear(0); 36 Clear(0);
40 } 37 }
41 38
42 ByteMap::~ByteMap() { 39 ByteMap::~ByteMap() {
43 delete[] bytes_; 40 delete[] bytes_;
44 bytes_ = NULL; 41 bytes_ = NULL;
45 } 42 }
46 43
47 void ByteMap::Copy(const ByteMap& other) { 44 void ByteMap::Copy(const ByteMap& other) {
48 CHECK(width_ == other.width_); 45 CHECK(size_ == other.size_);
49 CHECK(height_ == other.height_); 46 memcpy(bytes_, other.bytes_, size_.area());
50 memcpy(bytes_, other.bytes_, width_ * height_);
51 } 47 }
52 48
53 void ByteMap::Clear(unsigned char value) { 49 void ByteMap::Clear(unsigned char value) {
54 memset(bytes_, value, width_ * height_); 50 memset(bytes_, value, size_.width * size_.height);
55 } 51 }
56 52
57 void ByteMap::SetRectangle(int rect_x, int rect_y, 53 void ByteMap::SetRectangle(const Rect& rect, unsigned char value) {
58 int rect_width, int rect_height, 54 if (rect.empty())
59 unsigned char value) {
60 const int limit_x = min(rect_x + rect_width, width_);
61 const int limit_y = min(rect_y + rect_height, height_);
62 rect_x = max(rect_x, 0);
63 rect_y = max(rect_y, 0);
64
65 if (rect_x >= limit_x)
66 return; 55 return;
67 56
68 for (int y = rect_y; y < limit_y; ++y) 57 const int limit_x = min(rect.x + rect.width, size_.width);
69 memset(bytes_ + y * width_ + rect_x, value, limit_x - rect_x); 58 const int limit_y = min(rect.y + rect.height, size_.height);
59 const int capped_x = max(rect.x, 0);
60 const int capped_y = max(rect.y, 0);
61
62 if (capped_x >= limit_x)
63 return;
64
65 for (int y = capped_y; y < limit_y; ++y)
66 memset(bytes_ + y * size_.width + capped_x, value, limit_x - capped_x);
70 } 67 }
71 68
72 bool ByteMap::operator==(const ByteMap& other) { 69 bool ByteMap::operator==(const ByteMap& other) {
73 if (width_ != other.width_ || height_ != other.height_) 70 if (size_ != other.size_)
74 return false; 71 return false;
75 return memcmp(bytes_, other.bytes_, width_ * height_) == 0; 72 return memcmp(bytes_, other.bytes_, size_.area()) == 0;
76 } 73 }
77 74
78 75
79 namespace util { 76 namespace util {
80 77
81 string XidStr(unsigned long xid) { 78 string XidStr(unsigned long xid) {
82 return StringPrintf("0x%lx", xid); 79 return StringPrintf("0x%lx", xid);
83 } 80 }
84 81
85 string GetTimeAsString(time_t utime) { 82 string GetTimeAsString(time_t utime) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 154
158 command += " &"; 155 command += " &";
159 DLOG(INFO) << "Running command \"" << command << "\""; 156 DLOG(INFO) << "Running command \"" << command << "\"";
160 if (system(command.c_str()) < 0) 157 if (system(command.c_str()) < 0)
161 LOG(WARNING) << "Got error while running \"" << command << "\""; 158 LOG(WARNING) << "Got error while running \"" << command << "\"";
162 } 159 }
163 160
164 } // namespace util 161 } // namespace util
165 162
166 } // namespace window_manager 163 } // namespace window_manager
OLDNEW
« no previous file with comments | « util.h ('k') | util_test.cc » ('j') | window.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698