• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
7 
8 #include "gpu/command_buffer/service/shader_translator.h"
9 #include "ui/gl/gl_implementation.h"
10 #include "ui/gl/gl_mock.h"
11 
12 namespace gpu {
13 namespace gles2 {
14 
15 struct DisallowedFeatures;
16 class Buffer;
17 class BufferManager;
18 class MockErrorState;
19 class Shader;
20 class TextureRef;
21 class TextureManager;
22 
23 class TestHelper {
24  public:
25   static const GLuint kServiceBlackTexture2dId = 701;
26   static const GLuint kServiceDefaultTexture2dId = 702;
27   static const GLuint kServiceBlackTextureCubemapId = 703;
28   static const GLuint kServiceDefaultTextureCubemapId = 704;
29   static const GLuint kServiceBlackExternalTextureId = 705;
30   static const GLuint kServiceDefaultExternalTextureId = 706;
31   static const GLuint kServiceBlackRectangleTextureId = 707;
32   static const GLuint kServiceDefaultRectangleTextureId = 708;
33 
34   static const GLint kMaxSamples = 4;
35   static const GLint kMaxRenderbufferSize = 1024;
36   static const GLint kMaxTextureSize = 2048;
37   static const GLint kMaxCubeMapTextureSize = 256;
38   static const GLint kNumVertexAttribs = 16;
39   static const GLint kNumTextureUnits = 8;
40   static const GLint kMaxTextureImageUnits = 8;
41   static const GLint kMaxVertexTextureImageUnits = 2;
42   static const GLint kMaxFragmentUniformVectors = 16;
43   static const GLint kMaxFragmentUniformComponents =
44       kMaxFragmentUniformVectors * 4;
45   static const GLint kMaxVaryingVectors = 8;
46   static const GLint kMaxVaryingFloats = kMaxVaryingVectors * 4;
47   static const GLint kMaxVertexUniformVectors = 128;
48   static const GLint kMaxVertexUniformComponents = kMaxVertexUniformVectors * 4;
49 
50   struct AttribInfo {
51     const char* name;
52     GLint size;
53     GLenum type;
54     GLint location;
55   };
56 
57   struct UniformInfo {
58     const char* name;
59     GLint size;
60     GLenum type;
61     GLint fake_location;
62     GLint real_location;
63     GLint desired_location;
64     const char* good_name;
65   };
66 
67   static void SetupContextGroupInitExpectations(
68       ::gfx::MockGLInterface* gl,
69       const DisallowedFeatures& disallowed_features,
70       const char* extensions,
71       const char* gl_version,
72       bool bind_generates_resource);
73   static void SetupFeatureInfoInitExpectations(
74       ::gfx::MockGLInterface* gl, const char* extensions);
75   static void SetupFeatureInfoInitExpectationsWithGLVersion(
76       ::gfx::MockGLInterface* gl,
77       const char* extensions,
78       const char* gl_renderer,
79       const char* gl_version);
80   static void SetupTextureManagerInitExpectations(::gfx::MockGLInterface* gl,
81                                                   const char* extensions,
82                                                   bool use_default_textures);
83   static void SetupTextureManagerDestructionExpectations(
84       ::gfx::MockGLInterface* gl,
85       const char* extensions,
86       bool use_default_textures);
87 
88   static void SetupExpectationsForClearingUniforms(
89       ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms);
90 
91   static void SetupShader(
92       ::gfx::MockGLInterface* gl,
93       AttribInfo* attribs, size_t num_attribs,
94       UniformInfo* uniforms, size_t num_uniforms,
95       GLuint service_id);
96 
97   static void SetupProgramSuccessExpectations(::gfx::MockGLInterface* gl,
98       AttribInfo* attribs, size_t num_attribs,
99       UniformInfo* uniforms, size_t num_uniforms,
100       GLuint service_id);
101 
102   static void DoBufferData(
103       ::gfx::MockGLInterface* gl, MockErrorState* error_state,
104       BufferManager* manager, Buffer* buffer, GLsizeiptr size, GLenum usage,
105       const GLvoid* data, GLenum error);
106 
107   static void SetTexParameteriWithExpectations(
108       ::gfx::MockGLInterface* gl, MockErrorState* error_state,
109       TextureManager* manager, TextureRef* texture_ref,
110       GLenum pname, GLint value, GLenum error);
111 
112   static void SetShaderStates(
113       ::gfx::MockGLInterface* gl, Shader* shader,
114       bool expected_valid,
115       const std::string* const expected_log_info,
116       const std::string* const expected_translated_source,
117       const ShaderTranslatorInterface::VariableMap* const expected_attrib_map,
118       const ShaderTranslatorInterface::VariableMap* const expected_uniform_map,
119       const ShaderTranslatorInterface::VariableMap* const expected_varying_map,
120       const ShaderTranslatorInterface::NameMap* const expected_name_map);
121 
122   static void SetShaderStates(
123       ::gfx::MockGLInterface* gl, Shader* shader, bool valid);
124 
125  private:
126   static void SetupTextureInitializationExpectations(::gfx::MockGLInterface* gl,
127                                                      GLenum target,
128                                                      bool use_default_textures);
129   static void SetupTextureDestructionExpectations(::gfx::MockGLInterface* gl,
130                                                   GLenum target,
131                                                   bool use_default_textures);
132 };
133 
134 // This object temporaritly Sets what gfx::GetGLImplementation returns. During
135 // testing the GLImplementation is set to kGLImplemenationMockGL but lots of
136 // code branches based on what gfx::GetGLImplementation returns.
137 class ScopedGLImplementationSetter {
138  public:
139   explicit ScopedGLImplementationSetter(gfx::GLImplementation implementation);
140   ~ScopedGLImplementationSetter();
141 
142  private:
143   gfx::GLImplementation old_implementation_;
144 };
145 
146 }  // namespace gles2
147 }  // namespace gpu
148 
149 #endif  // GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
150 
151