Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/video/capture/screen/screen_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 "media/video/capture/screen/screen_capture_data.h" | 8 #include "media/video/capture/screen/screen_capture_data.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 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 ScreenCapturerFake::~ScreenCapturerFake() { | 37 ScreenCapturerFake::~ScreenCapturerFake() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 void ScreenCapturerFake::Start(Delegate* delegate) { | 40 void ScreenCapturerFake::Start(Delegate* delegate) { |
| 41 delegate_ = delegate; | 41 delegate_ = delegate; |
| 42 | |
| 43 // Create memory for the buffers. | |
| 44 int buffer_size = size_.height() * bytes_per_row_; | |
|
Cris Neckar
2013/02/06 19:31:24
nit: size_t
alexeypa (please no reviews)
2013/02/06 22:58:39
width, height and bytes_per_row_ are all |int| her
| |
| 45 for (int i = 0; i < kNumBuffers; i++) { | |
| 46 shared_buffers_[i] = delegate_->CreateSharedBuffer(buffer_size); | |
| 47 if (shared_buffers_[i]) { | |
| 48 buffers_[i] = reinterpret_cast<uint8*>(shared_buffers_[i]->ptr()); | |
| 49 } else { | |
| 50 private_buffers_[i].reset(new uint8[buffer_size]); | |
| 51 buffers_[i] = private_buffers_[i].get(); | |
| 52 } | |
| 53 } | |
| 42 } | 54 } |
| 43 | 55 |
| 44 void ScreenCapturerFake::Stop() { | 56 void ScreenCapturerFake::Stop() { |
| 45 } | 57 } |
| 46 | 58 |
| 47 void ScreenCapturerFake::InvalidateRegion(const SkRegion& invalid_region) { | 59 void ScreenCapturerFake::InvalidateRegion(const SkRegion& invalid_region) { |
| 48 helper_.InvalidateRegion(invalid_region); | 60 helper_.InvalidateRegion(invalid_region); |
| 49 } | 61 } |
| 50 | 62 |
| 51 void ScreenCapturerFake::CaptureFrame() { | 63 void ScreenCapturerFake::CaptureFrame() { |
| 52 base::Time capture_start_time = base::Time::Now(); | 64 base::Time capture_start_time = base::Time::Now(); |
| 53 | 65 |
| 54 GenerateImage(); | 66 GenerateImage(); |
| 55 helper_.InvalidateScreen(size_); | 67 helper_.InvalidateScreen(size_); |
| 56 | 68 |
| 57 SkRegion invalid_region; | 69 SkRegion invalid_region; |
| 58 helper_.SwapInvalidRegion(&invalid_region); | 70 helper_.SwapInvalidRegion(&invalid_region); |
| 59 | 71 |
| 60 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; | 72 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; |
| 61 | 73 |
| 62 scoped_refptr<ScreenCaptureData> capture_data(new ScreenCaptureData( | 74 scoped_refptr<ScreenCaptureData> capture_data(new ScreenCaptureData( |
| 63 buffers_[current_buffer_].get(), bytes_per_row_, size_)); | 75 buffers_[current_buffer_], bytes_per_row_, size_)); |
| 64 capture_data->mutable_dirty_region() = invalid_region; | 76 capture_data->mutable_dirty_region() = invalid_region; |
| 65 | 77 |
| 66 helper_.set_size_most_recent(capture_data->size()); | 78 helper_.set_size_most_recent(size_); |
| 79 | |
| 80 capture_data->set_shared_buffer(shared_buffers_[current_buffer_]); | |
| 67 | 81 |
| 68 capture_data->set_capture_time_ms( | 82 capture_data->set_capture_time_ms( |
| 69 (base::Time::Now() - capture_start_time).InMillisecondsRoundedUp()); | 83 (base::Time::Now() - capture_start_time).InMillisecondsRoundedUp()); |
| 70 delegate_->OnCaptureCompleted(capture_data); | 84 delegate_->OnCaptureCompleted(capture_data); |
| 71 } | 85 } |
| 72 | 86 |
| 73 void ScreenCapturerFake::GenerateImage() { | 87 void ScreenCapturerFake::GenerateImage() { |
| 74 memset(buffers_[current_buffer_].get(), 0xff, | 88 memset(buffers_[current_buffer_], 0xff, |
| 75 size_.width() * size_.height() * ScreenCaptureData::kBytesPerPixel); | 89 size_.width() * size_.height() * ScreenCaptureData::kBytesPerPixel); |
| 76 | 90 |
| 77 uint8* row = buffers_[current_buffer_].get() + | 91 uint8* row = buffers_[current_buffer_] + |
| 78 (box_pos_y_ * size_.width() + box_pos_x_) * | 92 (box_pos_y_ * size_.width() + box_pos_x_) * |
| 79 ScreenCaptureData::kBytesPerPixel; | 93 ScreenCaptureData::kBytesPerPixel; |
| 80 | 94 |
| 81 box_pos_x_ += box_speed_x_; | 95 box_pos_x_ += box_speed_x_; |
| 82 if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0) | 96 if (box_pos_x_ + kBoxWidth >= size_.width() || box_pos_x_ == 0) |
| 83 box_speed_x_ = -box_speed_x_; | 97 box_speed_x_ = -box_speed_x_; |
| 84 | 98 |
| 85 box_pos_y_ += box_speed_y_; | 99 box_pos_y_ += box_speed_y_; |
| 86 if (box_pos_y_ + kBoxHeight >= size_.height() || box_pos_y_ == 0) | 100 if (box_pos_y_ + kBoxHeight >= size_.height() || box_pos_y_ == 0) |
| 87 box_speed_y_ = -box_speed_y_; | 101 box_speed_y_ = -box_speed_y_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 100 row[x * ScreenCaptureData::kBytesPerPixel + 2] = b; | 114 row[x * ScreenCaptureData::kBytesPerPixel + 2] = b; |
| 101 row[x * ScreenCaptureData::kBytesPerPixel + 3] = 0xff; | 115 row[x * ScreenCaptureData::kBytesPerPixel + 3] = 0xff; |
| 102 } | 116 } |
| 103 row += bytes_per_row_; | 117 row += bytes_per_row_; |
| 104 } | 118 } |
| 105 } | 119 } |
| 106 | 120 |
| 107 void ScreenCapturerFake::ScreenConfigurationChanged() { | 121 void ScreenCapturerFake::ScreenConfigurationChanged() { |
| 108 size_ = SkISize::Make(kWidth, kHeight); | 122 size_ = SkISize::Make(kWidth, kHeight); |
| 109 bytes_per_row_ = size_.width() * ScreenCaptureData::kBytesPerPixel; | 123 bytes_per_row_ = size_.width() * ScreenCaptureData::kBytesPerPixel; |
| 110 | |
| 111 // Create memory for the buffers. | |
| 112 int buffer_size = size_.height() * bytes_per_row_; | |
| 113 for (int i = 0; i < kNumBuffers; i++) { | |
| 114 buffers_[i].reset(new uint8[buffer_size]); | |
| 115 } | |
| 116 } | 124 } |
| 117 | 125 |
| 118 } // namespace media | 126 } // namespace media |
| OLD | NEW |