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

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 #include "ui/gfx/geometry/rect_f.h" 16 #include "ui/gfx/geometry/rect_f.h"
13 17
14 using media::VideoFrame; 18 using media::VideoFrame;
15 19
16 namespace media { 20 namespace media {
17 21
18 static const int kWidth = 320; 22 static const int kWidth = 320;
19 static const int kHeight = 240; 23 static const int kHeight = 240;
20 static const gfx::RectF kNaturalRect(kWidth, kHeight); 24 static const gfx::RectF kNaturalRect(kWidth, kHeight);
21 25
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 73
70 // Getters for various frame sizes. 74 // Getters for various frame sizes.
71 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; } 75 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; }
72 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; } 76 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; }
73 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; } 77 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; }
74 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; } 78 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; }
75 79
76 // Standard canvas. 80 // Standard canvas.
77 SkCanvas* target_canvas() { return &target_canvas_; } 81 SkCanvas* target_canvas() { return &target_canvas_; }
78 82
79 private: 83 protected:
80 SkCanvasVideoRenderer renderer_; 84 SkCanvasVideoRenderer renderer_;
81 85
82 scoped_refptr<VideoFrame> natural_frame_; 86 scoped_refptr<VideoFrame> natural_frame_;
83 scoped_refptr<VideoFrame> larger_frame_; 87 scoped_refptr<VideoFrame> larger_frame_;
84 scoped_refptr<VideoFrame> smaller_frame_; 88 scoped_refptr<VideoFrame> smaller_frame_;
85 scoped_refptr<VideoFrame> cropped_frame_; 89 scoped_refptr<VideoFrame> cropped_frame_;
86 90
87 SkCanvas target_canvas_; 91 SkCanvas target_canvas_;
88 base::MessageLoop message_loop_; 92 base::MessageLoop message_loop_;
89 93
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 483 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0));
480 EXPECT_EQ(SK_ColorMAGENTA, 484 EXPECT_EQ(SK_ColorMAGENTA,
481 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 485 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1));
482 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 486 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1));
483 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 487 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2));
484 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 488 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2));
485 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 489 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1));
486 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 490 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1));
487 } 491 }
488 492
493 namespace {
494 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
495 public:
496 void GenTextures(GLsizei n, GLuint* textures) override {
497 DCHECK_EQ(1, n);
498 *textures = 1;
499 }
500 };
501 void MailboxHoldersReleased(uint32 sync_point) {}
502 } // namespace
503
504 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is
505 // abandoned.
506 TEST_F(SkCanvasVideoRendererTest, ContextLost) {
507 skia::RefPtr<const GrGLInterface> null_interface =
508 skia::AdoptRef(GrGLCreateNullInterface());
509 auto gr_context = skia::AdoptRef(GrContext::Create(
510 kOpenGL_GrBackend,
511 reinterpret_cast<GrBackendContext>(null_interface.get())));
512 gr_context->abandonContext();
513
514 SkCanvas canvas(AllocBitmap(kWidth, kHeight));
515
516 TestGLES2Interface gles2;
517 Context3D context_3d(&gles2, gr_context.get());
518 gfx::Size size(kWidth, kHeight);
519 gpu::MailboxHolder mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_RECTANGLE_ARB,
520 0);
521 auto video_frame = VideoFrame::WrapNativeTexture(
522 PIXEL_FORMAT_UYVY, mailbox, base::Bind(MailboxHoldersReleased), size,
523 gfx::Rect(size), size, kNoTimestamp());
524
525 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF,
526 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d);
527 }
489 } // namespace media 528 } // 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