| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/test/trace_event_analyzer.h" | 10 #include "base/test/trace_event_analyzer.h" |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 // Expect that the average time between RAFs is more than 15ms. That will | 435 // Expect that the average time between RAFs is more than 15ms. That will |
| 436 // indicate that the renderer is not simply spinning on RAF. | 436 // indicate that the renderer is not simply spinning on RAF. |
| 437 EXPECT_GT(stats.mean_us, 15000.0); | 437 EXPECT_GT(stats.mean_us, 15000.0); |
| 438 | 438 |
| 439 // Print out the trace events upon error to debug failures. | 439 // Print out the trace events upon error to debug failures. |
| 440 if (stats.mean_us <= 15000.0) { | 440 if (stats.mean_us <= 15000.0) { |
| 441 fprintf(stderr, "\n\nTRACE JSON:\n\n%s\n\n", trace_events_json_.c_str()); | 441 fprintf(stderr, "\n\nTRACE JSON:\n\n%s\n\n", trace_events_json_.c_str()); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 // Disable this test under ASAN <http://crbug.com/148633>. | 445 #if defined(OS_MACOSX) |
| 446 #if defined(OS_MACOSX) && !defined(ADDRESS_SANITIZER) | |
| 447 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, IOSurfaceReuse) { | 446 IN_PROC_BROWSER_TEST_F(GpuFeatureTest, IOSurfaceReuse) { |
| 448 if (!IOSurfaceSupport::Initialize()) | 447 if (!IOSurfaceSupport::Initialize()) |
| 449 return; | 448 return; |
| 450 | 449 |
| 451 const FilePath url(FILE_PATH_LITERAL("feature_compositing_static.html")); | 450 const FilePath url(FILE_PATH_LITERAL("feature_compositing_static.html")); |
| 452 FilePath test_path = gpu_test_dir_.Append(url); | 451 FilePath test_path = gpu_test_dir_.Append(url); |
| 453 ASSERT_TRUE(file_util::PathExists(test_path)) | 452 ASSERT_TRUE(file_util::PathExists(test_path)) |
| 454 << "Missing test file: " << test_path.value(); | 453 << "Missing test file: " << test_path.value(); |
| 455 | 454 |
| 456 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_path)); | 455 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_path)); |
| 457 | 456 |
| 458 gfx::Rect bounds = browser()->window()->GetBounds(); | 457 gfx::Rect bounds = browser()->window()->GetBounds(); |
| 459 gfx::Rect new_bounds = bounds; | 458 gfx::Rect new_bounds = bounds; |
| 460 | 459 |
| 461 TraceEventVector events; | |
| 462 const char* create_event = "IOSurfaceImageTransportSurface::CreateIOSurface"; | 460 const char* create_event = "IOSurfaceImageTransportSurface::CreateIOSurface"; |
| 463 const char* resize_event = "IOSurfaceImageTransportSurface::OnResize"; | 461 const char* resize_event = "IOSurfaceImageTransportSurface::OnResize"; |
| 462 const char* draw_event = "CompositingIOSurfaceMac::DrawIOSurface"; |
| 464 Query find_creates = Query::MatchBeginName(create_event); | 463 Query find_creates = Query::MatchBeginName(create_event); |
| 465 Query find_resizes = Query::MatchBeginName(resize_event) && | 464 Query find_resizes = Query::MatchBeginName(resize_event) && |
| 466 Query::EventHasNumberArg("width"); | 465 Query::EventHasNumberArg("old_width") && |
| 466 Query::EventHasNumberArg("new_width"); |
| 467 Query find_draws = Query::MatchBeginName(draw_event) && |
| 468 Query::EventHasNumberArg("scale"); |
| 467 | 469 |
| 468 // Skip the first resize event in case it's flaky: | 470 const int roundup = 64; |
| 471 // A few resize values assuming a roundup of 64 pixels. The test will resize |
| 472 // by these values one at a time and verify that CreateIOSurface only happens |
| 473 // when the rounded width changes. |
| 474 int offsets[] = { 1, roundup - 1, roundup, roundup + 1, 2*roundup}; |
| 475 int num_offsets = static_cast<int>(arraysize(offsets)); |
| 469 int w_start = bounds.width(); | 476 int w_start = bounds.width(); |
| 470 new_bounds.set_width(++w_start); | |
| 471 ASSERT_TRUE(ResizeAndWait(new_bounds, "gpu", "gpu", resize_event)); | |
| 472 | 477 |
| 473 // Remember starting IOSurface width, because it may not match the window | 478 for (int offset_i = 0; offset_i < num_offsets; ++offset_i) { |
| 474 // resolution -- it may be twice the resolution if this is a retina display. | 479 new_bounds.set_width(w_start + offsets[offset_i]); |
| 475 new_bounds.set_width(++w_start); | 480 ASSERT_TRUE(ResizeAndWait(new_bounds, "gpu", "gpu", resize_event)); |
| 476 ASSERT_TRUE(ResizeAndWait(new_bounds, "gpu", "gpu", resize_event)); | |
| 477 ASSERT_GT(analyzer_->FindEvents(find_resizes, &events), 0u); | |
| 478 int surface_w_start = events[events.size() - 1]->GetKnownArgAsInt("width"); | |
| 479 | 481 |
| 480 // Increase width by one and compare change in IOSurface width to determine | 482 TraceEventVector resize_events; |
| 481 // the expected pixel scale of the IOSurface compared to the window. | 483 analyzer_->FindEvents(find_resizes, &resize_events); |
| 482 new_bounds.set_width(++w_start); | 484 for (size_t resize_i = 0; resize_i < resize_events.size(); ++resize_i) { |
| 483 ASSERT_TRUE(ResizeAndWait(new_bounds, "gpu", "gpu", resize_event)); | 485 const trace_analyzer::TraceEvent* resize = resize_events[resize_i]; |
| 484 ASSERT_GT(analyzer_->FindEvents(find_resizes, &events), 0u); | 486 // Was a create allowed: |
| 485 int surface_w_end = events[events.size() - 1]->GetKnownArgAsInt("width"); | 487 int old_width = resize->GetKnownArgAsInt("old_width"); |
| 488 int new_width = resize->GetKnownArgAsInt("new_width"); |
| 489 bool expect_create = (old_width/roundup != new_width/roundup || |
| 490 old_width == 0); |
| 491 int expected_creates = expect_create ? 1 : 0; |
| 486 | 492 |
| 487 int surface_pixels_per_window_pixel = surface_w_end - surface_w_start; | 493 // Find the create event inside this resize event (if any). This will |
| 494 // determine if the resize triggered a reallocation of the IOSurface. |
| 495 double begin_time = resize->timestamp; |
| 496 double end_time = begin_time + resize->GetAbsTimeToOtherEvent(); |
| 497 Query find_this_create = find_creates && |
| 498 Query::EventTime() >= Query::Double(begin_time) && |
| 499 Query::EventTime() <= Query::Double(end_time); |
| 500 TraceEventVector create_events; |
| 501 int num_creates = static_cast<int>(analyzer_->FindEvents(find_this_create, |
| 502 &create_events)); |
| 503 EXPECT_EQ(expected_creates, num_creates); |
| 488 | 504 |
| 489 // A few edge cases for a roundup value of 64. The test will resize by these | 505 // For debugging failures, print out the width and height of each resize: |
| 490 // values one at a time and expect exactly one actual CreateIOSurface, because | |
| 491 // the offset range in this offsets array is 64. | |
| 492 int offsets[] = { 1, 2, 30, 63, 64 }; | |
| 493 | |
| 494 int num_creates = 0; | |
| 495 for (int i = 0; i < static_cast<int>(arraysize(offsets)); ++i) { | |
| 496 new_bounds.set_width(w_start + offsets[i]); | |
| 497 ASSERT_TRUE(ResizeAndWait(new_bounds, "gpu", "gpu", resize_event)); | |
| 498 int this_num_creates = analyzer_->FindEvents(find_creates, &events); | |
| 499 num_creates += this_num_creates; | |
| 500 | |
| 501 // For debugging failures, print out the width and height of each resize: | |
| 502 analyzer_->FindEvents(find_resizes, &events); | |
| 503 for (size_t j = 0; j < events.size(); ++j) { | |
| 504 LOG(INFO) << | 506 LOG(INFO) << |
| 505 base::StringPrintf( | 507 base::StringPrintf( |
| 506 "%d (resize offset %d): IOSurface subset %dx%d; Creates %d", | 508 "%d (resize offset %d): IOSurface width %d -> %d; Creates %d " |
| 507 i, offsets[i], events[j]->GetKnownArgAsInt("width"), | 509 "Expected %d", offset_i, offsets[offset_i], |
| 508 events[j]->GetKnownArgAsInt("height"), this_num_creates); | 510 old_width, new_width, num_creates, expected_creates); |
| 509 } | 511 } |
| 510 } | 512 } |
| 511 | |
| 512 EXPECT_EQ(surface_pixels_per_window_pixel, num_creates); | |
| 513 } | 513 } |
| 514 #endif | 514 #endif |
| 515 | 515 |
| 516 } // namespace anonymous | 516 } // namespace anonymous |
| OLD | NEW |