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> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gl/gl_context_stub_with_extensions.h" | 10 #include "ui/gl/gl_context_stub_with_extensions.h" |
9 #include "ui/gl/gl_implementation.h" | 11 #include "ui/gl/gl_implementation.h" |
10 #include "ui/gl/gl_mock.h" | 12 #include "ui/gl/gl_mock.h" |
11 #include "ui/gl/gpu_preference.h" | 13 #include "ui/gl/gpu_preference.h" |
12 #include "ui/gl/gpu_timing.h" | 14 #include "ui/gl/gpu_timing.h" |
13 #include "ui/gl/gpu_timing_fake.h" | 15 #include "ui/gl/gpu_timing_fake.h" |
14 #include "ui/gl/test/gl_surface_test_support.h" | 16 #include "ui/gl/test/gl_surface_test_support.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 EXPECT_FALSE(gpu_timer->IsAvailable()); | 120 EXPECT_FALSE(gpu_timer->IsAvailable()); |
119 | 121 |
120 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); | 122 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
121 EXPECT_TRUE(gpu_timer->IsAvailable()); | 123 EXPECT_TRUE(gpu_timer->IsAvailable()); |
122 | 124 |
123 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); | 125 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
124 EXPECT_TRUE(gpu_timer->IsAvailable()); | 126 EXPECT_TRUE(gpu_timer->IsAvailable()); |
125 | 127 |
126 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); | 128 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
127 | 129 |
128 int64 start, end; | 130 int64_t start, end; |
129 gpu_timer->GetStartEndTimestamps(&start, &end); | 131 gpu_timer->GetStartEndTimestamps(&start, &end); |
130 EXPECT_EQ(begin_cpu_time, start); | 132 EXPECT_EQ(begin_cpu_time, start); |
131 EXPECT_EQ(begin_cpu_time, end); | 133 EXPECT_EQ(begin_cpu_time, end); |
132 } | 134 } |
133 | 135 |
134 TEST_F(GPUTimingTest, QueryTimeStampUsingElapsedTest) { | 136 TEST_F(GPUTimingTest, QueryTimeStampUsingElapsedTest) { |
135 // Test timestamp queries using GL_EXT_timer_query which does not support | 137 // Test timestamp queries using GL_EXT_timer_query which does not support |
136 // timestamp queries. Internally we fall back to time elapsed queries. | 138 // timestamp queries. Internally we fall back to time elapsed queries. |
137 SetupGLContext("3.2", "GL_EXT_timer_query"); | 139 SetupGLContext("3.2", "GL_EXT_timer_query"); |
138 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); | 140 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); |
139 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); | 141 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); |
140 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); | 142 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); |
141 | 143 |
142 const int64_t begin_cpu_time = 123; | 144 const int64_t begin_cpu_time = 123; |
143 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; | 145 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; |
144 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; | 146 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; |
145 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); | 147 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); |
146 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); | 148 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
147 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); | 149 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); |
148 | 150 |
149 gpu_timer->QueryTimeStamp(); | 151 gpu_timer->QueryTimeStamp(); |
150 | 152 |
151 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); | 153 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); |
152 EXPECT_FALSE(gpu_timer->IsAvailable()); | 154 EXPECT_FALSE(gpu_timer->IsAvailable()); |
153 | 155 |
154 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); | 156 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
155 EXPECT_TRUE(gpu_timer->IsAvailable()); | 157 EXPECT_TRUE(gpu_timer->IsAvailable()); |
156 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); | 158 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
157 | 159 |
158 int64 start, end; | 160 int64_t start, end; |
159 gpu_timer->GetStartEndTimestamps(&start, &end); | 161 gpu_timer->GetStartEndTimestamps(&start, &end); |
160 EXPECT_EQ(begin_cpu_time, start); | 162 EXPECT_EQ(begin_cpu_time, start); |
161 EXPECT_EQ(begin_cpu_time, end); | 163 EXPECT_EQ(begin_cpu_time, end); |
162 } | 164 } |
163 | 165 |
164 } // namespace gpu | 166 } // namespace gpu |
OLD | NEW |