OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "content/browser/gpu/compositor_util.h" | 9 #include "content/browser/gpu/compositor_util.h" |
10 #include "content/browser/gpu/gpu_data_manager_impl.h" | 10 #include "content/browser/gpu/gpu_data_manager_impl.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Common base class for browser tests. This is subclassed twice: Once to test | 54 // Common base class for browser tests. This is subclassed twice: Once to test |
55 // the browser in forced-compositing mode, and once to test with compositing | 55 // the browser in forced-compositing mode, and once to test with compositing |
56 // mode disabled. | 56 // mode disabled. |
57 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { | 57 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { |
58 public: | 58 public: |
59 RenderWidgetHostViewBrowserTest() | 59 RenderWidgetHostViewBrowserTest() |
60 : frame_size_(400, 300), | 60 : frame_size_(400, 300), |
61 callback_invoke_count_(0), | 61 callback_invoke_count_(0), |
62 frames_captured_(0) {} | 62 frames_captured_(0) {} |
63 | 63 |
64 virtual void SetUpOnMainThread() override { | 64 void SetUpOnMainThread() override { |
65 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); | 65 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); |
66 } | 66 } |
67 | 67 |
68 // Attempts to set up the source surface. Returns false if unsupported on the | 68 // Attempts to set up the source surface. Returns false if unsupported on the |
69 // current platform. | 69 // current platform. |
70 virtual bool SetUpSourceSurface(const char* wait_message) = 0; | 70 virtual bool SetUpSourceSurface(const char* wait_message) = 0; |
71 | 71 |
72 int callback_invoke_count() const { | 72 int callback_invoke_count() const { |
73 return callback_invoke_count_; | 73 return callback_invoke_count_; |
74 } | 74 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (compositing_mode_ == SOFTWARE_COMPOSITING) | 211 if (compositing_mode_ == SOFTWARE_COMPOSITING) |
212 UseSoftwareCompositing(); | 212 UseSoftwareCompositing(); |
213 RenderWidgetHostViewBrowserTest::SetUp(); | 213 RenderWidgetHostViewBrowserTest::SetUp(); |
214 } | 214 } |
215 | 215 |
216 virtual GURL TestUrl() { | 216 virtual GURL TestUrl() { |
217 return net::FilePathToFileURL( | 217 return net::FilePathToFileURL( |
218 test_dir().AppendASCII("rwhv_compositing_animation.html")); | 218 test_dir().AppendASCII("rwhv_compositing_animation.html")); |
219 } | 219 } |
220 | 220 |
221 virtual bool SetUpSourceSurface(const char* wait_message) override { | 221 bool SetUpSourceSurface(const char* wait_message) override { |
222 content::DOMMessageQueue message_queue; | 222 content::DOMMessageQueue message_queue; |
223 NavigateToURL(shell(), TestUrl()); | 223 NavigateToURL(shell(), TestUrl()); |
224 if (wait_message != NULL) { | 224 if (wait_message != NULL) { |
225 std::string result(wait_message); | 225 std::string result(wait_message); |
226 if (!message_queue.WaitForMessage(&result)) { | 226 if (!message_queue.WaitForMessage(&result)) { |
227 EXPECT_TRUE(false) << "WaitForMessage " << result << " failed."; | 227 EXPECT_TRUE(false) << "WaitForMessage " << result << " failed."; |
228 return false; | 228 return false; |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 // A frame might not be available yet. So, wait for it. | 232 // A frame might not be available yet. So, wait for it. |
233 WaitForCopySourceReady(); | 233 WaitForCopySourceReady(); |
234 return true; | 234 return true; |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 const CompositingMode compositing_mode_; | 238 const CompositingMode compositing_mode_; |
239 | 239 |
240 DISALLOW_COPY_AND_ASSIGN(CompositingRenderWidgetHostViewBrowserTest); | 240 DISALLOW_COPY_AND_ASSIGN(CompositingRenderWidgetHostViewBrowserTest); |
241 }; | 241 }; |
242 | 242 |
243 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { | 243 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
244 public: | 244 public: |
245 FakeFrameSubscriber( | 245 FakeFrameSubscriber( |
246 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) | 246 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback) |
247 : callback_(callback) { | 247 : callback_(callback) { |
248 } | 248 } |
249 | 249 |
250 virtual bool ShouldCaptureFrame(const gfx::Rect& damage_rect, | 250 bool ShouldCaptureFrame(const gfx::Rect& damage_rect, |
251 base::TimeTicks present_time, | 251 base::TimeTicks present_time, |
252 scoped_refptr<media::VideoFrame>* storage, | 252 scoped_refptr<media::VideoFrame>* storage, |
253 DeliverFrameCallback* callback) override { | 253 DeliverFrameCallback* callback) override { |
254 // Only allow one frame capture to be made. Otherwise, the compositor could | 254 // Only allow one frame capture to be made. Otherwise, the compositor could |
255 // start multiple captures, unbounded, and eventually its own limiter logic | 255 // start multiple captures, unbounded, and eventually its own limiter logic |
256 // will begin invoking |callback| with a |false| result. This flakes out | 256 // will begin invoking |callback| with a |false| result. This flakes out |
257 // the unit tests, since they receive a "failed" callback before the later | 257 // the unit tests, since they receive a "failed" callback before the later |
258 // "success" callbacks. | 258 // "success" callbacks. |
259 if (callback_.is_null()) | 259 if (callback_.is_null()) |
260 return false; | 260 return false; |
261 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); | 261 *storage = media::VideoFrame::CreateBlackFrame(gfx::Size(100, 100)); |
262 *callback = callback_; | 262 *callback = callback_; |
263 callback_.Reset(); | 263 callback_.Reset(); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 void SetExpectedCopyFromCompositingSurfaceResult(bool result, | 499 void SetExpectedCopyFromCompositingSurfaceResult(bool result, |
500 const SkBitmap& bitmap) { | 500 const SkBitmap& bitmap) { |
501 expected_copy_from_compositing_surface_result_ = result; | 501 expected_copy_from_compositing_surface_result_ = result; |
502 expected_copy_from_compositing_surface_bitmap_ = bitmap; | 502 expected_copy_from_compositing_surface_bitmap_ = bitmap; |
503 } | 503 } |
504 | 504 |
505 void SetAllowableError(int amount) { allowable_error_ = amount; } | 505 void SetAllowableError(int amount) { allowable_error_ = amount; } |
506 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } | 506 void SetExcludeRect(gfx::Rect exclude) { exclude_rect_ = exclude; } |
507 | 507 |
508 virtual GURL TestUrl() override { | 508 GURL TestUrl() override { return GURL(test_url_); } |
509 return GURL(test_url_); | |
510 } | |
511 | 509 |
512 void SetTestUrl(std::string url) { test_url_ = url; } | 510 void SetTestUrl(std::string url) { test_url_ = url; } |
513 | 511 |
514 // Loads a page two boxes side-by-side, each half the width of | 512 // Loads a page two boxes side-by-side, each half the width of |
515 // |html_rect_size|, and with different background colors. The test then | 513 // |html_rect_size|, and with different background colors. The test then |
516 // copies from |copy_rect| region of the page into a bitmap of size | 514 // copies from |copy_rect| region of the page into a bitmap of size |
517 // |output_size|, and examines the resulting bitmap/VideoFrame. | 515 // |output_size|, and examines the resulting bitmap/VideoFrame. |
518 // Note that |output_size| may not have the same size as |copy_rect| (e.g. | 516 // Note that |output_size| may not have the same size as |copy_rect| (e.g. |
519 // when the output is scaled). | 517 // when the output is scaled). |
520 void PerformTestWithLeftRightRects(const gfx::Size& html_rect_size, | 518 void PerformTestWithLeftRightRects(const gfx::Size& html_rect_size, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 output_size, | 745 output_size, |
748 video_frame); | 746 video_frame); |
749 } | 747 } |
750 | 748 |
751 class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI | 749 class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI |
752 : public CompositingRenderWidgetHostViewBrowserTestTabCapture { | 750 : public CompositingRenderWidgetHostViewBrowserTestTabCapture { |
753 public: | 751 public: |
754 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {} | 752 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {} |
755 | 753 |
756 protected: | 754 protected: |
757 virtual void SetUpCommandLine(base::CommandLine* cmd) override { | 755 void SetUpCommandLine(base::CommandLine* cmd) override { |
758 CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); | 756 CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); |
759 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, | 757 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
760 base::StringPrintf("%f", scale())); | 758 base::StringPrintf("%f", scale())); |
761 } | 759 } |
762 | 760 |
763 virtual bool ShouldContinueAfterTestURLLoad() override { | 761 bool ShouldContinueAfterTestURLLoad() override { |
764 // Short-circuit a pass for platforms where setting up high-DPI fails. | 762 // Short-circuit a pass for platforms where setting up high-DPI fails. |
765 const float actual_scale_factor = | 763 const float actual_scale_factor = |
766 GetScaleFactorForView(GetRenderWidgetHostView()); | 764 GetScaleFactorForView(GetRenderWidgetHostView()); |
767 if (actual_scale_factor != scale()) { | 765 if (actual_scale_factor != scale()) { |
768 LOG(WARNING) << "Blindly passing this test; unable to force device scale " | 766 LOG(WARNING) << "Blindly passing this test; unable to force device scale " |
769 << "factor: seems to be " << actual_scale_factor | 767 << "factor: seems to be " << actual_scale_factor |
770 << " but expected " << scale(); | 768 << " but expected " << scale(); |
771 return false; | 769 return false; |
772 } | 770 } |
773 VLOG(1) << ("Successfully forced device scale factor. Moving forward with " | 771 VLOG(1) << ("Successfully forced device scale factor. Moving forward with " |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 906 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
909 INSTANTIATE_TEST_CASE_P( | 907 INSTANTIATE_TEST_CASE_P( |
910 GLAndSoftwareCompositing, | 908 GLAndSoftwareCompositing, |
911 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 909 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
912 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 910 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
913 | 911 |
914 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 912 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
915 | 913 |
916 } // namespace | 914 } // namespace |
917 } // namespace content | 915 } // namespace content |
OLD | NEW |