Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "app/app_switches.h" | 8 #include "app/app_switches.h" |
| 9 #include "app/gfx/gl/gl_implementation.h" | 9 #include "app/gfx/gl/gl_implementation.h" |
| 10 #include "base/callback.h" | |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/gpu_process_host.h" | 19 #include "chrome/browser/gpu_process_host.h" |
| 19 #include "chrome/browser/gpu_process_host_ui_shim.h" | 20 #include "chrome/browser/gpu_process_host_ui_shim.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 gfx::Point correction(desired_size.width() - container_rect.size().width(), | 72 gfx::Point correction(desired_size.width() - container_rect.size().width(), |
| 72 desired_size.height() - container_rect.size().height()); | 73 desired_size.height() - container_rect.size().height()); |
| 73 | 74 |
| 74 gfx::Rect window_rect = browser->window()->GetRestoredBounds(); | 75 gfx::Rect window_rect = browser->window()->GetRestoredBounds(); |
| 75 gfx::Size new_size = window_rect.size(); | 76 gfx::Size new_size = window_rect.size(); |
| 76 new_size.Enlarge(correction.x(), correction.y()); | 77 new_size.Enlarge(correction.x(), correction.y()); |
| 77 window_rect.set_size(new_size); | 78 window_rect.set_size(new_size); |
| 78 browser->window()->SetBounds(window_rect); | 79 browser->window()->SetBounds(window_rect); |
| 79 } | 80 } |
| 80 | 81 |
| 82 // Observes when the GPU info has been collected and quits the current message | |
| 83 // loop. | |
| 84 class GPUInfoCollectedObserver { | |
| 85 public: | |
| 86 explicit GPUInfoCollectedObserver(GpuProcessHostUIShim* gpu_host_shim) | |
| 87 : gpu_info_collected_(false) { | |
| 88 gpu_host_shim->set_gpu_info_collected_callback( | |
| 89 NewCallback(this, &GPUInfoCollectedObserver::OnGpuInfoCollected)); | |
| 90 } | |
| 91 | |
| 92 void OnGpuInfoCollected() { | |
| 93 gpu_info_collected_ = true; | |
| 94 MessageLoopForUI::current()->Quit(); | |
| 95 } | |
| 96 | |
| 97 bool gpu_info_collected() { return gpu_info_collected_; } | |
| 98 | |
| 99 private: | |
| 100 bool gpu_info_collected_; | |
| 101 }; | |
| 102 | |
| 103 // Collects info about the GPU. Iff the info is collected and it is valid, | |
| 104 // |client_info| will be set and true will be returned. This will return false | |
| 105 // if we are running in a virtualized environment. | |
| 106 bool CollectGPUInfo(GPUInfo* client_info) { | |
| 107 CHECK(client_info); | |
| 108 GpuProcessHostUIShim* gpu_host_shim = GpuProcessHostUIShim::GetInstance(); | |
| 109 if (!gpu_host_shim) | |
| 110 return false; | |
| 111 GPUInfo info = gpu_host_shim->gpu_info(); | |
| 112 if (info.progress() != GPUInfo::kComplete) { | |
|
apatrick_chromium
2010/12/13 21:16:35
If you only need the device and vendor id, this sh
kkania
2010/12/13 22:12:57
Done.
| |
| 113 GPUInfoCollectedObserver observer(gpu_host_shim); | |
| 114 gpu_host_shim->CollectGraphicsInfoAsynchronously(); | |
| 115 ui_test_utils::RunMessageLoop(); | |
| 116 if (!observer.gpu_info_collected()) | |
| 117 return false; | |
| 118 info = gpu_host_shim->gpu_info(); | |
| 119 } | |
| 120 if (info.vendor_id() == 0) { | |
| 121 return false; | |
| 122 } | |
| 123 *client_info = info; | |
| 124 return true; | |
| 125 } | |
| 126 | |
| 81 } // namespace | 127 } // namespace |
| 82 | 128 |
| 83 // Test fixture for GPU image comparison tests. | 129 // Test fixture for GPU image comparison tests. |
| 84 // TODO(kkania): Document how to add to/modify these tests. | 130 // TODO(kkania): Document how to add to/modify these tests. |
| 85 class GpuPixelBrowserTest : public InProcessBrowserTest { | 131 class GpuPixelBrowserTest : public InProcessBrowserTest { |
| 86 public: | 132 public: |
| 87 GpuPixelBrowserTest() {} | 133 GpuPixelBrowserTest() {} |
| 88 | 134 |
| 89 virtual void SetUpCommandLine(CommandLine* command_line) { | 135 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 90 // This enables DOM automation for tab contents. | 136 // This enables DOM automation for tab contents. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
| 150 const char* os_label = "win"; | 196 const char* os_label = "win"; |
| 151 #elif defined(OS_MACOSX) | 197 #elif defined(OS_MACOSX) |
| 152 const char* os_label = "mac"; | 198 const char* os_label = "mac"; |
| 153 #elif defined(OS_LINUX) | 199 #elif defined(OS_LINUX) |
| 154 const char* os_label = "linux"; | 200 const char* os_label = "linux"; |
| 155 #else | 201 #else |
| 156 #error "Not implemented for this platform" | 202 #error "Not implemented for this platform" |
| 157 #endif | 203 #endif |
| 158 if (using_gpu_) { | 204 if (using_gpu_) { |
| 159 const GPUInfo& info = GpuProcessHostUIShim::GetInstance()->gpu_info(); | 205 GPUInfo info; |
| 160 if (info.progress() != GPUInfo::kComplete) { | 206 if (!CollectGPUInfo(&info)) { |
| 161 LOG(ERROR) << "Could not get gpu info"; | 207 LOG(ERROR) << "Could not get gpu info"; |
| 162 return false; | 208 return false; |
| 163 } | 209 } |
| 164 img_name = StringPrintf("%s_%s_%x-%x.png", | 210 img_name = base::StringPrintf("%s_%s_%04x-%04x.png", |
| 165 img_name.c_str(), os_label, info.vendor_id(), info.device_id()); | 211 img_name.c_str(), os_label, info.vendor_id(), info.device_id()); |
| 166 } else { | 212 } else { |
| 167 img_name = StringPrintf("%s_%s_mesa.png", img_name.c_str(), os_label); | 213 img_name = base::StringPrintf("%s_%s_mesa.png", |
| 214 img_name.c_str(), os_label); | |
| 168 } | 215 } |
| 169 | 216 |
| 170 // Read the reference image and verify the images' dimensions are equal. | 217 // Read the reference image and verify the images' dimensions are equal. |
| 171 FilePath ref_img_path = reference_img_dir_.AppendASCII(img_name); | 218 FilePath ref_img_path = reference_img_dir_.AppendASCII(img_name); |
| 172 SkBitmap ref_bmp; | 219 SkBitmap ref_bmp; |
| 173 bool should_compare = true; | 220 bool should_compare = true; |
| 174 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { | 221 if (!ReadPNGFile(ref_img_path, &ref_bmp)) { |
| 175 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); | 222 LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); |
| 176 should_compare = false; | 223 should_compare = false; |
| 177 } | 224 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); | 313 ASSERT_TRUE(message_queue.WaitForMessage(NULL)); |
| 267 | 314 |
| 268 SkBitmap bitmap; | 315 SkBitmap bitmap; |
| 269 gfx::Size container_size(500, 500); | 316 gfx::Size container_size(500, 500); |
| 270 ResizeTabContainer(browser(), container_size); | 317 ResizeTabContainer(browser(), container_size); |
| 271 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( | 318 ASSERT_TRUE(ui_test_utils::TakeRenderWidgetSnapshot( |
| 272 browser()->GetSelectedTabContents()->render_view_host(), | 319 browser()->GetSelectedTabContents()->render_view_host(), |
| 273 container_size, &bitmap)); | 320 container_size, &bitmap)); |
| 274 ASSERT_TRUE(CompareImages(bitmap, "")); | 321 ASSERT_TRUE(CompareImages(bitmap, "")); |
| 275 } | 322 } |
| OLD | NEW |