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

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

Powered by Google App Engine
This is Rietveld 408576698