Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ui/gl/gpu_timing_unittest.cc

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gl/gpu_timing.cc ('k') | ui/gl/test/egl_initialization_displays_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gl/gpu_timing.h"
6
5 #include <stdint.h> 7 #include <stdint.h>
6 8
9 #include <memory>
10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gl/gl_context_stub_with_extensions.h" 13 #include "ui/gl/gl_context_stub_with_extensions.h"
11 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
12 #include "ui/gl/gl_mock.h" 15 #include "ui/gl/gl_mock.h"
13 #include "ui/gl/gpu_preference.h" 16 #include "ui/gl/gpu_preference.h"
14 #include "ui/gl/gpu_timing.h"
15 #include "ui/gl/gpu_timing_fake.h" 17 #include "ui/gl/gpu_timing_fake.h"
16 #include "ui/gl/test/gl_surface_test_support.h" 18 #include "ui/gl/test/gl_surface_test_support.h"
17 19
18 namespace gfx { 20 namespace gfx {
19 21
20 using ::testing::Exactly; 22 using ::testing::Exactly;
21 using ::testing::NotNull; 23 using ::testing::NotNull;
22 using ::testing::DoAll; 24 using ::testing::DoAll;
23 using ::testing::Return; 25 using ::testing::Return;
24 using ::testing::SetArgPointee; 26 using ::testing::SetArgPointee;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 if (!cpu_time_bounded_) { 69 if (!cpu_time_bounded_) {
68 client->SetCpuTimeForTesting(base::Bind(&GPUTimingFake::GetFakeCPUTime)); 70 client->SetCpuTimeForTesting(base::Bind(&GPUTimingFake::GetFakeCPUTime));
69 cpu_time_bounded_ = true; 71 cpu_time_bounded_ = true;
70 } 72 }
71 return client; 73 return client;
72 } 74 }
73 75
74 protected: 76 protected:
75 bool setup_ = false; 77 bool setup_ = false;
76 bool cpu_time_bounded_ = false; 78 bool cpu_time_bounded_ = false;
77 scoped_ptr< ::testing::StrictMock<MockGLInterface> > gl_; 79 std::unique_ptr<::testing::StrictMock<MockGLInterface>> gl_;
78 scoped_refptr<GLContextStubWithExtensions> context_; 80 scoped_refptr<GLContextStubWithExtensions> context_;
79 GPUTimingFake gpu_timing_fake_queries_; 81 GPUTimingFake gpu_timing_fake_queries_;
80 }; 82 };
81 83
82 TEST_F(GPUTimingTest, FakeTimerTest) { 84 TEST_F(GPUTimingTest, FakeTimerTest) {
83 scoped_refptr<GPUTimingClient> gpu_timing_client = CreateGPUTimingClient(); 85 scoped_refptr<GPUTimingClient> gpu_timing_client = CreateGPUTimingClient();
84 86
85 // Tests that we can properly set fake cpu times. 87 // Tests that we can properly set fake cpu times.
86 gpu_timing_fake_queries_.SetCurrentCPUTime(123); 88 gpu_timing_fake_queries_.SetCurrentCPUTime(123);
87 EXPECT_EQ(123, gpu_timing_client->GetCurrentCPUTime()); 89 EXPECT_EQ(123, gpu_timing_client->GetCurrentCPUTime());
(...skipping 16 matching lines...) Expand all
104 106
105 EXPECT_TRUE(client1->IsForceTimeElapsedQuery()); 107 EXPECT_TRUE(client1->IsForceTimeElapsedQuery());
106 108
107 scoped_refptr<GPUTimingClient> client2 = CreateGPUTimingClient(); 109 scoped_refptr<GPUTimingClient> client2 = CreateGPUTimingClient();
108 EXPECT_TRUE(client2->IsForceTimeElapsedQuery()); 110 EXPECT_TRUE(client2->IsForceTimeElapsedQuery());
109 } 111 }
110 112
111 TEST_F(GPUTimingTest, QueryTimeStampTest) { 113 TEST_F(GPUTimingTest, QueryTimeStampTest) {
112 SetupGLContext("3.2", "GL_ARB_timer_query"); 114 SetupGLContext("3.2", "GL_ARB_timer_query");
113 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); 115 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient();
114 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); 116 std::unique_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false);
115 117
116 const int64_t begin_cpu_time = 1230; 118 const int64_t begin_cpu_time = 1230;
117 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; 119 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond;
118 const int64_t cpu_gl_offset = 120 const int64_t cpu_gl_offset =
119 begin_gl_time / base::Time::kNanosecondsPerMicrosecond - begin_cpu_time; 121 begin_gl_time / base::Time::kNanosecondsPerMicrosecond - begin_cpu_time;
120 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); 122 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset);
121 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); 123 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time);
122 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, false); 124 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, false);
123 125
124 gpu_timer->QueryTimeStamp(); 126 gpu_timer->QueryTimeStamp();
(...skipping 13 matching lines...) Expand all
138 gpu_timer->GetStartEndTimestamps(&start, &end); 140 gpu_timer->GetStartEndTimestamps(&start, &end);
139 EXPECT_EQ(begin_cpu_time, start); 141 EXPECT_EQ(begin_cpu_time, start);
140 EXPECT_EQ(begin_cpu_time, end); 142 EXPECT_EQ(begin_cpu_time, end);
141 } 143 }
142 144
143 TEST_F(GPUTimingTest, QueryTimeStampUsingElapsedTest) { 145 TEST_F(GPUTimingTest, QueryTimeStampUsingElapsedTest) {
144 // Test timestamp queries using GL_EXT_timer_query which does not support 146 // Test timestamp queries using GL_EXT_timer_query which does not support
145 // timestamp queries. Internally we fall back to time elapsed queries. 147 // timestamp queries. Internally we fall back to time elapsed queries.
146 SetupGLContext("3.2", "GL_EXT_timer_query"); 148 SetupGLContext("3.2", "GL_EXT_timer_query");
147 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); 149 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient();
148 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); 150 std::unique_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false);
149 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); 151 ASSERT_TRUE(client->IsForceTimeElapsedQuery());
150 152
151 const int64_t begin_cpu_time = 123; 153 const int64_t begin_cpu_time = 123;
152 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; 154 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond;
153 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; 155 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time;
154 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); 156 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset);
155 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); 157 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time);
156 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); 158 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true);
157 159
158 gpu_timer->QueryTimeStamp(); 160 gpu_timer->QueryTimeStamp();
159 161
160 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1); 162 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time - 1);
161 EXPECT_FALSE(gpu_timer->IsAvailable()); 163 EXPECT_FALSE(gpu_timer->IsAvailable());
162 164
163 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1); 165 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time + 1);
164 EXPECT_TRUE(gpu_timer->IsAvailable()); 166 EXPECT_TRUE(gpu_timer->IsAvailable());
165 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed()); 167 EXPECT_EQ(0, gpu_timer->GetDeltaElapsed());
166 168
167 int64_t start, end; 169 int64_t start, end;
168 gpu_timer->GetStartEndTimestamps(&start, &end); 170 gpu_timer->GetStartEndTimestamps(&start, &end);
169 EXPECT_EQ(begin_cpu_time, start); 171 EXPECT_EQ(begin_cpu_time, start);
170 EXPECT_EQ(begin_cpu_time, end); 172 EXPECT_EQ(begin_cpu_time, end);
171 } 173 }
172 174
173 TEST_F(GPUTimingTest, QueryTimestampUsingElapsedARBTest) { 175 TEST_F(GPUTimingTest, QueryTimestampUsingElapsedARBTest) {
174 // Test timestamp queries on platforms with GL_ARB_timer_query but still lack 176 // Test timestamp queries on platforms with GL_ARB_timer_query but still lack
175 // support for timestamp queries 177 // support for timestamp queries
176 SetupGLContext("3.2", "GL_ARB_timer_query"); 178 SetupGLContext("3.2", "GL_ARB_timer_query");
177 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient(); 179 scoped_refptr<GPUTimingClient> client = CreateGPUTimingClient();
178 scoped_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false); 180 std::unique_ptr<GPUTimer> gpu_timer = client->CreateGPUTimer(false);
179 181
180 const int64_t begin_cpu_time = 123; 182 const int64_t begin_cpu_time = 123;
181 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond; 183 const int64_t begin_gl_time = 10 * base::Time::kNanosecondsPerMicrosecond;
182 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time; 184 const int64_t cpu_gl_offset = begin_gl_time - begin_cpu_time;
183 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset); 185 gpu_timing_fake_queries_.SetCPUGLOffset(cpu_gl_offset);
184 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time); 186 gpu_timing_fake_queries_.SetCurrentCPUTime(begin_cpu_time);
185 187
186 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true); 188 gpu_timing_fake_queries_.ExpectGPUTimeStampQuery(*gl_, true);
187 189
188 // Custom mock override to ensure the timestamp bits are 0 190 // Custom mock override to ensure the timestamp bits are 0
(...skipping 12 matching lines...) Expand all
201 203
202 int64_t start, end; 204 int64_t start, end;
203 gpu_timer->GetStartEndTimestamps(&start, &end); 205 gpu_timer->GetStartEndTimestamps(&start, &end);
204 // Force time elapsed won't be set until a query is actually attempted 206 // Force time elapsed won't be set until a query is actually attempted
205 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); 207 ASSERT_TRUE(client->IsForceTimeElapsedQuery());
206 EXPECT_EQ(begin_cpu_time, start); 208 EXPECT_EQ(begin_cpu_time, start);
207 EXPECT_EQ(begin_cpu_time, end); 209 EXPECT_EQ(begin_cpu_time, end);
208 } 210 }
209 211
210 } // namespace gpu 212 } // namespace gpu
OLDNEW
« no previous file with comments | « ui/gl/gpu_timing.cc ('k') | ui/gl/test/egl_initialization_displays_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698