OLD | NEW |
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" |
| 9 #include "android_webview/browser/shared_renderer_state.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
10 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
11 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
12 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
13 | 15 |
14 namespace android_webview { | 16 namespace android_webview { |
15 | 17 |
16 class FakeWindow::ScopedMakeCurrent { | 18 class FakeWindow::ScopedMakeCurrent { |
17 public: | 19 public: |
(...skipping 14 matching lines...) Expand all Loading... |
32 eglMakeCurrent(view_root_->surface_->GetDisplay(), EGL_NO_SURFACE, | 34 eglMakeCurrent(view_root_->surface_->GetDisplay(), EGL_NO_SURFACE, |
33 EGL_NO_SURFACE, EGL_NO_CONTEXT); | 35 EGL_NO_SURFACE, EGL_NO_CONTEXT); |
34 view_root_->context_->ReleaseCurrent(view_root_->surface_.get()); | 36 view_root_->context_->ReleaseCurrent(view_root_->surface_.get()); |
35 } | 37 } |
36 | 38 |
37 private: | 39 private: |
38 FakeWindow* view_root_; | 40 FakeWindow* view_root_; |
39 }; | 41 }; |
40 | 42 |
41 FakeWindow::FakeWindow(BrowserViewRenderer* view, | 43 FakeWindow::FakeWindow(BrowserViewRenderer* view, |
| 44 SharedRendererState* functor, |
42 WindowHooks* hooks, | 45 WindowHooks* hooks, |
43 gfx::Rect location) | 46 gfx::Rect location) |
44 : view_(view), | 47 : view_(view), |
45 hooks_(hooks), | 48 hooks_(hooks), |
46 surface_size_(100, 100), | 49 surface_size_(100, 100), |
47 location_(location), | 50 location_(location), |
48 on_draw_hardware_pending_(false), | 51 on_draw_hardware_pending_(false), |
49 functor_(nullptr), | 52 functor_(functor), |
50 context_current_(false), | 53 context_current_(false), |
51 weak_ptr_factory_(this) { | 54 weak_ptr_factory_(this) { |
52 CheckCurrentlyOnUIThread(); | 55 CheckCurrentlyOnUIThread(); |
53 DCHECK(view_); | 56 DCHECK(view_); |
54 view_->OnAttachedToWindow(location_.width(), location_.height()); | 57 view_->OnAttachedToWindow(location_.width(), location_.height()); |
55 view_->SetWindowVisibility(true); | 58 view_->SetWindowVisibility(true); |
56 view_->SetViewVisibility(true); | 59 view_->SetViewVisibility(true); |
57 } | 60 } |
58 | 61 |
59 FakeWindow::~FakeWindow() { | 62 FakeWindow::~FakeWindow() { |
60 CheckCurrentlyOnUIThread(); | 63 CheckCurrentlyOnUIThread(); |
61 } | 64 } |
62 | 65 |
63 void FakeWindow::Detach() { | 66 void FakeWindow::Detach() { |
64 CheckCurrentlyOnUIThread(); | 67 CheckCurrentlyOnUIThread(); |
| 68 functor_->DeleteHardwareRendererOnUI(); |
65 view_->OnDetachedFromWindow(); | 69 view_->OnDetachedFromWindow(); |
66 | 70 |
67 if (render_thread_loop_) { | 71 if (render_thread_loop_) { |
68 base::WaitableEvent completion(true, false); | 72 base::WaitableEvent completion(true, false); |
69 render_thread_loop_->PostTask( | 73 render_thread_loop_->PostTask( |
70 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), | 74 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), |
71 &completion)); | 75 &completion)); |
72 completion.Wait(); | 76 completion.Wait(); |
73 } | 77 } |
74 | 78 |
75 render_thread_.reset(); | 79 render_thread_.reset(); |
76 functor_ = nullptr; | |
77 } | 80 } |
78 | 81 |
79 void FakeWindow::RequestDrawGL(bool wait_for_completion) { | 82 void FakeWindow::RequestDrawGL(bool wait_for_completion) { |
80 CheckCurrentlyOnUIThread(); | 83 CheckCurrentlyOnUIThread(); |
81 base::WaitableEvent completion(true, false); | 84 base::WaitableEvent completion(true, false); |
82 render_thread_loop_->PostTask( | 85 render_thread_loop_->PostTask( |
83 FROM_HERE, | 86 FROM_HERE, |
84 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), | 87 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), |
85 wait_for_completion ? &completion : nullptr)); | 88 wait_for_completion ? &completion : nullptr)); |
86 if (wait_for_completion) | 89 if (wait_for_completion) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 169 } |
167 hooks_->DidDrawOnRT(functor_); | 170 hooks_->DidDrawOnRT(functor_); |
168 } | 171 } |
169 | 172 |
170 void FakeWindow::CheckCurrentlyOnUIThread() { | 173 void FakeWindow::CheckCurrentlyOnUIThread() { |
171 DCHECK(ui_checker_.CalledOnValidSequencedThread()); | 174 DCHECK(ui_checker_.CalledOnValidSequencedThread()); |
172 } | 175 } |
173 | 176 |
174 void FakeWindow::CreateRenderThreadIfNeeded() { | 177 void FakeWindow::CreateRenderThreadIfNeeded() { |
175 CheckCurrentlyOnUIThread(); | 178 CheckCurrentlyOnUIThread(); |
176 if (functor_) { | 179 if (render_thread_) { |
177 DCHECK(render_thread_.get()); | 180 DCHECK(render_thread_loop_); |
178 DCHECK(render_thread_loop_.get()); | |
179 return; | 181 return; |
180 } | 182 } |
181 functor_ = view_->GetAwDrawGLViewContext(); | |
182 render_thread_.reset(new base::Thread("TestRenderThread")); | 183 render_thread_.reset(new base::Thread("TestRenderThread")); |
183 render_thread_->Start(); | 184 render_thread_->Start(); |
184 render_thread_loop_ = render_thread_->task_runner(); | 185 render_thread_loop_ = render_thread_->task_runner(); |
185 rt_checker_.DetachFromSequence(); | 186 rt_checker_.DetachFromSequence(); |
186 | 187 |
187 base::WaitableEvent completion(true, false); | 188 base::WaitableEvent completion(true, false); |
188 render_thread_loop_->PostTask( | 189 render_thread_loop_->PostTask( |
189 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this), | 190 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this), |
190 &completion)); | 191 &completion)); |
191 completion.Wait(); | 192 completion.Wait(); |
192 } | 193 } |
193 | 194 |
194 void FakeWindow::InitializeOnRT(base::WaitableEvent* sync) { | 195 void FakeWindow::InitializeOnRT(base::WaitableEvent* sync) { |
195 CheckCurrentlyOnRT(); | 196 CheckCurrentlyOnRT(); |
196 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(surface_size_); | 197 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(surface_size_); |
197 DCHECK(surface_.get()); | 198 DCHECK(surface_); |
198 DCHECK(surface_->GetHandle()); | 199 DCHECK(surface_->GetHandle()); |
199 context_ = gfx::GLContext::CreateGLContext(nullptr, surface_.get(), | 200 context_ = gfx::GLContext::CreateGLContext(nullptr, surface_.get(), |
200 gfx::PreferDiscreteGpu); | 201 gfx::PreferDiscreteGpu); |
201 DCHECK(context_.get()); | 202 DCHECK(context_); |
202 sync->Signal(); | 203 sync->Signal(); |
203 } | 204 } |
204 | 205 |
205 void FakeWindow::DestroyOnRT(base::WaitableEvent* sync) { | 206 void FakeWindow::DestroyOnRT(base::WaitableEvent* sync) { |
206 CheckCurrentlyOnRT(); | 207 CheckCurrentlyOnRT(); |
207 if (context_) { | 208 if (context_) { |
208 DCHECK(!context_->IsCurrent(surface_.get())); | 209 DCHECK(!context_->IsCurrent(surface_.get())); |
209 context_ = nullptr; | 210 context_ = nullptr; |
210 surface_ = nullptr; | 211 surface_ = nullptr; |
211 } | 212 } |
212 sync->Signal(); | 213 sync->Signal(); |
213 } | 214 } |
214 | 215 |
215 void FakeWindow::CheckCurrentlyOnRT() { | 216 void FakeWindow::CheckCurrentlyOnRT() { |
216 DCHECK(rt_checker_.CalledOnValidSequencedThread()); | 217 DCHECK(rt_checker_.CalledOnValidSequencedThread()); |
217 } | 218 } |
218 | 219 |
219 } // namespace android_webview | 220 } // namespace android_webview |
OLD | NEW |