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