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

Side by Side Diff: content/renderer/media/canvas_capture_handler_unittest.cc

Issue 1737253002: Handle Alpha channel in Canvas capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "content/child/child_process.h" 8 #include "content/child/child_process.h"
9 #include "content/renderer/media/canvas_capture_handler.h" 9 #include "content/renderer/media/canvas_capture_handler.h"
10 #include "content/renderer/media/media_stream_video_capturer_source.h" 10 #include "content/renderer/media/media_stream_video_capturer_source.h"
11 #include "media/base/limits.h" 11 #include "media/base/limits.h"
12 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
17 #include "third_party/WebKit/public/platform/WebSize.h" 17 #include "third_party/WebKit/public/platform/WebSize.h"
18 #include "third_party/WebKit/public/web/WebHeap.h" 18 #include "third_party/WebKit/public/web/WebHeap.h"
19 19
20 using ::testing::_; 20 using ::testing::_;
21 using ::testing::InSequence; 21 using ::testing::InSequence;
22 using ::testing::Mock; 22 using ::testing::Mock;
23 using ::testing::SaveArg; 23 using ::testing::SaveArg;
24 using ::testing::Test; 24 using ::testing::Test;
25 25
26 namespace content { 26 namespace content {
27 27
28 namespace {
29
28 static const int kTestCanvasCaptureWidth = 320; 30 static const int kTestCanvasCaptureWidth = 320;
29 static const int kTestCanvasCaptureHeight = 240; 31 static const int kTestCanvasCaptureHeight = 240;
30 static const double kTestCanvasCaptureFramesPerSecond = 55.5; 32 static const double kTestCanvasCaptureFramesPerSecond = 55.5;
31 33
32 static const int kTestCanvasCaptureFrameWidth = 2; 34 static const int kTestCanvasCaptureFrameWidth = 2;
33 static const int kTestCanvasCaptureFrameHeight = 2; 35 static const int kTestCanvasCaptureFrameHeight = 2;
34 static const int kTestCanvasCaptureFrameErrorTolerance = 2; 36 static const int kTestCanvasCaptureFrameErrorTolerance = 2;
37 static const int kTestAlphaValue = 175;
35 38
36 ACTION_P(RunClosure, closure) { 39 ACTION_P(RunClosure, closure) {
37 closure.Run(); 40 closure.Run();
38 } 41 }
39 42
43 } // namespace
44
40 class CanvasCaptureHandlerTest : public Test { 45 class CanvasCaptureHandlerTest : public Test {
41 public: 46 public:
42 CanvasCaptureHandlerTest() {} 47 CanvasCaptureHandlerTest() {}
43 48
44 void SetUp() override { 49 void SetUp() override {
45 canvas_capture_handler_.reset( 50 canvas_capture_handler_.reset(
46 CanvasCaptureHandler::CreateCanvasCaptureHandler( 51 CanvasCaptureHandler::CreateCanvasCaptureHandler(
47 blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight), 52 blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight),
48 kTestCanvasCaptureFramesPerSecond, message_loop_.task_runner(), 53 kTestCanvasCaptureFramesPerSecond, message_loop_.task_runner(),
49 &track_)); 54 &track_));
(...skipping 23 matching lines...) Expand all
73 } 78 }
74 79
75 MOCK_METHOD1(DoOnRunning, void(bool)); 80 MOCK_METHOD1(DoOnRunning, void(bool));
76 void OnRunning(bool state) { DoOnRunning(state); } 81 void OnRunning(bool state) { DoOnRunning(state); }
77 82
78 // Verify returned frames. 83 // Verify returned frames.
79 static skia::RefPtr<SkImage> GenerateTestImage() { 84 static skia::RefPtr<SkImage> GenerateTestImage() {
80 SkBitmap testBitmap; 85 SkBitmap testBitmap;
81 testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth, 86 testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth,
82 kTestCanvasCaptureFrameHeight); 87 kTestCanvasCaptureFrameHeight);
83 testBitmap.eraseColor(SK_ColorBLUE); 88 testBitmap.eraseARGB(kTestAlphaValue, 30, 60, 200);
84 return skia::AdoptRef(SkImage::NewFromBitmap(testBitmap)); 89 return skia::AdoptRef(SkImage::NewFromBitmap(testBitmap));
85 } 90 }
86 91
87 void OnVerifyDeliveredFrame( 92 void OnVerifyDeliveredFrame(
88 const scoped_refptr<media::VideoFrame>& video_frame, 93 const scoped_refptr<media::VideoFrame>& video_frame,
89 base::TimeTicks estimated_capture_time) { 94 base::TimeTicks estimated_capture_time) {
90 EXPECT_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); 95 EXPECT_EQ(media::PIXEL_FORMAT_YV12A, video_frame->format());
91 const gfx::Size& size = video_frame->coded_size(); 96 const gfx::Size& size = video_frame->coded_size();
92 EXPECT_EQ(kTestCanvasCaptureFrameWidth, size.width()); 97 EXPECT_EQ(kTestCanvasCaptureFrameWidth, size.width());
93 EXPECT_EQ(kTestCanvasCaptureFrameHeight, size.height()); 98 EXPECT_EQ(kTestCanvasCaptureFrameHeight, size.height());
94 const uint8_t* y_plane = video_frame->data(0); 99 const uint8_t* y_plane = video_frame->data(media::VideoFrame::kYPlane);
95 EXPECT_NEAR(41, y_plane[0], kTestCanvasCaptureFrameErrorTolerance); 100 EXPECT_NEAR(74, y_plane[0], kTestCanvasCaptureFrameErrorTolerance);
96 const uint8_t* u_plane = video_frame->data(1); 101 const uint8_t* u_plane = video_frame->data(media::VideoFrame::kUPlane);
97 EXPECT_NEAR(239, u_plane[0], kTestCanvasCaptureFrameErrorTolerance); 102 EXPECT_NEAR(193, u_plane[0], kTestCanvasCaptureFrameErrorTolerance);
98 const uint8_t* v_plane = video_frame->data(2); 103 const uint8_t* v_plane = video_frame->data(media::VideoFrame::kVPlane);
99 EXPECT_NEAR(110, v_plane[0], kTestCanvasCaptureFrameErrorTolerance); 104 EXPECT_NEAR(105, v_plane[0], kTestCanvasCaptureFrameErrorTolerance);
105 const uint8_t* a_plane = video_frame->data(media::VideoFrame::kAPlane);
106 EXPECT_EQ(kTestAlphaValue, a_plane[0]);
100 } 107 }
101 108
102 blink::WebMediaStreamTrack track_; 109 blink::WebMediaStreamTrack track_;
103 // The Class under test. Needs to be scoped_ptr to force its destruction. 110 // The Class under test. Needs to be scoped_ptr to force its destruction.
104 scoped_ptr<CanvasCaptureHandler> canvas_capture_handler_; 111 scoped_ptr<CanvasCaptureHandler> canvas_capture_handler_;
105 112
106 protected: 113 protected:
107 media::VideoCapturerSource* GetVideoCapturerSource( 114 media::VideoCapturerSource* GetVideoCapturerSource(
108 MediaStreamVideoCapturerSource* ms_source) { 115 MediaStreamVideoCapturerSource* ms_source) {
109 return ms_source->source_.get(); 116 return ms_source->source_.get();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 media::VideoCapturerSource* source = 200 media::VideoCapturerSource* source =
194 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( 201 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>(
195 track_.source().extraData())); 202 track_.source().extraData()));
196 EXPECT_TRUE(source != nullptr); 203 EXPECT_TRUE(source != nullptr);
197 EXPECT_TRUE(canvas_capture_handler_->needsNewFrame()); 204 EXPECT_TRUE(canvas_capture_handler_->needsNewFrame());
198 source->StopCapture(); 205 source->StopCapture();
199 EXPECT_FALSE(canvas_capture_handler_->needsNewFrame()); 206 EXPECT_FALSE(canvas_capture_handler_->needsNewFrame());
200 } 207 }
201 208
202 } // namespace content 209 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698