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 #include <GLES3/gl3.h> |
6 | 7 |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
10 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 11 #include "gpu/command_buffer/client/gles2_interface_stub.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" |
(...skipping 489 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 |
| 517 GLuint CreateProgram() override { return ++program_base_; } |
| 518 |
| 519 unsigned program_base_ = 0; |
515 }; | 520 }; |
516 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} | 521 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} |
517 } // namespace | 522 } // namespace |
518 | 523 |
519 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is | 524 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is |
520 // abandoned. | 525 // abandoned. |
521 TEST_F(SkCanvasVideoRendererTest, ContextLost) { | 526 TEST_F(SkCanvasVideoRendererTest, ContextLost) { |
522 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | 527 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); |
523 sk_sp<GrContext> gr_context(GrContext::Create( | 528 sk_sp<GrContext> gr_context(GrContext::Create( |
524 kOpenGL_GrBackend, | 529 kOpenGL_GrBackend, |
525 reinterpret_cast<GrBackendContext>(null_interface.get()))); | 530 reinterpret_cast<GrBackendContext>(null_interface.get()))); |
526 gr_context->abandonContext(); | 531 gr_context->abandonContext(); |
527 | 532 |
528 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); | 533 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); |
529 | 534 |
530 TestGLES2Interface gles2; | 535 TestGLES2Interface gles2; |
531 Context3D context_3d(&gles2, gr_context.get()); | 536 Context3D context_3d(&gles2, gr_context.get()); |
532 gfx::Size size(kWidth, kHeight); | 537 gfx::Size size(kWidth, kHeight); |
533 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( | 538 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( |
534 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)}; | 539 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)}; |
535 auto video_frame = VideoFrame::WrapNativeTextures( | 540 auto video_frame = VideoFrame::WrapNativeTextures( |
536 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size, | 541 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size, |
537 gfx::Rect(size), size, kNoTimestamp); | 542 gfx::Rect(size), size, kNoTimestamp); |
538 | 543 |
539 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF, | 544 renderer_.Paint(video_frame, &canvas, kNaturalRect, 0xFF, |
540 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d); | 545 SkXfermode::kSrcOver_Mode, VIDEO_ROTATION_90, context_3d); |
541 } | 546 } |
| 547 |
| 548 // Test that cached resources are restored when gl context is lost and restored. |
| 549 TEST_F(SkCanvasVideoRendererTest, Y16CachedGLResourcesContextRestore) { |
| 550 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); |
| 551 sk_sp<GrContext> gr_context(GrContext::Create( |
| 552 kOpenGL_GrBackend, |
| 553 reinterpret_cast<GrBackendContext>(null_interface.get()))); |
| 554 |
| 555 SkCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 556 |
| 557 TestGLES2Interface gles2; |
| 558 TestGLES2Interface gl_destination; |
| 559 unsigned texture, texture1, texture2; |
| 560 gl_destination.GenTextures(1, &texture); |
| 561 Context3D context_3d(&gles2, gr_context.get()); |
| 562 gfx::Size size(kWidth, kHeight); |
| 563 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( |
| 564 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D)}; |
| 565 auto video_frame = VideoFrame::WrapNativeTextures( |
| 566 PIXEL_FORMAT_Y16, holders, base::Bind(MailboxHoldersReleased), size, |
| 567 gfx::Rect(size), size, kNoTimestamp); |
| 568 |
| 569 unsigned program_base_before = gles2.program_base_; |
| 570 renderer_.CopyVideoFrameTexturesToGLTexture( |
| 571 context_3d, &gl_destination, video_frame.get(), texture, GL_R32F, |
| 572 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/); |
| 573 // It is expected that the program for RG8 -> R32F conversion is created. |
| 574 EXPECT_EQ(gles2.program_base_ - program_base_before, 1u); |
| 575 |
| 576 gl_destination.GenTextures(1, &texture1); |
| 577 program_base_before = gles2.program_base_; |
| 578 renderer_.CopyVideoFrameTexturesToGLTexture( |
| 579 context_3d, &gl_destination, video_frame.get(), texture, GL_R32F, |
| 580 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/); |
| 581 // The program is expected to be cached - no new program created. |
| 582 EXPECT_EQ(gles2.program_base_ - program_base_before, 0u); |
| 583 |
| 584 gr_context->abandonContext(); |
| 585 |
| 586 sk_sp<const GrGLInterface> null_interface_1(GrGLCreateNullInterface()); |
| 587 sk_sp<GrContext> gr_context_1(GrContext::Create( |
| 588 kOpenGL_GrBackend, |
| 589 reinterpret_cast<GrBackendContext>(null_interface_1.get()))); |
| 590 |
| 591 gl_destination.GenTextures(1, &texture2); |
| 592 Context3D context_3d_1(&gles2, gr_context_1.get()); |
| 593 program_base_before = gles2.program_base_; |
| 594 renderer_.CopyVideoFrameTexturesToGLTexture( |
| 595 context_3d_1, &gl_destination, video_frame.get(), texture1, GL_R32F, |
| 596 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/); |
| 597 // As the new context is created, the new program is expected. |
| 598 EXPECT_EQ(gles2.program_base_ - program_base_before, 1u); |
| 599 } |
| 600 |
542 } // namespace media | 601 } // namespace media |
OLD | NEW |