Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: gpu/command_buffer/tests/gl_virtual_contexts_unittests.cc

Issue 11275120: Virtual GL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h>
7
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"
12
13
14 #define SHADER(Src) #Src
15
16 namespace gpu {
17
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;
23
24 virtual void SetUp() {
25 gl_real_.Initialize(gfx::Size(kSize0, kSize0));
26 gl_real_shared_.Initialize(gfx::Size(kSize0, kSize0));
27 gl1_.InitializeVirtual(gfx::Size(kSize1, kSize1), &gl_real_shared_);
28 gl2_.InitializeVirtual(gfx::Size(kSize2, kSize2), &gl_real_shared_);
29 }
30
31 virtual void TearDown() {
32 gl1_.Destroy();
33 gl2_.Destroy();
34 gl_real_shared_.Destroy();
35 gl_real_.Destroy();
36 }
37
38 GLManager gl_real_;
39 GLManager gl_real_shared_;
40 GLManager gl1_;
41 GLManager gl2_;
42 };
43
44 namespace {
45
46 void SetupSimpleShader(const uint8* color) {
47 static const char* v_shader_str = SHADER(
48 attribute vec4 a_Position;
49 void main()
50 {
51 gl_Position = a_Position;
52 }
53 );
54
55 static const char* f_shader_str = SHADER(
56 precision mediump float;
57 uniform vec4 u_color;
58 void main()
59 {
60 gl_FragColor = u_color;
61 }
62 );
63
64 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str);
65 glUseProgram(program);
66
67 GLuint position_loc = glGetAttribLocation(program, "a_Position");
68
69 GLTestHelper::SetupUnitQuad(position_loc);
70
71 GLuint color_loc = glGetUniformLocation(program, "u_color");
72 glUniform4f(
73 color_loc,
74 color[0] / 255.0f,
75 color[1] / 255.0f,
76 color[2] / 255.0f,
77 color[3] / 255.0f);
78 }
79
80 void TestDraw(int size) {
81 uint8 expected_clear[] = { 127, 0, 255, 0, };
82 glClearColor(0.5f, 0.0f, 1.0f, 0.0f);
83 glClear(GL_COLOR_BUFFER_BIT);
84 EXPECT_TRUE(GLTestHelper::CheckPixels(0, 0, size, size, 1, expected_clear));
85 glDrawArrays(GL_TRIANGLES, 0, 6);
86 }
87
88 } // anonymous namespace
89
90 TEST_F(GLVirtualContextsTest, Basic) {
91 struct TestInfo {
92 int size;
93 uint8 color[4];
94 GLManager* manager;
95 };
96 const int kNumTests = 3;
97 TestInfo tests[] = {
98 { kSize0, { 255, 0, 0, 0, }, &gl_real_, },
99 { kSize1, { 0, 255, 0, 0, }, &gl1_, },
100 { kSize2, { 0, 0, 255, 0, }, &gl2_, },
101 };
102
103 for (int ii = 0; ii < kNumTests; ++ii) {
104 const TestInfo& test = tests[ii];
105 GLManager* gl_manager = test.manager;
106 gl_manager->MakeCurrent();
107 SetupSimpleShader(test.color);
108 }
109
110 for (int ii = 0; ii < kNumTests; ++ii) {
111 const TestInfo& test = tests[ii];
112 GLManager* gl_manager = test.manager;
113 gl_manager->MakeCurrent();
114 TestDraw(test.size);
115 }
116
117 for (int ii = 0; ii < kNumTests; ++ii) {
118 const TestInfo& test = tests[ii];
119 GLManager* gl_manager = test.manager;
120 gl_manager->MakeCurrent();
121 EXPECT_TRUE(GLTestHelper::CheckPixels(
122 0, 0, test.size, test.size, 0, test.color));
123 }
124
125 for (int ii = 0; ii < kNumTests; ++ii) {
126 const TestInfo& test = tests[ii];
127 GLManager* gl_manager = test.manager;
128 gl_manager->MakeCurrent();
129 GLTestHelper::CheckGLError("no errors", __LINE__);
130 }
131 }
132
133 } // namespace gpu
134
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.cc ('k') | gpu/gpu.gyp » ('j') | ui/gl/DEPS » ('J')

Powered by Google App Engine
This is Rietveld 408576698