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 "ui/gl/gpu_timing.h" | 5 #include "ui/gl/gpu_timing.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gl/gl_context_stub_with_extensions.h" | 13 #include "ui/gl/gl_context_stub_with_extensions.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_mock.h" | 15 #include "ui/gl/gl_mock.h" |
16 #include "ui/gl/gl_surface_stub.h" | 16 #include "ui/gl/gl_surface_stub.h" |
17 #include "ui/gl/gpu_preference.h" | 17 #include "ui/gl/gpu_preference.h" |
18 #include "ui/gl/gpu_timing_fake.h" | 18 #include "ui/gl/gpu_timing_fake.h" |
19 #include "ui/gl/test/gl_surface_test_support.h" | 19 #include "ui/gl/test/gl_surface_test_support.h" |
20 | 20 |
21 namespace gfx { | 21 namespace gl { |
22 | 22 |
23 using ::testing::Exactly; | 23 using ::testing::Exactly; |
24 using ::testing::NotNull; | 24 using ::testing::NotNull; |
25 using ::testing::DoAll; | 25 using ::testing::DoAll; |
26 using ::testing::Return; | 26 using ::testing::Return; |
27 using ::testing::SetArgPointee; | 27 using ::testing::SetArgPointee; |
28 | 28 |
29 class GPUTimingTest : public testing::Test { | 29 class GPUTimingTest : public testing::Test { |
30 public: | 30 public: |
31 void SetUp() override { | 31 void SetUp() override { |
32 setup_ = false; | 32 setup_ = false; |
33 cpu_time_bounded_ = false; | 33 cpu_time_bounded_ = false; |
34 } | 34 } |
35 | 35 |
36 void TearDown() override { | 36 void TearDown() override { |
37 context_ = nullptr; | 37 context_ = nullptr; |
38 surface_ = nullptr; | 38 surface_ = nullptr; |
39 if (setup_) { | 39 if (setup_) { |
40 MockGLInterface::SetGLInterface(NULL); | 40 MockGLInterface::SetGLInterface(NULL); |
41 gfx::ClearGLBindings(); | 41 gl::ClearGLBindings(); |
42 } | 42 } |
43 setup_ = false; | 43 setup_ = false; |
44 cpu_time_bounded_ = false; | 44 cpu_time_bounded_ = false; |
45 gl_.reset(); | 45 gl_.reset(); |
46 gpu_timing_fake_queries_.Reset(); | 46 gpu_timing_fake_queries_.Reset(); |
47 } | 47 } |
48 | 48 |
49 void SetupGLContext(const char* gl_version, const char* gl_extensions) { | 49 void SetupGLContext(const char* gl_version, const char* gl_extensions) { |
50 ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; | 50 ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; |
51 SetGLGetProcAddressProc(MockGLInterface::GetGLProcAddress); | 51 SetGLGetProcAddressProc(MockGLInterface::GetGLProcAddress); |
52 GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 52 GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
53 gl_.reset(new ::testing::StrictMock<MockGLInterface>()); | 53 gl_.reset(new ::testing::StrictMock<MockGLInterface>()); |
54 MockGLInterface::SetGLInterface(gl_.get()); | 54 MockGLInterface::SetGLInterface(gl_.get()); |
55 | 55 |
56 context_ = new GLContextStubWithExtensions; | 56 context_ = new GLContextStubWithExtensions; |
57 context_->AddExtensionsString(gl_extensions); | 57 context_->AddExtensionsString(gl_extensions); |
58 context_->SetGLVersionString(gl_version); | 58 context_->SetGLVersionString(gl_version); |
59 surface_ = new gfx::GLSurfaceStub; | 59 surface_ = new gl::GLSurfaceStub; |
60 context_->MakeCurrent(surface_.get()); | 60 context_->MakeCurrent(surface_.get()); |
61 gpu_timing_fake_queries_.Reset(); | 61 gpu_timing_fake_queries_.Reset(); |
62 GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get()); | 62 GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get()); |
63 | 63 |
64 setup_ = true; | 64 setup_ = true; |
65 } | 65 } |
66 | 66 |
67 scoped_refptr<GPUTimingClient> CreateGPUTimingClient() { | 67 scoped_refptr<GPUTimingClient> CreateGPUTimingClient() { |
68 if (!setup_) { | 68 if (!setup_) { |
69 SetupGLContext("2.0", ""); | 69 SetupGLContext("2.0", ""); |
70 } | 70 } |
71 | 71 |
72 scoped_refptr<GPUTimingClient> client = context_->CreateGPUTimingClient(); | 72 scoped_refptr<GPUTimingClient> client = context_->CreateGPUTimingClient(); |
73 if (!cpu_time_bounded_) { | 73 if (!cpu_time_bounded_) { |
74 client->SetCpuTimeForTesting(base::Bind(&GPUTimingFake::GetFakeCPUTime)); | 74 client->SetCpuTimeForTesting(base::Bind(&GPUTimingFake::GetFakeCPUTime)); |
75 cpu_time_bounded_ = true; | 75 cpu_time_bounded_ = true; |
76 } | 76 } |
77 return client; | 77 return client; |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 bool setup_ = false; | 81 bool setup_ = false; |
82 bool cpu_time_bounded_ = false; | 82 bool cpu_time_bounded_ = false; |
83 std::unique_ptr<::testing::StrictMock<MockGLInterface>> gl_; | 83 std::unique_ptr<::testing::StrictMock<MockGLInterface>> gl_; |
84 scoped_refptr<GLContextStubWithExtensions> context_; | 84 scoped_refptr<GLContextStubWithExtensions> context_; |
85 scoped_refptr<gfx::GLSurfaceStub> surface_; | 85 scoped_refptr<gl::GLSurfaceStub> surface_; |
86 GPUTimingFake gpu_timing_fake_queries_; | 86 GPUTimingFake gpu_timing_fake_queries_; |
87 }; | 87 }; |
88 | 88 |
89 TEST_F(GPUTimingTest, FakeTimerTest) { | 89 TEST_F(GPUTimingTest, FakeTimerTest) { |
90 scoped_refptr<GPUTimingClient> gpu_timing_client = CreateGPUTimingClient(); | 90 scoped_refptr<GPUTimingClient> gpu_timing_client = CreateGPUTimingClient(); |
91 | 91 |
92 // Tests that we can properly set fake cpu times. | 92 // Tests that we can properly set fake cpu times. |
93 gpu_timing_fake_queries_.SetCurrentCPUTime(123); | 93 gpu_timing_fake_queries_.SetCurrentCPUTime(123); |
94 EXPECT_EQ(123, gpu_timing_client->GetCurrentCPUTime()); | 94 EXPECT_EQ(123, gpu_timing_client->GetCurrentCPUTime()); |
95 | 95 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 int64_t start, end; | 209 int64_t start, end; |
210 gpu_timer->GetStartEndTimestamps(&start, &end); | 210 gpu_timer->GetStartEndTimestamps(&start, &end); |
211 // Force time elapsed won't be set until a query is actually attempted | 211 // Force time elapsed won't be set until a query is actually attempted |
212 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); | 212 ASSERT_TRUE(client->IsForceTimeElapsedQuery()); |
213 EXPECT_EQ(begin_cpu_time, start); | 213 EXPECT_EQ(begin_cpu_time, start); |
214 EXPECT_EQ(begin_cpu_time, end); | 214 EXPECT_EQ(begin_cpu_time, end); |
215 } | 215 } |
216 | 216 |
217 } // namespace gpu | 217 } // namespace gpu |
OLD | NEW |