| 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 virtual 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 SOFTWARE_COMPOSITING, | 200 SOFTWARE_COMPOSITING, |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 class CompositingRenderWidgetHostViewBrowserTest | 203 class CompositingRenderWidgetHostViewBrowserTest |
| 204 : public RenderWidgetHostViewBrowserTest, | 204 : public RenderWidgetHostViewBrowserTest, |
| 205 public testing::WithParamInterface<CompositingMode> { | 205 public testing::WithParamInterface<CompositingMode> { |
| 206 public: | 206 public: |
| 207 explicit CompositingRenderWidgetHostViewBrowserTest() | 207 explicit CompositingRenderWidgetHostViewBrowserTest() |
| 208 : compositing_mode_(GetParam()) {} | 208 : compositing_mode_(GetParam()) {} |
| 209 | 209 |
| 210 virtual void SetUp() OVERRIDE { | 210 virtual void SetUp() override { |
| 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 virtual 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 virtual 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 401 } |
| 402 | 402 |
| 403 class CompositingRenderWidgetHostViewBrowserTestTabCapture | 403 class CompositingRenderWidgetHostViewBrowserTestTabCapture |
| 404 : public CompositingRenderWidgetHostViewBrowserTest { | 404 : public CompositingRenderWidgetHostViewBrowserTest { |
| 405 public: | 405 public: |
| 406 CompositingRenderWidgetHostViewBrowserTestTabCapture() | 406 CompositingRenderWidgetHostViewBrowserTestTabCapture() |
| 407 : expected_copy_from_compositing_surface_result_(false), | 407 : expected_copy_from_compositing_surface_result_(false), |
| 408 allowable_error_(0), | 408 allowable_error_(0), |
| 409 test_url_("data:text/html,<!doctype html>") {} | 409 test_url_("data:text/html,<!doctype html>") {} |
| 410 | 410 |
| 411 virtual void SetUp() OVERRIDE { | 411 virtual void SetUp() override { |
| 412 EnablePixelOutput(); | 412 EnablePixelOutput(); |
| 413 CompositingRenderWidgetHostViewBrowserTest::SetUp(); | 413 CompositingRenderWidgetHostViewBrowserTest::SetUp(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, | 416 void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, |
| 417 bool result, | 417 bool result, |
| 418 const SkBitmap& bitmap) { | 418 const SkBitmap& bitmap) { |
| 419 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); | 419 EXPECT_EQ(expected_copy_from_compositing_surface_result_, result); |
| 420 if (!result) { | 420 if (!result) { |
| 421 quit_callback.Run(); | 421 quit_callback.Run(); |
| (...skipping 76 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 virtual GURL TestUrl() override { |
| 509 return GURL(test_url_); | 509 return GURL(test_url_); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void SetTestUrl(std::string url) { test_url_ = url; } | 512 void SetTestUrl(std::string url) { test_url_ = url; } |
| 513 | 513 |
| 514 // Loads a page two boxes side-by-side, each half the width of | 514 // 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 | 515 // |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 | 516 // copies from |copy_rect| region of the page into a bitmap of size |
| 517 // |output_size|, and examines the resulting bitmap/VideoFrame. | 517 // |output_size|, and examines the resulting bitmap/VideoFrame. |
| 518 // Note that |output_size| may not have the same size as |copy_rect| (e.g. | 518 // Note that |output_size| may not have the same size as |copy_rect| (e.g. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 output_size, | 747 output_size, |
| 748 video_frame); | 748 video_frame); |
| 749 } | 749 } |
| 750 | 750 |
| 751 class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI | 751 class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI |
| 752 : public CompositingRenderWidgetHostViewBrowserTestTabCapture { | 752 : public CompositingRenderWidgetHostViewBrowserTestTabCapture { |
| 753 public: | 753 public: |
| 754 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {} | 754 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {} |
| 755 | 755 |
| 756 protected: | 756 protected: |
| 757 virtual void SetUpCommandLine(base::CommandLine* cmd) OVERRIDE { | 757 virtual void SetUpCommandLine(base::CommandLine* cmd) override { |
| 758 CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); | 758 CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd); |
| 759 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, | 759 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, |
| 760 base::StringPrintf("%f", scale())); | 760 base::StringPrintf("%f", scale())); |
| 761 } | 761 } |
| 762 | 762 |
| 763 virtual bool ShouldContinueAfterTestURLLoad() OVERRIDE { | 763 virtual bool ShouldContinueAfterTestURLLoad() override { |
| 764 // Short-circuit a pass for platforms where setting up high-DPI fails. | 764 // Short-circuit a pass for platforms where setting up high-DPI fails. |
| 765 const float actual_scale_factor = | 765 const float actual_scale_factor = |
| 766 GetScaleFactorForView(GetRenderWidgetHostView()); | 766 GetScaleFactorForView(GetRenderWidgetHostView()); |
| 767 if (actual_scale_factor != scale()) { | 767 if (actual_scale_factor != scale()) { |
| 768 LOG(WARNING) << "Blindly passing this test; unable to force device scale " | 768 LOG(WARNING) << "Blindly passing this test; unable to force device scale " |
| 769 << "factor: seems to be " << actual_scale_factor | 769 << "factor: seems to be " << actual_scale_factor |
| 770 << " but expected " << scale(); | 770 << " but expected " << scale(); |
| 771 return false; | 771 return false; |
| 772 } | 772 } |
| 773 VLOG(1) << ("Successfully forced device scale factor. Moving forward with " | 773 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)); | 908 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
| 909 INSTANTIATE_TEST_CASE_P( | 909 INSTANTIATE_TEST_CASE_P( |
| 910 GLAndSoftwareCompositing, | 910 GLAndSoftwareCompositing, |
| 911 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, | 911 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI, |
| 912 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); | 912 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING)); |
| 913 | 913 |
| 914 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 914 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 915 | 915 |
| 916 } // namespace | 916 } // namespace |
| 917 } // namespace content | 917 } // namespace content |
| OLD | NEW |