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.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/init/gl_factory.h" | 19 #include "ui/gl/init/gl_factory.h" |
20 #include "ui/gl/test/gl_surface_test_support.h" | 20 #include "ui/gl/test/gl_surface_test_support.h" |
21 | 21 |
22 namespace gl { | 22 namespace gl { |
23 | 23 |
(...skipping 23 matching lines...) Expand all Loading... |
47 gpu_timing_fake_queries_.Reset(); | 47 gpu_timing_fake_queries_.Reset(); |
48 } | 48 } |
49 | 49 |
50 void SetupGLContext(const char* gl_version, const char* gl_extensions) { | 50 void SetupGLContext(const char* gl_version, const char* gl_extensions) { |
51 ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; | 51 ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; |
52 SetGLGetProcAddressProc(MockGLInterface::GetGLProcAddress); | 52 SetGLGetProcAddressProc(MockGLInterface::GetGLProcAddress); |
53 GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 53 GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
54 gl_.reset(new ::testing::StrictMock<MockGLInterface>()); | 54 gl_.reset(new ::testing::StrictMock<MockGLInterface>()); |
55 MockGLInterface::SetGLInterface(gl_.get()); | 55 MockGLInterface::SetGLInterface(gl_.get()); |
56 | 56 |
57 context_ = new GLContextStubWithExtensions; | 57 context_ = new GLContextStub; |
58 context_->AddExtensionsString(gl_extensions); | 58 context_->SetExtensionsString(gl_extensions); |
59 context_->SetGLVersionString(gl_version); | 59 context_->SetGLVersionString(gl_version); |
60 surface_ = new GLSurfaceStub; | 60 surface_ = new GLSurfaceStub; |
61 context_->MakeCurrent(surface_.get()); | 61 context_->MakeCurrent(surface_.get()); |
62 gpu_timing_fake_queries_.Reset(); | 62 gpu_timing_fake_queries_.Reset(); |
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<GLContextStub> context_; |
85 scoped_refptr<GLSurfaceStub> surface_; | 85 scoped_refptr<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()); |
(...skipping 113 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 gl | 217 } // namespace gl |
OLD | NEW |