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 // |context_| looks sane. for example: | |
| 47 // context_->GetGLRenderer returns "Adreno (TM) 420" | |
| 48 // context_->GetGLVersion returns "OpenGL ES 3.2 V@145.0 (GIT@Idb2b4cb785)" | |
| 49 | |
| 50 surface_texture_ = SurfaceTextureGLOwner::Create(); | |
| 51 } | |
| 52 | |
| 53 void TearDown() override { | |
| 54 surface_texture_ = nullptr; | |
| 55 | |
| 56 // TODO(liberato): shut down gl. | |
| 57 } | |
| 58 | |
| 59 scoped_refptr<gl::GLSurface> surface_; | |
| 60 scoped_refptr<gl::GLShareGroup> share_group_; | |
| 61 scoped_refptr<gl::GLContext> context_; | |
| 62 | |
| 63 scoped_refptr<SurfaceTextureGLOwner> surface_texture_; | |
| 64 }; | |
| 65 | |
| 66 TEST_F(SurfaceTextureGLOwnerTest, TestThatShouldSucceedButDoesnt) { | |
| 67 GLuint tex = 0; | |
| 68 glGenTextures(1, &tex); | |
| 69 ASSERT_NE(tex, 0u); | |
| 70 // |tex| ends up being 1. calling it again gets 2. seems okay to me. | |
| 71 glBindTexture(GL_TEXTURE_2D, tex); | |
| 72 ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 73 glDeleteTextures(1, &tex); | |
| 74 ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 75 | |
| 76 // Try something that should produce a GL error. | |
| 77 glBindTexture(GL_TEXTURE_2D, 123); | |
| 78 // This assert fails with: | |
| 79 // Value of: ::gl::g_current_gl_context_tls->Get()->Api->glGetErrorFn() | |
| 80 // Actual: 0 | |
| 81 // Expected: static_cast<GLenum>(0x0501) | |
| 82 // 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,
| |
| 83 ASSERT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); | |
| 84 } | |
| 85 | |
| 86 // Verify that SurfaceTextureGLOwner creates a bindable GL texture, and deletes | |
| 87 // it during destruction. | |
| 88 TEST_F(SurfaceTextureGLOwnerTest, TestGLTextureIsCreatedAndDestroyed) { | |
| 89 scoped_refptr<SurfaceTextureGLOwner> surface_texture( | |
| 90 SurfaceTextureGLOwner::Create()); | |
| 91 ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 92 | |
| 93 // We should get a nonzero texture, and we should be able to bind it. | |
| 94 int texture_id = surface_texture->texture_id(); | |
| 95 ASSERT_NE(texture_id, 0); | |
| 96 glBindTexture(GL_TEXTURE_2D, texture_id); | |
| 97 ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 98 | |
| 99 // Unbind it. | |
| 100 glBindTexture(GL_TEXTURE_2D, 0); | |
| 101 ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 102 | |
| 103 // |texture_id| should not work anymore after we delete |surface_texture|. | |
| 104 surface_texture = nullptr; | |
| 105 glBindTexture(GL_TEXTURE_2D, texture_id); | |
| 106 ASSERT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); | |
| 107 } | |
| 108 | |
| 109 } // namespace media | |
| OLD | NEW |