James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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_unittest_base.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/strings/string_number_conversions.h" |
| 12 | #include "base/strings/string_split.h" |
| 13 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 14 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame] | 15 | #include "gpu/command_buffer/common/value_state.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 16 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 17 | #include "gpu/command_buffer/service/context_group.h" |
| 18 | #include "gpu/command_buffer/service/logger.h" |
| 19 | #include "gpu/command_buffer/service/mailbox_manager.h" |
| 20 | #include "gpu/command_buffer/service/program_manager.h" |
| 21 | #include "gpu/command_buffer/service/test_helper.h" |
| 22 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 23 | #include "testing/gtest/include/gtest/gtest.h" |
| 24 | #include "ui/gl/gl_implementation.h" |
| 25 | #include "ui/gl/gl_mock.h" |
| 26 | #include "ui/gl/gl_surface.h" |
| 27 | |
| 28 | using ::gfx::MockGLInterface; |
| 29 | using ::testing::_; |
| 30 | using ::testing::DoAll; |
| 31 | using ::testing::InSequence; |
| 32 | using ::testing::Invoke; |
| 33 | using ::testing::InvokeWithoutArgs; |
| 34 | using ::testing::MatcherCast; |
| 35 | using ::testing::Pointee; |
| 36 | using ::testing::Return; |
| 37 | using ::testing::SetArrayArgument; |
| 38 | using ::testing::SetArgPointee; |
| 39 | using ::testing::SetArgumentPointee; |
| 40 | using ::testing::StrEq; |
| 41 | using ::testing::StrictMock; |
| 42 | using ::testing::WithArg; |
| 43 | |
| 44 | namespace { |
| 45 | |
| 46 | void NormalizeInitState(gpu::gles2::GLES2DecoderTestBase::InitState* init) { |
| 47 | CHECK(init); |
| 48 | const char* kVAOExtensions[] = { |
| 49 | "GL_OES_vertex_array_object", |
| 50 | "GL_ARB_vertex_array_object", |
| 51 | "GL_APPLE_vertex_array_object" |
| 52 | }; |
| 53 | bool contains_vao_extension = false; |
| 54 | for (size_t ii = 0; ii < arraysize(kVAOExtensions); ++ii) { |
| 55 | if (init->extensions.find(kVAOExtensions[ii]) != std::string::npos) { |
| 56 | contains_vao_extension = true; |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | if (init->use_native_vao) { |
| 61 | if (contains_vao_extension) |
| 62 | return; |
| 63 | if (!init->extensions.empty()) |
| 64 | init->extensions += " "; |
| 65 | if (StartsWithASCII(init->gl_version, "opengl es", false)) { |
| 66 | init->extensions += kVAOExtensions[0]; |
| 67 | } else { |
| 68 | #if !defined(OS_MACOSX) |
| 69 | init->extensions += kVAOExtensions[1]; |
| 70 | #else |
| 71 | init->extensions += kVAOExtensions[2]; |
| 72 | #endif // OS_MACOSX |
| 73 | } |
| 74 | } else { |
| 75 | // Make sure we don't set up an invalid InitState. |
| 76 | CHECK(!contains_vao_extension); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | } // namespace Anonymous |
| 81 | |
| 82 | namespace gpu { |
| 83 | namespace gles2 { |
| 84 | |
| 85 | GLES2DecoderTestBase::GLES2DecoderTestBase() |
| 86 | : surface_(NULL), |
| 87 | context_(NULL), |
| 88 | memory_tracker_(NULL), |
| 89 | client_buffer_id_(100), |
| 90 | client_framebuffer_id_(101), |
| 91 | client_program_id_(102), |
| 92 | client_renderbuffer_id_(103), |
| 93 | client_shader_id_(104), |
| 94 | client_texture_id_(106), |
| 95 | client_element_buffer_id_(107), |
| 96 | client_vertex_shader_id_(121), |
| 97 | client_fragment_shader_id_(122), |
| 98 | client_query_id_(123), |
| 99 | client_vertexarray_id_(124), |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 100 | client_valuebuffer_id_(125), |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 101 | service_renderbuffer_id_(0), |
| 102 | service_renderbuffer_valid_(false), |
| 103 | ignore_cached_state_for_test_(GetParam()), |
| 104 | cached_color_mask_red_(true), |
| 105 | cached_color_mask_green_(true), |
| 106 | cached_color_mask_blue_(true), |
| 107 | cached_color_mask_alpha_(true), |
| 108 | cached_depth_mask_(true), |
| 109 | cached_stencil_front_mask_(static_cast<GLuint>(-1)), |
| 110 | cached_stencil_back_mask_(static_cast<GLuint>(-1)) { |
| 111 | memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_)); |
| 112 | } |
| 113 | |
| 114 | GLES2DecoderTestBase::~GLES2DecoderTestBase() {} |
| 115 | |
| 116 | void GLES2DecoderTestBase::SetUp() { |
| 117 | InitState init; |
| 118 | init.gl_version = "3.0"; |
| 119 | init.has_alpha = true; |
| 120 | init.has_depth = true; |
| 121 | init.request_alpha = true; |
| 122 | init.request_depth = true; |
| 123 | init.bind_generates_resource = true; |
| 124 | InitDecoder(init); |
| 125 | } |
| 126 | |
| 127 | void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() { |
| 128 | for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) { |
| 129 | EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f)) |
| 130 | .Times(1) |
| 131 | .RetiresOnSaturation(); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | GLES2DecoderTestBase::InitState::InitState() |
| 136 | : has_alpha(false), |
| 137 | has_depth(false), |
| 138 | has_stencil(false), |
| 139 | request_alpha(false), |
| 140 | request_depth(false), |
| 141 | request_stencil(false), |
| 142 | bind_generates_resource(false), |
| 143 | lose_context_when_out_of_memory(false), |
| 144 | use_native_vao(true) { |
| 145 | } |
| 146 | |
| 147 | void GLES2DecoderTestBase::InitDecoder(const InitState& init) { |
| 148 | InitDecoderWithCommandLine(init, NULL); |
| 149 | } |
| 150 | |
| 151 | void GLES2DecoderTestBase::InitDecoderWithCommandLine( |
| 152 | const InitState& init, |
| 153 | const base::CommandLine* command_line) { |
| 154 | InitState normalized_init = init; |
| 155 | NormalizeInitState(&normalized_init); |
| 156 | Framebuffer::ClearFramebufferCompleteComboMap(); |
| 157 | |
| 158 | gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); |
| 159 | gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); |
| 160 | |
| 161 | gl_.reset(new StrictMock<MockGLInterface>()); |
| 162 | ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 163 | |
| 164 | SetupMockGLBehaviors(); |
| 165 | |
| 166 | // Only create stream texture manager if extension is requested. |
| 167 | std::vector<std::string> list; |
| 168 | base::SplitString(normalized_init.extensions, ' ', &list); |
| 169 | scoped_refptr<FeatureInfo> feature_info; |
| 170 | if (command_line) |
| 171 | feature_info = new FeatureInfo(*command_line); |
| 172 | group_ = scoped_refptr<ContextGroup>( |
| 173 | new ContextGroup(NULL, |
| 174 | memory_tracker_, |
| 175 | new ShaderTranslatorCache, |
| 176 | feature_info.get(), |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame] | 177 | new ValueStateMap, |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 178 | normalized_init.bind_generates_resource)); |
| 179 | bool use_default_textures = normalized_init.bind_generates_resource; |
| 180 | |
| 181 | InSequence sequence; |
| 182 | |
| 183 | surface_ = new gfx::GLSurfaceStub; |
| 184 | surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); |
| 185 | |
| 186 | // Context needs to be created before initializing ContextGroup, which will |
| 187 | // in turn initialize FeatureInfo, which needs a context to determine |
| 188 | // extension support. |
| 189 | context_ = new gfx::GLContextStubWithExtensions; |
| 190 | context_->AddExtensionsString(normalized_init.extensions.c_str()); |
| 191 | context_->SetGLVersionString(normalized_init.gl_version.c_str()); |
| 192 | |
| 193 | context_->MakeCurrent(surface_.get()); |
| 194 | gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_.get()); |
| 195 | |
| 196 | TestHelper::SetupContextGroupInitExpectations( |
| 197 | gl_.get(), |
| 198 | DisallowedFeatures(), |
| 199 | normalized_init.extensions.c_str(), |
| 200 | normalized_init.gl_version.c_str(), |
| 201 | normalized_init.bind_generates_resource); |
| 202 | |
| 203 | // We initialize the ContextGroup with a MockGLES2Decoder so that |
| 204 | // we can use the ContextGroup to figure out how the real GLES2Decoder |
| 205 | // will initialize itself. |
| 206 | mock_decoder_.reset(new MockGLES2Decoder()); |
| 207 | |
| 208 | // Install FakeDoCommands handler so we can use individual DoCommand() |
| 209 | // expectations. |
| 210 | EXPECT_CALL(*mock_decoder_, DoCommands(_, _, _, _)).WillRepeatedly( |
| 211 | Invoke(mock_decoder_.get(), &MockGLES2Decoder::FakeDoCommands)); |
| 212 | |
| 213 | EXPECT_TRUE( |
| 214 | group_->Initialize(mock_decoder_.get(), DisallowedFeatures())); |
| 215 | |
| 216 | if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 217 | EXPECT_CALL(*gl_, GenVertexArraysOES(1, _)) |
| 218 | .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId)) |
| 219 | .RetiresOnSaturation(); |
| 220 | EXPECT_CALL(*gl_, BindVertexArrayOES(_)).Times(1).RetiresOnSaturation(); |
| 221 | } |
| 222 | |
| 223 | if (group_->feature_info()->workarounds().init_vertex_attributes) |
| 224 | AddExpectationsForVertexAttribManager(); |
| 225 | |
| 226 | AddExpectationsForBindVertexArrayOES(); |
| 227 | |
| 228 | EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) |
| 229 | .Times(1) |
| 230 | .RetiresOnSaturation(); |
| 231 | static GLuint attrib_0_id[] = { |
| 232 | kServiceAttrib0BufferId, |
| 233 | }; |
| 234 | static GLuint fixed_attrib_buffer_id[] = { |
| 235 | kServiceFixedAttribBufferId, |
| 236 | }; |
| 237 | EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _)) |
| 238 | .WillOnce(SetArrayArgument<1>(attrib_0_id, |
| 239 | attrib_0_id + arraysize(attrib_0_id))) |
| 240 | .RetiresOnSaturation(); |
| 241 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) |
| 242 | .Times(1) |
| 243 | .RetiresOnSaturation(); |
| 244 | EXPECT_CALL(*gl_, VertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL)) |
| 245 | .Times(1) |
| 246 | .RetiresOnSaturation(); |
| 247 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) |
| 248 | .Times(1) |
| 249 | .RetiresOnSaturation(); |
| 250 | EXPECT_CALL(*gl_, GenBuffersARB(arraysize(fixed_attrib_buffer_id), _)) |
| 251 | .WillOnce(SetArrayArgument<1>( |
| 252 | fixed_attrib_buffer_id, |
| 253 | fixed_attrib_buffer_id + arraysize(fixed_attrib_buffer_id))) |
| 254 | .RetiresOnSaturation(); |
| 255 | |
| 256 | for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) { |
| 257 | EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt)) |
| 258 | .Times(1) |
| 259 | .RetiresOnSaturation(); |
| 260 | if (group_->feature_info()->feature_flags().oes_egl_image_external) { |
| 261 | EXPECT_CALL(*gl_, |
| 262 | BindTexture(GL_TEXTURE_EXTERNAL_OES, |
| 263 | use_default_textures |
| 264 | ? TestHelper::kServiceDefaultExternalTextureId |
| 265 | : 0)) |
| 266 | .Times(1) |
| 267 | .RetiresOnSaturation(); |
| 268 | } |
| 269 | if (group_->feature_info()->feature_flags().arb_texture_rectangle) { |
| 270 | EXPECT_CALL( |
| 271 | *gl_, |
| 272 | BindTexture(GL_TEXTURE_RECTANGLE_ARB, |
| 273 | use_default_textures |
| 274 | ? TestHelper::kServiceDefaultRectangleTextureId |
| 275 | : 0)) |
| 276 | .Times(1) |
| 277 | .RetiresOnSaturation(); |
| 278 | } |
| 279 | EXPECT_CALL(*gl_, |
| 280 | BindTexture(GL_TEXTURE_CUBE_MAP, |
| 281 | use_default_textures |
| 282 | ? TestHelper::kServiceDefaultTextureCubemapId |
| 283 | : 0)) |
| 284 | .Times(1) |
| 285 | .RetiresOnSaturation(); |
| 286 | EXPECT_CALL( |
| 287 | *gl_, |
| 288 | BindTexture( |
| 289 | GL_TEXTURE_2D, |
| 290 | use_default_textures ? TestHelper::kServiceDefaultTexture2dId : 0)) |
| 291 | .Times(1) |
| 292 | .RetiresOnSaturation(); |
| 293 | } |
| 294 | EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
| 295 | .Times(1) |
| 296 | .RetiresOnSaturation(); |
| 297 | |
| 298 | EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) |
| 299 | .Times(1) |
| 300 | .RetiresOnSaturation(); |
| 301 | EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _)) |
| 302 | .WillOnce(SetArgumentPointee<1>(normalized_init.has_alpha ? 8 : 0)) |
| 303 | .RetiresOnSaturation(); |
| 304 | EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _)) |
| 305 | .WillOnce(SetArgumentPointee<1>(normalized_init.has_depth ? 24 : 0)) |
| 306 | .RetiresOnSaturation(); |
| 307 | EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _)) |
| 308 | .WillOnce(SetArgumentPointee<1>(normalized_init.has_stencil ? 8 : 0)) |
| 309 | .RetiresOnSaturation(); |
| 310 | |
| 311 | EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) |
| 312 | .Times(1) |
| 313 | .RetiresOnSaturation(); |
| 314 | |
| 315 | EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) |
| 316 | .Times(1) |
| 317 | .RetiresOnSaturation(); |
| 318 | |
| 319 | static GLint max_viewport_dims[] = { |
| 320 | kMaxViewportWidth, |
| 321 | kMaxViewportHeight |
| 322 | }; |
| 323 | EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VIEWPORT_DIMS, _)) |
| 324 | .WillOnce(SetArrayArgument<1>( |
| 325 | max_viewport_dims, max_viewport_dims + arraysize(max_viewport_dims))) |
| 326 | .RetiresOnSaturation(); |
| 327 | |
| 328 | SetupInitCapabilitiesExpectations(); |
| 329 | SetupInitStateExpectations(); |
| 330 | |
| 331 | EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
| 332 | .Times(1) |
| 333 | .RetiresOnSaturation(); |
| 334 | |
| 335 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, 0)) |
| 336 | .Times(1) |
| 337 | .RetiresOnSaturation(); |
| 338 | EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)) |
| 339 | .Times(1) |
| 340 | .RetiresOnSaturation(); |
| 341 | EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) |
| 342 | .Times(1) |
| 343 | .RetiresOnSaturation(); |
| 344 | EXPECT_CALL(*gl_, BindRenderbufferEXT(GL_RENDERBUFFER, 0)) |
| 345 | .Times(1) |
| 346 | .RetiresOnSaturation(); |
| 347 | |
| 348 | // TODO(boliu): Remove OS_ANDROID once crbug.com/259023 is fixed and the |
| 349 | // workaround has been reverted. |
| 350 | #if !defined(OS_ANDROID) |
| 351 | EXPECT_CALL(*gl_, Clear( |
| 352 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) |
| 353 | .Times(1) |
| 354 | .RetiresOnSaturation(); |
| 355 | #endif |
| 356 | |
| 357 | engine_.reset(new StrictMock<MockCommandBufferEngine>()); |
| 358 | scoped_refptr<gpu::Buffer> buffer = |
| 359 | engine_->GetSharedMemoryBuffer(kSharedMemoryId); |
| 360 | shared_memory_offset_ = kSharedMemoryOffset; |
| 361 | shared_memory_address_ = |
| 362 | reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_; |
| 363 | shared_memory_id_ = kSharedMemoryId; |
| 364 | shared_memory_base_ = buffer->memory(); |
| 365 | |
| 366 | static const int32 kLoseContextWhenOutOfMemory = 0x10002; |
| 367 | |
| 368 | int32 attributes[] = { |
| 369 | EGL_ALPHA_SIZE, |
| 370 | normalized_init.request_alpha ? 8 : 0, |
| 371 | EGL_DEPTH_SIZE, |
| 372 | normalized_init.request_depth ? 24 : 0, |
| 373 | EGL_STENCIL_SIZE, |
| 374 | normalized_init.request_stencil ? 8 : 0, |
| 375 | kLoseContextWhenOutOfMemory, |
| 376 | normalized_init.lose_context_when_out_of_memory ? 1 : 0, }; |
| 377 | std::vector<int32> attribs(attributes, attributes + arraysize(attributes)); |
| 378 | |
| 379 | decoder_.reset(GLES2Decoder::Create(group_.get())); |
| 380 | decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_); |
| 381 | decoder_->GetLogger()->set_log_synthesized_gl_errors(false); |
| 382 | decoder_->Initialize(surface_, |
| 383 | context_, |
| 384 | false, |
| 385 | surface_->GetSize(), |
| 386 | DisallowedFeatures(), |
| 387 | attribs); |
| 388 | decoder_->MakeCurrent(); |
| 389 | decoder_->set_engine(engine_.get()); |
| 390 | decoder_->BeginDecoding(); |
| 391 | |
| 392 | EXPECT_CALL(*gl_, GenBuffersARB(_, _)) |
| 393 | .WillOnce(SetArgumentPointee<1>(kServiceBufferId)) |
| 394 | .RetiresOnSaturation(); |
| 395 | GenHelper<cmds::GenBuffersImmediate>(client_buffer_id_); |
| 396 | EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _)) |
| 397 | .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId)) |
| 398 | .RetiresOnSaturation(); |
| 399 | GenHelper<cmds::GenFramebuffersImmediate>(client_framebuffer_id_); |
| 400 | EXPECT_CALL(*gl_, GenRenderbuffersEXT(_, _)) |
| 401 | .WillOnce(SetArgumentPointee<1>(kServiceRenderbufferId)) |
| 402 | .RetiresOnSaturation(); |
| 403 | GenHelper<cmds::GenRenderbuffersImmediate>(client_renderbuffer_id_); |
| 404 | EXPECT_CALL(*gl_, GenTextures(_, _)) |
| 405 | .WillOnce(SetArgumentPointee<1>(kServiceTextureId)) |
| 406 | .RetiresOnSaturation(); |
| 407 | GenHelper<cmds::GenTexturesImmediate>(client_texture_id_); |
| 408 | EXPECT_CALL(*gl_, GenBuffersARB(_, _)) |
| 409 | .WillOnce(SetArgumentPointee<1>(kServiceElementBufferId)) |
| 410 | .RetiresOnSaturation(); |
| 411 | GenHelper<cmds::GenBuffersImmediate>(client_element_buffer_id_); |
| 412 | |
| 413 | DoCreateProgram(client_program_id_, kServiceProgramId); |
| 414 | DoCreateShader(GL_VERTEX_SHADER, client_shader_id_, kServiceShaderId); |
| 415 | |
| 416 | EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 417 | } |
| 418 | |
| 419 | void GLES2DecoderTestBase::ResetDecoder() { |
| 420 | if (!decoder_.get()) |
| 421 | return; |
| 422 | // All Tests should have read all their GLErrors before getting here. |
| 423 | EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 424 | |
| 425 | EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)) |
| 426 | .Times(2) |
| 427 | .RetiresOnSaturation(); |
| 428 | if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 429 | EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, Pointee(kServiceVertexArrayId))) |
| 430 | .Times(1) |
| 431 | .RetiresOnSaturation(); |
| 432 | } |
| 433 | |
| 434 | decoder_->EndDecoding(); |
| 435 | decoder_->Destroy(true); |
| 436 | decoder_.reset(); |
| 437 | group_->Destroy(mock_decoder_.get(), false); |
| 438 | engine_.reset(); |
| 439 | ::gfx::MockGLInterface::SetGLInterface(NULL); |
| 440 | gl_.reset(); |
| 441 | gfx::ClearGLBindings(); |
| 442 | } |
| 443 | |
| 444 | void GLES2DecoderTestBase::TearDown() { |
| 445 | ResetDecoder(); |
| 446 | } |
| 447 | |
| 448 | void GLES2DecoderTestBase::ExpectEnableDisable(GLenum cap, bool enable) { |
| 449 | if (enable) { |
| 450 | EXPECT_CALL(*gl_, Enable(cap)) |
| 451 | .Times(1) |
| 452 | .RetiresOnSaturation(); |
| 453 | } else { |
| 454 | EXPECT_CALL(*gl_, Disable(cap)) |
| 455 | .Times(1) |
| 456 | .RetiresOnSaturation(); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
| 461 | GLint GLES2DecoderTestBase::GetGLError() { |
| 462 | EXPECT_CALL(*gl_, GetError()) |
| 463 | .WillOnce(Return(GL_NO_ERROR)) |
| 464 | .RetiresOnSaturation(); |
| 465 | cmds::GetError cmd; |
| 466 | cmd.Init(shared_memory_id_, shared_memory_offset_); |
| 467 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 468 | return static_cast<GLint>(*GetSharedMemoryAs<GLenum*>()); |
| 469 | } |
| 470 | |
| 471 | void GLES2DecoderTestBase::DoCreateShader( |
| 472 | GLenum shader_type, GLuint client_id, GLuint service_id) { |
| 473 | EXPECT_CALL(*gl_, CreateShader(shader_type)) |
| 474 | .Times(1) |
| 475 | .WillOnce(Return(service_id)) |
| 476 | .RetiresOnSaturation(); |
| 477 | cmds::CreateShader cmd; |
| 478 | cmd.Init(shader_type, client_id); |
| 479 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 480 | } |
| 481 | |
| 482 | bool GLES2DecoderTestBase::DoIsShader(GLuint client_id) { |
| 483 | return IsObjectHelper<cmds::IsShader, cmds::IsShader::Result>(client_id); |
| 484 | } |
| 485 | |
| 486 | void GLES2DecoderTestBase::DoDeleteShader( |
| 487 | GLuint client_id, GLuint service_id) { |
| 488 | EXPECT_CALL(*gl_, DeleteShader(service_id)) |
| 489 | .Times(1) |
| 490 | .RetiresOnSaturation(); |
| 491 | cmds::DeleteShader cmd; |
| 492 | cmd.Init(client_id); |
| 493 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 494 | } |
| 495 | |
| 496 | void GLES2DecoderTestBase::DoCreateProgram( |
| 497 | GLuint client_id, GLuint service_id) { |
| 498 | EXPECT_CALL(*gl_, CreateProgram()) |
| 499 | .Times(1) |
| 500 | .WillOnce(Return(service_id)) |
| 501 | .RetiresOnSaturation(); |
| 502 | cmds::CreateProgram cmd; |
| 503 | cmd.Init(client_id); |
| 504 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 505 | } |
| 506 | |
| 507 | bool GLES2DecoderTestBase::DoIsProgram(GLuint client_id) { |
| 508 | return IsObjectHelper<cmds::IsProgram, cmds::IsProgram::Result>(client_id); |
| 509 | } |
| 510 | |
| 511 | void GLES2DecoderTestBase::DoDeleteProgram( |
| 512 | GLuint client_id, GLuint /* service_id */) { |
| 513 | cmds::DeleteProgram cmd; |
| 514 | cmd.Init(client_id); |
| 515 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 516 | } |
| 517 | |
| 518 | void GLES2DecoderTestBase::SetBucketAsCString( |
| 519 | uint32 bucket_id, const char* str) { |
| 520 | uint32 size = str ? (strlen(str) + 1) : 0; |
| 521 | cmd::SetBucketSize cmd1; |
| 522 | cmd1.Init(bucket_id, size); |
| 523 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1)); |
| 524 | if (str) { |
| 525 | memcpy(shared_memory_address_, str, size); |
| 526 | cmd::SetBucketData cmd2; |
| 527 | cmd2.Init(bucket_id, 0, size, kSharedMemoryId, kSharedMemoryOffset); |
| 528 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2)); |
| 529 | ClearSharedMemory(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | void GLES2DecoderTestBase::SetupClearTextureExpectations( |
| 534 | GLuint service_id, |
| 535 | GLuint old_service_id, |
| 536 | GLenum bind_target, |
| 537 | GLenum target, |
| 538 | GLint level, |
| 539 | GLenum internal_format, |
| 540 | GLenum format, |
| 541 | GLenum type, |
| 542 | GLsizei width, |
| 543 | GLsizei height) { |
| 544 | EXPECT_CALL(*gl_, BindTexture(bind_target, service_id)) |
| 545 | .Times(1) |
| 546 | .RetiresOnSaturation(); |
| 547 | EXPECT_CALL(*gl_, TexImage2D( |
| 548 | target, level, internal_format, width, height, 0, format, type, _)) |
| 549 | .Times(1) |
| 550 | .RetiresOnSaturation(); |
| 551 | EXPECT_CALL(*gl_, BindTexture(bind_target, old_service_id)) |
| 552 | .Times(1) |
| 553 | .RetiresOnSaturation(); |
| 554 | } |
| 555 | |
| 556 | void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearing( |
| 557 | GLenum target, |
| 558 | GLuint clear_bits, |
| 559 | GLclampf restore_red, |
| 560 | GLclampf restore_green, |
| 561 | GLclampf restore_blue, |
| 562 | GLclampf restore_alpha, |
| 563 | GLuint restore_stencil, |
| 564 | GLclampf restore_depth, |
| 565 | bool restore_scissor_test) { |
| 566 | SetupExpectationsForFramebufferClearingMulti( |
| 567 | 0, |
| 568 | 0, |
| 569 | target, |
| 570 | clear_bits, |
| 571 | restore_red, |
| 572 | restore_green, |
| 573 | restore_blue, |
| 574 | restore_alpha, |
| 575 | restore_stencil, |
| 576 | restore_depth, |
| 577 | restore_scissor_test); |
| 578 | } |
| 579 | |
| 580 | void GLES2DecoderTestBase::SetupExpectationsForRestoreClearState( |
| 581 | GLclampf restore_red, |
| 582 | GLclampf restore_green, |
| 583 | GLclampf restore_blue, |
| 584 | GLclampf restore_alpha, |
| 585 | GLuint restore_stencil, |
| 586 | GLclampf restore_depth, |
| 587 | bool restore_scissor_test) { |
| 588 | EXPECT_CALL(*gl_, ClearColor( |
| 589 | restore_red, restore_green, restore_blue, restore_alpha)) |
| 590 | .Times(1) |
| 591 | .RetiresOnSaturation(); |
| 592 | EXPECT_CALL(*gl_, ClearStencil(restore_stencil)) |
| 593 | .Times(1) |
| 594 | .RetiresOnSaturation(); |
| 595 | EXPECT_CALL(*gl_, ClearDepth(restore_depth)) |
| 596 | .Times(1) |
| 597 | .RetiresOnSaturation(); |
| 598 | if (restore_scissor_test) { |
| 599 | EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST)) |
| 600 | .Times(1) |
| 601 | .RetiresOnSaturation(); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | void GLES2DecoderTestBase::SetupExpectationsForFramebufferClearingMulti( |
| 606 | GLuint read_framebuffer_service_id, |
| 607 | GLuint draw_framebuffer_service_id, |
| 608 | GLenum target, |
| 609 | GLuint clear_bits, |
| 610 | GLclampf restore_red, |
| 611 | GLclampf restore_green, |
| 612 | GLclampf restore_blue, |
| 613 | GLclampf restore_alpha, |
| 614 | GLuint restore_stencil, |
| 615 | GLclampf restore_depth, |
| 616 | bool restore_scissor_test) { |
| 617 | // TODO(gman): Figure out why InSequence stopped working. |
| 618 | // InSequence sequence; |
| 619 | EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(target)) |
| 620 | .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) |
| 621 | .RetiresOnSaturation(); |
| 622 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
| 623 | EXPECT_CALL(*gl_, BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0)) |
| 624 | .Times(1) |
| 625 | .RetiresOnSaturation(); |
| 626 | EXPECT_CALL(*gl_, BindFramebufferEXT( |
| 627 | GL_DRAW_FRAMEBUFFER_EXT, read_framebuffer_service_id)) |
| 628 | .Times(1) |
| 629 | .RetiresOnSaturation(); |
| 630 | } |
| 631 | if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) { |
| 632 | EXPECT_CALL(*gl_, ClearColor(0.0f, 0.0f, 0.0f, 0.0f)) |
| 633 | .Times(1) |
| 634 | .RetiresOnSaturation(); |
| 635 | SetupExpectationsForColorMask(true, true, true, true); |
| 636 | } |
| 637 | if ((clear_bits & GL_STENCIL_BUFFER_BIT) != 0) { |
| 638 | EXPECT_CALL(*gl_, ClearStencil(0)) |
| 639 | .Times(1) |
| 640 | .RetiresOnSaturation(); |
| 641 | EXPECT_CALL(*gl_, StencilMask(static_cast<GLuint>(-1))) |
| 642 | .Times(1) |
| 643 | .RetiresOnSaturation(); |
| 644 | } |
| 645 | if ((clear_bits & GL_DEPTH_BUFFER_BIT) != 0) { |
| 646 | EXPECT_CALL(*gl_, ClearDepth(1.0f)) |
| 647 | .Times(1) |
| 648 | .RetiresOnSaturation(); |
| 649 | SetupExpectationsForDepthMask(true); |
| 650 | } |
| 651 | SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, false); |
| 652 | EXPECT_CALL(*gl_, Clear(clear_bits)) |
| 653 | .Times(1) |
| 654 | .RetiresOnSaturation(); |
| 655 | SetupExpectationsForRestoreClearState( |
| 656 | restore_red, restore_green, restore_blue, restore_alpha, |
| 657 | restore_stencil, restore_depth, restore_scissor_test); |
| 658 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
| 659 | EXPECT_CALL(*gl_, BindFramebufferEXT( |
| 660 | GL_READ_FRAMEBUFFER_EXT, read_framebuffer_service_id)) |
| 661 | .Times(1) |
| 662 | .RetiresOnSaturation(); |
| 663 | EXPECT_CALL(*gl_, BindFramebufferEXT( |
| 664 | GL_DRAW_FRAMEBUFFER_EXT, draw_framebuffer_service_id)) |
| 665 | .Times(1) |
| 666 | .RetiresOnSaturation(); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void GLES2DecoderTestBase::SetupShaderForUniform(GLenum uniform_type) { |
| 671 | static AttribInfo attribs[] = { |
| 672 | { "foo", 1, GL_FLOAT, 1, }, |
| 673 | { "goo", 1, GL_FLOAT, 2, }, |
| 674 | }; |
| 675 | UniformInfo uniforms[] = { |
| 676 | { "bar", 1, uniform_type, 0, 2, -1, }, |
| 677 | { "car", 4, uniform_type, 1, 1, -1, }, |
| 678 | }; |
| 679 | const GLuint kClientVertexShaderId = 5001; |
| 680 | const GLuint kServiceVertexShaderId = 6001; |
| 681 | const GLuint kClientFragmentShaderId = 5002; |
| 682 | const GLuint kServiceFragmentShaderId = 6002; |
| 683 | SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms), |
| 684 | client_program_id_, kServiceProgramId, |
| 685 | kClientVertexShaderId, kServiceVertexShaderId, |
| 686 | kClientFragmentShaderId, kServiceFragmentShaderId); |
| 687 | |
| 688 | EXPECT_CALL(*gl_, UseProgram(kServiceProgramId)) |
| 689 | .Times(1) |
| 690 | .RetiresOnSaturation(); |
| 691 | cmds::UseProgram cmd; |
| 692 | cmd.Init(client_program_id_); |
| 693 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 694 | } |
| 695 | |
| 696 | void GLES2DecoderTestBase::DoBindBuffer( |
| 697 | GLenum target, GLuint client_id, GLuint service_id) { |
| 698 | EXPECT_CALL(*gl_, BindBuffer(target, service_id)) |
| 699 | .Times(1) |
| 700 | .RetiresOnSaturation(); |
| 701 | cmds::BindBuffer cmd; |
| 702 | cmd.Init(target, client_id); |
| 703 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 704 | } |
| 705 | |
| 706 | bool GLES2DecoderTestBase::DoIsBuffer(GLuint client_id) { |
| 707 | return IsObjectHelper<cmds::IsBuffer, cmds::IsBuffer::Result>(client_id); |
| 708 | } |
| 709 | |
| 710 | void GLES2DecoderTestBase::DoDeleteBuffer( |
| 711 | GLuint client_id, GLuint service_id) { |
| 712 | EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id))) |
| 713 | .Times(1) |
| 714 | .RetiresOnSaturation(); |
| 715 | GenHelper<cmds::DeleteBuffersImmediate>(client_id); |
| 716 | } |
| 717 | |
| 718 | void GLES2DecoderTestBase::SetupExpectationsForColorMask(bool red, |
| 719 | bool green, |
| 720 | bool blue, |
| 721 | bool alpha) { |
| 722 | if (ignore_cached_state_for_test_ || cached_color_mask_red_ != red || |
| 723 | cached_color_mask_green_ != green || cached_color_mask_blue_ != blue || |
| 724 | cached_color_mask_alpha_ != alpha) { |
| 725 | cached_color_mask_red_ = red; |
| 726 | cached_color_mask_green_ = green; |
| 727 | cached_color_mask_blue_ = blue; |
| 728 | cached_color_mask_alpha_ = alpha; |
| 729 | EXPECT_CALL(*gl_, ColorMask(red, green, blue, alpha)) |
| 730 | .Times(1) |
| 731 | .RetiresOnSaturation(); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | void GLES2DecoderTestBase::SetupExpectationsForDepthMask(bool mask) { |
| 736 | if (ignore_cached_state_for_test_ || cached_depth_mask_ != mask) { |
| 737 | cached_depth_mask_ = mask; |
| 738 | EXPECT_CALL(*gl_, DepthMask(mask)).Times(1).RetiresOnSaturation(); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | void GLES2DecoderTestBase::SetupExpectationsForStencilMask(GLuint front_mask, |
| 743 | GLuint back_mask) { |
| 744 | if (ignore_cached_state_for_test_ || |
| 745 | cached_stencil_front_mask_ != front_mask) { |
| 746 | cached_stencil_front_mask_ = front_mask; |
| 747 | EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_mask)) |
| 748 | .Times(1) |
| 749 | .RetiresOnSaturation(); |
| 750 | } |
| 751 | |
| 752 | if (ignore_cached_state_for_test_ || |
| 753 | cached_stencil_back_mask_ != back_mask) { |
| 754 | cached_stencil_back_mask_ = back_mask; |
| 755 | EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_mask)) |
| 756 | .Times(1) |
| 757 | .RetiresOnSaturation(); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void GLES2DecoderTestBase::SetupExpectationsForEnableDisable(GLenum cap, |
| 762 | bool enable) { |
| 763 | switch (cap) { |
| 764 | case GL_BLEND: |
| 765 | if (enable_flags_.cached_blend == enable && |
| 766 | !ignore_cached_state_for_test_) |
| 767 | return; |
| 768 | enable_flags_.cached_blend = enable; |
| 769 | break; |
| 770 | case GL_CULL_FACE: |
| 771 | if (enable_flags_.cached_cull_face == enable && |
| 772 | !ignore_cached_state_for_test_) |
| 773 | return; |
| 774 | enable_flags_.cached_cull_face = enable; |
| 775 | break; |
| 776 | case GL_DEPTH_TEST: |
| 777 | if (enable_flags_.cached_depth_test == enable && |
| 778 | !ignore_cached_state_for_test_) |
| 779 | return; |
| 780 | enable_flags_.cached_depth_test = enable; |
| 781 | break; |
| 782 | case GL_DITHER: |
| 783 | if (enable_flags_.cached_dither == enable && |
| 784 | !ignore_cached_state_for_test_) |
| 785 | return; |
| 786 | enable_flags_.cached_dither = enable; |
| 787 | break; |
| 788 | case GL_POLYGON_OFFSET_FILL: |
| 789 | if (enable_flags_.cached_polygon_offset_fill == enable && |
| 790 | !ignore_cached_state_for_test_) |
| 791 | return; |
| 792 | enable_flags_.cached_polygon_offset_fill = enable; |
| 793 | break; |
| 794 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 795 | if (enable_flags_.cached_sample_alpha_to_coverage == enable && |
| 796 | !ignore_cached_state_for_test_) |
| 797 | return; |
| 798 | enable_flags_.cached_sample_alpha_to_coverage = enable; |
| 799 | break; |
| 800 | case GL_SAMPLE_COVERAGE: |
| 801 | if (enable_flags_.cached_sample_coverage == enable && |
| 802 | !ignore_cached_state_for_test_) |
| 803 | return; |
| 804 | enable_flags_.cached_sample_coverage = enable; |
| 805 | break; |
| 806 | case GL_SCISSOR_TEST: |
| 807 | if (enable_flags_.cached_scissor_test == enable && |
| 808 | !ignore_cached_state_for_test_) |
| 809 | return; |
| 810 | enable_flags_.cached_scissor_test = enable; |
| 811 | break; |
| 812 | case GL_STENCIL_TEST: |
| 813 | if (enable_flags_.cached_stencil_test == enable && |
| 814 | !ignore_cached_state_for_test_) |
| 815 | return; |
| 816 | enable_flags_.cached_stencil_test = enable; |
| 817 | break; |
| 818 | default: |
| 819 | NOTREACHED(); |
| 820 | return; |
| 821 | } |
| 822 | if (enable) { |
| 823 | EXPECT_CALL(*gl_, Enable(cap)).Times(1).RetiresOnSaturation(); |
| 824 | } else { |
| 825 | EXPECT_CALL(*gl_, Disable(cap)).Times(1).RetiresOnSaturation(); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState( |
| 830 | bool framebuffer_is_rgb, |
| 831 | bool framebuffer_has_depth, |
| 832 | bool framebuffer_has_stencil, |
| 833 | GLuint color_bits, |
| 834 | bool depth_mask, |
| 835 | bool depth_enabled, |
| 836 | GLuint front_stencil_mask, |
| 837 | GLuint back_stencil_mask, |
| 838 | bool stencil_enabled) { |
| 839 | bool color_mask_red = (color_bits & 0x1000) != 0; |
| 840 | bool color_mask_green = (color_bits & 0x0100) != 0; |
| 841 | bool color_mask_blue = (color_bits & 0x0010) != 0; |
| 842 | bool color_mask_alpha = (color_bits & 0x0001) && !framebuffer_is_rgb; |
| 843 | |
| 844 | SetupExpectationsForColorMask( |
| 845 | color_mask_red, color_mask_green, color_mask_blue, color_mask_alpha); |
| 846 | SetupExpectationsForDepthMask(depth_mask); |
| 847 | SetupExpectationsForStencilMask(front_stencil_mask, back_stencil_mask); |
| 848 | SetupExpectationsForEnableDisable(GL_DEPTH_TEST, |
| 849 | framebuffer_has_depth && depth_enabled); |
| 850 | SetupExpectationsForEnableDisable(GL_STENCIL_TEST, |
| 851 | framebuffer_has_stencil && stencil_enabled); |
| 852 | } |
| 853 | |
| 854 | void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() { |
| 855 | SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB |
| 856 | false, // Framebuffer has depth |
| 857 | false, // Framebuffer has stencil |
| 858 | 0x1111, // color bits |
| 859 | true, // depth mask |
| 860 | false, // depth enabled |
| 861 | 0, // front stencil mask |
| 862 | 0, // back stencil mask |
| 863 | false); // stencil enabled |
| 864 | } |
| 865 | |
| 866 | GLES2DecoderTestBase::EnableFlags::EnableFlags() |
| 867 | : cached_blend(false), |
| 868 | cached_cull_face(false), |
| 869 | cached_depth_test(false), |
| 870 | cached_dither(true), |
| 871 | cached_polygon_offset_fill(false), |
| 872 | cached_sample_alpha_to_coverage(false), |
| 873 | cached_sample_coverage(false), |
| 874 | cached_scissor_test(false), |
| 875 | cached_stencil_test(false) { |
| 876 | } |
| 877 | |
| 878 | void GLES2DecoderTestBase::DoBindFramebuffer( |
| 879 | GLenum target, GLuint client_id, GLuint service_id) { |
| 880 | EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id)) |
| 881 | .Times(1) |
| 882 | .RetiresOnSaturation(); |
| 883 | cmds::BindFramebuffer cmd; |
| 884 | cmd.Init(target, client_id); |
| 885 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 886 | } |
| 887 | |
| 888 | bool GLES2DecoderTestBase::DoIsFramebuffer(GLuint client_id) { |
| 889 | return IsObjectHelper<cmds::IsFramebuffer, cmds::IsFramebuffer::Result>( |
| 890 | client_id); |
| 891 | } |
| 892 | |
| 893 | void GLES2DecoderTestBase::DoDeleteFramebuffer( |
| 894 | GLuint client_id, GLuint service_id, |
| 895 | bool reset_draw, GLenum draw_target, GLuint draw_id, |
| 896 | bool reset_read, GLenum read_target, GLuint read_id) { |
| 897 | if (reset_draw) { |
| 898 | EXPECT_CALL(*gl_, BindFramebufferEXT(draw_target, draw_id)) |
| 899 | .Times(1) |
| 900 | .RetiresOnSaturation(); |
| 901 | } |
| 902 | if (reset_read) { |
| 903 | EXPECT_CALL(*gl_, BindFramebufferEXT(read_target, read_id)) |
| 904 | .Times(1) |
| 905 | .RetiresOnSaturation(); |
| 906 | } |
| 907 | EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, Pointee(service_id))) |
| 908 | .Times(1) |
| 909 | .RetiresOnSaturation(); |
| 910 | GenHelper<cmds::DeleteFramebuffersImmediate>(client_id); |
| 911 | } |
| 912 | |
| 913 | void GLES2DecoderTestBase::DoBindRenderbuffer( |
| 914 | GLenum target, GLuint client_id, GLuint service_id) { |
| 915 | service_renderbuffer_id_ = service_id; |
| 916 | service_renderbuffer_valid_ = true; |
| 917 | EXPECT_CALL(*gl_, BindRenderbufferEXT(target, service_id)) |
| 918 | .Times(1) |
| 919 | .RetiresOnSaturation(); |
| 920 | cmds::BindRenderbuffer cmd; |
| 921 | cmd.Init(target, client_id); |
| 922 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 923 | } |
| 924 | |
| 925 | void GLES2DecoderTestBase::DoRenderbufferStorageMultisampleCHROMIUM( |
| 926 | GLenum target, |
| 927 | GLsizei samples, |
| 928 | GLenum internal_format, |
| 929 | GLenum gl_format, |
| 930 | GLsizei width, |
| 931 | GLsizei height) { |
| 932 | EXPECT_CALL(*gl_, GetError()) |
| 933 | .WillOnce(Return(GL_NO_ERROR)) |
| 934 | .RetiresOnSaturation(); |
| 935 | EXPECT_CALL(*gl_, |
| 936 | RenderbufferStorageMultisampleEXT( |
| 937 | target, samples, gl_format, width, height)) |
| 938 | .Times(1) |
| 939 | .RetiresOnSaturation(); |
| 940 | EXPECT_CALL(*gl_, GetError()) |
| 941 | .WillOnce(Return(GL_NO_ERROR)) |
| 942 | .RetiresOnSaturation(); |
| 943 | cmds::RenderbufferStorageMultisampleCHROMIUM cmd; |
| 944 | cmd.Init(target, samples, internal_format, width, height); |
| 945 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 946 | EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 947 | } |
| 948 | |
| 949 | void GLES2DecoderTestBase::RestoreRenderbufferBindings() { |
| 950 | GetDecoder()->RestoreRenderbufferBindings(); |
| 951 | service_renderbuffer_valid_ = false; |
| 952 | } |
| 953 | |
| 954 | void GLES2DecoderTestBase::EnsureRenderbufferBound(bool expect_bind) { |
| 955 | EXPECT_NE(expect_bind, service_renderbuffer_valid_); |
| 956 | |
| 957 | if (expect_bind) { |
| 958 | service_renderbuffer_valid_ = true; |
| 959 | EXPECT_CALL(*gl_, |
| 960 | BindRenderbufferEXT(GL_RENDERBUFFER, service_renderbuffer_id_)) |
| 961 | .Times(1) |
| 962 | .RetiresOnSaturation(); |
| 963 | } else { |
| 964 | EXPECT_CALL(*gl_, BindRenderbufferEXT(_, _)).Times(0); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | bool GLES2DecoderTestBase::DoIsRenderbuffer(GLuint client_id) { |
| 969 | return IsObjectHelper<cmds::IsRenderbuffer, cmds::IsRenderbuffer::Result>( |
| 970 | client_id); |
| 971 | } |
| 972 | |
| 973 | void GLES2DecoderTestBase::DoDeleteRenderbuffer( |
| 974 | GLuint client_id, GLuint service_id) { |
| 975 | EXPECT_CALL(*gl_, DeleteRenderbuffersEXT(1, Pointee(service_id))) |
| 976 | .Times(1) |
| 977 | .RetiresOnSaturation(); |
| 978 | GenHelper<cmds::DeleteRenderbuffersImmediate>(client_id); |
| 979 | } |
| 980 | |
| 981 | void GLES2DecoderTestBase::DoBindTexture( |
| 982 | GLenum target, GLuint client_id, GLuint service_id) { |
| 983 | EXPECT_CALL(*gl_, BindTexture(target, service_id)) |
| 984 | .Times(1) |
| 985 | .RetiresOnSaturation(); |
| 986 | cmds::BindTexture cmd; |
| 987 | cmd.Init(target, client_id); |
| 988 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 989 | } |
| 990 | |
| 991 | bool GLES2DecoderTestBase::DoIsTexture(GLuint client_id) { |
| 992 | return IsObjectHelper<cmds::IsTexture, cmds::IsTexture::Result>(client_id); |
| 993 | } |
| 994 | |
| 995 | void GLES2DecoderTestBase::DoDeleteTexture( |
| 996 | GLuint client_id, GLuint service_id) { |
| 997 | EXPECT_CALL(*gl_, DeleteTextures(1, Pointee(service_id))) |
| 998 | .Times(1) |
| 999 | .RetiresOnSaturation(); |
| 1000 | GenHelper<cmds::DeleteTexturesImmediate>(client_id); |
| 1001 | } |
| 1002 | |
| 1003 | void GLES2DecoderTestBase::DoTexImage2D( |
| 1004 | GLenum target, GLint level, GLenum internal_format, |
| 1005 | GLsizei width, GLsizei height, GLint border, |
| 1006 | GLenum format, GLenum type, |
| 1007 | uint32 shared_memory_id, uint32 shared_memory_offset) { |
| 1008 | EXPECT_CALL(*gl_, GetError()) |
| 1009 | .WillOnce(Return(GL_NO_ERROR)) |
| 1010 | .RetiresOnSaturation(); |
| 1011 | EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format, |
| 1012 | width, height, border, format, type, _)) |
| 1013 | .Times(1) |
| 1014 | .RetiresOnSaturation(); |
| 1015 | EXPECT_CALL(*gl_, GetError()) |
| 1016 | .WillOnce(Return(GL_NO_ERROR)) |
| 1017 | .RetiresOnSaturation(); |
| 1018 | cmds::TexImage2D cmd; |
| 1019 | cmd.Init(target, level, internal_format, width, height, format, |
| 1020 | type, shared_memory_id, shared_memory_offset); |
| 1021 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1022 | } |
| 1023 | |
| 1024 | void GLES2DecoderTestBase::DoTexImage2DConvertInternalFormat( |
| 1025 | GLenum target, GLint level, GLenum requested_internal_format, |
| 1026 | GLsizei width, GLsizei height, GLint border, |
| 1027 | GLenum format, GLenum type, |
| 1028 | uint32 shared_memory_id, uint32 shared_memory_offset, |
| 1029 | GLenum expected_internal_format) { |
| 1030 | EXPECT_CALL(*gl_, GetError()) |
| 1031 | .WillOnce(Return(GL_NO_ERROR)) |
| 1032 | .RetiresOnSaturation(); |
| 1033 | EXPECT_CALL(*gl_, TexImage2D(target, level, expected_internal_format, |
| 1034 | width, height, border, format, type, _)) |
| 1035 | .Times(1) |
| 1036 | .RetiresOnSaturation(); |
| 1037 | EXPECT_CALL(*gl_, GetError()) |
| 1038 | .WillOnce(Return(GL_NO_ERROR)) |
| 1039 | .RetiresOnSaturation(); |
| 1040 | cmds::TexImage2D cmd; |
| 1041 | cmd.Init(target, level, requested_internal_format, width, height, |
| 1042 | format, type, shared_memory_id, shared_memory_offset); |
| 1043 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1044 | } |
| 1045 | |
| 1046 | void GLES2DecoderTestBase::DoCompressedTexImage2D( |
| 1047 | GLenum target, GLint level, GLenum format, |
| 1048 | GLsizei width, GLsizei height, GLint border, |
| 1049 | GLsizei size, uint32 bucket_id) { |
| 1050 | EXPECT_CALL(*gl_, GetError()) |
| 1051 | .WillOnce(Return(GL_NO_ERROR)) |
| 1052 | .RetiresOnSaturation(); |
| 1053 | EXPECT_CALL(*gl_, CompressedTexImage2D( |
| 1054 | target, level, format, width, height, border, size, _)) |
| 1055 | .Times(1) |
| 1056 | .RetiresOnSaturation(); |
| 1057 | EXPECT_CALL(*gl_, GetError()) |
| 1058 | .WillOnce(Return(GL_NO_ERROR)) |
| 1059 | .RetiresOnSaturation(); |
| 1060 | CommonDecoder::Bucket* bucket = decoder_->CreateBucket(bucket_id); |
| 1061 | bucket->SetSize(size); |
| 1062 | cmds::CompressedTexImage2DBucket cmd; |
| 1063 | cmd.Init( |
| 1064 | target, level, format, width, height, |
| 1065 | bucket_id); |
| 1066 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1067 | } |
| 1068 | |
| 1069 | void GLES2DecoderTestBase::DoRenderbufferStorage( |
| 1070 | GLenum target, GLenum internal_format, GLenum actual_format, |
| 1071 | GLsizei width, GLsizei height, GLenum error) { |
| 1072 | EXPECT_CALL(*gl_, GetError()) |
| 1073 | .WillOnce(Return(GL_NO_ERROR)) |
| 1074 | .RetiresOnSaturation(); |
| 1075 | EXPECT_CALL(*gl_, RenderbufferStorageEXT( |
| 1076 | target, actual_format, width, height)) |
| 1077 | .Times(1) |
| 1078 | .RetiresOnSaturation(); |
| 1079 | EXPECT_CALL(*gl_, GetError()) |
| 1080 | .WillOnce(Return(error)) |
| 1081 | .RetiresOnSaturation(); |
| 1082 | cmds::RenderbufferStorage cmd; |
| 1083 | cmd.Init(target, internal_format, width, height); |
| 1084 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1085 | } |
| 1086 | |
| 1087 | void GLES2DecoderTestBase::DoFramebufferTexture2D( |
| 1088 | GLenum target, GLenum attachment, GLenum textarget, |
| 1089 | GLuint texture_client_id, GLuint texture_service_id, GLint level, |
| 1090 | GLenum error) { |
| 1091 | EXPECT_CALL(*gl_, GetError()) |
| 1092 | .WillOnce(Return(GL_NO_ERROR)) |
| 1093 | .RetiresOnSaturation(); |
| 1094 | EXPECT_CALL(*gl_, FramebufferTexture2DEXT( |
| 1095 | target, attachment, textarget, texture_service_id, level)) |
| 1096 | .Times(1) |
| 1097 | .RetiresOnSaturation(); |
| 1098 | EXPECT_CALL(*gl_, GetError()) |
| 1099 | .WillOnce(Return(error)) |
| 1100 | .RetiresOnSaturation(); |
| 1101 | cmds::FramebufferTexture2D cmd; |
| 1102 | cmd.Init(target, attachment, textarget, texture_client_id); |
| 1103 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1104 | } |
| 1105 | |
| 1106 | void GLES2DecoderTestBase::DoFramebufferRenderbuffer( |
| 1107 | GLenum target, |
| 1108 | GLenum attachment, |
| 1109 | GLenum renderbuffer_target, |
| 1110 | GLuint renderbuffer_client_id, |
| 1111 | GLuint renderbuffer_service_id, |
| 1112 | GLenum error) { |
| 1113 | EXPECT_CALL(*gl_, GetError()) |
| 1114 | .WillOnce(Return(GL_NO_ERROR)) |
| 1115 | .RetiresOnSaturation(); |
| 1116 | EXPECT_CALL(*gl_, FramebufferRenderbufferEXT( |
| 1117 | target, attachment, renderbuffer_target, renderbuffer_service_id)) |
| 1118 | .Times(1) |
| 1119 | .RetiresOnSaturation(); |
| 1120 | EXPECT_CALL(*gl_, GetError()) |
| 1121 | .WillOnce(Return(error)) |
| 1122 | .RetiresOnSaturation(); |
| 1123 | cmds::FramebufferRenderbuffer cmd; |
| 1124 | cmd.Init(target, attachment, renderbuffer_target, renderbuffer_client_id); |
| 1125 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1126 | } |
| 1127 | |
| 1128 | void GLES2DecoderTestBase::DoVertexAttribPointer( |
| 1129 | GLuint index, GLint size, GLenum type, GLsizei stride, GLuint offset) { |
| 1130 | EXPECT_CALL(*gl_, |
| 1131 | VertexAttribPointer(index, size, type, GL_FALSE, stride, |
| 1132 | BufferOffset(offset))) |
| 1133 | .Times(1) |
| 1134 | .RetiresOnSaturation(); |
| 1135 | cmds::VertexAttribPointer cmd; |
| 1136 | cmd.Init(index, size, GL_FLOAT, GL_FALSE, stride, offset); |
| 1137 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1138 | } |
| 1139 | |
| 1140 | void GLES2DecoderTestBase::DoVertexAttribDivisorANGLE( |
| 1141 | GLuint index, GLuint divisor) { |
| 1142 | EXPECT_CALL(*gl_, |
| 1143 | VertexAttribDivisorANGLE(index, divisor)) |
| 1144 | .Times(1) |
| 1145 | .RetiresOnSaturation(); |
| 1146 | cmds::VertexAttribDivisorANGLE cmd; |
| 1147 | cmd.Init(index, divisor); |
| 1148 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1149 | } |
| 1150 | |
| 1151 | void GLES2DecoderTestBase::AddExpectationsForGenVertexArraysOES(){ |
| 1152 | if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 1153 | EXPECT_CALL(*gl_, GenVertexArraysOES(1, _)) |
| 1154 | .WillOnce(SetArgumentPointee<1>(kServiceVertexArrayId)) |
| 1155 | .RetiresOnSaturation(); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | void GLES2DecoderTestBase::AddExpectationsForDeleteVertexArraysOES(){ |
| 1160 | if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 1161 | EXPECT_CALL(*gl_, DeleteVertexArraysOES(1, _)) |
| 1162 | .Times(1) |
| 1163 | .RetiresOnSaturation(); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | void GLES2DecoderTestBase::AddExpectationsForDeleteBoundVertexArraysOES() { |
| 1168 | // Expectations are the same as a delete, followed by binding VAO 0. |
| 1169 | AddExpectationsForDeleteVertexArraysOES(); |
| 1170 | AddExpectationsForBindVertexArrayOES(); |
| 1171 | } |
| 1172 | |
| 1173 | void GLES2DecoderTestBase::AddExpectationsForBindVertexArrayOES() { |
| 1174 | if (group_->feature_info()->feature_flags().native_vertex_array_object) { |
| 1175 | EXPECT_CALL(*gl_, BindVertexArrayOES(_)) |
| 1176 | .Times(1) |
| 1177 | .RetiresOnSaturation(); |
| 1178 | } else { |
| 1179 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
| 1180 | AddExpectationsForRestoreAttribState(vv); |
| 1181 | } |
| 1182 | |
| 1183 | EXPECT_CALL(*gl_, BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _)) |
| 1184 | .Times(1) |
| 1185 | .RetiresOnSaturation(); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) { |
| 1190 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _)) |
| 1191 | .Times(1) |
| 1192 | .RetiresOnSaturation(); |
| 1193 | |
| 1194 | EXPECT_CALL(*gl_, VertexAttribPointer(attrib, _, _, _, _, _)) |
| 1195 | .Times(1) |
| 1196 | .RetiresOnSaturation(); |
| 1197 | |
| 1198 | EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(attrib, _)) |
| 1199 | .Times(testing::AtMost(1)) |
| 1200 | .RetiresOnSaturation(); |
| 1201 | |
| 1202 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _)) |
| 1203 | .Times(1) |
| 1204 | .RetiresOnSaturation(); |
| 1205 | |
| 1206 | if (attrib != 0 || |
| 1207 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 1208 | |
| 1209 | // TODO(bajones): Not sure if I can tell which of these will be called |
| 1210 | EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib)) |
| 1211 | .Times(testing::AtMost(1)) |
| 1212 | .RetiresOnSaturation(); |
| 1213 | |
| 1214 | EXPECT_CALL(*gl_, DisableVertexAttribArray(attrib)) |
| 1215 | .Times(testing::AtMost(1)) |
| 1216 | .RetiresOnSaturation(); |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | // GCC requires these declarations, but MSVC requires they not be present |
| 1221 | #ifndef COMPILER_MSVC |
| 1222 | const int GLES2DecoderTestBase::kBackBufferWidth; |
| 1223 | const int GLES2DecoderTestBase::kBackBufferHeight; |
| 1224 | |
| 1225 | const GLint GLES2DecoderTestBase::kMaxTextureSize; |
| 1226 | const GLint GLES2DecoderTestBase::kMaxCubeMapTextureSize; |
| 1227 | const GLint GLES2DecoderTestBase::kNumVertexAttribs; |
| 1228 | const GLint GLES2DecoderTestBase::kNumTextureUnits; |
| 1229 | const GLint GLES2DecoderTestBase::kMaxTextureImageUnits; |
| 1230 | const GLint GLES2DecoderTestBase::kMaxVertexTextureImageUnits; |
| 1231 | const GLint GLES2DecoderTestBase::kMaxFragmentUniformVectors; |
| 1232 | const GLint GLES2DecoderTestBase::kMaxVaryingVectors; |
| 1233 | const GLint GLES2DecoderTestBase::kMaxVertexUniformVectors; |
| 1234 | const GLint GLES2DecoderTestBase::kMaxViewportWidth; |
| 1235 | const GLint GLES2DecoderTestBase::kMaxViewportHeight; |
| 1236 | |
| 1237 | const GLint GLES2DecoderTestBase::kViewportX; |
| 1238 | const GLint GLES2DecoderTestBase::kViewportY; |
| 1239 | const GLint GLES2DecoderTestBase::kViewportWidth; |
| 1240 | const GLint GLES2DecoderTestBase::kViewportHeight; |
| 1241 | |
| 1242 | const GLuint GLES2DecoderTestBase::kServiceAttrib0BufferId; |
| 1243 | const GLuint GLES2DecoderTestBase::kServiceFixedAttribBufferId; |
| 1244 | |
| 1245 | const GLuint GLES2DecoderTestBase::kServiceBufferId; |
| 1246 | const GLuint GLES2DecoderTestBase::kServiceFramebufferId; |
| 1247 | const GLuint GLES2DecoderTestBase::kServiceRenderbufferId; |
| 1248 | const GLuint GLES2DecoderTestBase::kServiceTextureId; |
| 1249 | const GLuint GLES2DecoderTestBase::kServiceProgramId; |
| 1250 | const GLuint GLES2DecoderTestBase::kServiceShaderId; |
| 1251 | const GLuint GLES2DecoderTestBase::kServiceElementBufferId; |
| 1252 | const GLuint GLES2DecoderTestBase::kServiceQueryId; |
| 1253 | const GLuint GLES2DecoderTestBase::kServiceVertexArrayId; |
| 1254 | |
| 1255 | const int32 GLES2DecoderTestBase::kSharedMemoryId; |
| 1256 | const size_t GLES2DecoderTestBase::kSharedBufferSize; |
| 1257 | const uint32 GLES2DecoderTestBase::kSharedMemoryOffset; |
| 1258 | const int32 GLES2DecoderTestBase::kInvalidSharedMemoryId; |
| 1259 | const uint32 GLES2DecoderTestBase::kInvalidSharedMemoryOffset; |
| 1260 | const uint32 GLES2DecoderTestBase::kInitialResult; |
| 1261 | const uint8 GLES2DecoderTestBase::kInitialMemoryValue; |
| 1262 | |
| 1263 | const uint32 GLES2DecoderTestBase::kNewClientId; |
| 1264 | const uint32 GLES2DecoderTestBase::kNewServiceId; |
| 1265 | const uint32 GLES2DecoderTestBase::kInvalidClientId; |
| 1266 | |
| 1267 | const GLuint GLES2DecoderTestBase::kServiceVertexShaderId; |
| 1268 | const GLuint GLES2DecoderTestBase::kServiceFragmentShaderId; |
| 1269 | |
| 1270 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumShaderId; |
| 1271 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumProgramId; |
| 1272 | |
| 1273 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTextureBufferId; |
| 1274 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumVertexBufferId; |
| 1275 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumFBOId; |
| 1276 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumPositionAttrib; |
| 1277 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumTexAttrib; |
| 1278 | const GLuint GLES2DecoderTestBase::kServiceCopyTextureChromiumSamplerLocation; |
| 1279 | |
| 1280 | const GLsizei GLES2DecoderTestBase::kNumVertices; |
| 1281 | const GLsizei GLES2DecoderTestBase::kNumIndices; |
| 1282 | const int GLES2DecoderTestBase::kValidIndexRangeStart; |
| 1283 | const int GLES2DecoderTestBase::kValidIndexRangeCount; |
| 1284 | const int GLES2DecoderTestBase::kInvalidIndexRangeStart; |
| 1285 | const int GLES2DecoderTestBase::kInvalidIndexRangeCount; |
| 1286 | const int GLES2DecoderTestBase::kOutOfRangeIndexRangeEnd; |
| 1287 | const GLuint GLES2DecoderTestBase::kMaxValidIndex; |
| 1288 | |
| 1289 | const GLint GLES2DecoderTestBase::kMaxAttribLength; |
| 1290 | const GLint GLES2DecoderTestBase::kAttrib1Size; |
| 1291 | const GLint GLES2DecoderTestBase::kAttrib2Size; |
| 1292 | const GLint GLES2DecoderTestBase::kAttrib3Size; |
| 1293 | const GLint GLES2DecoderTestBase::kAttrib1Location; |
| 1294 | const GLint GLES2DecoderTestBase::kAttrib2Location; |
| 1295 | const GLint GLES2DecoderTestBase::kAttrib3Location; |
| 1296 | const GLenum GLES2DecoderTestBase::kAttrib1Type; |
| 1297 | const GLenum GLES2DecoderTestBase::kAttrib2Type; |
| 1298 | const GLenum GLES2DecoderTestBase::kAttrib3Type; |
| 1299 | const GLint GLES2DecoderTestBase::kInvalidAttribLocation; |
| 1300 | const GLint GLES2DecoderTestBase::kBadAttribIndex; |
| 1301 | |
| 1302 | const GLint GLES2DecoderTestBase::kMaxUniformLength; |
| 1303 | const GLint GLES2DecoderTestBase::kUniform1Size; |
| 1304 | const GLint GLES2DecoderTestBase::kUniform2Size; |
| 1305 | const GLint GLES2DecoderTestBase::kUniform3Size; |
| 1306 | const GLint GLES2DecoderTestBase::kUniform1RealLocation; |
| 1307 | const GLint GLES2DecoderTestBase::kUniform2RealLocation; |
| 1308 | const GLint GLES2DecoderTestBase::kUniform2ElementRealLocation; |
| 1309 | const GLint GLES2DecoderTestBase::kUniform3RealLocation; |
| 1310 | const GLint GLES2DecoderTestBase::kUniform1FakeLocation; |
| 1311 | const GLint GLES2DecoderTestBase::kUniform2FakeLocation; |
| 1312 | const GLint GLES2DecoderTestBase::kUniform2ElementFakeLocation; |
| 1313 | const GLint GLES2DecoderTestBase::kUniform3FakeLocation; |
| 1314 | const GLint GLES2DecoderTestBase::kUniform1DesiredLocation; |
| 1315 | const GLint GLES2DecoderTestBase::kUniform2DesiredLocation; |
| 1316 | const GLint GLES2DecoderTestBase::kUniform3DesiredLocation; |
| 1317 | const GLenum GLES2DecoderTestBase::kUniform1Type; |
| 1318 | const GLenum GLES2DecoderTestBase::kUniform2Type; |
| 1319 | const GLenum GLES2DecoderTestBase::kUniform3Type; |
| 1320 | const GLenum GLES2DecoderTestBase::kUniformCubemapType; |
| 1321 | const GLint GLES2DecoderTestBase::kInvalidUniformLocation; |
| 1322 | const GLint GLES2DecoderTestBase::kBadUniformIndex; |
| 1323 | |
| 1324 | #endif |
| 1325 | |
| 1326 | const char* GLES2DecoderTestBase::kAttrib1Name = "attrib1"; |
| 1327 | const char* GLES2DecoderTestBase::kAttrib2Name = "attrib2"; |
| 1328 | const char* GLES2DecoderTestBase::kAttrib3Name = "attrib3"; |
| 1329 | const char* GLES2DecoderTestBase::kUniform1Name = "uniform1"; |
| 1330 | const char* GLES2DecoderTestBase::kUniform2Name = "uniform2[0]"; |
| 1331 | const char* GLES2DecoderTestBase::kUniform3Name = "uniform3[0]"; |
| 1332 | |
| 1333 | void GLES2DecoderTestBase::SetupDefaultProgram() { |
| 1334 | { |
| 1335 | static AttribInfo attribs[] = { |
| 1336 | { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, |
| 1337 | { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, |
| 1338 | { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, |
| 1339 | }; |
| 1340 | static UniformInfo uniforms[] = { |
| 1341 | { kUniform1Name, kUniform1Size, kUniform1Type, |
| 1342 | kUniform1FakeLocation, kUniform1RealLocation, |
| 1343 | kUniform1DesiredLocation }, |
| 1344 | { kUniform2Name, kUniform2Size, kUniform2Type, |
| 1345 | kUniform2FakeLocation, kUniform2RealLocation, |
| 1346 | kUniform2DesiredLocation }, |
| 1347 | { kUniform3Name, kUniform3Size, kUniform3Type, |
| 1348 | kUniform3FakeLocation, kUniform3RealLocation, |
| 1349 | kUniform3DesiredLocation }, |
| 1350 | }; |
| 1351 | SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms), |
| 1352 | client_program_id_, kServiceProgramId, |
| 1353 | client_vertex_shader_id_, kServiceVertexShaderId, |
| 1354 | client_fragment_shader_id_, kServiceFragmentShaderId); |
| 1355 | } |
| 1356 | |
| 1357 | { |
| 1358 | EXPECT_CALL(*gl_, UseProgram(kServiceProgramId)) |
| 1359 | .Times(1) |
| 1360 | .RetiresOnSaturation(); |
| 1361 | cmds::UseProgram cmd; |
| 1362 | cmd.Init(client_program_id_); |
| 1363 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | void GLES2DecoderTestBase::SetupCubemapProgram() { |
| 1368 | { |
| 1369 | static AttribInfo attribs[] = { |
| 1370 | { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, |
| 1371 | { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, |
| 1372 | { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, |
| 1373 | }; |
| 1374 | static UniformInfo uniforms[] = { |
| 1375 | { kUniform1Name, kUniform1Size, kUniformCubemapType, |
| 1376 | kUniform1FakeLocation, kUniform1RealLocation, |
| 1377 | kUniform1DesiredLocation, }, |
| 1378 | { kUniform2Name, kUniform2Size, kUniform2Type, |
| 1379 | kUniform2FakeLocation, kUniform2RealLocation, |
| 1380 | kUniform2DesiredLocation, }, |
| 1381 | { kUniform3Name, kUniform3Size, kUniform3Type, |
| 1382 | kUniform3FakeLocation, kUniform3RealLocation, |
| 1383 | kUniform3DesiredLocation, }, |
| 1384 | }; |
| 1385 | SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms), |
| 1386 | client_program_id_, kServiceProgramId, |
| 1387 | client_vertex_shader_id_, kServiceVertexShaderId, |
| 1388 | client_fragment_shader_id_, kServiceFragmentShaderId); |
| 1389 | } |
| 1390 | |
| 1391 | { |
| 1392 | EXPECT_CALL(*gl_, UseProgram(kServiceProgramId)) |
| 1393 | .Times(1) |
| 1394 | .RetiresOnSaturation(); |
| 1395 | cmds::UseProgram cmd; |
| 1396 | cmd.Init(client_program_id_); |
| 1397 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | void GLES2DecoderTestBase::SetupSamplerExternalProgram() { |
| 1402 | { |
| 1403 | static AttribInfo attribs[] = { |
| 1404 | { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, |
| 1405 | { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, |
| 1406 | { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, |
| 1407 | }; |
| 1408 | static UniformInfo uniforms[] = { |
| 1409 | { kUniform1Name, kUniform1Size, kUniformSamplerExternalType, |
| 1410 | kUniform1FakeLocation, kUniform1RealLocation, |
| 1411 | kUniform1DesiredLocation, }, |
| 1412 | { kUniform2Name, kUniform2Size, kUniform2Type, |
| 1413 | kUniform2FakeLocation, kUniform2RealLocation, |
| 1414 | kUniform2DesiredLocation, }, |
| 1415 | { kUniform3Name, kUniform3Size, kUniform3Type, |
| 1416 | kUniform3FakeLocation, kUniform3RealLocation, |
| 1417 | kUniform3DesiredLocation, }, |
| 1418 | }; |
| 1419 | SetupShader(attribs, arraysize(attribs), uniforms, arraysize(uniforms), |
| 1420 | client_program_id_, kServiceProgramId, |
| 1421 | client_vertex_shader_id_, kServiceVertexShaderId, |
| 1422 | client_fragment_shader_id_, kServiceFragmentShaderId); |
| 1423 | } |
| 1424 | |
| 1425 | { |
| 1426 | EXPECT_CALL(*gl_, UseProgram(kServiceProgramId)) |
| 1427 | .Times(1) |
| 1428 | .RetiresOnSaturation(); |
| 1429 | cmds::UseProgram cmd; |
| 1430 | cmd.Init(client_program_id_); |
| 1431 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | void GLES2DecoderWithShaderTestBase::TearDown() { |
| 1436 | GLES2DecoderTestBase::TearDown(); |
| 1437 | } |
| 1438 | |
| 1439 | void GLES2DecoderTestBase::SetupShader( |
| 1440 | GLES2DecoderTestBase::AttribInfo* attribs, size_t num_attribs, |
| 1441 | GLES2DecoderTestBase::UniformInfo* uniforms, size_t num_uniforms, |
| 1442 | GLuint program_client_id, GLuint program_service_id, |
| 1443 | GLuint vertex_shader_client_id, GLuint vertex_shader_service_id, |
| 1444 | GLuint fragment_shader_client_id, GLuint fragment_shader_service_id) { |
| 1445 | { |
| 1446 | InSequence s; |
| 1447 | |
| 1448 | EXPECT_CALL(*gl_, |
| 1449 | AttachShader(program_service_id, vertex_shader_service_id)) |
| 1450 | .Times(1) |
| 1451 | .RetiresOnSaturation(); |
| 1452 | EXPECT_CALL(*gl_, |
| 1453 | AttachShader(program_service_id, fragment_shader_service_id)) |
| 1454 | .Times(1) |
| 1455 | .RetiresOnSaturation(); |
| 1456 | TestHelper::SetupShader( |
| 1457 | gl_.get(), attribs, num_attribs, uniforms, num_uniforms, |
| 1458 | program_service_id); |
| 1459 | } |
| 1460 | |
| 1461 | DoCreateShader( |
| 1462 | GL_VERTEX_SHADER, vertex_shader_client_id, vertex_shader_service_id); |
| 1463 | DoCreateShader( |
| 1464 | GL_FRAGMENT_SHADER, fragment_shader_client_id, |
| 1465 | fragment_shader_service_id); |
| 1466 | |
| 1467 | TestHelper::SetShaderStates( |
| 1468 | gl_.get(), GetShader(vertex_shader_client_id), true); |
| 1469 | TestHelper::SetShaderStates( |
| 1470 | gl_.get(), GetShader(fragment_shader_client_id), true); |
| 1471 | |
| 1472 | cmds::AttachShader attach_cmd; |
| 1473 | attach_cmd.Init(program_client_id, vertex_shader_client_id); |
| 1474 | EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); |
| 1475 | |
| 1476 | attach_cmd.Init(program_client_id, fragment_shader_client_id); |
| 1477 | EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd)); |
| 1478 | |
| 1479 | cmds::LinkProgram link_cmd; |
| 1480 | link_cmd.Init(program_client_id); |
| 1481 | |
| 1482 | EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd)); |
| 1483 | } |
| 1484 | |
| 1485 | void GLES2DecoderTestBase::DoEnableDisable(GLenum cap, bool enable) { |
| 1486 | SetupExpectationsForEnableDisable(cap, enable); |
| 1487 | if (enable) { |
| 1488 | cmds::Enable cmd; |
| 1489 | cmd.Init(cap); |
| 1490 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1491 | } else { |
| 1492 | cmds::Disable cmd; |
| 1493 | cmd.Init(cap); |
| 1494 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | void GLES2DecoderTestBase::DoEnableVertexAttribArray(GLint index) { |
| 1499 | EXPECT_CALL(*gl_, EnableVertexAttribArray(index)) |
| 1500 | .Times(1) |
| 1501 | .RetiresOnSaturation(); |
| 1502 | cmds::EnableVertexAttribArray cmd; |
| 1503 | cmd.Init(index); |
| 1504 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1505 | } |
| 1506 | |
| 1507 | void GLES2DecoderTestBase::DoBufferData(GLenum target, GLsizei size) { |
| 1508 | EXPECT_CALL(*gl_, GetError()) |
| 1509 | .WillOnce(Return(GL_NO_ERROR)) |
| 1510 | .RetiresOnSaturation(); |
| 1511 | EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW)) |
| 1512 | .Times(1) |
| 1513 | .RetiresOnSaturation(); |
| 1514 | EXPECT_CALL(*gl_, GetError()) |
| 1515 | .WillOnce(Return(GL_NO_ERROR)) |
| 1516 | .RetiresOnSaturation(); |
| 1517 | cmds::BufferData cmd; |
| 1518 | cmd.Init(target, size, 0, 0, GL_STREAM_DRAW); |
| 1519 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1520 | } |
| 1521 | |
| 1522 | void GLES2DecoderTestBase::DoBufferSubData( |
| 1523 | GLenum target, GLint offset, GLsizei size, const void* data) { |
| 1524 | EXPECT_CALL(*gl_, BufferSubData(target, offset, size, |
| 1525 | shared_memory_address_)) |
| 1526 | .Times(1) |
| 1527 | .RetiresOnSaturation(); |
| 1528 | memcpy(shared_memory_address_, data, size); |
| 1529 | cmds::BufferSubData cmd; |
| 1530 | cmd.Init(target, offset, size, shared_memory_id_, shared_memory_offset_); |
| 1531 | EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 1532 | } |
| 1533 | |
| 1534 | void GLES2DecoderTestBase::SetupVertexBuffer() { |
| 1535 | DoEnableVertexAttribArray(1); |
| 1536 | DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId); |
James Robinson | c4c1c59 | 2014-11-21 18:27:04 -0800 | [diff] [blame] | 1537 | DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 2 * sizeof(GLfloat)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | void GLES2DecoderTestBase::SetupAllNeededVertexBuffers() { |
| 1541 | DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId); |
| 1542 | DoBufferData(GL_ARRAY_BUFFER, kNumVertices * 16 * sizeof(float)); |
| 1543 | DoEnableVertexAttribArray(0); |
| 1544 | DoEnableVertexAttribArray(1); |
| 1545 | DoEnableVertexAttribArray(2); |
| 1546 | DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0); |
| 1547 | DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0); |
| 1548 | DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0); |
| 1549 | } |
| 1550 | |
| 1551 | void GLES2DecoderTestBase::SetupIndexBuffer() { |
| 1552 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 1553 | client_element_buffer_id_, |
| 1554 | kServiceElementBufferId); |
| 1555 | static const GLshort indices[] = {100, 1, 2, 3, 4, 5, 6, 7, 100, 9}; |
| 1556 | COMPILE_ASSERT(arraysize(indices) == kNumIndices, Indices_is_not_10); |
| 1557 | DoBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices)); |
| 1558 | DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 2, indices); |
| 1559 | DoBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 2, sizeof(indices) - 2, &indices[1]); |
| 1560 | } |
| 1561 | |
| 1562 | void GLES2DecoderTestBase::SetupTexture() { |
| 1563 | DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); |
| 1564 | DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1565 | kSharedMemoryId, kSharedMemoryOffset); |
| 1566 | }; |
| 1567 | |
| 1568 | void GLES2DecoderTestBase::DeleteVertexBuffer() { |
| 1569 | DoDeleteBuffer(client_buffer_id_, kServiceBufferId); |
| 1570 | } |
| 1571 | |
| 1572 | void GLES2DecoderTestBase::DeleteIndexBuffer() { |
| 1573 | DoDeleteBuffer(client_element_buffer_id_, kServiceElementBufferId); |
| 1574 | } |
| 1575 | |
| 1576 | void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0WithError( |
| 1577 | GLsizei num_vertices, GLuint buffer_id, GLenum error) { |
| 1578 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 1579 | return; |
| 1580 | } |
| 1581 | |
| 1582 | EXPECT_CALL(*gl_, GetError()) |
| 1583 | .WillOnce(Return(GL_NO_ERROR)) |
| 1584 | .WillOnce(Return(error)) |
| 1585 | .RetiresOnSaturation(); |
| 1586 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, kServiceAttrib0BufferId)) |
| 1587 | .Times(1) |
| 1588 | .RetiresOnSaturation(); |
| 1589 | EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, |
| 1590 | num_vertices * sizeof(GLfloat) * 4, |
| 1591 | _, GL_DYNAMIC_DRAW)) |
| 1592 | .Times(1) |
| 1593 | .RetiresOnSaturation(); |
| 1594 | if (error == GL_NO_ERROR) { |
| 1595 | EXPECT_CALL(*gl_, BufferSubData( |
| 1596 | GL_ARRAY_BUFFER, 0, num_vertices * sizeof(GLfloat) * 4, _)) |
| 1597 | .Times(1) |
| 1598 | .RetiresOnSaturation(); |
| 1599 | EXPECT_CALL(*gl_, VertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL)) |
| 1600 | .Times(1) |
| 1601 | .RetiresOnSaturation(); |
| 1602 | EXPECT_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, buffer_id)) |
| 1603 | .Times(1) |
| 1604 | .RetiresOnSaturation(); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | void GLES2DecoderTestBase::AddExpectationsForSimulatedAttrib0( |
| 1609 | GLsizei num_vertices, GLuint buffer_id) { |
| 1610 | AddExpectationsForSimulatedAttrib0WithError( |
| 1611 | num_vertices, buffer_id, GL_NO_ERROR); |
| 1612 | } |
| 1613 | |
| 1614 | void GLES2DecoderTestBase::SetupMockGLBehaviors() { |
| 1615 | ON_CALL(*gl_, BindVertexArrayOES(_)) |
| 1616 | .WillByDefault(Invoke( |
| 1617 | &gl_states_, |
| 1618 | &GLES2DecoderTestBase::MockGLStates::OnBindVertexArrayOES)); |
| 1619 | ON_CALL(*gl_, BindBuffer(GL_ARRAY_BUFFER, _)) |
| 1620 | .WillByDefault(WithArg<1>(Invoke( |
| 1621 | &gl_states_, |
| 1622 | &GLES2DecoderTestBase::MockGLStates::OnBindArrayBuffer))); |
| 1623 | ON_CALL(*gl_, VertexAttribPointer(_, _, _, _, _, NULL)) |
| 1624 | .WillByDefault(InvokeWithoutArgs( |
| 1625 | &gl_states_, |
| 1626 | &GLES2DecoderTestBase::MockGLStates::OnVertexAttribNullPointer)); |
| 1627 | } |
| 1628 | |
| 1629 | GLES2DecoderWithShaderTestBase::MockCommandBufferEngine:: |
| 1630 | MockCommandBufferEngine() { |
| 1631 | |
| 1632 | scoped_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 1633 | shm->CreateAndMapAnonymous(kSharedBufferSize); |
| 1634 | valid_buffer_ = MakeBufferFromSharedMemory(shm.Pass(), kSharedBufferSize); |
| 1635 | |
| 1636 | ClearSharedMemory(); |
| 1637 | } |
| 1638 | |
| 1639 | GLES2DecoderWithShaderTestBase::MockCommandBufferEngine:: |
| 1640 | ~MockCommandBufferEngine() {} |
| 1641 | |
| 1642 | scoped_refptr<gpu::Buffer> |
| 1643 | GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetSharedMemoryBuffer( |
| 1644 | int32 shm_id) { |
| 1645 | return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_; |
| 1646 | } |
| 1647 | |
| 1648 | void GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::set_token( |
| 1649 | int32 token) { |
| 1650 | DCHECK(false); |
| 1651 | } |
| 1652 | |
| 1653 | bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetBuffer( |
| 1654 | int32 /* transfer_buffer_id */) { |
| 1655 | DCHECK(false); |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
| 1659 | bool GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::SetGetOffset( |
| 1660 | int32 offset) { |
| 1661 | DCHECK(false); |
| 1662 | return false; |
| 1663 | } |
| 1664 | |
| 1665 | int32 GLES2DecoderWithShaderTestBase::MockCommandBufferEngine::GetGetOffset() { |
| 1666 | DCHECK(false); |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
| 1670 | void GLES2DecoderWithShaderTestBase::SetUp() { |
| 1671 | GLES2DecoderTestBase::SetUp(); |
| 1672 | SetupDefaultProgram(); |
| 1673 | } |
| 1674 | |
| 1675 | // Include the auto-generated part of this file. We split this because it means |
| 1676 | // we can easily edit the non-auto generated parts right here in this file |
| 1677 | // instead of having to edit some template or the code generator. |
| 1678 | #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h" |
| 1679 | |
| 1680 | } // namespace gles2 |
| 1681 | } // namespace gpu |