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