Commit 04acdc0b authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Allow selective reentrancy of ScopedOnBeginFrame

Observers can be added while calling OnBeginFrame on existing observers.
In these cases, we reentrantly take ScopedOnBeginFrame.

There was a DCHECK preventing this, but given that this is supported
(we create a the ObserverList with iteration policy EXISTING_ONLY to
account for this), we should handle this case.

This allows for reentrant scopes in certain cases, making them a no-op.

Change-Id: Id5efacf89250fb8d93fe0f6bcb2ce626c1831b2b
Reviewed-on: https://chromium-review.googlesource.com/c/1354136Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613234}
parent 7fc92bec
......@@ -67,11 +67,13 @@ class WindowAndroid::WindowBeginFrameSource : public viz::BeginFrameSource {
class WindowAndroid::ScopedOnBeginFrame {
public:
explicit ScopedOnBeginFrame(WindowAndroid::WindowBeginFrameSource* bfs);
explicit ScopedOnBeginFrame(WindowAndroid::WindowBeginFrameSource* bfs,
bool allow_reentrancy);
~ScopedOnBeginFrame();
private:
WindowAndroid::WindowBeginFrameSource* const begin_frame_source_;
const bool reentrant_;
std::vector<base::OnceClosure> vsync_complete_callbacks_;
};
......@@ -100,7 +102,7 @@ void WindowAndroid::WindowBeginFrameSource::AddObserver(
// BeginFrames.
last_begin_frame_args_.deadline =
base::TimeTicks::Now() + last_begin_frame_args_.interval;
ScopedOnBeginFrame scope(this);
ScopedOnBeginFrame scope(this, true /* allow_reentrancy */);
obs->OnBeginFrame(last_begin_frame_args_);
}
}
......@@ -118,7 +120,7 @@ void WindowAndroid::WindowBeginFrameSource::RemoveObserver(
}
void WindowAndroid::WindowBeginFrameSource::OnGpuNoLongerBusy() {
ScopedOnBeginFrame scope(this);
ScopedOnBeginFrame scope(this, false /* allow_reentrancy */);
for (auto& obs : observers_)
obs.OnBeginFrame(last_begin_frame_args_);
}
......@@ -151,14 +153,26 @@ void WindowAndroid::WindowBeginFrameSource::AddBeginFrameCompletionCallback(
}
WindowAndroid::ScopedOnBeginFrame::ScopedOnBeginFrame(
WindowAndroid::WindowBeginFrameSource* bfs)
: begin_frame_source_(bfs) {
WindowAndroid::WindowBeginFrameSource* bfs,
bool allow_reentrancy)
: begin_frame_source_(bfs),
reentrant_(allow_reentrancy &&
begin_frame_source_->vsync_complete_callbacks_ptr_) {
if (reentrant_) {
DCHECK(begin_frame_source_->vsync_complete_callbacks_ptr_);
return;
}
DCHECK(!begin_frame_source_->vsync_complete_callbacks_ptr_);
begin_frame_source_->vsync_complete_callbacks_ptr_ =
&vsync_complete_callbacks_;
}
WindowAndroid::ScopedOnBeginFrame::~ScopedOnBeginFrame() {
if (reentrant_) {
DCHECK_NE(&vsync_complete_callbacks_,
begin_frame_source_->vsync_complete_callbacks_ptr_);
return;
}
DCHECK_EQ(&vsync_complete_callbacks_,
begin_frame_source_->vsync_complete_callbacks_ptr_);
begin_frame_source_->vsync_complete_callbacks_ptr_ = nullptr;
......
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