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

Side by Side Diff: media/blink/skcanvas_video_renderer_unittest.cc

Issue 1325173005: Video to canvas: don't draw if a SkImage can't be created. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on master. Created 5 years, 3 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 | « media/blink/skcanvas_video_renderer.cc ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/GLES2/gl2extchromium.h"
7 #include "gpu/command_buffer/client/gles2_interface_stub.h"
6 #include "media/base/timestamp_constants.h" 8 #include "media/base/timestamp_constants.h"
7 #include "media/base/video_frame.h" 9 #include "media/base/video_frame.h"
8 #include "media/base/video_util.h" 10 #include "media/base/video_util.h"
9 #include "media/blink/skcanvas_video_renderer.h" 11 #include "media/blink/skcanvas_video_renderer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/gpu/GrContext.h"
15 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
12 16
13 using media::VideoFrame; 17 using media::VideoFrame;
14 18
15 namespace media { 19 namespace media {
16 20
17 static const int kWidth = 320; 21 static const int kWidth = 320;
18 static const int kHeight = 240; 22 static const int kHeight = 240;
19 static const gfx::Rect kNaturalRect(0, 0, kWidth, kHeight); 23 static const gfx::Rect kNaturalRect(0, 0, kWidth, kHeight);
20 24
21 // Helper for filling a |canvas| with a solid |color|. 25 // Helper for filling a |canvas| with a solid |color|.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 72
69 // Getters for various frame sizes. 73 // Getters for various frame sizes.
70 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; } 74 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; }
71 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; } 75 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; }
72 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; } 76 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; }
73 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; } 77 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; }
74 78
75 // Standard canvas. 79 // Standard canvas.
76 SkCanvas* target_canvas() { return &target_canvas_; } 80 SkCanvas* target_canvas() { return &target_canvas_; }
77 81
78 private: 82 protected:
79 SkCanvasVideoRenderer renderer_; 83 SkCanvasVideoRenderer renderer_;
80 84
81 scoped_refptr<VideoFrame> natural_frame_; 85 scoped_refptr<VideoFrame> natural_frame_;
82 scoped_refptr<VideoFrame> larger_frame_; 86 scoped_refptr<VideoFrame> larger_frame_;
83 scoped_refptr<VideoFrame> smaller_frame_; 87 scoped_refptr<VideoFrame> smaller_frame_;
84 scoped_refptr<VideoFrame> cropped_frame_; 88 scoped_refptr<VideoFrame> cropped_frame_;
85 89
86 SkCanvas target_canvas_; 90 SkCanvas target_canvas_;
87 base::MessageLoop message_loop_; 91 base::MessageLoop message_loop_;
88 92
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 494 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0));
491 EXPECT_EQ(SK_ColorMAGENTA, 495 EXPECT_EQ(SK_ColorMAGENTA,
492 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 496 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1));
493 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 497 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1));
494 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 498 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2));
495 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 499 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2));
496 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 500 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1));
497 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 501 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1));
498 } 502 }
499 503
504 namespace {
505 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
506 public:
507 void GenTextures(GLsizei n, GLuint* textures) override {
508 DCHECK_EQ(1, n);
509 *textures = 1;
510 }
511 };
512 void MailboxHoldersReleased(uint32 sync_point) {}
513 } // namespace
514
515 TEST_F(SkCanvasVideoRendererTest, ContextLost) {
Justin Novosad 2015/09/08 19:14:17 Add a comment to say that this test passes by not
Daniele Castagna 2015/09/08 19:24:24 Done.
516 skia::RefPtr<const GrGLInterface> null_interface =
517 skia::AdoptRef(GrGLCreateNullInterface());
518 auto gr_context = skia::AdoptRef(GrContext::Create(
519 kOpenGL_GrBackend,
520 reinterpret_cast<GrBackendContext>(null_interface.get())));
521 SkCanvas canvas(AllocBitmap(kWidth, kHeight));
522 gr_context->abandonContext();
Justin Novosad 2015/09/08 19:14:17 Nit: I would have put this after constructing Cont
Daniele Castagna 2015/09/08 19:24:24 Done.
523
524 TestGLES2Interface gles2;
525 Context3D context_3d(&gles2, gr_context.get());
526 gfx::Size size(kWidth, kHeight);
527 gpu::MailboxHolder mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_RECTANGLE_ARB,
528 0);
529 auto video_frame = VideoFrame::WrapNativeTexture(
530 PIXEL_FORMAT_UYVY, mailbox, base::Bind(MailboxHoldersReleased), size,
531 gfx::Rect(size), size, kNoTimestamp());
532
533 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF,
534 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d);
535 }
500 } // namespace media 536 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/skcanvas_video_renderer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698