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

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: 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),
54 weak_ptr_factory_(this) { 52 weak_ptr_factory_(this) {
55 CheckCurrentlyOnUIThread(); 53 CheckCurrentlyOnUIThread();
56 DCHECK(view_); 54 DCHECK(view_);
57 view_->OnAttachedToWindow(location_.width(), location_.height()); 55 view_->OnAttachedToWindow(location_.width(), location_.height());
58 view_->SetWindowVisibility(true); 56 view_->SetWindowVisibility(true);
59 view_->SetViewVisibility(true); 57 view_->SetViewVisibility(true);
60 } 58 }
61 59
62 FakeWindow::~FakeWindow() { 60 FakeWindow::~FakeWindow() {
63 CheckCurrentlyOnUIThread(); 61 CheckCurrentlyOnUIThread();
64 if (render_thread_loop_) { 62 if (render_thread_loop_) {
65 base::WaitableEvent completion(true, false); 63 base::WaitableEvent completion(true, false);
66 render_thread_loop_->PostTask( 64 render_thread_loop_->PostTask(
67 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), 65 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this),
68 &completion)); 66 &completion));
69 completion.Wait(); 67 completion.Wait();
70 } 68 }
71 69
72 render_thread_.reset(); 70 render_thread_.reset();
73 } 71 }
74 72
75 void FakeWindow::Detach() { 73 void FakeWindow::Detach() {
76 CheckCurrentlyOnUIThread(); 74 CheckCurrentlyOnUIThread();
77 view_->OnDetachedFromWindow(); 75 view_->OnDetachedFromWindow();
78 } 76 }
79 77
80 void FakeWindow::RequestInvokeGL(bool wait_for_completion) { 78 void FakeWindow::RequestInvokeGL(FakeFunctor* functor,
79 bool wait_for_completion) {
81 CheckCurrentlyOnUIThread(); 80 CheckCurrentlyOnUIThread();
82 base::WaitableEvent completion(true, false); 81 base::WaitableEvent completion(true, false);
83 render_thread_loop_->PostTask( 82 render_thread_loop_->PostTask(
84 FROM_HERE, 83 FROM_HERE,
85 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), 84 base::Bind(&FakeWindow::InvokeFunctorOnRT, base::Unretained(this),
86 wait_for_completion ? &completion : nullptr)); 85 functor, wait_for_completion ? &completion : nullptr));
87 if (wait_for_completion) 86 if (wait_for_completion)
88 completion.Wait(); 87 completion.Wait();
89 } 88 }
90 89
91 void FakeWindow::ProcessFunctorOnRT(base::WaitableEvent* sync) { 90 void FakeWindow::InvokeFunctorOnRT(FakeFunctor* functor,
91 base::WaitableEvent* sync) {
92 CheckCurrentlyOnRT(); 92 CheckCurrentlyOnRT();
93 AwDrawGLInfo process_info; 93 ScopedMakeCurrent make_current(this);
94 process_info.version = kAwDrawGLInfoVersion; 94 functor->Invoke(sync, hooks_);
95 process_info.mode = AwDrawGLInfo::kModeProcess; 95 }
96 96
97 hooks_->WillProcessOnRT(); 97 void FakeWindow::SetDrawFunctor(FakeFunctor* functor) {
98 { 98 functor_ = functor;
99 ScopedMakeCurrent make_current(this); 99 }
100 draw_gl_.Run(&process_info);
101 }
102 hooks_->DidProcessOnRT();
103 100
104 if (sync) 101 void FakeWindow::RequestDrawGL(FakeFunctor* functor) {
105 sync->Signal(); 102 CheckCurrentlyOnUIThread();
103 render_thread_loop_->PostTask(FROM_HERE,
104 base::Bind(&FakeWindow::ProcessDrawOnRT,
105 base::Unretained(this), functor));
106 } 106 }
107 107
108 void FakeWindow::PostInvalidate() { 108 void FakeWindow::PostInvalidate() {
109 CheckCurrentlyOnUIThread(); 109 CheckCurrentlyOnUIThread();
110 if (on_draw_hardware_pending_) 110 if (on_draw_hardware_pending_)
111 return; 111 return;
112 on_draw_hardware_pending_ = true; 112 on_draw_hardware_pending_ = true;
113 base::ThreadTaskRunnerHandle::Get()->PostTask( 113 base::ThreadTaskRunnerHandle::Get()->PostTask(
114 FROM_HERE, 114 FROM_HERE,
115 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); 115 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr()));
116 } 116 }
117 117
118 void FakeWindow::OnDrawHardware() { 118 void FakeWindow::OnDrawHardware() {
119 CheckCurrentlyOnUIThread(); 119 CheckCurrentlyOnUIThread();
120 DCHECK(on_draw_hardware_pending_); 120 DCHECK(on_draw_hardware_pending_);
121 on_draw_hardware_pending_ = false; 121 on_draw_hardware_pending_ = false;
122 122
123 view_->PrepareToDraw(gfx::Vector2d(), location_); 123 view_->PrepareToDraw(gfx::Vector2d(), location_);
124 hooks_->WillOnDraw(); 124 hooks_->WillOnDraw();
125 bool success = view_->OnDrawHardware(); 125 bool success = view_->OnDrawHardware();
126 hooks_->DidOnDraw(success); 126 hooks_->DidOnDraw(success);
127 FakeFunctor* functor = hooks_->GetFunctorForView(view_);
128 DCHECK(functor);
boliu 2016/05/13 16:09:02 fwiw, production code should handle the case where
Tobias Sargeant 2016/05/13 17:02:37 Seems like we could simulate this by returning nul
127 if (success) { 129 if (success) {
128 CreateRenderThreadIfNeeded(); 130 CreateRenderThreadIfNeeded();
129 131
130 base::WaitableEvent completion(true, false); 132 base::WaitableEvent completion(true, false);
131 render_thread_loop_->PostTask( 133 render_thread_loop_->PostTask(
132 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, 134 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT,
133 base::Unretained(this), &completion)); 135 base::Unretained(this), functor, &completion));
134 completion.Wait(); 136 completion.Wait();
135 } 137 }
136 } 138 }
137 139
138 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { 140 void FakeWindow::ProcessSyncOnRT(FakeFunctor* functor,
141 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(FakeFunctor* 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(FakeFunctor* functor,
154 draw_info.version = kAwDrawGLInfoVersion; 153 base::WaitableEvent* sync) {
155 draw_info.mode = AwDrawGLInfo::kModeDraw; 154 ProcessSyncOnRT(functor, sync);
156 draw_info.clip_left = location.x(); 155 ProcessDrawOnRT(functor);
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 } 156 }
170 157
171 void FakeWindow::CheckCurrentlyOnUIThread() { 158 void FakeWindow::CheckCurrentlyOnUIThread() {
172 DCHECK(ui_checker_.CalledOnValidSequencedThread()); 159 DCHECK(ui_checker_.CalledOnValidSequencedThread());
173 } 160 }
174 161
175 void FakeWindow::CreateRenderThreadIfNeeded() { 162 void FakeWindow::CreateRenderThreadIfNeeded() {
176 CheckCurrentlyOnUIThread(); 163 CheckCurrentlyOnUIThread();
177 if (render_thread_) { 164 if (render_thread_) {
178 DCHECK(render_thread_loop_); 165 DCHECK(render_thread_loop_);
(...skipping 29 matching lines...) Expand all
208 context_ = nullptr; 195 context_ = nullptr;
209 surface_ = nullptr; 196 surface_ = nullptr;
210 } 197 }
211 sync->Signal(); 198 sync->Signal();
212 } 199 }
213 200
214 void FakeWindow::CheckCurrentlyOnRT() { 201 void FakeWindow::CheckCurrentlyOnRT() {
215 DCHECK(rt_checker_.CalledOnValidSequencedThread()); 202 DCHECK(rt_checker_.CalledOnValidSequencedThread());
216 } 203 }
217 204
205 FakeFunctor::FakeFunctor() : window_(nullptr) {}
206
207 FakeFunctor::~FakeFunctor() {
208 render_thread_manager_.reset();
209 }
210
211 CompositorFrameConsumer* FakeFunctor::GetCompositorFrameConsumer() {
212 return render_thread_manager_.get();
213 }
214
215 void FakeFunctor::Init(
216 FakeWindow* window,
217 std::unique_ptr<RenderThreadManager> render_thread_manager) {
218 window_ = window;
219 render_thread_manager_ = std::move(render_thread_manager);
220 callback_ = base::Bind(&RenderThreadManager::DrawGL,
221 base::Unretained(render_thread_manager_.get()));
222 }
223
224 void FakeFunctor::Sync(const gfx::Rect& location,
225 base::WaitableEvent* sync,
226 WindowHooks* hooks) {
227 DCHECK(!callback_.is_null());
228 committed_location_ = location;
229 AwDrawGLInfo sync_info;
230 sync_info.version = kAwDrawGLInfoVersion;
231 sync_info.mode = AwDrawGLInfo::kModeSync;
232 hooks->WillSyncOnRT();
233 callback_.Run(&sync_info);
234 hooks->DidSyncOnRT();
235 sync->Signal();
boliu 2016/05/13 16:09:01 My earlier comment about not having sync objects i
Tobias Sargeant 2016/05/13 16:23:17 Ahh, OK, I misunderstood what you meant the first
Tobias Sargeant 2016/05/13 17:02:36 Done.
236 }
237
238 void FakeFunctor::Draw(WindowHooks* hooks) {
239 DCHECK(!callback_.is_null());
240 AwDrawGLInfo draw_info;
241 draw_info.version = kAwDrawGLInfoVersion;
242 draw_info.mode = AwDrawGLInfo::kModeDraw;
243 draw_info.clip_left = committed_location_.x();
244 draw_info.clip_top = committed_location_.y();
245 draw_info.clip_right = committed_location_.x() + committed_location_.width();
246 draw_info.clip_bottom =
247 committed_location_.y() + committed_location_.height();
248 if (!hooks->WillDrawOnRT(&draw_info))
249 return;
250 callback_.Run(&draw_info);
251 hooks->DidDrawOnRT();
252 }
253
254 void FakeFunctor::Invoke(base::WaitableEvent* sync, WindowHooks* hooks) {
255 DCHECK(!callback_.is_null());
256 AwDrawGLInfo invoke_info;
257 invoke_info.version = kAwDrawGLInfoVersion;
258 invoke_info.mode = AwDrawGLInfo::kModeProcess;
259 hooks->WillProcessOnRT();
260 callback_.Run(&invoke_info);
261 hooks->DidProcessOnRT();
262 if (sync)
263 sync->Signal();
264 }
265
266 bool FakeFunctor::RequestInvokeGL(bool wait_for_completion) {
267 DCHECK(window_);
268 window_->RequestInvokeGL(this, wait_for_completion);
269 return true;
270 }
271
272 void FakeFunctor::DetachFunctorFromView() {}
273
218 } // namespace android_webview 274 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698