Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / gpu / command_buffer / tests / gl_virtual_contexts_unittests.cc
blob29c69e6c8957353d1f21308b713ca270ed2a409d
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 #include <GLES2/gl2.h>
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
16 namespace gpu {
18 class GLVirtualContextsTest : public testing::Test {
19 protected:
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() {
37 gl1_.Destroy();
38 gl2_.Destroy();
39 gl_real_shared_.Destroy();
40 gl_real_.Destroy();
43 GLManager gl_real_;
44 GLManager gl_real_shared_;
45 GLManager gl1_;
46 GLManager gl2_;
49 namespace {
51 void SetupSimpleShader(const uint8* color) {
52 static const char* v_shader_str = SHADER(
53 attribute vec4 a_Position;
54 void main()
56 gl_Position = a_Position;
60 static const char* f_shader_str = SHADER(
61 precision mediump float;
62 uniform vec4 u_color;
63 void main()
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");
77 glUniform4f(
78 color_loc,
79 color[0] / 255.0f,
80 color[1] / 255.0f,
81 color[2] / 255.0f,
82 color[3] / 255.0f);
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) {
96 struct TestInfo {
97 int size;
98 uint8 color[4];
99 GLManager* manager;
101 const int kNumTests = 3;
102 TestInfo tests[] = {
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();
119 TestDraw(test.size);
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__);
138 } // namespace gpu