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

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

Issue 2798413002: stop using copyPixelsTo -- deprecated (Closed)
Patch Set: support dst_stride being signed Created 3 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 | « no previous file | no next file » | 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/frame_generator_util.h" 5 #include "remoting/test/frame_generator_util.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 "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
13 #include "ui/gfx/codec/png_codec.h" 13 #include "ui/gfx/codec/png_codec.h"
14 14
15 namespace {
16 // dst_stride is int, not size_t, as it may be negative for inverted (in Y)
17 // images.
18 void CopyPixelsToBuffer(const SkBitmap& src,
19 uint8_t* dst_pixels,
20 int dst_stride) {
21 SkBitmap tmp(src);
22 tmp.lockPixels();
23 const char* src_pixels = static_cast<const char*>(tmp.getPixels());
24 size_t src_stride = tmp.rowBytes();
25 // Only need to copy the important parts of the row.
26 size_t bytes_per_row = tmp.width() * tmp.bytesPerPixel();
27 for (int y = 0; y < tmp.height(); ++y) {
28 memcpy(dst_pixels, src_pixels, bytes_per_row);
29 src_pixels += src_stride;
30 dst_pixels += dst_stride;
31 }
32 }
33 } // namespace
34
15 namespace remoting { 35 namespace remoting {
16 namespace test { 36 namespace test {
17 37
18 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( 38 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng(
19 const char* name) { 39 const char* name) {
20 base::FilePath file_path; 40 base::FilePath file_path;
21 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 41 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
22 file_path = file_path.AppendASCII("remoting"); 42 file_path = file_path.AppendASCII("remoting");
23 file_path = file_path.AppendASCII("test"); 43 file_path = file_path.AppendASCII("test");
24 file_path = file_path.AppendASCII("data"); 44 file_path = file_path.AppendASCII("data");
25 file_path = file_path.AppendASCII(name); 45 file_path = file_path.AppendASCII(name);
26 46
27 std::string file_content; 47 std::string file_content;
28 if (!base::ReadFileToString(file_path, &file_content)) 48 if (!base::ReadFileToString(file_path, &file_content))
29 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII() 49 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII()
30 << ". Please run remoting/test/data/download.sh"; 50 << ". Please run remoting/test/data/download.sh";
31 SkBitmap bitmap; 51 SkBitmap bitmap;
32 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()), 52 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()),
33 file_content.size(), &bitmap); 53 file_content.size(), &bitmap);
34 std::unique_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( 54 std::unique_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(
35 webrtc::DesktopSize(bitmap.width(), bitmap.height()))); 55 webrtc::DesktopSize(bitmap.width(), bitmap.height())));
36 bitmap.copyPixelsTo(frame->data(), 56 CopyPixelsToBuffer(bitmap, frame->data(), frame->stride());
37 frame->stride() * frame->size().height(),
38 frame->stride());
39 return frame; 57 return frame;
40 } 58 }
41 59
42 void DrawRect(webrtc::DesktopFrame* frame, 60 void DrawRect(webrtc::DesktopFrame* frame,
43 webrtc::DesktopRect rect, 61 webrtc::DesktopRect rect,
44 uint32_t color) { 62 uint32_t color) {
45 for (int y = rect.top(); y < rect.bottom(); ++y) { 63 for (int y = rect.top(); y < rect.bottom(); ++y) {
46 uint32_t* data = reinterpret_cast<uint32_t*>( 64 uint32_t* data = reinterpret_cast<uint32_t*>(
47 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); 65 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y)));
48 for (int x = 0; x < rect.width(); ++x) { 66 for (int x = 0; x < rect.width(); ++x) {
49 data[x] = color; 67 data[x] = color;
50 } 68 }
51 } 69 }
52 } 70 }
53 71
54 } // namespace test 72 } // namespace test
55 } // namespace remoting 73 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698