OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/host/capturer_fake.h" | 5 #include "remoting/host/capturer_fake.h" |
6 | 6 |
7 #include "gfx/rect.h" | 7 #include "gfx/rect.h" |
8 | 8 |
9 namespace remoting { | 9 namespace remoting { |
10 | 10 |
11 // CapturerFake generates a white picture of size kWidth x kHeight with a | 11 static const int kWidth = 320; |
12 // rectangle of size kBoxWidth x kBoxHeight. The rectangle moves kSpeed pixels | 12 static const int kHeight = 240; |
13 // per frame along both axes, and bounces off the sides of the screen. | |
14 static const int kWidth = 800; | |
15 static const int kHeight = 600; | |
16 static const int kBoxWidth = 140; | |
17 static const int kBoxHeight = 140; | |
18 static const int kSpeed = 20; | |
19 | |
20 COMPILE_ASSERT(kBoxWidth < kWidth && kBoxHeight < kHeight, bad_box_size); | |
21 COMPILE_ASSERT((kBoxWidth % kSpeed == 0) && (kWidth % kSpeed == 0) && | |
22 (kBoxHeight % kSpeed == 0) && (kHeight % kSpeed == 0), | |
23 sizes_must_be_multiple_of_kSpeed); | |
24 | |
25 static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. | 13 static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. |
| 14 static const int kMaxColorChannelValue = 255; |
26 | 15 |
27 CapturerFake::CapturerFake() | 16 CapturerFake::CapturerFake() |
28 : box_pos_x_(0), | 17 : seed_(0) { |
29 box_pos_y_(0), | |
30 box_speed_x_(kSpeed), | |
31 box_speed_y_(kSpeed) { | |
32 ScreenConfigurationChanged(); | 18 ScreenConfigurationChanged(); |
33 } | 19 } |
34 | 20 |
35 CapturerFake::~CapturerFake() { | 21 CapturerFake::~CapturerFake() { |
36 } | 22 } |
37 | 23 |
38 void CapturerFake::ScreenConfigurationChanged() { | 24 void CapturerFake::ScreenConfigurationChanged() { |
39 width_ = kWidth; | 25 width_ = kWidth; |
40 height_ = kHeight; | 26 height_ = kHeight; |
41 pixel_format_ = PIXEL_FORMAT_RGB32; | 27 pixel_format_ = PixelFormatRgb32; |
42 bytes_per_row_ = width_ * kBytesPerPixel; | 28 bytes_per_row_ = width_ * kBytesPerPixel; |
43 | 29 |
44 // Create memory for the buffers. | 30 // Create memory for the buffers. |
45 int buffer_size = height_ * bytes_per_row_; | 31 int buffer_size = height_ * bytes_per_row_; |
46 for (int i = 0; i < kNumBuffers; i++) { | 32 for (int i = 0; i < kNumBuffers; i++) { |
47 buffers_[i].reset(new uint8[buffer_size]); | 33 buffers_[i].reset(new uint8[buffer_size]); |
48 } | 34 } |
49 } | 35 } |
50 | 36 |
51 void CapturerFake::CalculateInvalidRects() { | 37 void CapturerFake::CalculateInvalidRects() { |
52 GenerateImage(); | 38 GenerateImage(); |
53 InvalidateFullScreen(); | 39 InvalidateFullScreen(); |
54 } | 40 } |
55 | 41 |
56 void CapturerFake::CaptureRects(const InvalidRects& rects, | 42 void CapturerFake::CaptureRects(const InvalidRects& rects, |
57 CaptureCompletedCallback* callback) { | 43 CaptureCompletedCallback* callback) { |
58 DataPlanes planes; | 44 DataPlanes planes; |
59 planes.data[0] = buffers_[current_buffer_].get(); | 45 planes.data[0] = buffers_[current_buffer_].get(); |
60 planes.strides[0] = bytes_per_row_; | 46 planes.strides[0] = bytes_per_row_; |
61 | 47 |
62 scoped_refptr<CaptureData> capture_data(new CaptureData(planes, | 48 scoped_refptr<CaptureData> capture_data(new CaptureData(planes, |
63 width_, | 49 width_, |
64 height_, | 50 height_, |
65 pixel_format_)); | 51 pixel_format_)); |
66 capture_data->mutable_dirty_rects() = rects; | 52 capture_data->mutable_dirty_rects() = rects; |
67 FinishCapture(capture_data, callback); | 53 FinishCapture(capture_data, callback); |
68 } | 54 } |
69 | 55 |
70 void CapturerFake::GenerateImage() { | 56 void CapturerFake::GenerateImage() { |
71 memset(buffers_[current_buffer_].get(), 0xff, | 57 uint8* row = buffers_[current_buffer_].get(); |
72 width_ * height_ * kBytesPerPixel); | 58 for (int y = 0; y < height_; ++y) { |
73 | 59 int offset = y % 3; |
74 uint8* row = buffers_[current_buffer_].get() + | 60 for (int x = 0; x < width_; ++x) { |
75 (box_pos_y_ * width_ + box_pos_x_) * kBytesPerPixel; | 61 row[x * kBytesPerPixel + offset] = seed_++; |
76 | 62 seed_ &= kMaxColorChannelValue; |
77 box_pos_x_ += box_speed_x_; | |
78 if (box_pos_x_ + kBoxWidth >= width_ || box_pos_x_ == 0) | |
79 box_speed_x_ = -box_speed_x_; | |
80 | |
81 box_pos_y_ += box_speed_y_; | |
82 if (box_pos_y_ + kBoxHeight >= height_ || box_pos_y_ == 0) | |
83 box_speed_y_ = -box_speed_y_; | |
84 | |
85 // Draw rectangle with the following colors in it's corners: | |
86 // cyan....yellow | |
87 // .............. | |
88 // blue.......red | |
89 for (int y = 0; y < kBoxHeight; ++y) { | |
90 for (int x = 0; x < kBoxWidth; ++x) { | |
91 int r = x * 255 / kBoxWidth; | |
92 int g = y * 255 / kBoxHeight; | |
93 int b = 255 - (x * 255 / kBoxWidth); | |
94 row[x * kBytesPerPixel] = r; | |
95 row[x * kBytesPerPixel+1] = g; | |
96 row[x * kBytesPerPixel+2] = b; | |
97 row[x * kBytesPerPixel+3] = 0xff; | |
98 } | 63 } |
99 row += bytes_per_row_; | 64 row += bytes_per_row_; |
100 } | 65 } |
| 66 ++seed_; |
101 } | 67 } |
102 | 68 |
103 } // namespace remoting | 69 } // namespace remoting |
OLD | NEW |