| OLD | NEW |
| 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/video_frame.h" | 8 #include "media/base/video_frame.h" |
| 7 #include "media/base/video_util.h" | 9 #include "media/base/video_util.h" |
| 8 #include "media/blink/skcanvas_video_renderer.h" | 10 #include "media/blink/skcanvas_video_renderer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/gpu/GrContext.h" |
| 14 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 11 | 15 |
| 12 using media::VideoFrame; | 16 using media::VideoFrame; |
| 13 | 17 |
| 14 namespace media { | 18 namespace media { |
| 15 | 19 |
| 16 static const int kWidth = 320; | 20 static const int kWidth = 320; |
| 17 static const int kHeight = 240; | 21 static const int kHeight = 240; |
| 18 static const gfx::Rect kNaturalRect(0, 0, kWidth, kHeight); | 22 static const gfx::Rect kNaturalRect(0, 0, kWidth, kHeight); |
| 19 | 23 |
| 20 // Helper for filling a |canvas| with a solid |color|. | 24 // Helper for filling a |canvas| with a solid |color|. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 71 |
| 68 // Getters for various frame sizes. | 72 // Getters for various frame sizes. |
| 69 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; } | 73 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; } |
| 70 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; } | 74 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; } |
| 71 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; } | 75 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; } |
| 72 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; } | 76 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; } |
| 73 | 77 |
| 74 // Standard canvas. | 78 // Standard canvas. |
| 75 SkCanvas* target_canvas() { return &target_canvas_; } | 79 SkCanvas* target_canvas() { return &target_canvas_; } |
| 76 | 80 |
| 77 private: | 81 protected: |
| 78 SkCanvasVideoRenderer renderer_; | 82 SkCanvasVideoRenderer renderer_; |
| 79 | 83 |
| 80 scoped_refptr<VideoFrame> natural_frame_; | 84 scoped_refptr<VideoFrame> natural_frame_; |
| 81 scoped_refptr<VideoFrame> larger_frame_; | 85 scoped_refptr<VideoFrame> larger_frame_; |
| 82 scoped_refptr<VideoFrame> smaller_frame_; | 86 scoped_refptr<VideoFrame> smaller_frame_; |
| 83 scoped_refptr<VideoFrame> cropped_frame_; | 87 scoped_refptr<VideoFrame> cropped_frame_; |
| 84 | 88 |
| 85 SkCanvas target_canvas_; | 89 SkCanvas target_canvas_; |
| 86 base::MessageLoop message_loop_; | 90 base::MessageLoop message_loop_; |
| 87 | 91 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); | 493 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); |
| 490 EXPECT_EQ(SK_ColorMAGENTA, | 494 EXPECT_EQ(SK_ColorMAGENTA, |
| 491 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); | 495 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); |
| 492 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); | 496 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); |
| 493 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); | 497 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); |
| 494 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); | 498 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); |
| 495 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 499 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 496 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); | 500 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); |
| 497 } | 501 } |
| 498 | 502 |
| 503 namespace { |
| 504 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { |
| 505 public: |
| 506 void GenTextures(GLsizei n, GLuint* textures) override { |
| 507 DCHECK_EQ(1, n); |
| 508 *textures = 1; |
| 509 } |
| 510 }; |
| 511 void MailboxHoldersReleased(uint32 sync_point) {} |
| 512 } // namespace |
| 513 |
| 514 TEST_F(SkCanvasVideoRendererTest, ContextLost) { |
| 515 skia::RefPtr<const GrGLInterface> null_interface = |
| 516 skia::AdoptRef(GrGLCreateNullInterface()); |
| 517 auto gr_context = skia::AdoptRef(GrContext::Create( |
| 518 kOpenGL_GrBackend, |
| 519 reinterpret_cast<GrBackendContext>(null_interface.get()))); |
| 520 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 521 gr_context->abandonContext(); |
| 522 |
| 523 TestGLES2Interface gles2; |
| 524 Context3D context_3d(&gles2, gr_context.get()); |
| 525 gfx::Size size(kWidth, kHeight); |
| 526 gpu::MailboxHolder mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_RECTANGLE_ARB, |
| 527 0); |
| 528 auto video_frame = VideoFrame::WrapNativeTexture( |
| 529 PIXEL_FORMAT_UYVY, mailbox, base::Bind(MailboxHoldersReleased), size, |
| 530 gfx::Rect(size), size, kNoTimestamp()); |
| 531 |
| 532 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF, |
| 533 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d); |
| 534 } |
| 499 } // namespace media | 535 } // namespace media |
| OLD | NEW |