Commit 3a004d56 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Fix DCHECK failure in SaveDesktopSnapshot.

This was causing a crash in interactive_ui_tests on Windows each time a
test timed out.

Based on a comment deep in WebRTC's capture code about a UI message
loop, I had previously taken pains to run a loop when capturing the
screen. Following some changes to base, this leads to a DCHECK failure
when the RunLoop is started. Looking deeper in WebRTC, I don't think
that a UI message loop is needed for the use at hand. In particular, the
comment was with regards to the use of the magnification API. Use of
this API is explicitly disabled by SaveDesktopSnapshot, so the capturer
is fully synchronous and doesn't need a message loop at all.

BUG=756338
R=sky@chromium.org

Change-Id: I92679a213e7bdf8dde03e0ab8e02c36f0fe2804b
Reviewed-on: https://chromium-review.googlesource.com/899349Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534664}
parent 39074f76
...@@ -8,12 +8,10 @@ ...@@ -8,12 +8,10 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -24,16 +22,10 @@ ...@@ -24,16 +22,10 @@
namespace { namespace {
// A worker that captures a single frame from a webrtc::DesktopCapturer and then // A callback that holds the last frame catpured by a webrtc::DesktopCapturer.
// runs a callback when done. class FrameHolder : public webrtc::DesktopCapturer::Callback {
class CaptureWorker : public webrtc::DesktopCapturer::Callback {
public: public:
CaptureWorker(std::unique_ptr<webrtc::DesktopCapturer> capturer, FrameHolder() = default;
base::Closure on_done)
: capturer_(std::move(capturer)), on_done_(std::move(on_done)) {
capturer_->Start(this);
capturer_->CaptureFrame();
}
// Returns the frame that was captured or null in case of failure. // Returns the frame that was captured or null in case of failure.
std::unique_ptr<webrtc::DesktopFrame> TakeFrame() { std::unique_ptr<webrtc::DesktopFrame> TakeFrame() {
...@@ -46,13 +38,10 @@ class CaptureWorker : public webrtc::DesktopCapturer::Callback { ...@@ -46,13 +38,10 @@ class CaptureWorker : public webrtc::DesktopCapturer::Callback {
std::unique_ptr<webrtc::DesktopFrame> frame) override { std::unique_ptr<webrtc::DesktopFrame> frame) override {
if (result == webrtc::DesktopCapturer::Result::SUCCESS) if (result == webrtc::DesktopCapturer::Result::SUCCESS)
frame_ = std::move(frame); frame_ = std::move(frame);
on_done_.Run();
} }
std::unique_ptr<webrtc::DesktopCapturer> capturer_;
base::Closure on_done_;
std::unique_ptr<webrtc::DesktopFrame> frame_; std::unique_ptr<webrtc::DesktopFrame> frame_;
DISALLOW_COPY_AND_ASSIGN(CaptureWorker); DISALLOW_COPY_AND_ASSIGN(FrameHolder);
}; };
// Captures and returns a snapshot of the screen, or an empty bitmap in case of // Captures and returns a snapshot of the screen, or an empty bitmap in case of
...@@ -66,16 +55,10 @@ SkBitmap CaptureScreen() { ...@@ -66,16 +55,10 @@ SkBitmap CaptureScreen() {
webrtc::DesktopCapturer::CreateScreenCapturer(options)); webrtc::DesktopCapturer::CreateScreenCapturer(options));
// Grab a single frame. // Grab a single frame.
std::unique_ptr<webrtc::DesktopFrame> frame; FrameHolder frame_holder;
{ capturer->Start(&frame_holder);
// While webrtc::DesktopCapturer seems to be synchronous, comments in its capturer->CaptureFrame();
// implementation seem to indicate that it may require a UI message loop on std::unique_ptr<webrtc::DesktopFrame> frame(frame_holder.TakeFrame());
// its thread.
base::RunLoop run_loop;
CaptureWorker worker(std::move(capturer), run_loop.QuitClosure());
run_loop.Run();
frame = worker.TakeFrame();
}
if (!frame) if (!frame)
return SkBitmap(); return SkBitmap();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment