| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> | 
| 6 #include <set> | 6 #include <set> | 
| 7 | 7 | 
| 8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 
| 9 #include "gpu/command_buffer/service/gpu_service_test.h" | 9 #include "gpu/command_buffer/service/gpu_service_test.h" | 
| 10 #include "gpu/command_buffer/service/gpu_tracer.h" | 10 #include "gpu/command_buffer/service/gpu_tracer.h" | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81     } | 81     } | 
| 82   } | 82   } | 
| 83 | 83 | 
| 84   void DeleteQueriesARB(GLsizei n, const GLuint* ids) { | 84   void DeleteQueriesARB(GLsizei n, const GLuint* ids) { | 
| 85     for (GLsizei i = 0; i < n; i++) { | 85     for (GLsizei i = 0; i < n; i++) { | 
| 86       alloced_queries_.erase(ids[i]); | 86       alloced_queries_.erase(ids[i]); | 
| 87       query_timestamp_.erase(ids[i]); | 87       query_timestamp_.erase(ids[i]); | 
| 88     } | 88     } | 
| 89   } | 89   } | 
| 90 | 90 | 
| 91   void GetQueryObjectiv(GLuint id, GLenum pname, GLint* params) { | 91   void GetQueryObjectivARB(GLuint id, GLenum pname, GLint* params) { | 
| 92     switch (pname) { | 92     switch (pname) { | 
| 93       case GL_QUERY_RESULT_AVAILABLE: { | 93       case GL_QUERY_RESULT_AVAILABLE: { | 
| 94         std::map<GLuint, GLint64>::iterator it = query_timestamp_.find(id); | 94         std::map<GLuint, GLint64>::iterator it = query_timestamp_.find(id); | 
| 95         if (it != query_timestamp_.end() && it->second <= current_time_) | 95         if (it != query_timestamp_.end() && it->second <= current_time_) | 
| 96           *params = 1; | 96           *params = 1; | 
| 97         else | 97         else | 
| 98           *params = 0; | 98           *params = 0; | 
| 99         break; | 99         break; | 
| 100       } | 100       } | 
| 101       default: | 101       default: | 
| 102         FAIL() << "Invalid variable passed to GetQueryObjectiv: " << pname; | 102         FAIL() << "Invalid variable passed to GetQueryObjectivARB: " << pname; | 
| 103     } | 103     } | 
| 104   } | 104   } | 
| 105 | 105 | 
| 106   void QueryCounter(GLuint id, GLenum target) { | 106   void QueryCounter(GLuint id, GLenum target) { | 
| 107     switch (target) { | 107     switch (target) { | 
| 108       case GL_TIMESTAMP: | 108       case GL_TIMESTAMP: | 
| 109         ASSERT_TRUE(alloced_queries_.find(id) != alloced_queries_.end()); | 109         ASSERT_TRUE(alloced_queries_.find(id) != alloced_queries_.end()); | 
| 110         query_timestamp_[id] = current_time_; | 110         query_timestamp_[id] = current_time_; | 
| 111         break; | 111         break; | 
| 112       default: | 112       default: | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 248     GpuServiceTest::TearDown(); | 248     GpuServiceTest::TearDown(); | 
| 249   } | 249   } | 
| 250 | 250 | 
| 251   void ExpectTraceQueryMocks() { | 251   void ExpectTraceQueryMocks() { | 
| 252     if (GetTracerType() != kTracerTypeInvalid) { | 252     if (GetTracerType() != kTracerTypeInvalid) { | 
| 253       // Delegate query APIs used by GPUTrace to a GlFakeQueries | 253       // Delegate query APIs used by GPUTrace to a GlFakeQueries | 
| 254       EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) | 254       EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) | 
| 255           .WillRepeatedly( | 255           .WillRepeatedly( | 
| 256               Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); | 256               Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); | 
| 257 | 257 | 
| 258       EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, | 258       EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, | 
| 259                                          NotNull())) | 259                                          NotNull())) | 
| 260           .WillRepeatedly( | 260           .WillRepeatedly( | 
| 261                Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); | 261                Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); | 
| 262 | 262 | 
| 263       if (GetTracerType() == kTracerTypeDisjointTimer) { | 263       if (GetTracerType() == kTracerTypeDisjointTimer) { | 
| 264         EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) | 264         EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) | 
| 265           .WillRepeatedly( | 265           .WillRepeatedly( | 
| 266                Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 266                Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 
| 267       } | 267       } | 
| 268 | 268 | 
| 269       EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) | 269       EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) | 
| 270           .WillRepeatedly( | 270           .WillRepeatedly( | 
| 271                Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 271                Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 323     if (GetTracerType() == kTracerTypeDisjointTimer) { | 323     if (GetTracerType() == kTracerTypeDisjointTimer) { | 
| 324       EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) | 324       EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) | 
| 325           .WillRepeatedly( | 325           .WillRepeatedly( | 
| 326               Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); | 326               Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); | 
| 327     } else { | 327     } else { | 
| 328       EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); | 328       EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); | 
| 329     } | 329     } | 
| 330 | 330 | 
| 331     // Timer offset calculation should only happen for the regular timer. | 331     // Timer offset calculation should only happen for the regular timer. | 
| 332     if (GetTracerType() != kTracerTypeARBTimer) { | 332     if (GetTracerType() != kTracerTypeARBTimer) { | 
| 333       EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(Exactly(0)); | 333       EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 
| 334       EXPECT_CALL(*gl_, Finish()).Times(Exactly(0)); |  | 
| 335       EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(Exactly(0)); |  | 
| 336       EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |  | 
| 337           .Times(Exactly(0)); | 334           .Times(Exactly(0)); | 
| 338       EXPECT_CALL(*gl_, DeleteQueriesARB(_, NotNull())).Times(Exactly(0)); |  | 
| 339     } else { | 335     } else { | 
| 340       EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(AtLeast(1)) | 336       EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 
| 341           .WillRepeatedly( |  | 
| 342               Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); |  | 
| 343 |  | 
| 344       EXPECT_CALL(*gl_, Finish()).Times(AtLeast(2)) |  | 
| 345           .WillRepeatedly( |  | 
| 346               Invoke(&gl_fake_queries_, &GlFakeQueries::Finish)); |  | 
| 347 |  | 
| 348       EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) |  | 
| 349           .Times(AtLeast(1)) | 337           .Times(AtLeast(1)) | 
| 350           .WillRepeatedly( | 338           .WillRepeatedly( | 
| 351                Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 339               Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 
| 352 |  | 
| 353       EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |  | 
| 354           .Times(AtLeast(1)) |  | 
| 355           .WillRepeatedly( |  | 
| 356                Invoke(&gl_fake_queries_, |  | 
| 357                       &GlFakeQueries::GetQueryObjectui64v)); |  | 
| 358 |  | 
| 359       EXPECT_CALL(*gl_, DeleteQueriesARB(1, NotNull())) |  | 
| 360           .Times(AtLeast(1)) |  | 
| 361           .WillRepeatedly( |  | 
| 362                Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueriesARB)); |  | 
| 363     } | 340     } | 
| 364   } | 341   } | 
| 365 | 342 | 
| 366   GpuTracerType GetTracerType() { return test_tracer_type_; } | 343   GpuTracerType GetTracerType() { return test_tracer_type_; } | 
| 367 | 344 | 
| 368   GpuTracerType test_tracer_type_; | 345   GpuTracerType test_tracer_type_; | 
| 369   GlFakeQueries gl_fake_queries_; | 346   GlFakeQueries gl_fake_queries_; | 
| 370 | 347 | 
| 371   scoped_refptr<MockOutputter> outputter_ref_; | 348   scoped_refptr<MockOutputter> outputter_ref_; | 
| 372   scoped_refptr<FakeCPUTime> cpu_time_ref_; | 349   scoped_refptr<FakeCPUTime> cpu_time_ref_; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 397 | 374 | 
| 398     ExpectTraceQueryMocks(); | 375     ExpectTraceQueryMocks(); | 
| 399     ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, | 376     ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, | 
| 400                          expect_start_time, expect_end_time); | 377                          expect_start_time, expect_end_time); | 
| 401 | 378 | 
| 402     scoped_refptr<GPUTrace> trace = | 379     scoped_refptr<GPUTrace> trace = | 
| 403         new GPUTrace(outputter_ref_, cpu_time_ref_, category_name, trace_name, | 380         new GPUTrace(outputter_ref_, cpu_time_ref_, category_name, trace_name, | 
| 404                      offset_time, GetTracerType()); | 381                      offset_time, GetTracerType()); | 
| 405 | 382 | 
| 406     gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 383     gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 
|  | 384     cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 
| 407     trace->Start(true); | 385     trace->Start(true); | 
| 408 | 386 | 
| 409     // Shouldn't be available before End() call | 387     // Shouldn't be available before End() call | 
| 410     gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 388     gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 
| 411     EXPECT_FALSE(trace->IsAvailable()); | 389     EXPECT_FALSE(trace->IsAvailable()); | 
| 412 | 390 | 
| 413     trace->End(true); | 391     trace->End(true); | 
| 414 | 392 | 
| 415     // Shouldn't be available until the queries complete | 393     // Shouldn't be available until the queries complete | 
| 416     gl_fake_queries_.SetCurrentGLTime(end_timestamp - | 394     gl_fake_queries_.SetCurrentGLTime(end_timestamp - | 
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 689                                    kTraceGroupMarker)); | 667                                    kTraceGroupMarker)); | 
| 690 | 668 | 
| 691   ASSERT_TRUE(tracer_tester.BeginDecoding()); | 669   ASSERT_TRUE(tracer_tester.BeginDecoding()); | 
| 692   EXPECT_TRUE(tracer_tester.Begin(category_name, trace_name, | 670   EXPECT_TRUE(tracer_tester.Begin(category_name, trace_name, | 
| 693                                   kTraceGroupMarker)); | 671                                   kTraceGroupMarker)); | 
| 694   ASSERT_TRUE(tracer_tester.EndDecoding()); | 672   ASSERT_TRUE(tracer_tester.EndDecoding()); | 
| 695 } | 673 } | 
| 696 | 674 | 
| 697 }  // namespace gles2 | 675 }  // namespace gles2 | 
| 698 }  // namespace gpu | 676 }  // namespace gpu | 
| OLD | NEW | 
|---|