OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gl/gl_context_stub_with_extensions.h" | 10 #include "ui/gl/gl_context_stub_with_extensions.h" |
11 #include "ui/gl/gl_implementation.h" | 11 #include "ui/gl/gl_implementation.h" |
12 #include "ui/gl/gl_mock.h" | 12 #include "ui/gl/gl_mock.h" |
13 #include "ui/gl/gpu_preference.h" | 13 #include "ui/gl/gpu_preference.h" |
14 #include "ui/gl/gpu_timing.h" | 14 #include "ui/gl/gpu_timing.h" |
15 #include "ui/gl/gpu_timing_fake.h" | 15 #include "ui/gl/gpu_timing_fake.h" |
16 #include "ui/gl/test/gl_surface_test_support.h" | 16 #include "ui/gl/test/gl_surface_test_support.h" |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
| 20 using ::testing::Exactly; |
| 21 using ::testing::NotNull; |
| 22 using ::testing::DoAll; |
| 23 using ::testing::Return; |
| 24 using ::testing::SetArgPointee; |
| 25 |
20 class GPUTimingTest : public testing::Test { | 26 class GPUTimingTest : public testing::Test { |
21 public: | 27 public: |
22 void SetUp() override { | 28 void SetUp() override { |
23 setup_ = false; | 29 setup_ = false; |
24 cpu_time_bounded_ = false; | 30 cpu_time_bounded_ = false; |
25 } | 31 } |
26 | 32 |
27 void TearDown() override { | 33 void TearDown() override { |
28 if (setup_) { | 34 if (setup_) { |
29 MockGLInterface::SetGLInterface(NULL); | 35 MockGLInterface::SetGLInterface(NULL); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); | 162 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
157 EXPECT_TRUE(gpu_timer->IsAvailable()); | 163 EXPECT_TRUE(gpu_timer->IsAvailable()); |
158 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); | 164 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
159 | 165 |
160 int64_t start, end; | 166 int64_t start, end; |
161 gpu_timer->GetStartEndTimestamps(&start, &end); | 167 gpu_timer->GetStartEndTimestamps(&start, &end); |
162 EXPECT_EQ(begin_cpu_time, start); | 168 EXPECT_EQ(begin_cpu_time, start); |
163 EXPECT_EQ(begin_cpu_time, end); | 169 EXPECT_EQ(begin_cpu_time, end); |
164 } | 170 } |
165 | 171 |
| 172 TEST_F(GPUTimingTest, QueryTimestampUsingElapsedARBTest) { |
| 173 // Test timestamp queries on platforms with GL_ARB_timer_query but still lack |
| 174 // support for timestamp queries |
| 175 SetupGLContext("3.2", "GL_ARB_timer_query"); |
| 176 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); |
| 177 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); |
| 178 |
| 179 const int64_t begin_cpu_time = 123; |
| 180 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; |
| 181 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; |
| 182 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); |
| 183 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
| 184 |
| 185 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); |
| 186 |
| 187 // Custom mock override to ensure the timestamp bits are 0 |
| 188 EXPECT_CALL(*gl_, GetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, NotNull())) |
| 189 .Times(Exactly(1)) |
| 190 .WillRepeatedly(DoAll(SetArgPointee<2>(0), Return())); |
| 191 |
| 192 gpu_timer->QueryTimeStamp(); |
| 193 |
| 194 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); |
| 195 EXPECT_FALSE(gpu_timer->IsAvailable()); |
| 196 |
| 197 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
| 198 EXPECT_TRUE(gpu_timer->IsAvailable()); |
| 199 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
| 200 |
| 201 int64_t start, end; |
| 202 gpu_timer->GetStartEndTimestamps(&start, &end); |
| 203 // Force time elapsed won't be set until a query is actually attempted |
| 204 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); |
| 205 EXPECT_EQ(begin_cpu_time, start); |
| 206 EXPECT_EQ(begin_cpu_time, end); |
| 207 } |
| 208 |
166 } // namespace gpu | 209 } // namespace gpu |
OLD | NEW |