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

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

Issue 2798413002: stop using copyPixelsTo -- deprecated (Closed)
Patch Set: 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 void CopyPixelsToBuffer(const SkBitmap& src,
17 void* dst_pixels,
18 size_t dst_stride) {
Sergey Ulanov 2017/04/06 19:04:28 In webrtc::DesktopFrame stride may be negative, so
reed1 2017/04/07 12:28:13 The old logic cast it to size_t when it called cop
Sergey Ulanov 2017/04/07 18:05:12 It's used for the case when rows are stored from b
reed1 2017/04/07 21:11:25 Got it. The old code-path (the method being deprec
19 SkBitmap tmp(src);
20 tmp.lockPixels();
21 const char* src_pixels = static_cast<const char*>(tmp.getPixels());
22 size_t src_stride = tmp.rowBytes();
23 // only need to copy the important parts of the row
Sergey Ulanov 2017/04/06 19:04:28 I don't think this comment is necessary, but if yo
reed1 2017/04/07 12:28:13 Done.
24 size_t bytes_per_row = tmp.width() * tmp.bytesPerPixel();
25 DCHECK(bytes_per_row <= dst_stride);
Sergey Ulanov 2017/04/06 19:04:28 stride may be negative for webrtc::DesktopFrame, s
reed1 2017/04/07 12:28:13 Should this fail if it sees a negative?
Sergey Ulanov 2017/04/07 18:05:12 No.
reed1 2017/04/07 21:11:25 Done.
26 for (int y = 0; y < tmp.height(); ++y) {
27 memcpy(dst_pixels, src_pixels, bytes_per_row);
28 src_pixels += src_stride;
29 dst_pixels = (char*)dst_pixels + dst_stride;
Sergey Ulanov 2017/04/06 19:04:28 I don't think you need the cast here. dst_pixel
reed1 2017/04/07 12:28:13 dst_pixels is void*, so it cannot perform += witho
Sergey Ulanov 2017/04/07 18:05:12 Maybe change it to uint8_t*? It's the type used fo
reed1 2017/04/07 21:11:25 Done.
30 }
31 }
32 }
Sergey Ulanov 2017/04/06 19:04:28 // namespace
reed1 2017/04/07 12:28:13 Done.
33
15 namespace remoting { 34 namespace remoting {
16 namespace test { 35 namespace test {
17 36
18 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( 37 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng(
19 const char* name) { 38 const char* name) {
20 base::FilePath file_path; 39 base::FilePath file_path;
21 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 40 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
22 file_path = file_path.AppendASCII("remoting"); 41 file_path = file_path.AppendASCII("remoting");
23 file_path = file_path.AppendASCII("test"); 42 file_path = file_path.AppendASCII("test");
24 file_path = file_path.AppendASCII("data"); 43 file_path = file_path.AppendASCII("data");
25 file_path = file_path.AppendASCII(name); 44 file_path = file_path.AppendASCII(name);
26 45
27 std::string file_content; 46 std::string file_content;
28 if (!base::ReadFileToString(file_path, &file_content)) 47 if (!base::ReadFileToString(file_path, &file_content))
29 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII() 48 LOG(FATAL) << "Failed to read " << file_path.MaybeAsASCII()
30 << ". Please run remoting/test/data/download.sh"; 49 << ". Please run remoting/test/data/download.sh";
31 SkBitmap bitmap; 50 SkBitmap bitmap;
32 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()), 51 gfx::PNGCodec::Decode(reinterpret_cast<const uint8_t*>(file_content.data()),
33 file_content.size(), &bitmap); 52 file_content.size(), &bitmap);
34 std::unique_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame( 53 std::unique_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(
35 webrtc::DesktopSize(bitmap.width(), bitmap.height()))); 54 webrtc::DesktopSize(bitmap.width(), bitmap.height())));
36 bitmap.copyPixelsTo(frame->data(), 55 CopyPixelsToBuffer(bitmap, frame->data(), frame->stride());
37 frame->stride() * frame->size().height(),
38 frame->stride());
39 return frame; 56 return frame;
40 } 57 }
41 58
42 void DrawRect(webrtc::DesktopFrame* frame, 59 void DrawRect(webrtc::DesktopFrame* frame,
43 webrtc::DesktopRect rect, 60 webrtc::DesktopRect rect,
44 uint32_t color) { 61 uint32_t color) {
45 for (int y = rect.top(); y < rect.bottom(); ++y) { 62 for (int y = rect.top(); y < rect.bottom(); ++y) {
46 uint32_t* data = reinterpret_cast<uint32_t*>( 63 uint32_t* data = reinterpret_cast<uint32_t*>(
47 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); 64 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y)));
48 for (int x = 0; x < rect.width(); ++x) { 65 for (int x = 0; x < rect.width(); ++x) {
49 data[x] = color; 66 data[x] = color;
50 } 67 }
51 } 68 }
52 } 69 }
53 70
54 } // namespace test 71 } // namespace test
55 } // namespace remoting 72 } // 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