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
, 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
);
72 decoder_
.get(), ContextGroup::CONTEXT_TYPE_OTHER
, DisallowedFeatures());
73 EXPECT_EQ(static_cast<uint32
>(TestHelper::kNumVertexAttribs
),
74 group_
->max_vertex_attribs());
75 EXPECT_EQ(static_cast<uint32
>(TestHelper::kNumTextureUnits
),
76 group_
->max_texture_units());
77 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxTextureImageUnits
),
78 group_
->max_texture_image_units());
79 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVertexTextureImageUnits
),
80 group_
->max_vertex_texture_image_units());
81 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxFragmentUniformVectors
),
82 group_
->max_fragment_uniform_vectors());
83 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVaryingVectors
),
84 group_
->max_varying_vectors());
85 EXPECT_EQ(static_cast<uint32
>(TestHelper::kMaxVertexUniformVectors
),
86 group_
->max_vertex_uniform_vectors());
87 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
88 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
89 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
90 EXPECT_TRUE(group_
->texture_manager() != NULL
);
91 EXPECT_TRUE(group_
->program_manager() != NULL
);
92 EXPECT_TRUE(group_
->shader_manager() != NULL
);
94 group_
->Destroy(decoder_
.get(), false);
95 EXPECT_TRUE(group_
->buffer_manager() == NULL
);
96 EXPECT_TRUE(group_
->framebuffer_manager() == NULL
);
97 EXPECT_TRUE(group_
->renderbuffer_manager() == NULL
);
98 EXPECT_TRUE(group_
->texture_manager() == NULL
);
99 EXPECT_TRUE(group_
->program_manager() == NULL
);
100 EXPECT_TRUE(group_
->shader_manager() == NULL
);
103 TEST_F(ContextGroupTest
, MultipleContexts
) {
104 scoped_ptr
<MockGLES2Decoder
> decoder2_(new MockGLES2Decoder());
105 TestHelper::SetupContextGroupInitExpectations(
106 gl_
.get(), DisallowedFeatures(), "", "", kBindGeneratesResource
);
107 EXPECT_TRUE(group_
->Initialize(
108 decoder_
.get(), ContextGroup::CONTEXT_TYPE_OTHER
, DisallowedFeatures()));
109 EXPECT_FALSE(group_
->Initialize(
110 decoder2_
.get(), ContextGroup::CONTEXT_TYPE_WEBGL1
,
111 DisallowedFeatures()));
112 EXPECT_FALSE(group_
->Initialize(
113 decoder2_
.get(), ContextGroup::CONTEXT_TYPE_WEBGL2
,
114 DisallowedFeatures()));
115 EXPECT_FALSE(group_
->Initialize(
116 decoder2_
.get(), ContextGroup::CONTEXT_TYPE_UNDEFINED
,
117 DisallowedFeatures()));
118 EXPECT_TRUE(group_
->Initialize(
119 decoder2_
.get(), ContextGroup::CONTEXT_TYPE_OTHER
, DisallowedFeatures()));
121 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
122 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
123 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
124 EXPECT_TRUE(group_
->texture_manager() != NULL
);
125 EXPECT_TRUE(group_
->program_manager() != NULL
);
126 EXPECT_TRUE(group_
->shader_manager() != NULL
);
128 group_
->Destroy(decoder_
.get(), false);
130 EXPECT_TRUE(group_
->buffer_manager() != NULL
);
131 EXPECT_TRUE(group_
->framebuffer_manager() != NULL
);
132 EXPECT_TRUE(group_
->renderbuffer_manager() != NULL
);
133 EXPECT_TRUE(group_
->texture_manager() != NULL
);
134 EXPECT_TRUE(group_
->program_manager() != NULL
);
135 EXPECT_TRUE(group_
->shader_manager() != NULL
);
137 group_
->Destroy(decoder2_
.get(), false);
139 EXPECT_TRUE(group_
->buffer_manager() == NULL
);
140 EXPECT_TRUE(group_
->framebuffer_manager() == NULL
);
141 EXPECT_TRUE(group_
->renderbuffer_manager() == NULL
);
142 EXPECT_TRUE(group_
->texture_manager() == NULL
);
143 EXPECT_TRUE(group_
->program_manager() == NULL
);
144 EXPECT_TRUE(group_
->shader_manager() == NULL
);