| OLD | NEW |
| (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/host/capturer_fake.h" | |
| 6 | |
| 7 #include "remoting/base/capture_data.h" | |
| 8 | |
| 9 namespace remoting { | |
| 10 | |
| 11 // CapturerFake generates a white picture of size kWidth x kHeight with a | |
| 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 | |
| 25 static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. | |
| 26 | |
| 27 CapturerFake::CapturerFake() | |
| 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 pixel_format_(media::VideoFrame::RGB32) { | |
| 35 ScreenConfigurationChanged(); | |
| 36 } | |
| 37 | |
| 38 CapturerFake::~CapturerFake() { | |
| 39 } | |
| 40 | |
| 41 void CapturerFake::Start( | |
| 42 const CursorShapeChangedCallback& callback) { | |
| 43 } | |
| 44 | |
| 45 void CapturerFake::Stop() { | |
| 46 } | |
| 47 | |
| 48 void CapturerFake::ScreenConfigurationChanged() { | |
| 49 size_ = SkISize::Make(kWidth, kHeight); | |
| 50 bytes_per_row_ = size_.width() * kBytesPerPixel; | |
| 51 pixel_format_ = media::VideoFrame::RGB32; | |
| 52 | |
| 53 // Create memory for the buffers. | |
| 54 int buffer_size = size_.height() * bytes_per_row_; | |
| 55 for (int i = 0; i < kNumBuffers; i++) { | |
| 56 buffers_[i].reset(new uint8[buffer_size]); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 media::VideoFrame::Format CapturerFake::pixel_format() const { | |
| 61 return pixel_format_; | |
| 62 } | |
| 63 | |
| 64 void CapturerFake::ClearInvalidRegion() { | |
| 65 helper.ClearInvalidRegion(); | |
| 66 } | |
| 67 | |
| 68 void CapturerFake::InvalidateRegion(const SkRegion& invalid_region) { | |
| 69 helper.InvalidateRegion(invalid_region); | |
| 70 } | |
| 71 | |
| 72 void CapturerFake::InvalidateScreen(const SkISize& size) { | |
| 73 helper.InvalidateScreen(size); | |
| 74 } | |
| 75 | |
| 76 void CapturerFake::InvalidateFullScreen() { | |
| 77 helper.InvalidateFullScreen(); | |
| 78 } | |
| 79 | |
| 80 void CapturerFake::CaptureInvalidRegion( | |
| 81 const CaptureCompletedCallback& callback) { | |
| 82 GenerateImage(); | |
| 83 InvalidateScreen(size_); | |
| 84 | |
| 85 SkRegion invalid_region; | |
| 86 helper.SwapInvalidRegion(&invalid_region); | |
| 87 | |
| 88 DataPlanes planes; | |
| 89 planes.data[0] = buffers_[current_buffer_].get(); | |
| 90 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | |
| 91 planes.strides[0] = bytes_per_row_; | |
| 92 | |
| 93 scoped_refptr<CaptureData> capture_data(new CaptureData(planes, | |
| 94 size_, | |
| 95 pixel_format_)); | |
| 96 capture_data->mutable_dirty_region() = invalid_region; | |
| 97 | |
| 98 helper.set_size_most_recent(capture_data->size()); | |
| 99 | |
| 100 callback.Run(capture_data); | |
| 101 } | |
| 102 | |
| 103 const SkISize& CapturerFake::size_most_recent() const { | |
| 104 return helper.size_most_recent(); | |
| 105 } | |
| 106 | |
| 107 void CapturerFake::GenerateImage() { | |
| 108 memset(buffers_[current_buffer_].get(), 0xff, | |
| 109 size_.width() * size_.height() * kBytesPerPixel); | |
| 110 | |
| 111 uint8* row = buffers_[current_buffer_].get() + | |
| 112 (box_pos_y_ * size_.width() + box_pos_x_) * kBytesPerPixel; | |
| 113 | |
| 114 box_pos_x_ += box_speed_x_; | |
| 115 if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0) | |
| 116 box_speed_x_ = -box_speed_x_; | |
| 117 | |
| 118 box_pos_y_ += box_speed_y_; | |
| 119 if (box_pos_y_ + kBoxHeight >= size_.height() || box_pos_y_ == 0) | |
| 120 box_speed_y_ = -box_speed_y_; | |
| 121 | |
| 122 // Draw rectangle with the following colors in its corners: | |
| 123 // cyan....yellow | |
| 124 // .............. | |
| 125 // blue.......red | |
| 126 for (int y = 0; y < kBoxHeight; ++y) { | |
| 127 for (int x = 0; x < kBoxWidth; ++x) { | |
| 128 int r = x * 255 / kBoxWidth; | |
| 129 int g = y * 255 / kBoxHeight; | |
| 130 int b = 255 - (x * 255 / kBoxWidth); | |
| 131 row[x * kBytesPerPixel] = r; | |
| 132 row[x * kBytesPerPixel+1] = g; | |
| 133 row[x * kBytesPerPixel+2] = b; | |
| 134 row[x * kBytesPerPixel+3] = 0xff; | |
| 135 } | |
| 136 row += bytes_per_row_; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 } // namespace remoting | |
| OLD | NEW |