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.
6 #include <GLES2/gl2ext.h>
8 #include "gpu/command_buffer/tests/gl_manager.h"
9 #include "gpu/command_buffer/tests/gl_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
14 #define SHADER(Src) #Src
18 class GLVirtualContextsTest
: public testing::Test
{
20 static const int kSize0
= 4;
21 static const int kSize1
= 8;
22 static const int kSize2
= 16;
24 virtual void SetUp() {
25 GLManager::Options options
;
26 options
.size
= gfx::Size(kSize0
, kSize0
);
27 gl_real_
.Initialize(options
);
28 gl_real_shared_
.Initialize(options
);
29 options
.virtual_manager
= &gl_real_shared_
;
30 options
.size
= gfx::Size(kSize1
, kSize1
);
31 gl1_
.Initialize(options
);
32 options
.size
= gfx::Size(kSize2
, kSize2
);
33 gl2_
.Initialize(options
);
36 virtual void TearDown() {
39 gl_real_shared_
.Destroy();
44 GLManager gl_real_shared_
;
51 void SetupSimpleShader(const uint8
* color
) {
52 static const char* v_shader_str
= SHADER(
53 attribute vec4 a_Position
;
56 gl_Position
= a_Position
;
60 static const char* f_shader_str
= SHADER(
61 precision mediump
float;
65 gl_FragColor
= u_color
;
69 GLuint program
= GLTestHelper::LoadProgram(v_shader_str
, f_shader_str
);
70 glUseProgram(program
);
72 GLuint position_loc
= glGetAttribLocation(program
, "a_Position");
74 GLTestHelper::SetupUnitQuad(position_loc
);
76 GLuint color_loc
= glGetUniformLocation(program
, "u_color");
85 void TestDraw(int size
) {
86 uint8 expected_clear
[] = { 127, 0, 255, 0, };
87 glClearColor(0.5f
, 0.0f
, 1.0f
, 0.0f
);
88 glClear(GL_COLOR_BUFFER_BIT
);
89 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size
, size
, 1, expected_clear
));
90 glDrawArrays(GL_TRIANGLES
, 0, 6);
93 } // anonymous namespace
95 TEST_F(GLVirtualContextsTest
, Basic
) {
101 const int kNumTests
= 3;
103 { kSize0
, { 255, 0, 0, 0, }, &gl_real_
, },
104 { kSize1
, { 0, 255, 0, 0, }, &gl1_
, },
105 { kSize2
, { 0, 0, 255, 0, }, &gl2_
, },
108 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
109 const TestInfo
& test
= tests
[ii
];
110 GLManager
* gl_manager
= test
.manager
;
111 gl_manager
->MakeCurrent();
112 SetupSimpleShader(test
.color
);
115 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
116 const TestInfo
& test
= tests
[ii
];
117 GLManager
* gl_manager
= test
.manager
;
118 gl_manager
->MakeCurrent();
122 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
123 const TestInfo
& test
= tests
[ii
];
124 GLManager
* gl_manager
= test
.manager
;
125 gl_manager
->MakeCurrent();
126 EXPECT_TRUE(GLTestHelper::CheckPixels(
127 0, 0, test
.size
, test
.size
, 0, test
.color
));
130 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
131 const TestInfo
& test
= tests
[ii
];
132 GLManager
* gl_manager
= test
.manager
;
133 gl_manager
->MakeCurrent();
134 GLTestHelper::CheckGLError("no errors", __LINE__
);