1 // Copyright (c) 2012 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.
5 #include "gpu/command_buffer/service/context_group.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/command_buffer/common/value_state.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
10 #include "gpu/command_buffer/service/gpu_service_test.h"
11 #include "gpu/command_buffer/service/mailbox_manager.h"
12 #include "gpu/command_buffer/service/test_helper.h"
13 #include "gpu/command_buffer/service/texture_manager.h"
14 #include "gpu/command_buffer/service/valuebuffer_manager.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gl/gl_mock.h"
19 using ::testing::DoAll
;
20 using ::testing::HasSubstr
;
21 using ::testing::InSequence
;
22 using ::testing::MatcherCast
;
24 using ::testing::Pointee
;
25 using ::testing::Return
;
26 using ::testing::SetArrayArgument
;
27 using ::testing::SetArgumentPointee
;
28 using ::testing::StrEq
;
33 class ContextGroupTest
: public GpuServiceTest
{
35 static const bool kBindGeneratesResource
= false;
40 void SetUp() override
{
41 GpuServiceTest::SetUp();
42 decoder_
.reset(new MockGLES2Decoder());
43 group_
= scoped_refptr
<ContextGroup
>(new ContextGroup(
44 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, kBindGeneratesResource
));
47 scoped_ptr
<MockGLES2Decoder
> decoder_
;
48 scoped_refptr
<ContextGroup
> group_
;
51 TEST_F(ContextGroupTest
, Basic
) {
52 // Test it starts off uninitialized.
53 EXPECT_EQ(0u, group_
->max_vertex_attribs());
54 EXPECT_EQ(0u, group_
->max_texture_units());
55 EXPECT_EQ(0u, group_
->max_texture_image_units());
56 EXPECT_EQ(0u, group_
->max_vertex_texture_image_units());
57 EXPECT_EQ(0u, group_
->max_fragment_uniform_vectors());
58 EXPECT_EQ(0u, group_
->max_varying_vectors());
59 EXPECT_EQ(0u, group_
->max_vertex_uniform_vectors());
60 EXPECT_TRUE(group_
->buffer_manager() == NULL
);
61 EXPECT_TRUE(group_
->framebuffer_manager() == NULL
);
62 EXPECT_TRUE(group_
->renderbuffer_manager() == NULL
);
63 EXPECT_TRUE(group_
->texture_manager() == NULL
);
64 EXPECT_TRUE(group_
->program_manager() == NULL
);
65 EXPECT_TRUE(group_
->shader_manager() == NULL
);
68 TEST_F(ContextGroupTest
, InitializeNoExtensions
) {
69 TestHelper::SetupContextGroupInitExpectations(
70 gl_
.get(), DisallowedFeatures(), "", "", kBindGeneratesResource
);
71 group_
->Initialize(decoder_
.get(), DisallowedFeatures());
72 EXPECT_EQ(static_cast<uint32
>(TestHelper::kNumVertexAttribs
),
73 group_
->max_vertex_attribs());
74 EXPECT_EQ(static_cast<uint32
>(TestHelper::kNumTextureUnits
),
75 group_
->max_texture_units());
76 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxTextureImageUnits
),
77 group_
->max_texture_image_units());
78 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVertexTextureImageUnits
),
79 group_
->max_vertex_texture_image_units());
80 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxFragmentUniformVectors
),
81 group_
->max_fragment_uniform_vectors());
82 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVaryingVectors
),
83 group_
->max_varying_vectors());
84 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVertexUniformVectors
),
85 group_
->max_vertex_uniform_vectors());
86 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
87 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
88 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
89 EXPECT_TRUE(group_
->texture_manager() != NULL
);
90 EXPECT_TRUE(group_
->program_manager() != NULL
);
91 EXPECT_TRUE(group_
->shader_manager() != NULL
);
93 group_
->Destroy(decoder_
.get(), false);
94 EXPECT_TRUE(group_
->buffer_manager() == NULL
);
95 EXPECT_TRUE(group_
->framebuffer_manager() == NULL
);
96 EXPECT_TRUE(group_
->renderbuffer_manager() == NULL
);
97 EXPECT_TRUE(group_
->texture_manager() == NULL
);
98 EXPECT_TRUE(group_
->program_manager() == NULL
);
99 EXPECT_TRUE(group_
->shader_manager() == NULL
);
102 TEST_F(ContextGroupTest
, MultipleContexts
) {
103 scoped_ptr
<MockGLES2Decoder
> decoder2_(new MockGLES2Decoder());
104 TestHelper::SetupContextGroupInitExpectations(
105 gl_
.get(), DisallowedFeatures(), "", "", kBindGeneratesResource
);
106 group_
->Initialize(decoder_
.get(), DisallowedFeatures());
107 group_
->Initialize(decoder2_
.get(), DisallowedFeatures());
109 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
110 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
111 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
112 EXPECT_TRUE(group_
->texture_manager() != NULL
);
113 EXPECT_TRUE(group_
->program_manager() != NULL
);
114 EXPECT_TRUE(group_
->shader_manager() != NULL
);
116 group_
->Destroy(decoder_
.get(), false);
118 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
119 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
120 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
121 EXPECT_TRUE(group_
->texture_manager() != NULL
);
122 EXPECT_TRUE(group_
->program_manager() != NULL
);
123 EXPECT_TRUE(group_
->shader_manager() != NULL
);
125 group_
->Destroy(decoder2_
.get(), false);
127 EXPECT_TRUE(group_
->buffer_manager() == NULL
);
128 EXPECT_TRUE(group_
->framebuffer_manager() == NULL
);
129 EXPECT_TRUE(group_
->renderbuffer_manager() == NULL
);
130 EXPECT_TRUE(group_
->texture_manager() == NULL
);
131 EXPECT_TRUE(group_
->program_manager() == NULL
);
132 EXPECT_TRUE(group_
->shader_manager() == NULL
);