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

Side by Side Diff: media/video/capture/screen/screen_capturer_fake.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_fake.h" 5 #include "media/video/capture/screen/screen_capturer_fake.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "remoting/capturer/capture_data.h" 8 #include "media/video/capture/screen/screen_capture_data.h"
9 9
10 namespace remoting { 10 namespace media {
11 11
12 // VideoFrameCapturerFake generates a white picture of size kWidth x kHeight 12 // ScreenCapturerFake generates a white picture of size kWidth x kHeight
13 // with a rectangle of size kBoxWidth x kBoxHeight. The rectangle moves kSpeed 13 // with a rectangle of size kBoxWidth x kBoxHeight. The rectangle moves kSpeed
14 // pixels per frame along both axes, and bounces off the sides of the screen. 14 // pixels per frame along both axes, and bounces off the sides of the screen.
15 static const int kWidth = VideoFrameCapturerFake::kWidth; 15 static const int kWidth = ScreenCapturerFake::kWidth;
16 static const int kHeight = VideoFrameCapturerFake::kHeight; 16 static const int kHeight = ScreenCapturerFake::kHeight;
17 static const int kBoxWidth = 140; 17 static const int kBoxWidth = 140;
18 static const int kBoxHeight = 140; 18 static const int kBoxHeight = 140;
19 static const int kSpeed = 20; 19 static const int kSpeed = 20;
20 20
21 COMPILE_ASSERT(kBoxWidth < kWidth && kBoxHeight < kHeight, bad_box_size); 21 COMPILE_ASSERT(kBoxWidth < kWidth && kBoxHeight < kHeight, bad_box_size);
22 COMPILE_ASSERT((kBoxWidth % kSpeed == 0) && (kWidth % kSpeed == 0) && 22 COMPILE_ASSERT((kBoxWidth % kSpeed == 0) && (kWidth % kSpeed == 0) &&
23 (kBoxHeight % kSpeed == 0) && (kHeight % kSpeed == 0), 23 (kBoxHeight % kSpeed == 0) && (kHeight % kSpeed == 0),
24 sizes_must_be_multiple_of_kSpeed); 24 sizes_must_be_multiple_of_kSpeed);
25 25
26 VideoFrameCapturerFake::VideoFrameCapturerFake() 26 ScreenCapturerFake::ScreenCapturerFake()
27 : size_(SkISize::Make(0, 0)), 27 : size_(SkISize::Make(0, 0)),
28 bytes_per_row_(0), 28 bytes_per_row_(0),
29 box_pos_x_(0), 29 box_pos_x_(0),
30 box_pos_y_(0), 30 box_pos_y_(0),
31 box_speed_x_(kSpeed), 31 box_speed_x_(kSpeed),
32 box_speed_y_(kSpeed), 32 box_speed_y_(kSpeed),
33 current_buffer_(0) { 33 current_buffer_(0) {
34 ScreenConfigurationChanged(); 34 ScreenConfigurationChanged();
35 } 35 }
36 36
37 VideoFrameCapturerFake::~VideoFrameCapturerFake() { 37 ScreenCapturerFake::~ScreenCapturerFake() {
38 } 38 }
39 39
40 void VideoFrameCapturerFake::Start(Delegate* delegate) { 40 void ScreenCapturerFake::Start(Delegate* delegate) {
41 delegate_ = delegate; 41 delegate_ = delegate;
42 } 42 }
43 43
44 void VideoFrameCapturerFake::Stop() { 44 void ScreenCapturerFake::Stop() {
45 } 45 }
46 46
47 void VideoFrameCapturerFake::InvalidateRegion(const SkRegion& invalid_region) { 47 void ScreenCapturerFake::InvalidateRegion(const SkRegion& invalid_region) {
48 helper_.InvalidateRegion(invalid_region); 48 helper_.InvalidateRegion(invalid_region);
49 } 49 }
50 50
51 void VideoFrameCapturerFake::CaptureFrame() { 51 void ScreenCapturerFake::CaptureFrame() {
52 base::Time capture_start_time = base::Time::Now(); 52 base::Time capture_start_time = base::Time::Now();
53 53
54 GenerateImage(); 54 GenerateImage();
55 helper_.InvalidateScreen(size_); 55 helper_.InvalidateScreen(size_);
56 56
57 SkRegion invalid_region; 57 SkRegion invalid_region;
58 helper_.SwapInvalidRegion(&invalid_region); 58 helper_.SwapInvalidRegion(&invalid_region);
59 59
60 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; 60 current_buffer_ = (current_buffer_ + 1) % kNumBuffers;
61 61
62 scoped_refptr<CaptureData> capture_data(new CaptureData( 62 scoped_refptr<ScreenCaptureData> capture_data(new ScreenCaptureData(
63 buffers_[current_buffer_].get(), bytes_per_row_, size_)); 63 buffers_[current_buffer_].get(), bytes_per_row_, size_));
64 capture_data->mutable_dirty_region() = invalid_region; 64 capture_data->mutable_dirty_region() = invalid_region;
65 65
66 helper_.set_size_most_recent(capture_data->size()); 66 helper_.set_size_most_recent(capture_data->size());
67 67
68 capture_data->set_capture_time_ms( 68 capture_data->set_capture_time_ms(
69 (base::Time::Now() - capture_start_time).InMillisecondsRoundedUp()); 69 (base::Time::Now() - capture_start_time).InMillisecondsRoundedUp());
70 delegate_->OnCaptureCompleted(capture_data); 70 delegate_->OnCaptureCompleted(capture_data);
71 } 71 }
72 72
73 void VideoFrameCapturerFake::GenerateImage() { 73 void ScreenCapturerFake::GenerateImage() {
74 memset(buffers_[current_buffer_].get(), 0xff, 74 memset(buffers_[current_buffer_].get(), 0xff,
75 size_.width() * size_.height() * CaptureData::kBytesPerPixel); 75 size_.width() * size_.height() * ScreenCaptureData::kBytesPerPixel);
76 76
77 uint8* row = buffers_[current_buffer_].get() + 77 uint8* row = buffers_[current_buffer_].get() +
78 (box_pos_y_ * size_.width() + box_pos_x_) * CaptureData::kBytesPerPixel; 78 (box_pos_y_ * size_.width() + box_pos_x_) *
79 ScreenCaptureData::kBytesPerPixel;
79 80
80 box_pos_x_ += box_speed_x_; 81 box_pos_x_ += box_speed_x_;
81 if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0) 82 if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0)
82 box_speed_x_ = -box_speed_x_; 83 box_speed_x_ = -box_speed_x_;
83 84
84 box_pos_y_ += box_speed_y_; 85 box_pos_y_ += box_speed_y_;
85 if (box_pos_y_ + kBoxHeight >= size_.height() || box_pos_y_ == 0) 86 if (box_pos_y_ + kBoxHeight >= size_.height() || box_pos_y_ == 0)
86 box_speed_y_ = -box_speed_y_; 87 box_speed_y_ = -box_speed_y_;
87 88
88 // Draw rectangle with the following colors in its corners: 89 // Draw rectangle with the following colors in its corners:
89 // cyan....yellow 90 // cyan....yellow
90 // .............. 91 // ..............
91 // blue.......red 92 // blue.......red
92 for (int y = 0; y < kBoxHeight; ++y) { 93 for (int y = 0; y < kBoxHeight; ++y) {
93 for (int x = 0; x < kBoxWidth; ++x) { 94 for (int x = 0; x < kBoxWidth; ++x) {
94 int r = x * 255 / kBoxWidth; 95 int r = x * 255 / kBoxWidth;
95 int g = y * 255 / kBoxHeight; 96 int g = y * 255 / kBoxHeight;
96 int b = 255 - (x * 255 / kBoxWidth); 97 int b = 255 - (x * 255 / kBoxWidth);
97 row[x * CaptureData::kBytesPerPixel] = r; 98 row[x * ScreenCaptureData::kBytesPerPixel] = r;
98 row[x * CaptureData::kBytesPerPixel + 1] = g; 99 row[x * ScreenCaptureData::kBytesPerPixel + 1] = g;
99 row[x * CaptureData::kBytesPerPixel + 2] = b; 100 row[x * ScreenCaptureData::kBytesPerPixel + 2] = b;
100 row[x * CaptureData::kBytesPerPixel + 3] = 0xff; 101 row[x * ScreenCaptureData::kBytesPerPixel + 3] = 0xff;
101 } 102 }
102 row += bytes_per_row_; 103 row += bytes_per_row_;
103 } 104 }
104 } 105 }
105 106
106 void VideoFrameCapturerFake::ScreenConfigurationChanged() { 107 void ScreenCapturerFake::ScreenConfigurationChanged() {
107 size_ = SkISize::Make(kWidth, kHeight); 108 size_ = SkISize::Make(kWidth, kHeight);
108 bytes_per_row_ = size_.width() * CaptureData::kBytesPerPixel; 109 bytes_per_row_ = size_.width() * ScreenCaptureData::kBytesPerPixel;
109 110
110 // Create memory for the buffers. 111 // Create memory for the buffers.
111 int buffer_size = size_.height() * bytes_per_row_; 112 int buffer_size = size_.height() * bytes_per_row_;
112 for (int i = 0; i < kNumBuffers; i++) { 113 for (int i = 0; i < kNumBuffers; i++) {
113 buffers_[i].reset(new uint8[buffer_size]); 114 buffers_[i].reset(new uint8[buffer_size]);
114 } 115 }
115 } 116 }
116 117
117 } // namespace remoting 118 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/screen/screen_capturer_fake.h ('k') | media/video/capture/screen/screen_capturer_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698