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

Side by Side Diff: media/renderers/skcanvas_video_renderer_unittest.cc

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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
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 <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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); 513 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6));
513 } 514 }
514 515
515 namespace { 516 namespace {
516 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub { 517 class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
517 public: 518 public:
518 void GenTextures(GLsizei n, GLuint* textures) override { 519 void GenTextures(GLsizei n, GLuint* textures) override {
519 DCHECK_EQ(1, n); 520 DCHECK_EQ(1, n);
520 *textures = 1; 521 *textures = 1;
521 } 522 }
523
524 GLuint CreateProgram() override { return ++program_base_; }
525
526 unsigned program_base_ = 0;
522 }; 527 };
523 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {} 528 void MailboxHoldersReleased(const gpu::SyncToken& sync_token) {}
524 } // namespace 529 } // namespace
525 530
526 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is 531 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is
527 // abandoned. 532 // abandoned.
528 TEST_F(SkCanvasVideoRendererTest, ContextLost) { 533 TEST_F(SkCanvasVideoRendererTest, ContextLost) {
529 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); 534 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface());
530 sk_sp<GrContext> gr_context(GrContext::Create( 535 sk_sp<GrContext> gr_context(GrContext::Create(
531 kOpenGL_GrBackend, 536 kOpenGL_GrBackend,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 588
584 gfx::RectF visible_rect(visible_size.width(), visible_size.height()); 589 gfx::RectF visible_rect(visible_size.width(), visible_size.height());
585 SkPaint paint; 590 SkPaint paint;
586 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0, 591 renderer_.Paint(video_frame, canvas, visible_rect, paint, VIDEO_ROTATION_0,
587 context_3d); 592 context_3d);
588 593
589 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width()); 594 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().width());
590 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height()); 595 EXPECT_EQ(fWidth / 2, renderer_.LastImageDimensionsForTesting().height());
591 } 596 }
592 597
598 // Test that cached resources are restored when gl context is lost and restored.
599 TEST_F(SkCanvasVideoRendererTest, Y16CachedGLResourcesContextRestore) {
600 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface());
601 sk_sp<GrContext> gr_context(GrContext::Create(
602 kOpenGL_GrBackend,
603 reinterpret_cast<GrBackendContext>(null_interface.get())));
604
605 SkCanvas canvas(AllocBitmap(kWidth, kHeight));
606
607 TestGLES2Interface gles2;
608 TestGLES2Interface gl_destination;
609 unsigned texture, texture1, texture2;
610 gl_destination.GenTextures(1, &texture);
611 Context3D context_3d(&gles2, gr_context.get());
612 gfx::Size size(kWidth, kHeight);
613 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder(
614 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D)};
615 auto video_frame = VideoFrame::WrapNativeTextures(
616 PIXEL_FORMAT_Y16, holders, base::Bind(MailboxHoldersReleased), size,
617 gfx::Rect(size), size, kNoTimestamp);
618
619 unsigned program_base_before = gles2.program_base_;
620 renderer_.CopyVideoFrameTexturesToGLTexture(
621 context_3d, &gl_destination, video_frame.get(), texture, GL_R32F,
622 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/);
623 // It is expected that the program for RG8 -> R32F conversion is created.
624 EXPECT_EQ(gles2.program_base_ - program_base_before, 1u);
625
626 gl_destination.GenTextures(1, &texture1);
627 program_base_before = gles2.program_base_;
628 renderer_.CopyVideoFrameTexturesToGLTexture(
629 context_3d, &gl_destination, video_frame.get(), texture, GL_R32F,
630 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/);
631 // The program is expected to be cached - no new program created.
632 EXPECT_EQ(gles2.program_base_ - program_base_before, 0u);
633
634 gr_context->abandonContext();
635
636 sk_sp<const GrGLInterface> null_interface_1(GrGLCreateNullInterface());
637 sk_sp<GrContext> gr_context_1(GrContext::Create(
638 kOpenGL_GrBackend,
639 reinterpret_cast<GrBackendContext>(null_interface_1.get())));
640
641 gl_destination.GenTextures(1, &texture2);
642 Context3D context_3d_1(&gles2, gr_context_1.get());
643 program_base_before = gles2.program_base_;
644 renderer_.CopyVideoFrameTexturesToGLTexture(
645 context_3d_1, &gl_destination, video_frame.get(), texture1, GL_R32F,
646 GL_FLOAT, true /*premultiply_alpha*/, true /*flip_y*/);
647 // As the new context is created, the new program is expected.
648 EXPECT_EQ(gles2.program_base_ - program_base_before, 1u);
649 }
650
593 } // namespace media 651 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/skcanvas_video_renderer.cc ('k') | media/video/gpu_memory_buffer_video_frame_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698