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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
22 using testing::Invoke;
23 using testing::NiceMock;
24 using testing::_;
25
26 namespace media {
27
28 class SurfaceTextureGLOwnerTest : public testing::Test {
29 public:
30 SurfaceTextureGLOwnerTest() {}
31 ~SurfaceTextureGLOwnerTest() override {}
32
33 protected:
34 void SetUp() override {
35 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2,
36 false, false, false);
37 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240));
38 surface_->Initialize();
39
40 share_group_ = new gl::GLShareGroup;
41 context_ = new gl::GLContextEGL(share_group_.get());
42 context_->Initialize(surface_.get(), gl::GLContextAttribs());
43 ASSERT_TRUE(context_->MakeCurrent(surface_.get()));
44
45 surface_texture_ = SurfaceTextureGLOwner::Create();
46 texture_id_ = surface_texture_->texture_id();
47 // Bind and un-bind the texture, since that's required for glIsTexture to
48 // return true.
49 glBindTexture(GL_TEXTURE_2D, texture_id_);
50 glBindTexture(GL_TEXTURE_2D, 0);
51 ASSERT_TRUE(glIsTexture(texture_id_));
52 }
53
54 void TearDown() override {
55 surface_texture_ = nullptr;
56 context_ = nullptr;
57 share_group_ = nullptr;
58 surface_ = nullptr;
59 gl::init::ShutdownGL();
60 }
61
62 scoped_refptr<SurfaceTextureGLOwner> surface_texture_;
63 GLuint texture_id_ = 0;
64
65 scoped_refptr<gl::GLContext> context_;
66 scoped_refptr<gl::GLShareGroup> share_group_;
67 scoped_refptr<gl::GLSurface> surface_;
68 };
69
70 // Verify that SurfaceTextureGLOwner creates a bindable GL texture, and deletes
71 // it during destruction.
72 TEST_F(SurfaceTextureGLOwnerTest, GLTextureIsCreatedAndDestroyed) {
73 // |texture_id| should not work anymore after we delete |surface_texture|.
74 surface_texture_ = nullptr;
75 ASSERT_FALSE(glIsTexture(texture_id_));
76 }
77
78 // Calling ReleaseSurfaceTexture shouldn't deallocate the texture handle.
79 TEST_F(SurfaceTextureGLOwnerTest, ReleaseDoesntDestroyTexture) {
80 surface_texture_->ReleaseSurfaceTexture();
81 ASSERT_TRUE(glIsTexture(texture_id_));
82 }
83
84 // Make sure that |surface_texture_| remembers the correct context and surface.
85 TEST_F(SurfaceTextureGLOwnerTest, ContextAndSurfaceAreCaptured) {
86 ASSERT_EQ(context_, surface_texture_->context());
87 ASSERT_EQ(surface_, surface_texture_->surface());
88 }
89
90 // Verify that destruction works even if some other context is current.
91 TEST_F(SurfaceTextureGLOwnerTest, DestructionWorksWithWrongContext) {
92 scoped_refptr<gl::GLSurface> new_surface(
93 new gl::PbufferGLSurfaceEGL(gfx::Size(320, 240)));
94 new_surface->Initialize();
95
96 scoped_refptr<gl::GLShareGroup> new_share_group(new gl::GLShareGroup);
97 scoped_refptr<gl::GLContext> new_context(
98 new gl::GLContextEGL(new_share_group.get()));
99 new_context->Initialize(new_surface.get(), gl::GLContextAttribs());
100 ASSERT_TRUE(new_context->MakeCurrent(new_surface.get()));
101
102 surface_texture_ = nullptr;
103 ASSERT_FALSE(glIsTexture(texture_id_));
104
105 // |new_context| should still be current.
106 ASSERT_TRUE(new_context->IsCurrent(new_surface.get()));
107
108 new_context = nullptr;
109 new_share_group = nullptr;
110 new_surface = nullptr;
111 }
112
113 } // namespace media
OLDNEW
« 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