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.
4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6
7 #include "base/command_line.h"
8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
10 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/program_manager.h"
13 #include "gpu/command_buffer/service/test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_mock.h"
16
17 using ::gl::MockGLInterface;
18 using ::testing::_;
19 using ::testing::DoAll;
20 using ::testing::InSequence;
21 using ::testing::MatcherCast;
22 using ::testing::Pointee;
23 using ::testing::Return;
24 using ::testing::SetArrayArgument;
25 using ::testing::SetArgPointee;
26 using ::testing::StrEq;
27
28 namespace gpu {
29 namespace gles2 {
30
31 class GLES2DecoderTest1 : public GLES2DecoderTestBase {
32 public:
33 GLES2DecoderTest1() = default;
34 };
35
36 class GLES3DecoderTest1 : public GLES2DecoderTest1 {
37 public:
GLES3DecoderTest1()38 GLES3DecoderTest1() { shader_language_version_ = 300; }
39 protected:
SetUp()40 void SetUp() override {
41 InitState init;
42 init.gl_version = "OpenGL ES 3.0";
43 init.bind_generates_resource = true;
44 init.context_type = CONTEXT_TYPE_OPENGLES3;
45 InitDecoder(init);
46 }
47 };
48
49 INSTANTIATE_TEST_SUITE_P(Service, GLES2DecoderTest1, ::testing::Bool());
50 INSTANTIATE_TEST_SUITE_P(Service, GLES3DecoderTest1, ::testing::Bool());
51
52 template <>
SpecializedSetup(bool valid)53 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenerateMipmap, 0>(
54 bool valid) {
55 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
56 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
57 shared_memory_id_, kSharedMemoryOffset);
58 if (valid) {
59 EXPECT_CALL(*gl_, GetError())
60 .WillOnce(Return(GL_NO_ERROR))
61 .WillOnce(Return(GL_NO_ERROR))
62 .RetiresOnSaturation();
63 }
64 }
65
66 template <>
SpecializedSetup(bool)67 void GLES2DecoderTestBase::SpecializedSetup<cmds::CheckFramebufferStatus, 0>(
68 bool /* valid */) {
69 // Give it a valid framebuffer.
70 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
71 kServiceRenderbufferId);
72 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
73 kServiceFramebufferId);
74 DoRenderbufferStorage(
75 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
76 DoFramebufferRenderbuffer(
77 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
78 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
79 }
80
81 template <>
SpecializedSetup(bool valid)82 void GLES2DecoderTestBase::SpecializedSetup<cmds::Clear, 0>(bool valid) {
83 if (valid) {
84 SetupExpectationsForApplyingDefaultDirtyState();
85 }
86 }
87
88 template <>
SpecializedSetup(bool)89 void GLES2DecoderTestBase::SpecializedSetup<cmds::ColorMask, 0>(
90 bool /* valid */) {
91 // We bind a framebuffer color the colormask test since the framebuffer
92 // will be considered RGB.
93 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
94 kServiceFramebufferId);
95 }
96
97 template <>
SpecializedSetup(bool valid)98 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexImage2D, 0>(
99 bool valid) {
100 if (valid) {
101 EXPECT_CALL(*gl_, GetError())
102 .WillOnce(Return(GL_NO_ERROR))
103 .WillOnce(Return(GL_NO_ERROR))
104 .RetiresOnSaturation();
105 }
106 }
107
108 template <>
SpecializedSetup(bool valid)109 void GLES2DecoderTestBase::SpecializedSetup<cmds::CopyTexSubImage2D, 0>(
110 bool valid) {
111 if (valid) {
112 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
113 DoTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 16, 16, 0, GL_RGBA,
114 GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
115 }
116 }
117
118 template <>
SpecializedSetup(bool valid)119 void GLES2DecoderTestBase::SpecializedSetup<cmds::DetachShader, 0>(bool valid) {
120 if (valid) {
121 EXPECT_CALL(*gl_,
122 AttachShader(kServiceProgramId, kServiceShaderId))
123 .Times(1)
124 .RetiresOnSaturation();
125 cmds::AttachShader attach_cmd;
126 attach_cmd.Init(client_program_id_, client_shader_id_);
127 EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
128 }
129 }
130
131 template <>
SpecializedSetup(bool valid)132 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferRenderbuffer, 0>(
133 bool valid) {
134 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
135 kServiceFramebufferId);
136 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
137 kServiceRenderbufferId);
138 if (valid) {
139 EXPECT_CALL(*gl_, GetError())
140 .WillOnce(Return(GL_NO_ERROR))
141 .WillOnce(Return(GL_NO_ERROR))
142 .RetiresOnSaturation();
143 }
144 }
145
146 template <>
SpecializedSetup(bool valid)147 void GLES2DecoderTestBase::SpecializedSetup<cmds::FramebufferTextureLayer, 0>(
148 bool valid) {
149 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
150 kServiceFramebufferId);
151 if (valid) {
152 EXPECT_CALL(*gl_, GetError())
153 .WillOnce(Return(GL_NO_ERROR))
154 .WillOnce(Return(GL_NO_ERROR))
155 .RetiresOnSaturation();
156 }
157 }
158
159 template <>
SpecializedSetup(bool)160 void GLES2DecoderTestBase::SpecializedSetup<
161 cmds::GetBufferParameteri64v, 0>(bool /* valid */) {
162 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
163 }
164
165 template <>
SpecializedSetup(bool)166 void GLES2DecoderTestBase::SpecializedSetup<
167 cmds::GetBufferParameteriv, 0>(bool /* valid */) {
168 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
169 }
170
171 template <>
SpecializedSetup(bool)172 void GLES2DecoderTestBase::SpecializedSetup<
173 cmds::GetFramebufferAttachmentParameteriv, 0>(bool /* valid */) {
174 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
175 kServiceFramebufferId);
176 }
177
178 template <>
SpecializedSetup(bool valid)179 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetProgramiv, 0>(
180 bool valid) {
181 if (valid) {
182 // GetProgramiv calls ClearGLError then GetError to make sure
183 // it actually got a value so it can report correctly to the client.
184 EXPECT_CALL(*gl_, GetError())
185 .WillOnce(Return(GL_NO_ERROR))
186 .RetiresOnSaturation();
187 EXPECT_CALL(*gl_, GetError())
188 .WillOnce(Return(GL_NO_ERROR))
189 .RetiresOnSaturation();
190 }
191 }
192
193 template <>
194 void GLES2DecoderTestBase::
SpecializedSetup(bool valid)195 SpecializedSetup<cmds::GenTransformFeedbacksImmediate, 0>(bool valid) {
196 if (valid) {
197 // Transform feedbacks are per-context, not per-group, so they get cleaned
198 // up at the end of the test.
199 EXPECT_CALL(*gl_, DeleteTransformFeedbacks(_, _))
200 .Times(1)
201 .RetiresOnSaturation();
202 }
203 }
204
205 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_1_autogen.h"
206
207 } // namespace gles2
208 } // namespace gpu
209
210