| 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" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 SetupGLContext("3.2", "GL_ARB_timer_query"); | 105 SetupGLContext("3.2", "GL_ARB_timer_query"); |
| 106 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); | 106 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); |
| 107 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); | 107 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); |
| 108 | 108 |
| 109 const int64_t begin_cpu_time = 1230; | 109 const int64_t begin_cpu_time = 1230; |
| 110 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; | 110 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; |
| 111 const int64_t cpu_gl_offset = | 111 const int64_t cpu_gl_offset = |
| 112 begin_gl_time / base::Time::kNanosecondsPerMicrosecond - begin_cpu_time; | 112 begin_gl_time / base::Time::kNanosecondsPerMicrosecond - begin_cpu_time; |
| 113 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); | 113 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); |
| 114 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); | 114 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
| 115 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, false); | 115 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, false, true); |
| 116 | 116 |
| 117 gpu_timer->QueryTimeStamp(); | 117 gpu_timer->QueryTimeStamp(); |
| 118 | 118 |
| 119 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); | 119 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); |
| 120 EXPECT_FALSE(gpu_timer->IsAvailable()); | 120 EXPECT_FALSE(gpu_timer->IsAvailable()); |
| 121 | 121 |
| 122 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); | 122 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
| 123 EXPECT_TRUE(gpu_timer->IsAvailable()); | 123 EXPECT_TRUE(gpu_timer->IsAvailable()); |
| 124 | 124 |
| 125 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); | 125 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 139 SetupGLContext("3.2", "GL_EXT_timer_query"); | 139 SetupGLContext("3.2", "GL_EXT_timer_query"); |
| 140 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); | 140 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); |
| 141 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); | 141 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); |
| 142 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); | 142 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); |
| 143 | 143 |
| 144 const int64_t begin_cpu_time = 123; | 144 const int64_t begin_cpu_time = 123; |
| 145 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; | 145 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; |
| 146 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; |
| 147 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); | 147 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); |
| 148 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); | 148 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
| 149 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); | 149 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true, false); |
| 150 | 150 |
| 151 gpu_timer->QueryTimeStamp(); | 151 gpu_timer->QueryTimeStamp(); |
| 152 | 152 |
| 153 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); | 153 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); |
| 154 EXPECT_FALSE(gpu_timer->IsAvailable()); | 154 EXPECT_FALSE(gpu_timer->IsAvailable()); |
| 155 | 155 |
| 156 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); | 156 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
| 157 EXPECT_TRUE(gpu_timer->IsAvailable()); | 157 EXPECT_TRUE(gpu_timer->IsAvailable()); |
| 158 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); | 158 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
| 159 | 159 |
| 160 int64_t start, end; | 160 int64_t start, end; |
| 161 gpu_timer->GetStartEndTimestamps(&start, &end); | 161 gpu_timer->GetStartEndTimestamps(&start, &end); |
| 162 EXPECT_EQ(begin_cpu_time, start); | 162 EXPECT_EQ(begin_cpu_time, start); |
| 163 EXPECT_EQ(begin_cpu_time, end); | 163 EXPECT_EQ(begin_cpu_time, end); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(GPUTimingTest, QueryTimestampUsingElapsedARBTest) { |
| 167 // Test timestamp queries on platforms with GL_ARB_timer_query but still lack |
| 168 // support for timestamp queries |
| 169 SetupGLContext("3.2", "GL_ARB_timer_query"); |
| 170 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); |
| 171 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); |
| 172 |
| 173 const int64_t begin_cpu_time = 123; |
| 174 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; |
| 175 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; |
| 176 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); |
| 177 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); |
| 178 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true, true); |
| 179 |
| 180 gpu_timer->QueryTimeStamp(); |
| 181 |
| 182 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); |
| 183 EXPECT_FALSE(gpu_timer->IsAvailable()); |
| 184 |
| 185 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); |
| 186 EXPECT_TRUE(gpu_timer->IsAvailable()); |
| 187 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); |
| 188 |
| 189 int64_t start, end; |
| 190 gpu_timer->GetStartEndTimestamps(&start, &end); |
| 191 // Force time elapsed won't be set until a query is actually attempted |
| 192 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); |
| 193 EXPECT_EQ(begin_cpu_time, start); |
| 194 EXPECT_EQ(begin_cpu_time, end); |
| 195 } |
| 196 |
| 166 } // namespace gpu | 197 } // namespace gpu |
| OLD | NEW |