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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_browsertest.cc

Issue 12220024: Fix CopyFromBackingStore giving back empty SkBitmaps on mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ifdef Created 7 years, 10 months 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 | « content/browser/renderer_host/compositing_iosurface_mac.mm ('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) 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/path_service.h" 6 #include "base/path_service.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/port/browser/render_widget_host_view_port.h" 8 #include "content/port/browser/render_widget_host_view_port.h"
9 #include "content/public/browser/render_view_host.h" 9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/content_paths.h" 11 #include "content/public/common/content_paths.h"
12 #include "content/shell/shell.h" 12 #include "content/shell/shell.h"
13 #include "content/test/content_browser_test.h" 13 #include "content/test/content_browser_test.h"
14 #include "content/test/content_browser_test_utils.h" 14 #include "content/test/content_browser_test_utils.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "skia/ext/platform_canvas.h" 16 #include "skia/ext/platform_canvas.h"
17 #include "ui/compositor/compositor_setup.h" 17 #include "ui/compositor/compositor_setup.h"
18 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
19 #include "ui/surface/io_surface_support_mac.h" 19 #include "ui/surface/io_surface_support_mac.h"
20 #endif 20 #endif
21 21
22 namespace content { 22 namespace content {
23 23
24 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { 24 class RenderWidgetHostViewBrowserTest : public ContentBrowserTest {
25 public: 25 public:
26 RenderWidgetHostViewBrowserTest() : finish_called_(false) {} 26 RenderWidgetHostViewBrowserTest() : finish_called_(false), size_(400, 300) {}
27 27
28 virtual void SetUpInProcessBrowserTestFixture() { 28 virtual void SetUpInProcessBrowserTestFixture() {
29 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_)); 29 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_));
30 } 30 }
31 31
32 virtual void SetUpCommandLine(CommandLine* command_line) { 32 virtual void SetUpCommandLine(CommandLine* command_line) {
33 ui::DisableTestCompositor(); 33 ui::DisableTestCompositor();
34 } 34 }
35 35
36 void FinishCopyFromBackingStore(bool expected_result, bool result, 36 #if defined(OS_MACOSX)
37 void SetupCompositingSurface() {
38 NavigateToURL(shell(), net::FilePathToFileURL(
39 test_dir_.AppendASCII("rwhv_compositing_static.html")));
40
41 RenderViewHost* const rwh =
42 shell()->web_contents()->GetRenderViewHost();
43 RenderWidgetHostViewPort* rwhvp =
44 static_cast<RenderWidgetHostViewPort*>(rwh->GetView());
45
46 // Wait until an IoSurface is created by repeatedly resizing the window.
47 // TODO(justinlin): Find a better way to force an IoSurface when possible.
48 int increment = 0;
49 while (!rwhvp->HasAcceleratedSurface(gfx::Size())) {
50 base::RunLoop run_loop;
51 SetWindowBounds(shell()->window(), gfx::Rect(size_.width() + increment,
52 size_.height()));
53 // Wait for any ViewHostMsg_CompositorSurfaceBuffersSwapped message.
54 run_loop.RunUntilIdle();
55 increment++;
56 ASSERT_LT(increment, 50);
57 }
58 }
59 #endif
60
61 void FinishCopyFromBackingStore(bool expected_result,
62 const base::Callback<void ()> quit_closure,
63 bool result,
37 const SkBitmap& bitmap) { 64 const SkBitmap& bitmap) {
65 quit_closure.Run();
38 ASSERT_EQ(expected_result, result); 66 ASSERT_EQ(expected_result, result);
67 if (expected_result)
68 ASSERT_FALSE(bitmap.empty());
39 finish_called_ = true; 69 finish_called_ = true;
40 } 70 }
41 71
42 protected: 72 protected:
43 FilePath test_dir_; 73 FilePath test_dir_;
44 bool finish_called_; 74 bool finish_called_;
75 gfx::Size size_;
45 }; 76 };
46 77
47 #if defined(OS_MACOSX) 78 #if defined(OS_MACOSX)
48 // Tests that the callback passed to CopyFromBackingStore is always called, even 79 // Tests that the callback passed to CopyFromBackingStore is always called, even
49 // when the RenderWidgetHost is deleting in the middle of an async copy. 80 // when the RenderWidgetHost is deleting in the middle of an async copy.
50 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest, 81 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest,
51 MacAsyncCopyFromBackingStoreCallbackTest) { 82 MacAsyncCopyFromBackingStoreCallbackTest) {
52 if (!IOSurfaceSupport::Initialize()) 83 if (!IOSurfaceSupport::Initialize())
53 return; 84 return;
54 85
55 NavigateToURL(shell(), net::FilePathToFileURL( 86 SetupCompositingSurface();
56 test_dir_.AppendASCII("rwhv_compositing_static.html"))); 87
88 base::RunLoop run_loop;
57 89
58 RenderViewHost* const rwh = 90 RenderViewHost* const rwh =
59 shell()->web_contents()->GetRenderViewHost(); 91 shell()->web_contents()->GetRenderViewHost();
60 RenderWidgetHostViewPort* rwhvp = 92 RenderWidgetHostViewPort* rwhvp =
61 static_cast<RenderWidgetHostViewPort*>(rwh->GetView()); 93 static_cast<RenderWidgetHostViewPort*>(rwh->GetView());
62 94
63 // Wait until an IoSurface is created by repeatedly resizing the window.
64 // TODO(justinlin): Find a better way to force an IoSurface when possible.
65 gfx::Size size(400, 300);
66 int increment = 0;
67 while (!rwhvp->HasAcceleratedSurface(gfx::Size())) {
68 base::RunLoop run_loop;
69 SetWindowBounds(shell()->window(), gfx::Rect(size.width() + increment,
70 size.height()));
71 // Wait for any ViewHostMsg_CompositorSurfaceBuffersSwapped message to post.
72 run_loop.RunUntilIdle();
73 increment++;
74 ASSERT_LT(increment, 50);
75 }
76
77 rwh->CopyFromBackingStore( 95 rwh->CopyFromBackingStore(
78 gfx::Rect(), 96 gfx::Rect(),
79 size, 97 size_,
80 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore, 98 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore,
81 base::Unretained(this), false)); 99 base::Unretained(this), false, run_loop.QuitClosure()));
82 100
83 // Delete the surface before the callback is run. This is synchronous until 101 // Delete the surface before the callback is run. This is synchronous until
84 // we get to the copy_timer_, so we will always end up in the destructor 102 // we get to the copy_timer_, so we will always end up in the destructor
85 // before the timer fires. 103 // before the timer fires.
86 rwhvp->AcceleratedSurfaceRelease(); 104 rwhvp->AcceleratedSurfaceRelease();
87 base::RunLoop run_loop; 105 run_loop.Run();
88 run_loop.RunUntilIdle();
89 106
90 ASSERT_TRUE(finish_called_); 107 ASSERT_TRUE(finish_called_);
91 } 108 }
109
110 // TODO(justinlin): Enable this test for other platforms.
111 IN_PROC_BROWSER_TEST_F(RenderWidgetHostViewBrowserTest,
112 MacAsyncCopyFromBackingStoreTest) {
113 if (!IOSurfaceSupport::Initialize())
114 return;
115
116 SetupCompositingSurface();
117
118 base::RunLoop run_loop;
119 shell()->web_contents()->GetRenderViewHost()->CopyFromBackingStore(
120 gfx::Rect(),
121 size_,
122 base::Bind(&RenderWidgetHostViewBrowserTest::FinishCopyFromBackingStore,
123 base::Unretained(this), true, run_loop.QuitClosure()));
124 run_loop.Run();
125
126 ASSERT_TRUE(finish_called_);
127 }
92 #endif 128 #endif
93 129
94 } // namespace content 130 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositing_iosurface_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698