1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250

gpu / command_buffer / service / test_helper.h [blame]

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
#define GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_

#include <stddef.h>

#include <string>
#include <vector>

#include "gpu/command_buffer/common/context_creation_attribs.h"
#include "gpu/command_buffer/service/shader_translator.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"

namespace gpu {
namespace gles2 {

struct DisallowedFeatures;
class Buffer;
class BufferManager;
class FeatureInfo;
class MockErrorState;
class Shader;
class TextureRef;
class TextureManager;

class TestHelper {
 public:
  static const GLuint kServiceBlackTexture2dId = 701;
  static const GLuint kServiceDefaultTexture2dId = 702;
  static const GLuint kServiceBlackTexture3dId = 703;
  static const GLuint kServiceDefaultTexture3dId = 704;
  static const GLuint kServiceBlackTexture2dArrayId = 705;
  static const GLuint kServiceDefaultTexture2dArrayId = 706;
  static const GLuint kServiceBlackTextureCubemapId = 707;
  static const GLuint kServiceDefaultTextureCubemapId = 708;
  static const GLuint kServiceBlackExternalTextureId = 709;
  static const GLuint kServiceDefaultExternalTextureId = 710;
  static const GLuint kServiceBlackRectangleTextureId = 711;
  static const GLuint kServiceDefaultRectangleTextureId = 712;

  static const GLint kMaxSamples = 4;
  static const GLint kMaxRenderbufferSize = 1024;
  static const GLint kMaxTextureSize = 2048;
  static const GLint kMaxCubeMapTextureSize = 2048;
  static const GLint kMax3DTextureSize = 1024;
  static const GLint kMaxArrayTextureLayers = 256;
  static const GLint kMaxRectangleTextureSize = 64;
  static const GLint kNumVertexAttribs = 16;
  static const GLint kNumTextureUnits = 8;
  static const GLint kMaxTextureImageUnits = 8;
  static const GLint kMaxVertexTextureImageUnits = 2;
  static const GLint kMaxFragmentUniformVectors = 16;
  static const GLint kMaxFragmentUniformComponents =
      kMaxFragmentUniformVectors * 4;
  static const GLint kMaxVaryingVectors = 8;
  static const GLint kMaxVaryingFloats = kMaxVaryingVectors * 4;
  static const GLint kMaxVertexUniformVectors = 128;
  static const GLint kMaxVertexUniformComponents = kMaxVertexUniformVectors * 4;
  static const GLint kMaxVertexOutputComponents = 64;
  static const GLint kMaxFragmentInputComponents = 60;
  static const GLint kMaxProgramTexelOffset = 7;
  static const GLint kMinProgramTexelOffset = -8;

  static const GLint kMaxTransformFeedbackSeparateAttribs = 4;
  static const GLint kMaxUniformBufferBindings = 24;
  static const GLint kUniformBufferOffsetAlignment = 1;

  struct AttribInfo {
    const char* name;
    GLint size;
    GLenum type;
    GLint location;
  };

  struct UniformInfo {
    const char* name;
    GLint size;
    GLenum type;
    GLint fake_location;
    GLint real_location;
    GLint desired_location;
    const char* good_name;
  };

  struct VaryingInfo {
    const char* name;
    GLint size;
    GLenum type;
    GLint fake_location;
    GLint real_location;
    GLint desired_location;
  };
  struct ProgramOutputInfo {
    const char* name;
    GLint size;
    GLenum type;
    GLint color_name;
    GLuint index;
  };

  static void SetupContextGroupInitExpectations(
      ::gl::MockGLInterface* gl,
      const DisallowedFeatures& disallowed_features,
      const char* extensions,
      const char* gl_version,
      ContextType context_type,
      bool bind_generates_resource);
  static void SetupFeatureInfoInitExpectations(::gl::MockGLInterface* gl,
                                               const char* extensions);
  static void SetupFeatureInfoInitExpectationsWithGLVersion(
      ::gl::MockGLInterface* gl,
      const char* extensions,
      const char* gl_renderer,
      const char* gl_version,
      ContextType context_type);
  static void SetupTextureManagerInitExpectations(
      ::gl::MockGLInterface* gl,
      bool is_es3_enabled,
      bool is_es3_capable,
      const gfx::ExtensionSet& extensions,
      bool use_default_textures);
  static void SetupTextureManagerDestructionExpectations(
      ::gl::MockGLInterface* gl,
      bool is_es3_enabled,
      const gfx::ExtensionSet& extensions,
      bool use_default_textures);

