diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-01 19:59:42 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-01 19:59:42 +0000 |
commit | 2cc0ec84815e5167b7ecbdae94a47033e95422e6 (patch) | |
tree | e4a66d4b83294f108acde9878cb5b2e6ec60ca7b /remoting/base | |
parent | a4ff9eaea74e058144eda4164fe4694e6e1b9c21 (diff) | |
download | chromium_src-2cc0ec84815e5167b7ecbdae94a47033e95422e6.zip chromium_src-2cc0ec84815e5167b7ecbdae94a47033e95422e6.tar.gz chromium_src-2cc0ec84815e5167b7ecbdae94a47033e95422e6.tar.bz2 |
Optimize mac capturer to copy memory only dirty rect.
This optimization shave a lot of memory copies when there are small changes on
the screen. On the computer I tested capturer nows run with 9ms when before was
20ms. This however increases capture time when more than half of the screen is
changing or the dirty rects overlap.
There are several further optimiations can be done:
1. Merge dirty rects so that they don't overlap.
2. Subtract current dirty rects from last dirty rects.
If the above two are implemented we can then shave copying in OpenGL. This
can be done by grouping rectangles and download them as a bulk, this can bring
capture time to be less than 5ms.
Overall this patch shaves 11ms, about 20% of latency on the mac host I uses.
BUG=91201
TEST=Mac capturer runs faster
Review URL: http://codereview.chromium.org/7540024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/util.cc | 23 | ||||
-rw-r--r-- | remoting/base/util.h | 8 |
2 files changed, 31 insertions, 0 deletions
diff --git a/remoting/base/util.cc b/remoting/base/util.cc index 788c602..2e7d7df 100644 --- a/remoting/base/util.cc +++ b/remoting/base/util.cc @@ -146,4 +146,27 @@ gfx::Rect ScaleRect(const gfx::Rect& rect, return scaled_rect; } +void CopyRect(const uint8* src_plane, + int src_plane_stride, + uint8* dest_plane, + int dest_plane_stride, + int bytes_per_pixel, + const gfx::Rect& rect) { + // Get the address of the starting point. + const int src_y_offset = src_plane_stride * rect.y(); + const int dest_y_offset = dest_plane_stride * rect.y(); + const int x_offset = bytes_per_pixel * rect.x(); + src_plane += src_y_offset + x_offset; + dest_plane += dest_y_offset + x_offset; + + // Copy pixels in the rectangle line by line. + const int bytes_per_line = bytes_per_pixel * rect.width(); + const int height = rect.height(); + for (int i = 0 ; i < height; ++i) { + memcpy(dest_plane, src_plane, bytes_per_line); + src_plane += src_plane_stride; + dest_plane += dest_plane_stride; + } +} + } // namespace remoting diff --git a/remoting/base/util.h b/remoting/base/util.h index 920bb89..bd0f95c 100644 --- a/remoting/base/util.h +++ b/remoting/base/util.h @@ -56,6 +56,14 @@ gfx::Rect ScaleRect(const gfx::Rect& rect, double horizontal_ratio, double vertical_ratio); +// Copy pixels in the rectangle from source to destination. +void CopyRect(const uint8* src_plane, + int src_plane_stride, + uint8* dest_plane, + int dest_plane_stride, + int bytes_per_pixel, + const gfx::Rect& rect); + } // namespace remoting #endif // REMOTING_BASE_UTIL_H_ |