| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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/test/scroll_frame_generator.h" | |
| 6 | |
| 7 #include "remoting/test/frame_generator_util.h" | |
| 8 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 9 | |
| 10 namespace remoting { | |
| 11 namespace test { | |
| 12 | |
| 13 namespace { | |
| 14 int kScrollSpeedPixelsPerSecond = 500; | |
| 15 } // namespace | |
| 16 | |
| 17 ScrollFrameGenerator::ScrollFrameGenerator() | |
| 18 : base_frame_(LoadDesktopFrameFromPng("test_frame2.png")), | |
| 19 start_time_(base::TimeTicks::Now()) {} | |
| 20 ScrollFrameGenerator::~ScrollFrameGenerator() {} | |
| 21 | |
| 22 std::unique_ptr<webrtc::DesktopFrame> ScrollFrameGenerator::GenerateFrame( | |
| 23 webrtc::SharedMemoryFactory* shared_memory_factory) { | |
| 24 base::TimeTicks now = base::TimeTicks::Now(); | |
| 25 int position = static_cast<int>(kScrollSpeedPixelsPerSecond * | |
| 26 (now - start_time_).InSecondsF()) % | |
| 27 base_frame_->size().height(); | |
| 28 std::unique_ptr<webrtc::DesktopFrame> result( | |
| 29 new webrtc::BasicDesktopFrame(base_frame_->size())); | |
| 30 | |
| 31 int top_height = base_frame_->size().height() - position; | |
| 32 | |
| 33 result->CopyPixelsFrom(*base_frame_, webrtc::DesktopVector(0, position), | |
| 34 webrtc::DesktopRect::MakeLTRB( | |
| 35 0, 0, base_frame_->size().width(), top_height)); | |
| 36 result->CopyPixelsFrom( | |
| 37 *base_frame_, webrtc::DesktopVector(0, 0), | |
| 38 webrtc::DesktopRect::MakeLTRB(0, top_height, base_frame_->size().width(), | |
| 39 base_frame_->size().height())); | |
| 40 | |
| 41 result->mutable_updated_region()->SetRect( | |
| 42 webrtc::DesktopRect::MakeSize(result->size())); | |
| 43 | |
| 44 ++last_frame_id_; | |
| 45 frame_timestamp_[last_frame_id_] = now; | |
| 46 DrawBarcode(last_frame_id_, true, result.get()); | |
| 47 | |
| 48 return result; | |
| 49 } | |
| 50 | |
| 51 base::TimeDelta ScrollFrameGenerator::GetFrameLatency( | |
| 52 const webrtc::DesktopFrame& frame) { | |
| 53 int frame_id = ReadBarcode(frame); | |
| 54 if (!frame_timestamp_.count(frame_id)) | |
| 55 LOG(FATAL) << "Unknown frame_id."; | |
| 56 return base::TimeTicks::Now() - frame_timestamp_[frame_id]; | |
| 57 } | |
| 58 | |
| 59 } // namespace test | |
| 60 } // namespace remoting | |
| OLD | NEW |