| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 #ifndef REMOTING_HOST_DIFFER_H_ | 5 #ifndef REMOTING_HOST_DIFFER_H_ |
| 6 #define REMOTING_HOST_DIFFER_H_ | 6 #define REMOTING_HOST_DIFFER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "remoting/base/types.h" | 12 #include "third_party/skia/include/core/SkRegion.h" |
| 13 #include "ui/gfx/rect.h" | |
| 14 | 13 |
| 15 namespace remoting { | 14 namespace remoting { |
| 16 | 15 |
| 17 typedef uint8 DiffInfo; | 16 typedef uint8 DiffInfo; |
| 18 | 17 |
| 19 // Size (in pixels) of each square block used for diffing. | 18 // Size (in pixels) of each square block used for diffing. |
| 20 // This must be a multiple of sizeof(uint64). | 19 // This must be a multiple of sizeof(uint64). |
| 21 static const int kBlockSize = 32; | 20 static const int kBlockSize = 32; |
| 22 | 21 |
| 22 // TODO: Simplify differ now that we are working with SkRegions. |
| 23 // diff_info_ should no longer be needed, as we can put our data directly into |
| 24 // the region that we are calculating. |
| 25 // http://crbug.com/92379 |
| 23 class Differ { | 26 class Differ { |
| 24 public: | 27 public: |
| 25 // Create a differ that operates on bitmaps with the specified width, height | 28 // Create a differ that operates on bitmaps with the specified width, height |
| 26 // and bytes_per_pixel. | 29 // and bytes_per_pixel. |
| 27 Differ(int width, int height, int bytes_per_pixel, int stride); | 30 Differ(int width, int height, int bytes_per_pixel, int stride); |
| 28 ~Differ(); | 31 ~Differ(); |
| 29 | 32 |
| 30 int width() { return width_; } | 33 int width() { return width_; } |
| 31 int height() { return height_; } | 34 int height() { return height_; } |
| 32 int bytes_per_pixel() { return bytes_per_pixel_; } | 35 int bytes_per_pixel() { return bytes_per_pixel_; } |
| 33 int bytes_per_row() { return bytes_per_row_; } | 36 int bytes_per_row() { return bytes_per_row_; } |
| 34 | 37 |
| 35 // Given the previous and current screen buffer, calculate the set of | 38 // Given the previous and current screen buffer, calculate the dirty region |
| 36 // rectangles that enclose all the changed pixels in the new screen. | 39 // that encloses all of the changed pixels in the new screen. |
| 37 void CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, | 40 void CalcDirtyRegion(const void* prev_buffer, const void* curr_buffer, |
| 38 InvalidRects* rects); | 41 SkRegion* region); |
| 42 |
| 43 private: |
| 44 // Allow tests to access our private parts. |
| 45 friend class DifferTest; |
| 39 | 46 |
| 40 // Identify all of the blocks that contain changed pixels. | 47 // Identify all of the blocks that contain changed pixels. |
| 41 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); | 48 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); |
| 42 | 49 |
| 43 // After the dirty blocks have been identified, this routine merges adjacent | 50 // After the dirty blocks have been identified, this routine merges adjacent |
| 44 // blocks into larger rectangular units. | 51 // blocks into a region. |
| 45 // The goal is to minimize the number of rects that cover the dirty blocks, | 52 // The goal is to minimize the region that covers the dirty blocks. |
| 46 // although it is not required to calc the absolute minimum of rects. | 53 void MergeBlocks(SkRegion* region); |
| 47 void MergeBlocks(InvalidRects* rects); | |
| 48 | |
| 49 // Allow tests to access our private parts. | |
| 50 friend class DifferTest; | |
| 51 | |
| 52 private: | |
| 53 | 54 |
| 54 // Check for diffs in upper-left portion of the block. The size of the portion | 55 // Check for diffs in upper-left portion of the block. The size of the portion |
| 55 // to check is specified by the |width| and |height| values. | 56 // to check is specified by the |width| and |height| values. |
| 56 // Note that if we force the capturer to always return images whose width and | 57 // Note that if we force the capturer to always return images whose width and |
| 57 // height are multiples of kBlockSize, then this will never be called. | 58 // height are multiples of kBlockSize, then this will never be called. |
| 58 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, | 59 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, |
| 59 int stride, int width, int height); | 60 int stride, int width, int height); |
| 60 | 61 |
| 61 // Dimensions of screen. | 62 // Dimensions of screen. |
| 62 int width_; | 63 int width_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 76 int diff_info_width_; | 77 int diff_info_width_; |
| 77 int diff_info_height_; | 78 int diff_info_height_; |
| 78 int diff_info_size_; | 79 int diff_info_size_; |
| 79 | 80 |
| 80 DISALLOW_COPY_AND_ASSIGN(Differ); | 81 DISALLOW_COPY_AND_ASSIGN(Differ); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 } // namespace remoting | 84 } // namespace remoting |
| 84 | 85 |
| 85 #endif // REMOTING_HOST_DIFFER_H_ | 86 #endif // REMOTING_HOST_DIFFER_H_ |
| OLD | NEW |