Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/test/gpu/gpu_pixel_browsertest.cc

Issue 5698009: Wait for the GPU info to be collected. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gpu_process_host_ui_shim.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 any 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_host_shim_(gpu_host_shim),
88 gpu_info_collected_(false) {
89 gpu_host_shim_->set_gpu_info_collected_callback(
90 NewCallback(this, &GPUInfoCollectedObserver::OnGpuInfoCollected));
91 }
92
93 void OnGpuInfoCollected() {
94 gpu_info_collected_ = true;
95 gpu_host_shim_->set_gpu_info_collected_callback(NULL);
96 MessageLoopForUI::current()->Quit();
97 }
98
99 bool gpu_info_collected() { return gpu_info_collected_; }
100
101 private:
102 GpuProcessHostUIShim* gpu_host_shim_;
103 bool gpu_info_collected_;
104 };
105
106 // Collects info about the GPU. Iff the info is collected, |client_info| will be
107 // set and true will be returned. This info may be partial or complete. This
108 // will return false if we are running in a virtualized environment.
109 bool CollectGPUInfo(GPUInfo* client_info) {
110 CHECK(client_info);
111 GpuProcessHostUIShim* gpu_host_shim = GpuProcessHostUIShim::GetInstance();
112 if (!gpu_host_shim)
113 return false;
114 GPUInfo info = gpu_host_shim->gpu_info();
115 if (info.progress() == GPUInfo::kUninitialized) {
116 GPUInfoCollectedObserver observer(gpu_host_shim);
117 gpu_host_shim->CollectGraphicsInfoAsynchronously();
118 ui_test_utils::RunMessageLoop();
119 if (!observer.gpu_info_collected())
120 return false;
121 info = gpu_host_shim->gpu_info();
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/gpu_process_host_ui_shim.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698