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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "android_webview/browser/test/fake_window.h" 5 #include "android_webview/browser/test/fake_window.h"
6 6
7 #include "android_webview/browser/browser_view_renderer.h" 7 #include "android_webview/browser/browser_view_renderer.h"
8 #include "android_webview/browser/child_frame.h" 8 #include "android_webview/browser/child_frame.h"
9 #include "android_webview/browser/render_thread_manager.h" 9 #include "android_webview/browser/render_thread_manager.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 23 matching lines...) Expand all
34 eglMakeCurrent(view_root_->surface_->GetDisplay(), EGL_NO_SURFACE, 34 eglMakeCurrent(view_root_->surface_->GetDisplay(), EGL_NO_SURFACE,
35 EGL_NO_SURFACE, EGL_NO_CONTEXT); 35 EGL_NO_SURFACE, EGL_NO_CONTEXT);
36 view_root_->context_->ReleaseCurrent(view_root_->surface_.get()); 36 view_root_->context_->ReleaseCurrent(view_root_->surface_.get());
37 } 37 }
38 38
39 private: 39 private:
40 FakeWindow* view_root_; 40 FakeWindow* view_root_;
41 }; 41 };
42 42
43 FakeWindow::FakeWindow(BrowserViewRenderer* view, 43 FakeWindow::FakeWindow(BrowserViewRenderer* view,
44 const DrawGLCallback& draw_gl,
45 WindowHooks* hooks, 44 WindowHooks* hooks,
46 gfx::Rect location) 45 gfx::Rect location)
47 : view_(view), 46 : view_(view),
48 hooks_(hooks), 47 hooks_(hooks),
49 surface_size_(100, 100), 48 surface_size_(100, 100),
50 location_(location), 49 location_(location),
51 on_draw_hardware_pending_(false), 50 on_draw_hardware_pending_(false),
52 draw_gl_(draw_gl),
53 context_current_(false), 51 context_current_(false),
52 functor_(nullptr),
54 weak_ptr_factory_(this) { 53 weak_ptr_factory_(this) {
55 CheckCurrentlyOnUIThread(); 54 CheckCurrentlyOnUIThread();
56 DCHECK(view_); 55 DCHECK(view_);
57 view_->OnAttachedToWindow(location_.width(), location_.height()); 56 view_->OnAttachedToWindow(location_.width(), location_.height());
58 view_->SetWindowVisibility(true); 57 view_->SetWindowVisibility(true);
59 view_->SetViewVisibility(true); 58 view_->SetViewVisibility(true);
60 } 59 }
61 60
62 FakeWindow::~FakeWindow() { 61 FakeWindow::~FakeWindow() {
63 CheckCurrentlyOnUIThread(); 62 CheckCurrentlyOnUIThread();
63 LOG(WARNING) << "XXX " << __PRETTY_FUNCTION__;
64 if (render_thread_loop_) { 64 if (render_thread_loop_) {
65 base::WaitableEvent completion(true, false); 65 base::WaitableEvent completion(true, false);
66 render_thread_loop_->PostTask( 66 render_thread_loop_->PostTask(
67 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), 67 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this),
68 &completion)); 68 &completion));
69 completion.Wait(); 69 completion.Wait();
70 } 70 }
71 71
72 render_thread_.reset(); 72 render_thread_.reset();
73 } 73 }
74 74
75 void FakeWindow::Detach() { 75 void FakeWindow::Detach() {
76 CheckCurrentlyOnUIThread(); 76 CheckCurrentlyOnUIThread();
77 view_->OnDetachedFromWindow(); 77 view_->OnDetachedFromWindow();
78 } 78 }
79 79
80 void FakeWindow::RequestInvokeGL(bool wait_for_completion) { 80 void FakeWindow::RequestInvokeGL(Functor* functor, bool wait_for_completion) {
81 CheckCurrentlyOnUIThread(); 81 CheckCurrentlyOnUIThread();
82 base::WaitableEvent completion(true, false); 82 base::WaitableEvent completion(true, false);
83 render_thread_loop_->PostTask( 83 render_thread_loop_->PostTask(
84 FROM_HERE, 84 FROM_HERE,
85 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), 85 base::Bind(&FakeWindow::InvokeFunctorOnRT, base::Unretained(this),
86 wait_for_completion ? &completion : nullptr)); 86 functor, wait_for_completion ? &completion : nullptr));
87 if (wait_for_completion) 87 if (wait_for_completion)
88 completion.Wait(); 88 completion.Wait();
89 } 89 }
90 90
91 void FakeWindow::ProcessFunctorOnRT(base::WaitableEvent* sync) { 91 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
92 base::WaitableEvent* sync) {
92 CheckCurrentlyOnRT(); 93 CheckCurrentlyOnRT();
93 AwDrawGLInfo process_info; 94 ScopedMakeCurrent make_current(this);
94 process_info.version = kAwDrawGLInfoVersion; 95 functor_->Invoke(sync, hooks_);
95 process_info.mode = AwDrawGLInfo::kModeProcess; 96 }
96 97
97 hooks_->WillProcessOnRT(); 98 void FakeWindow::SetDrawFunctor(Functor* functor) {
98 { 99 functor_ = functor;
99 ScopedMakeCurrent make_current(this); 100 functor_->Attach(this);
100 draw_gl_.Run(&process_info); 101 }
101 }
102 hooks_->DidProcessOnRT();
103 102
104 if (sync) 103 void FakeWindow::RequestDrawGL(Functor* functor) {
105 sync->Signal(); 104 CheckCurrentlyOnUIThread();
105 render_thread_loop_->PostTask(FROM_HERE,
106 base::Bind(&FakeWindow::ProcessDrawOnRT,
107 base::Unretained(this), functor));
106 } 108 }
107 109
108 void FakeWindow::PostInvalidate() { 110 void FakeWindow::PostInvalidate() {
109 CheckCurrentlyOnUIThread(); 111 CheckCurrentlyOnUIThread();
110 if (on_draw_hardware_pending_) 112 if (on_draw_hardware_pending_)
111 return; 113 return;
112 on_draw_hardware_pending_ = true; 114 on_draw_hardware_pending_ = true;
113 base::ThreadTaskRunnerHandle::Get()->PostTask( 115 base::ThreadTaskRunnerHandle::Get()->PostTask(
114 FROM_HERE, 116 FROM_HERE,
115 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); 117 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr()));
116 } 118 }
117 119
118 void FakeWindow::OnDrawHardware() { 120 void FakeWindow::OnDrawHardware() {
119 CheckCurrentlyOnUIThread(); 121 CheckCurrentlyOnUIThread();
120 DCHECK(on_draw_hardware_pending_); 122 DCHECK(on_draw_hardware_pending_);
123 DCHECK(functor_);
121 on_draw_hardware_pending_ = false; 124 on_draw_hardware_pending_ = false;
122 125
123 view_->PrepareToDraw(gfx::Vector2d(), location_); 126 view_->PrepareToDraw(gfx::Vector2d(), location_);
124 hooks_->WillOnDraw(); 127 hooks_->WillOnDraw();
125 bool success = view_->OnDrawHardware(); 128 bool success = view_->OnDrawHardware();
126 hooks_->DidOnDraw(success); 129 hooks_->DidOnDraw(success);
127 if (success) { 130 if (success) {
128 CreateRenderThreadIfNeeded(); 131 CreateRenderThreadIfNeeded();
129 132
130 base::WaitableEvent completion(true, false); 133 base::WaitableEvent completion(true, false);
131 render_thread_loop_->PostTask( 134 render_thread_loop_->PostTask(
132 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, 135 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT,
133 base::Unretained(this), &completion)); 136 base::Unretained(this), functor_, &completion));
134 completion.Wait(); 137 completion.Wait();
135 } 138 }
136 } 139 }
137 140
138 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { 141 void FakeWindow::ProcessSyncOnRT(Functor* functor, base::WaitableEvent* sync) {
139 CheckCurrentlyOnRT(); 142 CheckCurrentlyOnRT();
140 // Ok to access UI functions until sync is signalled. 143 functor->Sync(location_, sync, hooks_);
141 gfx::Rect location = location_; 144 }
142 {
143 AwDrawGLInfo process_info;
144 process_info.version = kAwDrawGLInfoVersion;
145 process_info.mode = AwDrawGLInfo::kModeSync;
146 145
147 hooks_->WillSyncOnRT(); 146 void FakeWindow::ProcessDrawOnRT(Functor* functor) {
148 draw_gl_.Run(&process_info); 147 CheckCurrentlyOnRT();
149 hooks_->DidSyncOnRT(); 148 ScopedMakeCurrent make_current(this);
150 } 149 functor->Draw(hooks_);
151 sync->Signal(); 150 }
152 151
153 AwDrawGLInfo draw_info; 152 void FakeWindow::DrawFunctorOnRT(Functor* functor, base::WaitableEvent* sync) {
154 draw_info.version = kAwDrawGLInfoVersion; 153 ProcessSyncOnRT(functor, sync);
155 draw_info.mode = AwDrawGLInfo::kModeDraw; 154 ProcessDrawOnRT(functor);
156 draw_info.clip_left = location.x();
157 draw_info.clip_top = location.y();
158 draw_info.clip_right = location.x() + location.width();
159 draw_info.clip_bottom = location.y() + location.height();
160
161 if (!hooks_->WillDrawOnRT(&draw_info))
162 return;
163
164 {
165 ScopedMakeCurrent make_current(this);
166 draw_gl_.Run(&draw_info);
167 }
168 hooks_->DidDrawOnRT();
169 } 155 }
170 156
171 void FakeWindow::CheckCurrentlyOnUIThread() { 157 void FakeWindow::CheckCurrentlyOnUIThread() {
172 DCHECK(ui_checker_.CalledOnValidSequencedThread()); 158 DCHECK(ui_checker_.CalledOnValidSequencedThread());
173 } 159 }
174 160
175 void FakeWindow::CreateRenderThreadIfNeeded() { 161 void FakeWindow::CreateRenderThreadIfNeeded() {
176 CheckCurrentlyOnUIThread(); 162 CheckCurrentlyOnUIThread();
177 if (render_thread_) { 163 if (render_thread_) {
178 DCHECK(render_thread_loop_); 164 DCHECK(render_thread_loop_);
(...skipping 29 matching lines...) Expand all
208 context_ = nullptr; 194 context_ = nullptr;
209 surface_ = nullptr; 195 surface_ = nullptr;
210 } 196 }
211 sync->Signal(); 197 sync->Signal();
212 } 198 }
213 199
214 void FakeWindow::CheckCurrentlyOnRT() { 200 void FakeWindow::CheckCurrentlyOnRT() {
215 DCHECK(rt_checker_.CalledOnValidSequencedThread()); 201 DCHECK(rt_checker_.CalledOnValidSequencedThread());
216 } 202 }
217 203
204 Functor::Functor(RenderThreadManagerFactory render_thread_manager_factory)
205 : 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
206 callback_ = base::Bind(&RenderThreadManager::DrawGL,
207 base::Unretained(render_thread_manager_.get()));
208 }
209
210 Functor::~Functor() {}
211
212 CompositorFrameConsumer* Functor::GetCompositorFrameConsumer() {
213 return render_thread_manager_.get();
214 }
215
216 void Functor::Attach(FakeWindow* window) {
217 window_ = window;
218 }
219
220 void Functor::Sync(const gfx::Rect& location,
221 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?
222 WindowHooks* hooks) {
223 committed_location_ = location;
224 AwDrawGLInfo sync_info;
225 sync_info.version = kAwDrawGLInfoVersion;
226 sync_info.mode = AwDrawGLInfo::kModeSync;
227 hooks->WillSyncOnRT();
228 LOG(WARNING) << "XXX " << __PRETTY_FUNCTION__
229 << " render_thread_manager_ = " << render_thread_manager_.get();
230 callback_.Run(&sync_info);
231 hooks->DidSyncOnRT();
232 sync->Signal();
233 }
234
235 void Functor::Draw(WindowHooks* hooks) {
236 AwDrawGLInfo draw_info;
237 draw_info.version = kAwDrawGLInfoVersion;
238 draw_info.mode = AwDrawGLInfo::kModeDraw;
239 draw_info.clip_left = committed_location_.x();
240 draw_info.clip_top = committed_location_.y();
241 draw_info.clip_right = committed_location_.x() + committed_location_.width();
242 draw_info.clip_bottom =
243 committed_location_.y() + committed_location_.height();
244 if (!hooks->WillDrawOnRT(&draw_info))
245 return;
246 callback_.Run(&draw_info);
247 hooks->DidDrawOnRT();
248 }
249
250 void Functor::Invoke(base::WaitableEvent* sync, WindowHooks* hooks) {
251 AwDrawGLInfo invoke_info;
252 invoke_info.version = kAwDrawGLInfoVersion;
253 invoke_info.mode = AwDrawGLInfo::kModeProcess;
254 hooks->WillProcessOnRT();
255 callback_.Run(&invoke_info);
256 hooks->DidProcessOnRT();
257 if (sync)
258 sync->Signal();
259 }
260
261 bool Functor::RequestInvokeGL(bool wait_for_completion) {
262 DCHECK(window_);
263 window_->RequestInvokeGL(this, wait_for_completion);
264 return true;
265 }
266
267 void Functor::DetachFunctorFromView() {}
268
218 } // namespace android_webview 269 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698