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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
10 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 10 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
| 11 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
11 #include "media/base/timestamp_constants.h" | 12 #include "media/base/timestamp_constants.h" |
12 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
13 #include "media/base/video_util.h" | 14 #include "media/base/video_util.h" |
14 #include "media/renderers/skcanvas_video_renderer.h" | 15 #include "media/renderers/skcanvas_video_renderer.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/libyuv/include/libyuv/convert.h" | 17 #include "third_party/libyuv/include/libyuv/convert.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
18 #include "third_party/skia/include/gpu/GrContext.h" | 19 #include "third_party/skia/include/gpu/GrContext.h" |
19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
20 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); | 506 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); |
506 } | 507 } |
507 | 508 |
508 namespace { | 509 namespace { |
509 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { | 510 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { |
510 public: | 511 public: |
511 void GenTextures(GLsizei n, GLuint* textures) override { | 512 void GenTextures(GLsizei n, GLuint* textures) override { |
512 DCHECK_EQ(1, n); | 513 DCHECK_EQ(1, n); |
513 *textures = 1; | 514 *textures = 1; |
514 } | 515 } |
| 516 const GLubyte* GetString(GLenum name) override { |
| 517 switch (name) { |
| 518 case GL_EXTENSIONS: |
| 519 return reinterpret_cast<const GLubyte*>(""); |
| 520 case GL_SHADING_LANGUAGE_VERSION: |
| 521 return reinterpret_cast<const GLubyte*>("OpenGL ES GLSL ES 1.00"); |
| 522 case GL_VERSION: |
| 523 return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0"); |
| 524 default: |
| 525 return nullptr; |
| 526 } |
| 527 } |
515 }; | 528 }; |
516 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} | 529 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} |
517 } // namespace | 530 } // namespace |
518 | 531 |
519 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is | 532 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is |
520 // abandoned. | 533 // abandoned. |
521 TEST_F(SkCanvasVideoRendererTest, ContextLost) { | 534 TEST_F(SkCanvasVideoRendererTest, ContextLost) { |
522 skia::RefPtr<const GrGLInterface> null_interface = | |
523 skia::AdoptRef(GrGLCreateNullInterface()); | |
524 auto gr_context = skia::AdoptRef(GrContext::Create( | |
525 kOpenGL_GrBackend, | |
526 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
527 gr_context->abandonContext(); | |
528 | |
529 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); | 535 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); |
530 | 536 |
531 TestGLES2Interface gles2; | 537 TestGLES2Interface gles2; |
| 538 |
| 539 skia::RefPtr<GrGLInterface> gl_interface = skia::AdoptRef(new GrGLInterface); |
| 540 skia_bindings::InitGLES2InterfaceBindings(gl_interface.get(), &gles2); |
| 541 auto gr_context = skia::AdoptRef(GrContext::Create( |
| 542 kOpenGL_GrBackend, |
| 543 reinterpret_cast<GrBackendContext>(gl_interface.get()))); |
| 544 gr_context->abandonContext(); |
| 545 |
532 Context3D context_3d(&gles2, gr_context.get()); | 546 Context3D context_3d(&gles2, gr_context.get()); |
533 gfx::Size size(kWidth, kHeight); | 547 gfx::Size size(kWidth, kHeight); |
534 gpu::MailboxHolder mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), | 548 gpu::MailboxHolder mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), |
535 GL_TEXTURE_RECTANGLE_ARB); | 549 GL_TEXTURE_RECTANGLE_ARB); |
536 auto video_frame = VideoFrame::WrapNativeTexture( | 550 auto video_frame = VideoFrame::WrapNativeTexture( |
537 PIXEL_FORMAT_UYVY, mailbox, base::Bind(MailboxHoldersReleased), size, | 551 PIXEL_FORMAT_UYVY, mailbox, base::Bind(MailboxHoldersReleased), size, |
538 gfx::Rect(size), size, kNoTimestamp()); | 552 gfx::Rect(size), size, kNoTimestamp()); |
539 | 553 |
540 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF, | 554 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF, |
541 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d); | 555 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d); |
542 } | 556 } |
543 } // namespace media | 557 } // namespace media |
OLD | NEW |