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 11namespace gpu { 12namespace gles2 { 13 14struct DisallowedFeatures; 15class Buffer; 16class BufferManager; 17class MockErrorState; 18class TextureRef; 19class TextureManager; 20 21class 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 static void SetupFeatureInfoInitExpectations( 70 ::gfx::MockGLInterface* gl, const char* extensions); 71 static void SetupFeatureInfoInitExpectationsWithGLVersion( 72 ::gfx::MockGLInterface* gl, 73 const char* extensions, 74 const char* gl_renderer, 75 const char* gl_version); 76 static void SetupTextureManagerInitExpectations( 77 ::gfx::MockGLInterface* gl, const char* extensions); 78 static void SetupTextureManagerDestructionExpectations( 79 ::gfx::MockGLInterface* gl, const char* extensions); 80 81 static void SetupExpectationsForClearingUniforms( 82 ::gfx::MockGLInterface* gl, UniformInfo* uniforms, size_t num_uniforms); 83 84 static void SetupShader( 85 ::gfx::MockGLInterface* gl, 86 AttribInfo* attribs, size_t num_attribs, 87 UniformInfo* uniforms, size_t num_uniforms, 88 GLuint service_id); 89 90 static void SetupProgramSuccessExpectations(::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 DoBufferData( 96 ::gfx::MockGLInterface* gl, MockErrorState* error_state, 97 BufferManager* manager, Buffer* buffer, GLsizeiptr size, GLenum usage, 98 const GLvoid* data, GLenum error); 99 100 static void SetTexParameterWithExpectations( 101 ::gfx::MockGLInterface* gl, MockErrorState* error_state, 102 TextureManager* manager, TextureRef* texture_ref, 103 GLenum pname, GLint value, GLenum error); 104 105 private: 106 static void SetupTextureInitializationExpectations( 107 ::gfx::MockGLInterface* gl, GLenum target); 108 static void SetupTextureDestructionExpectations( 109 ::gfx::MockGLInterface* gl, GLenum target); 110}; 111 112// This object temporaritly Sets what gfx::GetGLImplementation returns. During 113// testing the GLImplementation is set to kGLImplemenationMockGL but lots of 114// code branches based on what gfx::GetGLImplementation returns. 115class ScopedGLImplementationSetter { 116 public: 117 explicit ScopedGLImplementationSetter(gfx::GLImplementation implementation); 118 ~ScopedGLImplementationSetter(); 119 120 private: 121 gfx::GLImplementation old_implementation_; 122}; 123 124} // namespace gles2 125} // namespace gpu 126 127#endif // GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_ 128 129