Skip to content

Commit

Permalink
Add GrabWindowSnapshotAsync aura tests
Browse files Browse the repository at this point in the history
This adds a version of GrabWindowSnapshotAsync that behaves identically
to GrabWindowSnapshot except with a callback.  The snapshot aura unit
tests are updated to use this new async function instead of the sync
one.

In order to make the snapshot tests work properly, they also now have to
use a real gl context so that real drawing and readback can occur
through the compositor.

BUG=331410, 332167

Review URL: https://codereview.chromium.org/119753007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243700 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
enne@chromium.org committed Jan 8, 2014
1 parent 914d8bf commit c051d5a
Show file tree
Hide file tree
Showing 28 changed files with 268 additions and 88 deletions.
5 changes: 3 additions & 2 deletions chrome/browser/media/desktop_media_list_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id,
gfx::Rect(thumbnail_size_), window_rect.size());

++pending_window_capture_requests_;
ui::GrabWindowSnapshotAsync(
window, window_rect,
ui::GrabWindowSnapshotAndScaleAsync(
window,
window_rect,
scaled_rect.size(),
BrowserThread::GetBlockingPool(),
base::Bind(&DesktopMediaListAsh::OnThumbnailCaptured,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class AccessibilityEventRouterViewsTest
views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
#if defined(USE_AURA)
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);
#endif // USE_AURA
EnableAccessibilityAndListenToFocusNotifications();
}
Expand Down
3 changes: 2 additions & 1 deletion chrome/test/base/browser_with_test_window_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void BrowserWithTestWindowTest::SetUp() {
#elif defined(USE_AURA)
aura_test_helper_.reset(new aura::test::AuraTestHelper(
base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);
#endif // USE_AURA
#if defined(TOOLKIT_VIEWS)
views_delegate_.reset(CreateViewsDelegate());
Expand Down
3 changes: 2 additions & 1 deletion chrome/test/base/view_event_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void ViewEventTestBase::SetUp() {
// the test screen.
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);
context = aura_test_helper_->root_window();
#endif // !USE_ASH && USE_AURA

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class DesktopCaptureDeviceAuraTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
helper_->SetUp();
bool allow_test_contexts = true;
helper_->SetUp(allow_test_contexts);

// We need a window to cover desktop area so that DesktopCaptureDeviceAura
// can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);

browser_context_.reset(new TestBrowserContext);
process_host_ = new MockRenderProcessHost(browser_context_.get());
Expand Down
3 changes: 2 additions & 1 deletion content/public/test/test_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ void RenderViewHostTestHarness::SetUp() {
#if defined(USE_AURA)
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);
#endif

DCHECK(!browser_context_);
Expand Down
1 change: 1 addition & 0 deletions ui/aura/remote_root_window_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds)
}

RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() {
DestroyCompositor();
g_instance = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions ui/aura/root_window_host_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ WindowTreeHostOzone::WindowTreeHostOzone(const gfx::Rect& bounds)

WindowTreeHostOzone::~WindowTreeHostOzone() {
base::MessagePumpOzone::Current()->RemoveDispatcherForRootWindow(0);
DestroyCompositor();
}

bool WindowTreeHostOzone::Dispatch(const base::NativeEvent& ne) {
Expand Down
1 change: 1 addition & 0 deletions ui/aura/root_window_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
}

WindowTreeHostWin::~WindowTreeHostWin() {
DestroyCompositor();
DestroyWindow(hwnd());
}

Expand Down
1 change: 1 addition & 0 deletions ui/aura/root_window_host_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ WindowTreeHostX11::~WindowTreeHostX11() {

UnConfineCursor();

DestroyCompositor();
XDestroyWindow(xdisplay_, xwindow_);
}

Expand Down
3 changes: 2 additions & 1 deletion ui/aura/test/aura_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ void AuraTestBase::SetUp() {
ui::GestureConfiguration::set_fling_velocity_cap(15000.0f);

helper_.reset(new AuraTestHelper(&message_loop_));
helper_->SetUp();
bool allow_test_contexts = true;
helper_->SetUp(allow_test_contexts);
}

void AuraTestBase::TearDown() {
Expand Down
3 changes: 1 addition & 2 deletions ui/aura/test/aura_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ AuraTestHelper::~AuraTestHelper() {
<< "AuraTestHelper::TearDown() never called.";
}

void AuraTestHelper::SetUp() {
void AuraTestHelper::SetUp(bool allow_test_contexts) {
setup_called_ = true;

// The ContextFactory must exist before any Compositors are created.
bool allow_test_contexts = true;
ui::InitializeContextFactoryForTests(allow_test_contexts);

Env::CreateInstance();
Expand Down
2 changes: 1 addition & 1 deletion ui/aura/test/aura_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AuraTestHelper {
~AuraTestHelper();

// Creates and initializes (shows and sizes) the RootWindow for use in tests.
void SetUp();
void SetUp(bool allow_test_contexts);

// Clean up objects that are created for tests. This also deletes the Env
// object.
Expand Down
9 changes: 3 additions & 6 deletions ui/aura/window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ class SimpleRootWindowTransformer : public RootWindowTransformer {
// WindowTreeHost, public:

WindowTreeHost::~WindowTreeHost() {
// TODO(beng): this represents an ordering change. In the old code, the
// compositor was reset before the window hierarchy was destroyed.
// verify that this has no adverse effects.
// Make sure to destroy the compositor before terminating so that state is
// cleared and we don't hit asserts.
compositor_.reset();
DCHECK(!compositor_) << "compositor must be destroyed before root window";
}

void WindowTreeHost::InitHost() {
Expand Down Expand Up @@ -172,6 +167,8 @@ WindowTreeHost::WindowTreeHost()
: delegate_(NULL) {
}

void WindowTreeHost::DestroyCompositor() { compositor_.reset(); }

void WindowTreeHost::CreateCompositor(
gfx::AcceleratedWidget accelerated_widget) {
compositor_.reset(new ui::Compositor(GetAcceleratedWidget()));
Expand Down
1 change: 1 addition & 0 deletions ui/aura/window_tree_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class AURA_EXPORT WindowTreeHost {
friend class TestScreen; // TODO(beng): see if we can remove/consolidate.

WindowTreeHost();
void DestroyCompositor();

void CreateCompositor(gfx::AcceleratedWidget accelerated_widget);

Expand Down
3 changes: 2 additions & 1 deletion ui/keyboard/keyboard_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class KeyboardControllerTest : public testing::Test {

virtual void SetUp() OVERRIDE {
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();
bool allow_test_contexts = true;
aura_test_helper_->SetUp(allow_test_contexts);
ui::SetUpInputMethodFactoryForTesting();
focus_controller_.reset(new TestFocusController(root_window()));
proxy_ = new TestKeyboardControllerProxy();
Expand Down
13 changes: 9 additions & 4 deletions ui/snapshot/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ui {
// intended to be used for debugging purposes where no BrowserProcess instance
// is available (ie. tests). This function is synchronous, so it should NOT be
// used in a result of user action. Use asynchronous GrabWindowSnapshotAsync()
// instead.
// instead on supported platforms.
SNAPSHOT_EXPORT bool GrabWindowSnapshot(
gfx::NativeWindow window,
std::vector<unsigned char>* png_representation,
Expand All @@ -39,16 +39,21 @@ SNAPSHOT_EXPORT bool GrabViewSnapshot(
std::vector<unsigned char>* png_representation,
const gfx::Rect& snapshot_bounds);

// GrabWindowSnapshotAsync() copies snapshot of |source_rect| from window and
// scales it to |target_size| asynchronously.
typedef base::Callback<void(const gfx::Image& snapshot)>
GrabWindowSnapshotAsyncCallback;
SNAPSHOT_EXPORT void GrabWindowSnapshotAsync(
// GrabWindowSnapshotAndScaleAsync() copies snapshot of |source_rect| from
// window and scales it to |target_size| asynchronously.
SNAPSHOT_EXPORT void GrabWindowSnapshotAndScaleAsync(
gfx::NativeWindow window,
const gfx::Rect& source_rect,
const gfx::Size& target_size,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncCallback& callback);
SNAPSHOT_EXPORT void GrabWindowSnapshotAsync(
gfx::NativeWindow window,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncCallback& callback);

} // namespace ui

Expand Down
10 changes: 9 additions & 1 deletion ui/snapshot/snapshot_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool GrabWindowSnapshot(gfx::NativeWindow window,
scaled_bounds.height(), png_representation);
}

SNAPSHOT_EXPORT void GrabWindowSnapshotAsync(
void GrabWindowSnapshotAndScaleAsync(
gfx::NativeWindow window,
const gfx::Rect& snapshot_bounds,
const gfx::Size& target_size,
Expand All @@ -42,4 +42,12 @@ SNAPSHOT_EXPORT void GrabWindowSnapshotAsync(
NOTIMPLEMENTED();
}

void GrabWindowSnapshotAsync(
gfx::NativeWindow window,
const gfx::Rect& source_rect,
scoped_refptr<base::TaskRunner> background_task_runner,
const GrabWindowSnapshotAsyncCallback& callback) {
NOTIMPLEMENTED();
}

} // namespace ui
Loading

0 comments on commit c051d5a

Please sign in to comment.