Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: remoting/test/cyclic_frame_generator.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/test/cyclic_frame_generator.h ('k') | remoting/test/fake_network_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/test/cyclic_frame_generator.h" 5 #include "remoting/test/cyclic_frame_generator.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 13 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
14 #include "ui/gfx/codec/png_codec.h" 14 #include "ui/gfx/codec/png_codec.h"
15 15
16 namespace remoting { 16 namespace remoting {
17 namespace test { 17 namespace test {
18 18
19 namespace { 19 namespace {
20 20
21 const int kBarcodeCellWidth = 8; 21 const int kBarcodeCellWidth = 8;
22 const int kBarcodeCellHeight = 8; 22 const int kBarcodeCellHeight = 8;
23 const int kBarcodeBits = 10; 23 const int kBarcodeBits = 10;
24 const int kBarcodeBlackThreshold = 85; 24 const int kBarcodeBlackThreshold = 85;
25 const int kBarcodeWhiteThreshold = 170; 25 const int kBarcodeWhiteThreshold = 170;
26 26
27 scoped_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( 27 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng(
28 const base::FilePath& file_path) { 28 const base::FilePath& file_path) {
29 std::string file_content; 29 std::string file_content;
30 if (!base::ReadFileToString(file_path, &file_content)) 30 if (!base::ReadFileToString(file_path, &file_content))
31 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII() 31 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII()
32 << ". Please run remoting/test/data/download.sh"; 32 << ". Please run remoting/test/data/download.sh";
33 SkBitmap bitmap; 33 SkBitmap bitmap;
34 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()), 34 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()),
35 file_content.size(), &bitmap); 35 file_content.size(), &bitmap);
36 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( 36 std::unique_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(
37 webrtc::DesktopSize(bitmap.width(), bitmap.height()))); 37 webrtc::DesktopSize(bitmap.width(), bitmap.height())));
38 bitmap.copyPixelsTo(frame->data(), 38 bitmap.copyPixelsTo(frame->data(),
39 frame->stride() * frame->size().height(), 39 frame->stride() * frame->size().height(),
40 frame->stride()); 40 frame->stride());
41 return frame; 41 return frame;
42 } 42 }
43 43
44 void DrawRect(webrtc::DesktopFrame* frame, 44 void DrawRect(webrtc::DesktopFrame* frame,
45 webrtc::DesktopRect rect, 45 webrtc::DesktopRect rect,
46 uint32_t color) { 46 uint32_t color) {
(...skipping 16 matching lines...) Expand all
63 : frame_id(frame_id), type(type), timestamp(timestamp) {} 63 : frame_id(frame_id), type(type), timestamp(timestamp) {}
64 64
65 // static 65 // static
66 scoped_refptr<CyclicFrameGenerator> CyclicFrameGenerator::Create() { 66 scoped_refptr<CyclicFrameGenerator> CyclicFrameGenerator::Create() {
67 base::FilePath test_data_path; 67 base::FilePath test_data_path;
68 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_path); 68 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_path);
69 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("remoting")); 69 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("remoting"));
70 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test")); 70 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test"));
71 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data")); 71 test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data"));
72 72
73 std::vector<scoped_ptr<webrtc::DesktopFrame>> frames; 73 std::vector<std::unique_ptr<webrtc::DesktopFrame>> frames;
74 frames.push_back( 74 frames.push_back(
75 LoadDesktopFrameFromPng(test_data_path.AppendASCII("test_frame1.png"))); 75 LoadDesktopFrameFromPng(test_data_path.AppendASCII("test_frame1.png")));
76 frames.push_back( 76 frames.push_back(
77 LoadDesktopFrameFromPng(test_data_path.AppendASCII("test_frame2.png"))); 77 LoadDesktopFrameFromPng(test_data_path.AppendASCII("test_frame2.png")));
78 return new CyclicFrameGenerator(std::move(frames)); 78 return new CyclicFrameGenerator(std::move(frames));
79 } 79 }
80 80
81 CyclicFrameGenerator::CyclicFrameGenerator( 81 CyclicFrameGenerator::CyclicFrameGenerator(
82 std::vector<scoped_ptr<webrtc::DesktopFrame>> reference_frames) 82 std::vector<std::unique_ptr<webrtc::DesktopFrame>> reference_frames)
83 : reference_frames_(std::move(reference_frames)), 83 : reference_frames_(std::move(reference_frames)),
84 clock_(&default_tick_clock_), 84 clock_(&default_tick_clock_),
85 started_time_(clock_->NowTicks()) { 85 started_time_(clock_->NowTicks()) {
86 CHECK(!reference_frames_.empty()); 86 CHECK(!reference_frames_.empty());
87 screen_size_ = reference_frames_[0]->size(); 87 screen_size_ = reference_frames_[0]->size();
88 for (const auto& frame : reference_frames_) { 88 for (const auto& frame : reference_frames_) {
89 CHECK(screen_size_.equals(frame->size())) 89 CHECK(screen_size_.equals(frame->size()))
90 << "All reference frames should have the same size."; 90 << "All reference frames should have the same size.";
91 } 91 }
92 } 92 }
93 93
94 CyclicFrameGenerator::~CyclicFrameGenerator() {} 94 CyclicFrameGenerator::~CyclicFrameGenerator() {}
95 95
96 void CyclicFrameGenerator::SetTickClock(base::TickClock* tick_clock) { 96 void CyclicFrameGenerator::SetTickClock(base::TickClock* tick_clock) {
97 clock_ = tick_clock; 97 clock_ = tick_clock;
98 started_time_ = clock_->NowTicks(); 98 started_time_ = clock_->NowTicks();
99 } 99 }
100 100
101 scoped_ptr<webrtc::DesktopFrame> CyclicFrameGenerator::GenerateFrame( 101 std::unique_ptr<webrtc::DesktopFrame> CyclicFrameGenerator::GenerateFrame(
102 webrtc::SharedMemoryFactory* shared_memory_factory) { 102 webrtc::SharedMemoryFactory* shared_memory_factory) {
103 base::TimeTicks now = clock_->NowTicks(); 103 base::TimeTicks now = clock_->NowTicks();
104 int reference_frame = 104 int reference_frame =
105 ((now - started_time_) / frame_cycle_period_) % reference_frames_.size(); 105 ((now - started_time_) / frame_cycle_period_) % reference_frames_.size();
106 bool cursor_state = ((now - started_time_) / cursor_blink_period_) % 2; 106 bool cursor_state = ((now - started_time_) / cursor_blink_period_) % 2;
107 107
108 scoped_ptr<webrtc::DesktopFrame> frame( 108 std::unique_ptr<webrtc::DesktopFrame> frame(
109 new webrtc::BasicDesktopFrame(screen_size_)); 109 new webrtc::BasicDesktopFrame(screen_size_));
110 frame->CopyPixelsFrom(*reference_frames_[reference_frame], 110 frame->CopyPixelsFrom(*reference_frames_[reference_frame],
111 webrtc::DesktopVector(), 111 webrtc::DesktopVector(),
112 webrtc::DesktopRect::MakeSize(screen_size_)); 112 webrtc::DesktopRect::MakeSize(screen_size_));
113 113
114 // Render the cursor. 114 // Render the cursor.
115 webrtc::DesktopRect cursor_rect = 115 webrtc::DesktopRect cursor_rect =
116 webrtc::DesktopRect::MakeXYWH(20, 20, 2, 20); 116 webrtc::DesktopRect::MakeXYWH(20, 20, 2, 20);
117 if (cursor_state) { 117 if (cursor_state) {
118 DrawRect(frame.get(), cursor_rect, 0); 118 DrawRect(frame.get(), cursor_rect, 0);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 196 }
197 197
198 if (!generated_frames_info_.count(frame_id)) 198 if (!generated_frames_info_.count(frame_id))
199 LOG(FATAL) << "Barcode contains unknown frame_id: " << frame_id; 199 LOG(FATAL) << "Barcode contains unknown frame_id: " << frame_id;
200 200
201 return generated_frames_info_[frame_id]; 201 return generated_frames_info_[frame_id];
202 } 202 }
203 203
204 } // namespace test 204 } // namespace test
205 } // namespace remoting 205 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/cyclic_frame_generator.h ('k') | remoting/test/fake_network_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698