1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
gpu / command_buffer / tests / gl_query_unittest.cc [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
#include <stdint.h>
#include "base/logging.h"
#include "base/threading/platform_thread.h"
#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gpu {
class QueryTest : public testing::Test {
protected:
void SetUp() override { gl_.Initialize(GLManager::Options()); }
void TearDown() override { gl_.Destroy(); }
GLManager gl_;
};
TEST_F(QueryTest, MultipleQueries) {
EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query"));
GLuint error_query = 0;
GLuint commands_issue_query = 0;
glGenQueriesEXT(1, &error_query);
glGenQueriesEXT(1, &commands_issue_query);
GLuint available;
GLuint result;
base::TimeTicks before = base::TimeTicks::Now();
// Begin two queries of different types
glBeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, commands_issue_query);
glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, error_query);
glEnable(GL_TEXTURE_2D); // Generates an INVALID_ENUM error
// End the two queries
glEndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
glEndQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM);
glFinish();
base::TimeTicks after = base::TimeTicks::Now();
// Check that we got result on both queries.
available = 0;
result = 0;
glGetQueryObjectuivEXT(commands_issue_query,
GL_QUERY_RESULT_AVAILABLE_EXT,
&available);
EXPECT_TRUE(available);
glGetQueryObjectuivEXT(commands_issue_query, GL_QUERY_RESULT_EXT, &result);
// Sanity check - the resulting delta is shorter than the time it took to
// run this test.
EXPECT_LE(result, base::TimeDelta(after - before).InMicroseconds());
result = 0;
available = 0;
glGetQueryObjectuivEXT(error_query,
GL_QUERY_RESULT_AVAILABLE_EXT,
&available);
EXPECT_TRUE(available);
glGetQueryObjectuivEXT(error_query, GL_QUERY_RESULT_EXT, &result);
EXPECT_EQ(static_cast<uint32_t>(GL_INVALID_ENUM), result);
}
TEST_F(QueryTest, GetErrorBasic) {
EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query"));
GLuint query = 0;
glGenQueriesEXT(1, &query);
GLuint query_status = 0;
GLuint result = 0;
glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, query);
glEnable(GL_TEXTURE_2D); // Generates an INVALID_ENUM error
glEndQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM);
glFinish();
query_status = 0;
result = 0;
glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &result);
EXPECT_TRUE(result);
glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_status);
EXPECT_EQ(static_cast<uint32_t>(GL_INVALID_ENUM), query_status);
}
TEST_F(QueryTest, CommandsCompleted) {
if (!GLTestHelper::HasExtension("GL_CHROMIUM_sync_query")) {
LOG(INFO) << "GL_CHROMIUM_sync_query not supported. Skipping test...";
return;
}
base::TimeTicks before = base::TimeTicks::Now();
GLuint query;
glGenQueriesEXT(1, &query);
glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query);
glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glEndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
glFlush();
GLuint result = 0;
glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &result);
base::TimeTicks after = base::TimeTicks::Now();
// Sanity check - the resulting delta is shorter than the time it took to
// run this test.
EXPECT_LE(result, base::TimeDelta(after - before).InMicroseconds());
glDeleteQueriesEXT(1, &query);
GLTestHelper::CheckGLError("no errors", __LINE__);
}
TEST_F(QueryTest, CommandsCompletedWithFinish) {
if (!GLTestHelper::HasExtension("GL_CHROMIUM_sync_query")) {
LOG(INFO) << "GL_CHROMIUM_sync_query not supported. Skipping test...";
return;
}
GLuint query;
glGenQueriesEXT(1, &query);
glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query);
glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glEndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
glFinish();
GLuint result = 0;
glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &result);
EXPECT_EQ(1u, result);
glDeleteQueriesEXT(1, &query);
GLTestHelper::CheckGLError("no errors", __LINE__);
}
} // namespace gpu