OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
8 | 8 |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
11 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 | 16 |
17 class QueryTest : public testing::Test { | 17 class QueryTest : public testing::Test { |
18 protected: | 18 protected: |
19 virtual void SetUp() { | 19 virtual void SetUp() { |
20 gl_.Initialize(GLManager::Options()); | 20 gl_.Initialize(GLManager::Options()); |
21 } | 21 } |
22 | 22 |
23 virtual void TearDown() { | 23 virtual void TearDown() { |
24 gl_.Destroy(); | 24 gl_.Destroy(); |
25 } | 25 } |
26 | 26 |
27 GLManager gl_; | 27 GLManager gl_; |
28 }; | 28 }; |
29 | 29 |
| 30 TEST_F(QueryTest, MultipleQueries) { |
| 31 EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query")); |
| 32 EXPECT_TRUE(GLTestHelper::HasExtension( |
| 33 "GL_CHROMIUM_command_buffer_latency_query")); |
| 34 |
| 35 GLuint error_query = 0; |
| 36 GLuint commands_issue_query = 0; |
| 37 glGenQueriesEXT(1, &error_query); |
| 38 glGenQueriesEXT(1, &commands_issue_query); |
| 39 |
| 40 GLuint available; |
| 41 GLuint result; |
| 42 |
| 43 base::TimeTicks before = base::TimeTicks::HighResNow(); |
| 44 |
| 45 // Begin two queries of different types |
| 46 glBeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, commands_issue_query); |
| 47 glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, error_query); |
| 48 |
| 49 glEnable(GL_TEXTURE_2D); // Generates an INVALID_ENUM error |
| 50 |
| 51 // End the two queries |
| 52 glEndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 53 glEndQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM); |
| 54 |
| 55 glFinish(); |
| 56 |
| 57 base::TimeTicks after = base::TimeTicks::HighResNow(); |
| 58 |
| 59 // Check that we got result on both queries. |
| 60 |
| 61 available = 0; |
| 62 result = 0; |
| 63 glGetQueryObjectuivEXT(commands_issue_query, |
| 64 GL_QUERY_RESULT_AVAILABLE_EXT, |
| 65 &available); |
| 66 EXPECT_TRUE(available); |
| 67 glGetQueryObjectuivEXT(commands_issue_query, GL_QUERY_RESULT_EXT, &result); |
| 68 // Sanity check - the resulting delta is shorter than the time it took to |
| 69 // run this test. |
| 70 EXPECT_LT(result, base::TimeDelta(after - before).InMicroseconds()); |
| 71 |
| 72 result = 0; |
| 73 available = 0; |
| 74 glGetQueryObjectuivEXT(error_query, |
| 75 GL_QUERY_RESULT_AVAILABLE_EXT, |
| 76 &available); |
| 77 EXPECT_TRUE(available); |
| 78 glGetQueryObjectuivEXT(error_query, GL_QUERY_RESULT_EXT, &result); |
| 79 EXPECT_EQ(static_cast<uint32>(GL_INVALID_ENUM), result); |
| 80 } |
| 81 |
30 TEST_F(QueryTest, GetErrorBasic) { | 82 TEST_F(QueryTest, GetErrorBasic) { |
31 EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query")); | 83 EXPECT_TRUE(GLTestHelper::HasExtension("GL_CHROMIUM_get_error_query")); |
32 | 84 |
33 GLuint query = 0; | 85 GLuint query = 0; |
34 glGenQueriesEXT(1, &query); | 86 glGenQueriesEXT(1, &query); |
35 | 87 |
36 GLuint query_status = 0; | 88 GLuint query_status = 0; |
37 GLuint result = 0; | 89 GLuint result = 0; |
38 | 90 |
39 glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, query); | 91 glBeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, query); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &available); | 146 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_AVAILABLE_EXT, &available); |
95 EXPECT_TRUE(available); | 147 EXPECT_TRUE(available); |
96 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_result); | 148 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &query_result); |
97 | 149 |
98 EXPECT_LE(query_result, kTimePrecisionMicroseconds); | 150 EXPECT_LE(query_result, kTimePrecisionMicroseconds); |
99 } | 151 } |
100 | 152 |
101 } // namespace gpu | 153 } // namespace gpu |
102 | 154 |
103 | 155 |
OLD | NEW |