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

Side by Side Diff: media/video/capture/screen/screen_capturer_helper.cc

Issue 12047101: Move screen capturers from remoting/capturer to media/video/capturer/screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "remoting/capturer/video_frame_capturer_helper.h" 5 #include "media/video/capture/screen/screen_capturer_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 11
12 namespace remoting { 12 namespace media {
13 13
14 VideoFrameCapturerHelper::VideoFrameCapturerHelper() : 14 ScreenCapturerHelper::ScreenCapturerHelper() :
15 size_most_recent_(SkISize::Make(0, 0)), 15 size_most_recent_(SkISize::Make(0, 0)),
16 log_grid_size_(0) { 16 log_grid_size_(0) {
17 } 17 }
18 18
19 VideoFrameCapturerHelper::~VideoFrameCapturerHelper() { 19 ScreenCapturerHelper::~ScreenCapturerHelper() {
20 } 20 }
21 21
22 void VideoFrameCapturerHelper::ClearInvalidRegion() { 22 void ScreenCapturerHelper::ClearInvalidRegion() {
23 base::AutoLock auto_invalid_region_lock(invalid_region_lock_); 23 base::AutoLock auto_invalid_region_lock(invalid_region_lock_);
24 invalid_region_.setEmpty(); 24 invalid_region_.setEmpty();
25 } 25 }
26 26
27 void VideoFrameCapturerHelper::InvalidateRegion( 27 void ScreenCapturerHelper::InvalidateRegion(
28 const SkRegion& invalid_region) { 28 const SkRegion& invalid_region) {
29 base::AutoLock auto_invalid_region_lock(invalid_region_lock_); 29 base::AutoLock auto_invalid_region_lock(invalid_region_lock_);
30 invalid_region_.op(invalid_region, SkRegion::kUnion_Op); 30 invalid_region_.op(invalid_region, SkRegion::kUnion_Op);
31 } 31 }
32 32
33 void VideoFrameCapturerHelper::InvalidateScreen(const SkISize& size) { 33 void ScreenCapturerHelper::InvalidateScreen(const SkISize& size) {
34 base::AutoLock auto_invalid_region_lock(invalid_region_lock_); 34 base::AutoLock auto_invalid_region_lock(invalid_region_lock_);
35 invalid_region_.op(SkIRect::MakeWH(size.width(), size.height()), 35 invalid_region_.op(SkIRect::MakeWH(size.width(), size.height()),
36 SkRegion::kUnion_Op); 36 SkRegion::kUnion_Op);
37 } 37 }
38 38
39 void VideoFrameCapturerHelper::InvalidateFullScreen() { 39 void ScreenCapturerHelper::InvalidateFullScreen() {
40 if (!size_most_recent_.isZero()) 40 if (!size_most_recent_.isZero())
41 InvalidateScreen(size_most_recent_); 41 InvalidateScreen(size_most_recent_);
42 } 42 }
43 43
44 void VideoFrameCapturerHelper::SwapInvalidRegion(SkRegion* invalid_region) { 44 void ScreenCapturerHelper::SwapInvalidRegion(SkRegion* invalid_region) {
45 { 45 {
46 base::AutoLock auto_invalid_region_lock(invalid_region_lock_); 46 base::AutoLock auto_invalid_region_lock(invalid_region_lock_);
47 invalid_region->swap(invalid_region_); 47 invalid_region->swap(invalid_region_);
48 } 48 }
49 if (log_grid_size_ > 0) { 49 if (log_grid_size_ > 0) {
50 scoped_ptr<SkRegion> expanded_region( 50 scoped_ptr<SkRegion> expanded_region(
51 ExpandToGrid(*invalid_region, log_grid_size_)); 51 ExpandToGrid(*invalid_region, log_grid_size_));
52 invalid_region->swap(*expanded_region); 52 invalid_region->swap(*expanded_region);
53 invalid_region->op(SkRegion(SkIRect::MakeSize(size_most_recent_)), 53 invalid_region->op(SkRegion(SkIRect::MakeSize(size_most_recent_)),
54 SkRegion::kIntersect_Op); 54 SkRegion::kIntersect_Op);
55 } 55 }
56 } 56 }
57 57
58 void VideoFrameCapturerHelper::SetLogGridSize(int log_grid_size) { 58 void ScreenCapturerHelper::SetLogGridSize(int log_grid_size) {
59 log_grid_size_ = log_grid_size; 59 log_grid_size_ = log_grid_size;
60 } 60 }
61 61
62 const SkISize& VideoFrameCapturerHelper::size_most_recent() const { 62 const SkISize& ScreenCapturerHelper::size_most_recent() const {
63 return size_most_recent_; 63 return size_most_recent_;
64 } 64 }
65 65
66 void VideoFrameCapturerHelper::set_size_most_recent(const SkISize& size) { 66 void ScreenCapturerHelper::set_size_most_recent(const SkISize& size) {
67 size_most_recent_ = size; 67 size_most_recent_ = size;
68 } 68 }
69 69
70 // Returns the largest multiple of |n| that is <= |x|. 70 // Returns the largest multiple of |n| that is <= |x|.
71 // |n| must be a power of 2. |nMask| is ~(|n| - 1). 71 // |n| must be a power of 2. |nMask| is ~(|n| - 1).
72 static int DownToMultiple(int x, int nMask) { 72 static int DownToMultiple(int x, int nMask) {
73 return (x & nMask); 73 return (x & nMask);
74 } 74 }
75 75
76 // Returns the smallest multiple of |n| that is >= |x|. 76 // Returns the smallest multiple of |n| that is >= |x|.
77 // |n| must be a power of 2. |nMask| is ~(|n| - 1). 77 // |n| must be a power of 2. |nMask| is ~(|n| - 1).
78 static int UpToMultiple(int x, int n, int nMask) { 78 static int UpToMultiple(int x, int n, int nMask) {
79 return ((x + n - 1) & nMask); 79 return ((x + n - 1) & nMask);
80 } 80 }
81 81
82 scoped_ptr<SkRegion> VideoFrameCapturerHelper::ExpandToGrid( 82 scoped_ptr<SkRegion> ScreenCapturerHelper::ExpandToGrid(
83 const SkRegion& region, 83 const SkRegion& region,
84 int log_grid_size) { 84 int log_grid_size) {
85 DCHECK(log_grid_size >= 1); 85 DCHECK(log_grid_size >= 1);
86 int grid_size = 1 << log_grid_size; 86 int grid_size = 1 << log_grid_size;
87 int grid_size_mask = ~(grid_size - 1); 87 int grid_size_mask = ~(grid_size - 1);
88 // Count the rects in the region. 88 // Count the rects in the region.
89 int rectNum = 0; 89 int rectNum = 0;
90 SkRegion::Iterator iter(region); 90 SkRegion::Iterator iter(region);
91 while (!iter.done()) { 91 while (!iter.done()) {
92 iter.next(); 92 iter.next();
(...skipping 15 matching lines...) Expand all
108 top = DownToMultiple(top, grid_size_mask); 108 top = DownToMultiple(top, grid_size_mask);
109 bottom = UpToMultiple(bottom, grid_size, grid_size_mask); 109 bottom = UpToMultiple(bottom, grid_size, grid_size_mask);
110 rects[rectI++] = SkIRect::MakeLTRB(left, top, right, bottom); 110 rects[rectI++] = SkIRect::MakeLTRB(left, top, right, bottom);
111 } 111 }
112 // Make the union of the expanded rects. 112 // Make the union of the expanded rects.
113 scoped_ptr<SkRegion> regionNew(new SkRegion()); 113 scoped_ptr<SkRegion> regionNew(new SkRegion());
114 regionNew->setRects(rects.get(), rectNum); 114 regionNew->setRects(rects.get(), rectNum);
115 return regionNew.Pass(); 115 return regionNew.Pass();
116 } 116 }
117 117
118 } // namespace remoting 118 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/screen/screen_capturer_helper.h ('k') | media/video/capture/screen/screen_capturer_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698