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 static const int kWidth = 320; | 11 // CapturerFake generates a white picture of size kWidth x kHeight with a |
12 static const int kHeight = 240; | 12 // rectangle of size kBoxWidth x kBoxHeight. The rectangle moves kSpeed pixels |
| 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 |
13 static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. | 25 static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. |
14 static const int kMaxColorChannelValue = 255; | |
15 | 26 |
16 CapturerFake::CapturerFake() | 27 CapturerFake::CapturerFake() |
17 : seed_(0) { | 28 : box_pos_x_(0), |
| 29 box_pos_y_(0), |
| 30 box_speed_x_(kSpeed), |
| 31 box_speed_y_(kSpeed) { |
18 ScreenConfigurationChanged(); | 32 ScreenConfigurationChanged(); |
19 } | 33 } |
20 | 34 |
21 CapturerFake::~CapturerFake() { | 35 CapturerFake::~CapturerFake() { |
22 } | 36 } |
23 | 37 |
24 void CapturerFake::ScreenConfigurationChanged() { | 38 void CapturerFake::ScreenConfigurationChanged() { |
25 width_ = kWidth; | 39 width_ = kWidth; |
26 height_ = kHeight; | 40 height_ = kHeight; |
27 pixel_format_ = PixelFormatRgb32; | 41 pixel_format_ = PIXEL_FORMAT_RGB32; |
28 bytes_per_row_ = width_ * kBytesPerPixel; | 42 bytes_per_row_ = width_ * kBytesPerPixel; |
29 | 43 |
30 // Create memory for the buffers. | 44 // Create memory for the buffers. |
31 int buffer_size = height_ * bytes_per_row_; | 45 int buffer_size = height_ * bytes_per_row_; |
32 for (int i = 0; i < kNumBuffers; i++) { | 46 for (int i = 0; i < kNumBuffers; i++) { |
33 buffers_[i].reset(new uint8[buffer_size]); | 47 buffers_[i].reset(new uint8[buffer_size]); |
34 } | 48 } |
35 } | 49 } |
36 | 50 |
37 void CapturerFake::CalculateInvalidRects() { | 51 void CapturerFake::CalculateInvalidRects() { |
38 GenerateImage(); | 52 GenerateImage(); |
39 InvalidateFullScreen(); | 53 InvalidateFullScreen(); |
40 } | 54 } |
41 | 55 |
42 void CapturerFake::CaptureRects(const InvalidRects& rects, | 56 void CapturerFake::CaptureRects(const InvalidRects& rects, |
43 CaptureCompletedCallback* callback) { | 57 CaptureCompletedCallback* callback) { |
44 DataPlanes planes; | 58 DataPlanes planes; |
45 planes.data[0] = buffers_[current_buffer_].get(); | 59 planes.data[0] = buffers_[current_buffer_].get(); |
46 planes.strides[0] = bytes_per_row_; | 60 planes.strides[0] = bytes_per_row_; |
47 | 61 |
48 scoped_refptr<CaptureData> capture_data(new CaptureData(planes, | 62 scoped_refptr<CaptureData> capture_data(new CaptureData(planes, |
49 width_, | 63 width_, |
50 height_, | 64 height_, |
51 pixel_format_)); | 65 pixel_format_)); |
52 capture_data->mutable_dirty_rects() = rects; | 66 capture_data->mutable_dirty_rects() = rects; |
53 FinishCapture(capture_data, callback); | 67 FinishCapture(capture_data, callback); |
54 } | 68 } |
55 | 69 |
56 void CapturerFake::GenerateImage() { | 70 void CapturerFake::GenerateImage() { |
57 uint8* row = buffers_[current_buffer_].get(); | 71 memset(buffers_[current_buffer_].get(), 0xff, |
58 for (int y = 0; y < height_; ++y) { | 72 width_ * height_ * kBytesPerPixel); |
59 int offset = y % 3; | 73 |
60 for (int x = 0; x < width_; ++x) { | 74 uint8* row = buffers_[current_buffer_].get() + |
61 row[x * kBytesPerPixel + offset] = seed_++; | 75 (box_pos_y_ * width_ + box_pos_x_) * kBytesPerPixel; |
62 seed_ &= kMaxColorChannelValue; | 76 |
| 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; |
63 } | 98 } |
64 row += bytes_per_row_; | 99 row += bytes_per_row_; |
65 } | 100 } |
66 ++seed_; | |
67 } | 101 } |
68 | 102 |
69 } // namespace remoting | 103 } // namespace remoting |
OLD | NEW |