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

Unified Diff: media/gpu/surface_texture_gl_owner_unittest.cc

Issue 2706653002: Added SurfaceTextureGLOwner to create / own GL objects. (Closed)
Patch Set: stopped including gl_initializer.h Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/gpu/surface_texture_gl_owner.cc ('k') | ui/gl/android/surface_texture.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..11ce8f3f08a0c0220bc7ec06b3cd8d0372516663
--- /dev/null
+++ b/media/gpu/surface_texture_gl_owner_unittest.cc
@@ -0,0 +1,113 @@
+// 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"
+
+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()));
+
+ surface_texture_ = SurfaceTextureGLOwner::Create();
+ texture_id_ = surface_texture_->texture_id();
+ // Bind and un-bind the texture, since that's required for glIsTexture to
+ // return true.
+ glBindTexture(GL_TEXTURE_2D, texture_id_);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ ASSERT_TRUE(glIsTexture(texture_id_));
+ }
+
+ void TearDown() override {
+ surface_texture_ = nullptr;
+ context_ = nullptr;
+ share_group_ = nullptr;
+ surface_ = nullptr;
+ gl::init::ShutdownGL();
+ }
+
+ scoped_refptr<SurfaceTextureGLOwner> surface_texture_;
+ GLuint texture_id_ = 0;
+
+ scoped_refptr<gl::GLContext> context_;
+ scoped_refptr<gl::GLShareGroup> share_group_;
+ scoped_refptr<gl::GLSurface> surface_;
+};
+
+// Verify that SurfaceTextureGLOwner creates a bindable GL texture, and deletes
+// it during destruction.
+TEST_F(SurfaceTextureGLOwnerTest, GLTextureIsCreatedAndDestroyed) {
+ // |texture_id| should not work anymore after we delete |surface_texture|.
+ surface_texture_ = nullptr;
+ ASSERT_FALSE(glIsTexture(texture_id_));
+}
+
+// Calling ReleaseSurfaceTexture shouldn't deallocate the texture handle.
+TEST_F(SurfaceTextureGLOwnerTest, ReleaseDoesntDestroyTexture) {
+ surface_texture_->ReleaseSurfaceTexture();
+ ASSERT_TRUE(glIsTexture(texture_id_));
+}
+
+// Make sure that |surface_texture_| remembers the correct context and surface.
+TEST_F(SurfaceTextureGLOwnerTest, ContextAndSurfaceAreCaptured) {
+ ASSERT_EQ(context_, surface_texture_->context());
+ ASSERT_EQ(surface_, surface_texture_->surface());
+}
+
+// Verify that destruction works even if some other context is current.
+TEST_F(SurfaceTextureGLOwnerTest, DestructionWorksWithWrongContext) {
+ scoped_refptr<gl::GLSurface> new_surface(
+ new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240)));
+ new_surface->Initialize();
+
+ scoped_refptr<gl::GLShareGroup> new_share_group(new gl::GLShareGroup);
+ scoped_refptr<gl::GLContext> new_context(
+ new gl::GLContextEGL(new_share_group.get()));
+ new_context->Initialize(new_surface.get(), gl::GLContextAttribs());
+ ASSERT_TRUE(new_context->MakeCurrent(new_surface.get()));
+
+ surface_texture_ = nullptr;
+ ASSERT_FALSE(glIsTexture(texture_id_));
+
+ // |new_context| should still be current.
+ ASSERT_TRUE(new_context->IsCurrent(new_surface.get()));
+
+ new_context = nullptr;
+ new_share_group = nullptr;
+ new_surface = nullptr;
+}
+
+} // namespace media
« no previous file with comments | « media/gpu/surface_texture_gl_owner.cc ('k') | ui/gl/android/surface_texture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698