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

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

Powered by Google App Engine
This is Rietveld 408576698