Home | History | Annotate | Download | only in service
      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 "gpu/command_buffer/common/gles2_cmd_format.h"
      8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
      9 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
     10 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
     11 #include "gpu/command_buffer/service/context_group.h"
     12 #include "gpu/command_buffer/service/program_manager.h"
     13 #include "testing/gtest/include/gtest/gtest.h"
     14 #include "ui/gl/gl_mock.h"
     15 
     16 using ::gfx::MockGLInterface;
     17 using ::testing::_;
     18 using ::testing::DoAll;
     19 using ::testing::InSequence;
     20 using ::testing::MatcherCast;
     21 using ::testing::Pointee;
     22 using ::testing::Return;
     23 using ::testing::SetArrayArgument;
     24 using ::testing::SetArgumentPointee;
     25 using ::testing::StrEq;
     26 
     27 namespace gpu {
     28 namespace gles2 {
     29 
     30 class GLES2DecoderTest2 : public GLES2DecoderTestBase {
     31  public:
     32   GLES2DecoderTest2() { }
     33 };
     34 
     35 template <>
     36 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenQueriesEXT, 0>(
     37     bool valid) {
     38   if (!valid) {
     39     // Make the client_query_id_ so that trying to make it again
     40     // will fail.
     41     GetSharedMemoryAs<GLuint*>()[0] = client_query_id_;
     42     cmds::GenQueriesEXT cmd;
     43     cmd.Init(1, shared_memory_id_, shared_memory_offset_);
     44     EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
     45   }
     46 };
     47 
     48 template <>
     49 void GLES2DecoderTestBase::SpecializedSetup<cmds::GenQueriesEXTImmediate, 0>(
     50     bool valid) {
     51   if (!valid) {
     52     // Make the client_query_id_ so that trying to make it again
     53     // will fail.
     54     GetSharedMemoryAs<GLuint*>()[0] = client_query_id_;
     55     cmds::GenQueriesEXT cmd;
     56     cmd.Init(1, shared_memory_id_, shared_memory_offset_);
     57     EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
     58   }
     59 };
     60 
     61 template <>
     62 void GLES2DecoderTestBase::SpecializedSetup<cmds::DeleteQueriesEXT, 0>(
     63     bool valid) {
     64   if (valid) {
     65     // Make the client_query_id_ so that trying to delete it will succeed.
     66     GetSharedMemoryAs<GLuint*>()[0] = client_query_id_;
     67     cmds::GenQueriesEXT cmd;
     68     cmd.Init(1, shared_memory_id_, shared_memory_offset_);
     69     EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
     70   }
     71 };
     72 
     73 template <>
     74 void GLES2DecoderTestBase::SpecializedSetup<cmds::DeleteQueriesEXTImmediate, 0>(
     75     bool valid) {
     76   if (valid) {
     77     // Make the client_query_id_ so that trying to delete it will succeed.
     78     GetSharedMemoryAs<GLuint*>()[0] = client_query_id_;
     79     cmds::GenQueriesEXT cmd;
     80     cmd.Init(1, shared_memory_id_, shared_memory_offset_);
     81     EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
     82   }
     83 };
     84 
     85 template <>
     86 void GLES2DecoderTestBase::SpecializedSetup<cmds::LinkProgram, 0>(
     87     bool /* valid */) {
     88   const GLuint kClientVertexShaderId = 5001;
     89   const GLuint kServiceVertexShaderId = 6001;
     90   const GLuint kClientFragmentShaderId = 5002;
     91   const GLuint kServiceFragmentShaderId = 6002;
     92   DoCreateShader(
     93       GL_VERTEX_SHADER, kClientVertexShaderId, kServiceVertexShaderId);
     94   DoCreateShader(
     95       GL_FRAGMENT_SHADER, kClientFragmentShaderId, kServiceFragmentShaderId);
     96 
     97   GetShader(kClientVertexShaderId)->SetStatus(true, "", NULL);
     98   GetShader(kClientFragmentShaderId)->SetStatus(true, "", NULL);
     99 
    100   InSequence dummy;
    101   EXPECT_CALL(*gl_,
    102               AttachShader(kServiceProgramId, kServiceVertexShaderId))
    103       .Times(1)
    104       .RetiresOnSaturation();
    105   EXPECT_CALL(*gl_,
    106               AttachShader(kServiceProgramId, kServiceFragmentShaderId))
    107       .Times(1)
    108       .RetiresOnSaturation();
    109   EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_LINK_STATUS, _))
    110       .WillOnce(SetArgumentPointee<2>(1));
    111   EXPECT_CALL(*gl_,
    112       GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _))
    113       .WillOnce(SetArgumentPointee<2>(0))
    114       .RetiresOnSaturation();
    115   EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTES, _))
    116       .WillOnce(SetArgumentPointee<2>(0));
    117   EXPECT_CALL(
    118       *gl_,
    119       GetProgramiv(kServiceProgramId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, _))
    120       .WillOnce(SetArgumentPointee<2>(0));
    121   EXPECT_CALL(*gl_, GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORMS, _))
    122       .WillOnce(SetArgumentPointee<2>(0));
    123   EXPECT_CALL(
    124       *gl_,
    125       GetProgramiv(kServiceProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, _))
    126       .WillOnce(SetArgumentPointee<2>(0));
    127 
    128   cmds::AttachShader attach_cmd;
    129   attach_cmd.Init(client_program_id_, kClientVertexShaderId);
    130   EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
    131 
    132   attach_cmd.Init(client_program_id_, kClientFragmentShaderId);
    133   EXPECT_EQ(error::kNoError, ExecuteCmd(attach_cmd));
    134 };
    135 
    136 template <>
    137 void GLES2DecoderTestBase::SpecializedSetup<cmds::ValidateProgram, 0>(
    138     bool /* valid */) {
    139   // Needs the same setup as LinkProgram.
    140   SpecializedSetup<cmds::LinkProgram, 0>(false);
    141 
    142   EXPECT_CALL(*gl_, LinkProgram(kServiceProgramId))
    143       .Times(1)
    144       .RetiresOnSaturation();
    145 
    146   cmds::LinkProgram link_cmd;
    147   link_cmd.Init(client_program_id_);
    148   EXPECT_EQ(error::kNoError, ExecuteCmd(link_cmd));
    149 
    150   EXPECT_CALL(*gl_,
    151       GetProgramiv(kServiceProgramId, GL_INFO_LOG_LENGTH, _))
    152       .WillOnce(SetArgumentPointee<2>(0))
    153       .RetiresOnSaturation();
    154 };
    155 
    156 template <>
    157 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform1f, 0>(
    158     bool /* valid */) {
    159   SetupShaderForUniform(GL_FLOAT);
    160 };
    161 
    162 template <>
    163 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform1fv, 0>(
    164     bool /* valid */) {
    165   SetupShaderForUniform(GL_FLOAT);
    166 };
    167 
    168 template <>
    169 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform1fvImmediate, 0>(
    170     bool /* valid */) {
    171   SetupShaderForUniform(GL_FLOAT);
    172 };
    173 
    174 template <>
    175 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform1iv, 0>(
    176     bool /* valid */) {
    177   SetupShaderForUniform(GL_INT);
    178 };
    179 
    180 template <>
    181 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform1ivImmediate, 0>(
    182     bool /* valid */) {
    183   SetupShaderForUniform(GL_INT);
    184 };
    185 
    186 template <>
    187 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2f, 0>(
    188     bool /* valid */) {
    189   SetupShaderForUniform(GL_FLOAT_VEC2);
    190 };
    191 
    192 template <>
    193 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2i, 0>(
    194     bool /* valid */) {
    195   SetupShaderForUniform(GL_INT_VEC2);
    196 };
    197 
    198 template <>
    199 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2fv, 0>(
    200     bool /* valid */) {
    201   SetupShaderForUniform(GL_FLOAT_VEC2);
    202 };
    203 
    204 template <>
    205 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2iv, 0>(
    206     bool /* valid */) {
    207   SetupShaderForUniform(GL_INT_VEC2);
    208 };
    209 
    210 template <>
    211 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2fvImmediate, 0>(
    212     bool /* valid */) {
    213   SetupShaderForUniform(GL_FLOAT_VEC2);
    214 };
    215 
    216 template <>
    217 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform2ivImmediate, 0>(
    218     bool /* valid */) {
    219   SetupShaderForUniform(GL_INT_VEC2);
    220 };
    221 
    222 template <>
    223 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3f, 0>(
    224     bool /* valid */) {
    225   SetupShaderForUniform(GL_FLOAT_VEC3);
    226 };
    227 
    228 template <>
    229 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3i, 0>(
    230     bool /* valid */) {
    231   SetupShaderForUniform(GL_INT_VEC3);
    232 };
    233 
    234 template <>
    235 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3fv, 0>(
    236     bool /* valid */) {
    237   SetupShaderForUniform(GL_FLOAT_VEC3);
    238 };
    239 
    240 template <>
    241 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3iv, 0>(
    242     bool /* valid */) {
    243   SetupShaderForUniform(GL_INT_VEC3);
    244 };
    245 
    246 template <>
    247 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3fvImmediate, 0>(
    248     bool /* valid */) {
    249   SetupShaderForUniform(GL_FLOAT_VEC3);
    250 };
    251 
    252 template <>
    253 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform3ivImmediate, 0>(
    254     bool /* valid */) {
    255   SetupShaderForUniform(GL_INT_VEC3);
    256 };
    257 
    258 template <>
    259 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4f, 0>(
    260     bool /* valid */) {
    261   SetupShaderForUniform(GL_FLOAT_VEC4);
    262 };
    263 
    264 template <>
    265 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4i, 0>(
    266     bool /* valid */) {
    267   SetupShaderForUniform(GL_INT_VEC4);
    268 };
    269 
    270 template <>
    271 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4fv, 0>(
    272     bool /* valid */) {
    273   SetupShaderForUniform(GL_FLOAT_VEC4);
    274 };
    275 
    276 template <>
    277 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4iv, 0>(
    278     bool /* valid */) {
    279   SetupShaderForUniform(GL_INT_VEC4);
    280 };
    281 
    282 template <>
    283 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4fvImmediate, 0>(
    284     bool /* valid */) {
    285   SetupShaderForUniform(GL_FLOAT_VEC4);
    286 };
    287 
    288 template <>
    289 void GLES2DecoderTestBase::SpecializedSetup<cmds::Uniform4ivImmediate, 0>(
    290     bool /* valid */) {
    291   SetupShaderForUniform(GL_INT_VEC4);
    292 };
    293 
    294 template <>
    295 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix2fv, 0>(
    296     bool /* valid */) {
    297   SetupShaderForUniform(GL_FLOAT_MAT2);
    298 };
    299 
    300 template <>
    301 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix2fvImmediate, 0>(
    302     bool /* valid */) {
    303   SetupShaderForUniform(GL_FLOAT_MAT2);
    304 };
    305 
    306 template <>
    307 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix3fv, 0>(
    308     bool /* valid */) {
    309   SetupShaderForUniform(GL_FLOAT_MAT3);
    310 };
    311 
    312 template <>
    313 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix3fvImmediate, 0>(
    314     bool /* valid */) {
    315   SetupShaderForUniform(GL_FLOAT_MAT3);
    316 };
    317 
    318 template <>
    319 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix4fv, 0>(
    320     bool /* valid */) {
    321   SetupShaderForUniform(GL_FLOAT_MAT4);
    322 };
    323 
    324 template <>
    325 void GLES2DecoderTestBase::SpecializedSetup<cmds::UniformMatrix4fvImmediate, 0>(
    326     bool /* valid */) {
    327   SetupShaderForUniform(GL_FLOAT_MAT4);
    328 };
    329 
    330 template <>
    331 void GLES2DecoderTestBase::SpecializedSetup<cmds::RenderbufferStorage, 0>(
    332     bool valid) {
    333   DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
    334                     kServiceRenderbufferId);
    335   if (valid) {
    336     EXPECT_CALL(*gl_, GetError())
    337         .WillOnce(Return(GL_NO_ERROR))
    338         .RetiresOnSaturation();
    339     EXPECT_CALL(*gl_,
    340                 RenderbufferStorageEXT(GL_RENDERBUFFER, _, 3, 4))
    341         .Times(1)
    342         .RetiresOnSaturation();
    343     EXPECT_CALL(*gl_, GetError())
    344         .WillOnce(Return(GL_NO_ERROR))
    345         .RetiresOnSaturation();
    346   }
    347 };
    348 
    349 template <>
    350 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameterf, 0>(
    351     bool /* valid */) {
    352   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    353 };
    354 
    355 template <>
    356 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameteri, 0>(
    357     bool /* valid */) {
    358   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    359 };
    360 
    361 template <>
    362 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameterfv, 0>(
    363     bool /* valid */) {
    364   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    365 };
    366 
    367 template <>
    368 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameterfvImmediate, 0>(
    369     bool /* valid */) {
    370   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    371 };
    372 
    373 template <>
    374 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameteriv, 0>(
    375     bool /* valid */) {
    376   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    377 };
    378 
    379 template <>
    380 void GLES2DecoderTestBase::SpecializedSetup<cmds::TexParameterivImmediate, 0>(
    381     bool /* valid */) {
    382   DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
    383 };
    384 
    385 template <>
    386 void GLES2DecoderTestBase::SpecializedSetup<cmds::GetVertexAttribiv, 0>(
    387     bool valid) {
    388   DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
    389   DoVertexAttribPointer(1, 1, GL_FLOAT, 0, 0);
    390   if (valid) {
    391     EXPECT_CALL(*gl_, GetError())
    392         .WillOnce(Return(GL_NO_ERROR))
    393         .WillOnce(Return(GL_NO_ERROR))
    394         .RetiresOnSaturation();
    395   }
    396 };
    397 
    398 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_2_autogen.h"
    399 
    400 }  // namespace gles2
    401 }  // namespace gpu
    402 
    403