  static void SetupShaderExpectations(::gl::MockGLInterface* gl,
                                      const FeatureInfo* feature_info,
                                      AttribInfo* attribs,
                                      size_t num_attribs,
                                      UniformInfo* uniforms,
                                      size_t num_uniforms,
                                      GLuint service_id);

  static void SetupShaderExpectationsWithVaryings(
      ::gl::MockGLInterface* gl,
      const FeatureInfo* feature_info,
      AttribInfo* attribs,
      size_t num_attribs,
      UniformInfo* uniforms,
      size_t num_uniforms,
      VaryingInfo* varyings,
      size_t num_varyings,
      ProgramOutputInfo* program_outputs,
      size_t num_program_outputs,
      GLuint service_id);

  static void SetupProgramSuccessExpectations(
      ::gl::MockGLInterface* gl,
      const FeatureInfo* feature_info,
      AttribInfo* attribs,
      size_t num_attribs,
      UniformInfo* uniforms,
      size_t num_uniforms,
      VaryingInfo* varyings,
      size_t num_varyings,
      ProgramOutputInfo* program_outputs,
      size_t num_program_outputs,
      GLuint service_id);

  static void DoBufferData(::gl::MockGLInterface* gl,
                           MockErrorState* error_state,
                           BufferManager* manager,
                           Buffer* buffer,
                           GLenum target,
                           GLsizeiptr size,
                           GLenum usage,
                           const GLvoid* data,
                           GLenum error);

  static void SetTexParameteriWithExpectations(::gl::MockGLInterface* gl,
                                               MockErrorState* error_state,
                                               TextureManager* manager,
                                               TextureRef* texture_ref,
                                               GLenum pname,
                                               GLint value,
                                               GLenum error);

  static void SetShaderStates(
      ::gl::MockGLInterface* gl,
      Shader* shader,
      bool expected_valid,
      const std::string* const expected_log_info,
      const std::string* const expected_translated_source,
      const int* const expected_shader_version,
      const AttributeMap* const expected_attrib_map,
      const UniformMap* const expected_uniform_map,
      const VaryingMap* const expected_varying_map,
      const InterfaceBlockMap* const expected_interface_block_map,
      const OutputVariableList* const expected_output_variable_list,
      OptionsAffectingCompilationString* options_affecting_compilation);

  static void SetShaderStates(::gl::MockGLInterface* gl,
                              Shader* shader,
                              bool valid);

  static void SetShaderStates(::gl::MockGLInterface* gl,
                              Shader* shader,
                              bool valid,
                              const std::string& options_affecting_compilation);

  static sh::Attribute ConstructAttribute(
      GLenum type, GLint array_size, GLenum precision,
      bool static_use, const std::string& name);
  static sh::Uniform ConstructUniform(
      GLenum type, GLint array_size, GLenum precision,
      bool static_use, const std::string& name);
  static sh::Varying ConstructVarying(
      GLenum type, GLint array_size, GLenum precision,
      bool static_use, const std::string& name);
  static sh::InterfaceBlockField ConstructInterfaceBlockField(
      GLenum type,
      GLint array_size,
      GLenum precision,
      bool static_use,
      const std::string& name);
  static sh::InterfaceBlock ConstructInterfaceBlock(
      GLint array_size,
      sh::BlockLayoutType layout,
      bool is_row_major_layout,
      bool static_use,
      const std::string& name,
      const std::string& instance_name,
      const std::vector<sh::InterfaceBlockField>& fields);
  static sh::OutputVariable ConstructOutputVariable(GLenum type,
                                                    GLint array_size,
                                                    GLenum precision,
                                                    bool static_use,
                                                    const std::string& name);

 private:
  static void SetupTextureInitializationExpectations(::gl::MockGLInterface* gl,
                                                     GLenum target,
                                                     bool use_default_textures);
  static void SetupTextureDestructionExpectations(::gl::MockGLInterface* gl,
                                                  GLenum target,
                                                  bool use_default_textures);

  static std::vector<std::string> split_extensions_;
};

}  // namespace gles2
}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_