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

Unified Diff: android_webview/browser/test/fake_window.cc

Issue 1943963003: WIP Handle AwContents needing multiple live functors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Testing framework changes to support testing multiple RenderThreadManager instances. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/browser/test/fake_window.cc
diff --git a/android_webview/browser/test/fake_window.cc b/android_webview/browser/test/fake_window.cc
index a13be3376b1fe87673cca7bcb4fdac93a4cee3a9..00f1f9f38eb3bb7bb7f3983f9278b101de6b219a 100644
--- a/android_webview/browser/test/fake_window.cc
+++ b/android_webview/browser/test/fake_window.cc
@@ -41,7 +41,6 @@ class FakeWindow::ScopedMakeCurrent {
};
FakeWindow::FakeWindow(BrowserViewRenderer* view,
- const DrawGLCallback& draw_gl,
WindowHooks* hooks,
gfx::Rect location)
: view_(view),
@@ -49,8 +48,8 @@ FakeWindow::FakeWindow(BrowserViewRenderer* view,
surface_size_(100, 100),
location_(location),
on_draw_hardware_pending_(false),
- draw_gl_(draw_gl),
context_current_(false),
+ functor_(nullptr),
weak_ptr_factory_(this) {
CheckCurrentlyOnUIThread();
DCHECK(view_);
@@ -61,6 +60,7 @@ FakeWindow::FakeWindow(BrowserViewRenderer* view,
FakeWindow::~FakeWindow() {
CheckCurrentlyOnUIThread();
+ LOG(WARNING) << "XXX " << __PRETTY_FUNCTION__;
if (render_thread_loop_) {
base::WaitableEvent completion(true, false);
render_thread_loop_->PostTask(
@@ -77,32 +77,34 @@ void FakeWindow::Detach() {
view_->OnDetachedFromWindow();
}
-void FakeWindow::RequestInvokeGL(bool wait_for_completion) {
+void FakeWindow::RequestInvokeGL(Functor* functor, bool wait_for_completion) {
CheckCurrentlyOnUIThread();
base::WaitableEvent completion(true, false);
render_thread_loop_->PostTask(
FROM_HERE,
- base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this),
- wait_for_completion ? &completion : nullptr));
+ base::Bind(&FakeWindow::InvokeFunctorOnRT, base::Unretained(this),
+ functor, wait_for_completion ? &completion : nullptr));
if (wait_for_completion)
completion.Wait();
}
-void FakeWindow::ProcessFunctorOnRT(base::WaitableEvent* sync) {
+void FakeWindow::InvokeFunctorOnRT(Functor* functor,
boliu 2016/05/10 15:18:19 why have both |functor_| and all these methods tha
Tobias Sargeant 2016/05/10 16:01:17 I guess functor_ should really be current_functor_
boliu 2016/05/10 16:37:53 But look like this method. You have |functor| arg,
Tobias Sargeant 2016/05/13 13:23:56 Ok. It's always passed in now, but as far as I can
+ base::WaitableEvent* sync) {
CheckCurrentlyOnRT();
- AwDrawGLInfo process_info;
- process_info.version = kAwDrawGLInfoVersion;
- process_info.mode = AwDrawGLInfo::kModeProcess;
-
- hooks_->WillProcessOnRT();
- {
- ScopedMakeCurrent make_current(this);
- draw_gl_.Run(&process_info);
- }
- hooks_->DidProcessOnRT();
+ ScopedMakeCurrent make_current(this);
+ functor_->Invoke(sync, hooks_);
+}
- if (sync)
- sync->Signal();
+void FakeWindow::SetDrawFunctor(Functor* functor) {
+ functor_ = functor;
+ functor_->Attach(this);
+}
+
+void FakeWindow::RequestDrawGL(Functor* functor) {
+ CheckCurrentlyOnUIThread();
+ render_thread_loop_->PostTask(FROM_HERE,
+ base::Bind(&FakeWindow::ProcessDrawOnRT,
+ base::Unretained(this), functor));
}
void FakeWindow::PostInvalidate() {
@@ -118,6 +120,7 @@ void FakeWindow::PostInvalidate() {
void FakeWindow::OnDrawHardware() {
CheckCurrentlyOnUIThread();
DCHECK(on_draw_hardware_pending_);
+ DCHECK(functor_);
on_draw_hardware_pending_ = false;
view_->PrepareToDraw(gfx::Vector2d(), location_);
@@ -130,42 +133,25 @@ void FakeWindow::OnDrawHardware() {
base::WaitableEvent completion(true, false);
render_thread_loop_->PostTask(
FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT,
- base::Unretained(this), &completion));
+ base::Unretained(this), functor_, &completion));
completion.Wait();
}
}
-void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) {
+void FakeWindow::ProcessSyncOnRT(Functor* functor, base::WaitableEvent* sync) {
CheckCurrentlyOnRT();
- // Ok to access UI functions until sync is signalled.
- gfx::Rect location = location_;
- {
- AwDrawGLInfo process_info;
- process_info.version = kAwDrawGLInfoVersion;
- process_info.mode = AwDrawGLInfo::kModeSync;
-
- hooks_->WillSyncOnRT();
- draw_gl_.Run(&process_info);
- hooks_->DidSyncOnRT();
- }
- sync->Signal();
-
- AwDrawGLInfo draw_info;
- draw_info.version = kAwDrawGLInfoVersion;
- draw_info.mode = AwDrawGLInfo::kModeDraw;
- draw_info.clip_left = location.x();
- draw_info.clip_top = location.y();
- draw_info.clip_right = location.x() + location.width();
- draw_info.clip_bottom = location.y() + location.height();
+ functor->Sync(location_, sync, hooks_);
+}
- if (!hooks_->WillDrawOnRT(&draw_info))
- return;
+void FakeWindow::ProcessDrawOnRT(Functor* functor) {
+ CheckCurrentlyOnRT();
+ ScopedMakeCurrent make_current(this);
+ functor->Draw(hooks_);
+}
- {
- ScopedMakeCurrent make_current(this);
- draw_gl_.Run(&draw_info);
- }
- hooks_->DidDrawOnRT();
+void FakeWindow::DrawFunctorOnRT(Functor* functor, base::WaitableEvent* sync) {
+ ProcessSyncOnRT(functor, sync);
+ ProcessDrawOnRT(functor);
}
void FakeWindow::CheckCurrentlyOnUIThread() {
@@ -215,4 +201,69 @@ void FakeWindow::CheckCurrentlyOnRT() {
DCHECK(rt_checker_.CalledOnValidSequencedThread());
}
+Functor::Functor(RenderThreadManagerFactory render_thread_manager_factory)
+ : render_thread_manager_(render_thread_manager_factory.Run(this)) {
boliu 2016/05/10 15:18:19 Hmm, is this safe? Is the object constructed far e
Tobias Sargeant 2016/05/10 16:01:17 This is effectively the pattern we use with AwGLFu
boliu 2016/05/10 16:37:53 It's a technical concern. The object may not be fu
Tobias Sargeant 2016/05/13 13:23:56 Took this approach. I can't see any reason why thi
+ callback_ = base::Bind(&RenderThreadManager::DrawGL,
+ base::Unretained(render_thread_manager_.get()));
+}
+
+Functor::~Functor() {}
+
+CompositorFrameConsumer* Functor::GetCompositorFrameConsumer() {
+ return render_thread_manager_.get();
+}
+
+void Functor::Attach(FakeWindow* window) {
+ window_ = window;
+}
+
+void Functor::Sync(const gfx::Rect& location,
+ base::WaitableEvent* sync,
boliu 2016/05/10 15:18:19 keep the sync event logic in FakeWindow
Tobias Sargeant 2016/05/10 16:01:17 Could do, but then callback_ has to be available t
boliu 2016/05/10 16:37:53 Hmm, don't see why that's needed?
+ WindowHooks* hooks) {
+ committed_location_ = location;
+ AwDrawGLInfo sync_info;
+ sync_info.version = kAwDrawGLInfoVersion;
+ sync_info.mode = AwDrawGLInfo::kModeSync;
+ hooks->WillSyncOnRT();
+ LOG(WARNING) << "XXX " << __PRETTY_FUNCTION__
+ << " render_thread_manager_ = " << render_thread_manager_.get();
+ callback_.Run(&sync_info);
+ hooks->DidSyncOnRT();
+ sync->Signal();
+}
+
+void Functor::Draw(WindowHooks* hooks) {
+ AwDrawGLInfo draw_info;
+ draw_info.version = kAwDrawGLInfoVersion;
+ draw_info.mode = AwDrawGLInfo::kModeDraw;
+ draw_info.clip_left = committed_location_.x();
+ draw_info.clip_top = committed_location_.y();
+ draw_info.clip_right = committed_location_.x() + committed_location_.width();
+ draw_info.clip_bottom =
+ committed_location_.y() + committed_location_.height();
+ if (!hooks->WillDrawOnRT(&draw_info))
+ return;
+ callback_.Run(&draw_info);
+ hooks->DidDrawOnRT();
+}
+
+void Functor::Invoke(base::WaitableEvent* sync, WindowHooks* hooks) {
+ AwDrawGLInfo invoke_info;
+ invoke_info.version = kAwDrawGLInfoVersion;
+ invoke_info.mode = AwDrawGLInfo::kModeProcess;
+ hooks->WillProcessOnRT();
+ callback_.Run(&invoke_info);
+ hooks->DidProcessOnRT();
+ if (sync)
+ sync->Signal();
+}
+
+bool Functor::RequestInvokeGL(bool wait_for_completion) {
+ DCHECK(window_);
+ window_->RequestInvokeGL(this, wait_for_completion);
+ return true;
+}
+
+void Functor::DetachFunctorFromView() {}
+
} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698