Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / test_helper.h
blob5998915b3826f9f92aa88bcbe34f50fcf0656a0c
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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_
8 #include <string>
9 #include <vector>
11 #include "gpu/command_buffer/service/shader_translator.h"
12 #include "ui/gl/gl_implementation.h"
13 #include "ui/gl/gl_mock.h"
15 namespace gpu {
16 namespace gles2 {
18 struct DisallowedFeatures;
19 class Buffer;
20 class BufferManager;
21 class MockErrorState;
22 class Shader;
23 class TextureRef;
24 class TextureManager;
26 class TestHelper {
27 public:
28 static const GLuint kServiceBlackTexture2dId = 701;
29 static const GLuint kServiceDefaultTexture2dId = 702;
30 static const GLuint kServiceBlackTexture3dId = 703;
31 static const GLuint kServiceDefaultTexture3dId = 704;
32 static const GLuint kServiceBlackTexture2dArrayId = 705;
33 static const GLuint kServiceDefaultTexture2dArrayId = 706;
34 static const GLuint kServiceBlackTextureCubemapId = 707;
35 static const GLuint kServiceDefaultTextureCubemapId = 708;
36 static const GLuint kServiceBlackExternalTextureId = 709;
37 static const GLuint kServiceDefaultExternalTextureId = 710;
38 static const GLuint kServiceBlackRectangleTextureId = 711;
39 static const GLuint kServiceDefaultRectangleTextureId = 712;
41 static const GLint kMaxSamples = 4;
42 static const GLint kMaxRenderbufferSize = 1024;
43 static const GLint kMaxTextureSize = 2048;
44 static const GLint kMaxCubeMapTextureSize = 256;
45 static const GLint kMax3DTextureSize = 256;
46 static const GLint kMaxRectangleTextureSize = 64;
47 static const GLint kNumVertexAttribs = 16;
48 static const GLint kNumTextureUnits = 8;
49 static const GLint kMaxTextureImageUnits = 8;
50 static const GLint kMaxVertexTextureImageUnits = 2;
51 static const GLint kMaxFragmentUniformVectors = 16;
52 static const GLint kMaxFragmentUniformComponents =
53 kMaxFragmentUniformVectors * 4;
54 static const GLint kMaxVaryingVectors = 8;
55 static const GLint kMaxVaryingFloats = kMaxVaryingVectors * 4;
56 static const GLint kMaxVertexUniformVectors = 128;
57 static const GLint kMaxVertexUniformComponents = kMaxVertexUniformVectors * 4;
59 struct AttribInfo {
60 const char* name;
61 GLint size;
62 GLenum type;
63 GLint location;
66 struct UniformInfo {
67 const char* name;
68 GLint size;
69 GLenum type;
70 GLint fake_location;
71 GLint real_location;
72 GLint desired_location;
73 const char* good_name;
76 static void SetupContextGroupInitExpectations(
77 ::gfx::MockGLInterface* gl,
78 const DisallowedFeatures& disallowed_features,
79 const char* extensions,
80 const char* gl_version,
81 bool bind_generates_resource);
82 static void SetupFeatureInfoInitExpectations(
83 ::gfx::MockGLInterface* gl, const char* extensions);
84 static void SetupFeatureInfoInitExpectationsWithGLVersion(
85 ::gfx::MockGLInterface* gl,
86 const char* extensions,
87 const char* gl_renderer,
88 const char* gl_version);
89 static void SetupTextureManagerInitExpectations(::gfx::MockGLInterface* gl,
90 bool is_es3_enabled,
91 const char* extensions,
92 bool use_default_textures);
93 static void SetupTextureManagerDestructionExpectations(
94 ::gfx::MockGLInterface* gl,
95 bool is_es3_enabled,
96 const char* extensions,
97 bool use_default_textures);
99 static void SetupExpectationsForClearingUniforms(
100 ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms);
102 static void SetupShader(
103 ::gfx::MockGLInterface* gl,
104 AttribInfo* attribs, size_t num_attribs,
105 UniformInfo* uniforms, size_t num_uniforms,
106 GLuint service_id);
108 static void SetupProgramSuccessExpectations(::gfx::MockGLInterface* gl,
109 AttribInfo* attribs, size_t num_attribs,
110 UniformInfo* uniforms, size_t num_uniforms,
111 GLuint service_id);
113 static void DoBufferData(
114 ::gfx::MockGLInterface* gl, MockErrorState* error_state,
115 BufferManager* manager, Buffer* buffer, GLenum target, GLsizeiptr size,
116 GLenum usage, const GLvoid* data, GLenum error);
118 static void SetTexParameteriWithExpectations(
119 ::gfx::MockGLInterface* gl, MockErrorState* error_state,
120 TextureManager* manager, TextureRef* texture_ref,
121 GLenum pname, GLint value, GLenum error);
123 static void SetShaderStates(
124 ::gfx::MockGLInterface* gl, Shader* shader,
125 bool expected_valid,
126 const std::string* const expected_log_info,
127 const std::string* const expected_translated_source,
128 const int* const expected_shader_version,
129 const AttributeMap* const expected_attrib_map,
130 const UniformMap* const expected_uniform_map,
131 const VaryingMap* const expected_varying_map,
132 const NameMap* const expected_name_map);
134 static void SetShaderStates(
135 ::gfx::MockGLInterface* gl, Shader* shader, bool valid);
137 static sh::Attribute ConstructAttribute(
138 GLenum type, GLint array_size, GLenum precision,
139 bool static_use, const std::string& name);
140 static sh::Uniform ConstructUniform(
141 GLenum type, GLint array_size, GLenum precision,
142 bool static_use, const std::string& name);
143 static sh::Varying ConstructVarying(
144 GLenum type, GLint array_size, GLenum precision,
145 bool static_use, const std::string& name);
147 private:
148 static void SetupTextureInitializationExpectations(::gfx::MockGLInterface* gl,
149 GLenum target,
150 bool use_default_textures);
151 static void SetupTextureDestructionExpectations(::gfx::MockGLInterface* gl,
152 GLenum target,
153 bool use_default_textures);
155 static std::vector<std::string> split_extensions_;
158 // This object temporaritly Sets what gfx::GetGLImplementation returns. During
159 // testing the GLImplementation is set to kGLImplemenationMockGL but lots of
160 // code branches based on what gfx::GetGLImplementation returns.
161 class ScopedGLImplementationSetter {
162 public:
163 explicit ScopedGLImplementationSetter(gfx::GLImplementation implementation);
164 ~ScopedGLImplementationSetter();
166 private:
167 gfx::GLImplementation old_implementation_;
170 } // namespace gles2
171 } // namespace gpu
173 #endif // GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_