| 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" | 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 Loading... |
| 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 RenderThreadManager* functor, | 44 const DrawGLCallback& draw_gl, |
| 45 WindowHooks* hooks, | 45 WindowHooks* hooks, |
| 46 gfx::Rect location) | 46 gfx::Rect location) |
| 47 : view_(view), | 47 : view_(view), |
| 48 hooks_(hooks), | 48 hooks_(hooks), |
| 49 surface_size_(100, 100), | 49 surface_size_(100, 100), |
| 50 location_(location), | 50 location_(location), |
| 51 on_draw_hardware_pending_(false), | 51 on_draw_hardware_pending_(false), |
| 52 functor_(functor), | 52 draw_gl_(draw_gl), |
| 53 context_current_(false), | 53 context_current_(false), |
| 54 weak_ptr_factory_(this) { | 54 weak_ptr_factory_(this) { |
| 55 CheckCurrentlyOnUIThread(); | 55 CheckCurrentlyOnUIThread(); |
| 56 DCHECK(view_); | 56 DCHECK(view_); |
| 57 view_->OnAttachedToWindow(location_.width(), location_.height()); | 57 view_->OnAttachedToWindow(location_.width(), location_.height()); |
| 58 view_->SetWindowVisibility(true); | 58 view_->SetWindowVisibility(true); |
| 59 view_->SetViewVisibility(true); | 59 view_->SetViewVisibility(true); |
| 60 } | 60 } |
| 61 | 61 |
| 62 FakeWindow::~FakeWindow() { | 62 FakeWindow::~FakeWindow() { |
| 63 CheckCurrentlyOnUIThread(); | 63 CheckCurrentlyOnUIThread(); |
| 64 } | |
| 65 | |
| 66 void FakeWindow::Detach() { | |
| 67 CheckCurrentlyOnUIThread(); | |
| 68 functor_->DeleteHardwareRendererOnUI(); | |
| 69 view_->OnDetachedFromWindow(); | |
| 70 | |
| 71 if (render_thread_loop_) { | 64 if (render_thread_loop_) { |
| 72 base::WaitableEvent completion(true, false); | 65 base::WaitableEvent completion(true, false); |
| 73 render_thread_loop_->PostTask( | 66 render_thread_loop_->PostTask( |
| 74 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), | 67 FROM_HERE, base::Bind(&FakeWindow::DestroyOnRT, base::Unretained(this), |
| 75 &completion)); | 68 &completion)); |
| 76 completion.Wait(); | 69 completion.Wait(); |
| 77 } | 70 } |
| 78 | 71 |
| 79 render_thread_.reset(); | 72 render_thread_.reset(); |
| 80 } | 73 } |
| 81 | 74 |
| 75 void FakeWindow::Detach() { |
| 76 CheckCurrentlyOnUIThread(); |
| 77 view_->OnDetachedFromWindow(); |
| 78 } |
| 79 |
| 82 void FakeWindow::RequestInvokeGL(bool wait_for_completion) { | 80 void FakeWindow::RequestInvokeGL(bool wait_for_completion) { |
| 83 CheckCurrentlyOnUIThread(); | 81 CheckCurrentlyOnUIThread(); |
| 84 base::WaitableEvent completion(true, false); | 82 base::WaitableEvent completion(true, false); |
| 85 render_thread_loop_->PostTask( | 83 render_thread_loop_->PostTask( |
| 86 FROM_HERE, | 84 FROM_HERE, |
| 87 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), | 85 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), |
| 88 wait_for_completion ? &completion : nullptr)); | 86 wait_for_completion ? &completion : nullptr)); |
| 89 if (wait_for_completion) | 87 if (wait_for_completion) |
| 90 completion.Wait(); | 88 completion.Wait(); |
| 91 } | 89 } |
| 92 | 90 |
| 93 void FakeWindow::ProcessFunctorOnRT(base::WaitableEvent* sync) { | 91 void FakeWindow::ProcessFunctorOnRT(base::WaitableEvent* sync) { |
| 94 CheckCurrentlyOnRT(); | 92 CheckCurrentlyOnRT(); |
| 95 AwDrawGLInfo process_info; | 93 AwDrawGLInfo process_info; |
| 96 process_info.version = kAwDrawGLInfoVersion; | 94 process_info.version = kAwDrawGLInfoVersion; |
| 97 process_info.mode = AwDrawGLInfo::kModeProcess; | 95 process_info.mode = AwDrawGLInfo::kModeProcess; |
| 98 | 96 |
| 99 hooks_->WillProcessOnRT(functor_); | 97 hooks_->WillProcessOnRT(); |
| 100 { | 98 { |
| 101 ScopedMakeCurrent make_current(this); | 99 ScopedMakeCurrent make_current(this); |
| 102 functor_->DrawGL(&process_info); | 100 draw_gl_.Run(&process_info); |
| 103 } | 101 } |
| 104 hooks_->DidProcessOnRT(functor_); | 102 hooks_->DidProcessOnRT(); |
| 105 | 103 |
| 106 if (sync) | 104 if (sync) |
| 107 sync->Signal(); | 105 sync->Signal(); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void FakeWindow::PostInvalidate() { | 108 void FakeWindow::PostInvalidate() { |
| 111 CheckCurrentlyOnUIThread(); | 109 CheckCurrentlyOnUIThread(); |
| 112 if (on_draw_hardware_pending_) | 110 if (on_draw_hardware_pending_) |
| 113 return; | 111 return; |
| 114 on_draw_hardware_pending_ = true; | 112 on_draw_hardware_pending_ = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 139 | 137 |
| 140 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { | 138 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { |
| 141 CheckCurrentlyOnRT(); | 139 CheckCurrentlyOnRT(); |
| 142 // Ok to access UI functions until sync is signalled. | 140 // Ok to access UI functions until sync is signalled. |
| 143 gfx::Rect location = location_; | 141 gfx::Rect location = location_; |
| 144 { | 142 { |
| 145 AwDrawGLInfo process_info; | 143 AwDrawGLInfo process_info; |
| 146 process_info.version = kAwDrawGLInfoVersion; | 144 process_info.version = kAwDrawGLInfoVersion; |
| 147 process_info.mode = AwDrawGLInfo::kModeSync; | 145 process_info.mode = AwDrawGLInfo::kModeSync; |
| 148 | 146 |
| 149 hooks_->WillSyncOnRT(functor_); | 147 hooks_->WillSyncOnRT(); |
| 150 functor_->DrawGL(&process_info); | 148 draw_gl_.Run(&process_info); |
| 151 hooks_->DidSyncOnRT(functor_); | 149 hooks_->DidSyncOnRT(); |
| 152 } | 150 } |
| 153 sync->Signal(); | 151 sync->Signal(); |
| 154 | 152 |
| 155 AwDrawGLInfo draw_info; | 153 AwDrawGLInfo draw_info; |
| 156 draw_info.version = kAwDrawGLInfoVersion; | 154 draw_info.version = kAwDrawGLInfoVersion; |
| 157 draw_info.mode = AwDrawGLInfo::kModeDraw; | 155 draw_info.mode = AwDrawGLInfo::kModeDraw; |
| 158 draw_info.clip_left = location.x(); | 156 draw_info.clip_left = location.x(); |
| 159 draw_info.clip_top = location.y(); | 157 draw_info.clip_top = location.y(); |
| 160 draw_info.clip_right = location.x() + location.width(); | 158 draw_info.clip_right = location.x() + location.width(); |
| 161 draw_info.clip_bottom = location.y() + location.height(); | 159 draw_info.clip_bottom = location.y() + location.height(); |
| 162 | 160 |
| 163 if (!hooks_->WillDrawOnRT(functor_, &draw_info)) | 161 if (!hooks_->WillDrawOnRT(&draw_info)) |
| 164 return; | 162 return; |
| 165 | 163 |
| 166 { | 164 { |
| 167 ScopedMakeCurrent make_current(this); | 165 ScopedMakeCurrent make_current(this); |
| 168 functor_->DrawGL(&draw_info); | 166 draw_gl_.Run(&draw_info); |
| 169 } | 167 } |
| 170 hooks_->DidDrawOnRT(functor_); | 168 hooks_->DidDrawOnRT(); |
| 171 } | 169 } |
| 172 | 170 |
| 173 void FakeWindow::CheckCurrentlyOnUIThread() { | 171 void FakeWindow::CheckCurrentlyOnUIThread() { |
| 174 DCHECK(ui_checker_.CalledOnValidSequencedThread()); | 172 DCHECK(ui_checker_.CalledOnValidSequencedThread()); |
| 175 } | 173 } |
| 176 | 174 |
| 177 void FakeWindow::CreateRenderThreadIfNeeded() { | 175 void FakeWindow::CreateRenderThreadIfNeeded() { |
| 178 CheckCurrentlyOnUIThread(); | 176 CheckCurrentlyOnUIThread(); |
| 179 if (render_thread_) { | 177 if (render_thread_) { |
| 180 DCHECK(render_thread_loop_); | 178 DCHECK(render_thread_loop_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 211 surface_ = nullptr; | 209 surface_ = nullptr; |
| 212 } | 210 } |
| 213 sync->Signal(); | 211 sync->Signal(); |
| 214 } | 212 } |
| 215 | 213 |
| 216 void FakeWindow::CheckCurrentlyOnRT() { | 214 void FakeWindow::CheckCurrentlyOnRT() { |
| 217 DCHECK(rt_checker_.CalledOnValidSequencedThread()); | 215 DCHECK(rt_checker_.CalledOnValidSequencedThread()); |
| 218 } | 216 } |
| 219 | 217 |
| 220 } // namespace android_webview | 218 } // namespace android_webview |
| OLD | NEW |