Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/gpu/surface_texture_gl_owner.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/bind.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "ui/gl/gl_bindings.h" | |
| 16 #include "ui/gl/gl_context_egl.h" | |
| 17 #include "ui/gl/gl_implementation.h" | |
| 18 #include "ui/gl/gl_share_group.h" | |
| 19 #include "ui/gl/gl_surface_egl.h" | |
| 20 #include "ui/gl/init/gl_factory.h" | |
| 21 #include "ui/gl/init/gl_initializer.h" | |
| 22 | |
| 23 using testing::Invoke; | |
| 24 using testing::NiceMock; | |
| 25 using testing::_; | |
| 26 | |
| 27 namespace media { | |
| 28 | |
| 29 class SurfaceTextureGLOwnerTest : public testing::Test { | |
| 30 public: | |
| 31 SurfaceTextureGLOwnerTest() {} | |
| 32 ~SurfaceTextureGLOwnerTest() override {} | |
| 33 | |
| 34 protected: | |
| 35 void SetUp() override { | |
| 36 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, | |
| 37 false, false, false); | |
| 38 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240)); | |
| 39 surface_->Initialize(); | |
| 40 | |
| 41 share_group_ = new gl::GLShareGroup; | |
| 42 context_ = new gl::GLContextEGL(share_group_.get()); | |
| 43 context_->Initialize(surface_.get(), gl::GLContextAttribs()); | |
| 44 ASSERT_TRUE(context_->MakeCurrent(surface_.get())); | |
| 45 | |
| 46 surface_texture_ = SurfaceTextureGLOwner::Create(); | |
| 47 texture_id_ = surface_texture_->texture_id(); | |
| 48 // Bind and un-bind the texture, since that's required for glIsTexture to | |
| 49 // return true. | |
| 50 glBindTexture(GL_TEXTURE_2D, texture_id_); | |
| 51 glBindTexture(GL_TEXTURE_2D, 0); | |
| 52 ASSERT_TRUE(glIsTexture(texture_id_)); | |
| 53 } | |
| 54 | |
| 55 void TearDown() override { | |
| 56 surface_texture_ = nullptr; | |
| 57 context_ = nullptr; | |
| 58 share_group_ = nullptr; | |
| 59 surface_ = nullptr; | |
|
watk
2017/02/23 19:52:40
These are all automatic because gtest instantiates
liberato (no reviews please)
2017/03/06 21:43:55
i wanted to clear these down before ShutdownGL. p
| |
| 60 gl::init::ShutdownGL(); | |
| 61 } | |
| 62 | |
| 63 scoped_refptr<gl::GLSurface> surface_; | |
| 64 scoped_refptr<gl::GLShareGroup> share_group_; | |
| 65 scoped_refptr<gl::GLContext> context_; | |
| 66 | |
| 67 scoped_refptr<SurfaceTextureGLOwner> surface_texture_; | |
| 68 GLuint texture_id_ = 0; | |
| 69 }; | |
| 70 | |
| 71 // Verify that SurfaceTextureGLOwner creates a bindable GL texture, and deletes | |
| 72 // it during destruction. | |
| 73 TEST_F(SurfaceTextureGLOwnerTest, TestGLTextureIsCreatedAndDestroyed) { | |
| 74 // |texture_id| should not work anymore after we delete |surface_texture|. | |
| 75 surface_texture_ = nullptr; | |
| 76 ASSERT_FALSE(glIsTexture(texture_id_)); | |
| 77 } | |
| 78 | |
| 79 // Calling ReleaseSurfaceTexture shouldn't deallocate the texture handle. | |
| 80 TEST_F(SurfaceTextureGLOwnerTest, TestReleaseDoesntDestroyTexture) { | |
|
watk
2017/02/23 19:52:39
Remove "Test" prefix from test names.
liberato (no reviews please)
2017/03/06 21:43:55
Done.
| |
| 81 surface_texture_->ReleaseSurfaceTexture(); | |
| 82 ASSERT_TRUE(glIsTexture(texture_id_)); | |
| 83 } | |
| 84 | |
| 85 // Make sure that |surface_texture_| remembers the correct context and surface. | |
| 86 TEST_F(SurfaceTextureGLOwnerTest, TestContextAndSurfaceAreCaptured) { | |
| 87 ASSERT_EQ(context_, surface_texture_->context()); | |
| 88 ASSERT_EQ(surface_, surface_texture_->surface()); | |
| 89 } | |
| 90 | |
| 91 // Verify that destruction works even if some other context is current. | |
| 92 TEST_F(SurfaceTextureGLOwnerTest, TestDestructionWorksWithWrongContext) { | |
| 93 scoped_refptr<gl::GLSurface> new_surface( | |
| 94 new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240))); | |
| 95 new_surface->Initialize(); | |
| 96 | |
| 97 scoped_refptr<gl::GLShareGroup> new_share_group(new gl::GLShareGroup); | |
| 98 scoped_refptr<gl::GLContext> new_context( | |
| 99 new gl::GLContextEGL(new_share_group.get())); | |
| 100 new_context->Initialize(new_surface.get(), gl::GLContextAttribs()); | |
| 101 ASSERT_TRUE(new_context->MakeCurrent(new_surface.get())); | |
| 102 | |
| 103 surface_texture_ = nullptr; | |
| 104 ASSERT_FALSE(glIsTexture(texture_id_)); | |
| 105 | |
| 106 // |new_context| should still be current. | |
| 107 ASSERT_TRUE(new_context->IsCurrent(new_surface.get())); | |
| 108 | |
| 109 new_context = nullptr; | |
| 110 new_share_group = nullptr; | |
| 111 new_surface = nullptr; | |
| 112 } | |
| 113 | |
| 114 } // namespace media | |
| OLD | NEW |