Chromium Code Reviews| Index: media/gpu/surface_texture_gl_owner_unittest.cc |
| diff --git a/media/gpu/surface_texture_gl_owner_unittest.cc b/media/gpu/surface_texture_gl_owner_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d9b7c139b2f19c470cbb7901f53275b81dad9f5 |
| --- /dev/null |
| +++ b/media/gpu/surface_texture_gl_owner_unittest.cc |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/gpu/surface_texture_gl_owner.h" |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gl/gl_bindings.h" |
| +#include "ui/gl/gl_context_egl.h" |
| +#include "ui/gl/gl_implementation.h" |
| +#include "ui/gl/gl_share_group.h" |
| +#include "ui/gl/gl_surface_egl.h" |
| +#include "ui/gl/init/gl_factory.h" |
| +#include "ui/gl/init/gl_initializer.h" |
| + |
| +using testing::Invoke; |
| +using testing::NiceMock; |
| +using testing::_; |
| + |
| +namespace media { |
| + |
| +class SurfaceTextureGLOwnerTest : public testing::Test { |
| + public: |
| + SurfaceTextureGLOwnerTest() {} |
| + ~SurfaceTextureGLOwnerTest() override {} |
| + |
| + protected: |
| + void SetUp() override { |
| + gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, |
| + false, false, false); |
| + surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240)); |
| + surface_->Initialize(); |
| + |
| + share_group_ = new gl::GLShareGroup; |
| + context_ = new gl::GLContextEGL(share_group_.get()); |
| + context_->Initialize(surface_.get(), gl::GLContextAttribs()); |
| + ASSERT_TRUE(context_->MakeCurrent(surface_.get())); |
| + |
| + // |context_| looks sane. for example: |
| + // context_->GetGLRenderer returns "Adreno (TM) 420" |
| + // context_->GetGLVersion returns "OpenGL ES 3.2 V@145.0 (GIT@Idb2b4cb785)" |
| + |
| + surface_texture_ = SurfaceTextureGLOwner::Create(); |
| + } |
| + |
| + void TearDown() override { |
| + surface_texture_ = nullptr; |
| + |
| + // TODO(liberato): shut down gl. |
| + } |
| + |
| + scoped_refptr<gl::GLSurface> surface_; |
| + scoped_refptr<gl::GLShareGroup> share_group_; |
| + scoped_refptr<gl::GLContext> context_; |
| + |
| + scoped_refptr<SurfaceTextureGLOwner> surface_texture_; |
| +}; |
| + |
| +TEST_F(SurfaceTextureGLOwnerTest, TestThatShouldSucceedButDoesnt) { |
| + GLuint tex = 0; |
| + glGenTextures(1, &tex); |
| + ASSERT_NE(tex, 0u); |
| + // |tex| ends up being 1. calling it again gets 2. seems okay to me. |
| + glBindTexture(GL_TEXTURE_2D, tex); |
| + ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + glDeleteTextures(1, &tex); |
| + ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + |
| + // Try something that should produce a GL error. |
| + glBindTexture(GL_TEXTURE_2D, 123); |
| + // This assert fails with: |
| + // Value of: ::gl::g_current_gl_context_tls->Get()->Api->glGetErrorFn() |
| + // Actual: 0 |
| + // Expected: static_cast<GLenum>(0x0501) |
| + // Which is: 1281 |
|
Ken Russell (switch to Gerrit)
2017/02/23 02:38:09
This won't generate an error with real OpenGL or O
liberato (no reviews please)
2017/02/23 05:43:35
<facepalm/>
thank you! glIsTexture works!
fwiw,
|
| + ASSERT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); |
| +} |
| + |
| +// Verify that SurfaceTextureGLOwner creates a bindable GL texture, and deletes |
| +// it during destruction. |
| +TEST_F(SurfaceTextureGLOwnerTest, TestGLTextureIsCreatedAndDestroyed) { |
| + scoped_refptr<SurfaceTextureGLOwner> surface_texture( |
| + SurfaceTextureGLOwner::Create()); |
| + ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + |
| + // We should get a nonzero texture, and we should be able to bind it. |
| + int texture_id = surface_texture->texture_id(); |
| + ASSERT_NE(texture_id, 0); |
| + glBindTexture(GL_TEXTURE_2D, texture_id); |
| + ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + |
| + // Unbind it. |
| + glBindTexture(GL_TEXTURE_2D, 0); |
| + ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| + |
| + // |texture_id| should not work anymore after we delete |surface_texture|. |
| + surface_texture = nullptr; |
| + glBindTexture(GL_TEXTURE_2D, texture_id); |
| + ASSERT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); |
| +} |
| + |
| +} // namespace media |