1 // Copyright 2014 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 #if !defined(OS_ANDROID)
52 void SetupSimpleShader(const uint8
* color
) {
53 static const char* v_shader_str
= SHADER(
54 attribute vec4 a_Position
;
57 gl_Position
= a_Position
;
61 static const char* f_shader_str
= SHADER(
62 precision mediump
float;
66 gl_FragColor
= u_color
;
70 GLuint program
= GLTestHelper::LoadProgram(v_shader_str
, f_shader_str
);
71 glUseProgram(program
);
73 GLuint position_loc
= glGetAttribLocation(program
, "a_Position");
75 GLTestHelper::SetupUnitQuad(position_loc
);
77 GLuint color_loc
= glGetUniformLocation(program
, "u_color");
86 void TestDraw(int size
) {
87 uint8 expected_clear
[] = { 127, 0, 255, 0, };
88 glClearColor(0.5f
, 0.0f
, 1.0f
, 0.0f
);
89 glClear(GL_COLOR_BUFFER_BIT
);
90 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size
, size
, 1, expected_clear
));
91 glDrawArrays(GL_TRIANGLES
, 0, 6);
94 #endif // !defined(OS_ANDROID)
96 } // anonymous namespace
98 // http://crbug.com/281565
99 #if !defined(OS_ANDROID)
100 TEST_F(GLVirtualContextsTest
, Basic
) {
106 const int kNumTests
= 3;
108 { kSize0
, { 255, 0, 0, 0, }, &gl_real_
, },
109 { kSize1
, { 0, 255, 0, 0, }, &gl1_
, },
110 { kSize2
, { 0, 0, 255, 0, }, &gl2_
, },
113 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
114 const TestInfo
& test
= tests
[ii
];
115 GLManager
* gl_manager
= test
.manager
;
116 gl_manager
->MakeCurrent();
117 SetupSimpleShader(test
.color
);
120 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
121 const TestInfo
& test
= tests
[ii
];
122 GLManager
* gl_manager
= test
.manager
;
123 gl_manager
->MakeCurrent();
127 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
128 const TestInfo
& test
= tests
[ii
];
129 GLManager
* gl_manager
= test
.manager
;
130 gl_manager
->MakeCurrent();
131 EXPECT_TRUE(GLTestHelper::CheckPixels(
132 0, 0, test
.size
, test
.size
, 0, test
.color
));
135 for (int ii
= 0; ii
< kNumTests
; ++ii
) {
136 const TestInfo
& test
= tests
[ii
];
137 GLManager
* gl_manager
= test
.manager
;
138 gl_manager
->MakeCurrent();
139 GLTestHelper::CheckGLError("no errors", __LINE__
);