 Chromium Code Reviews
 Chromium Code Reviews Issue 1002013003:
  Unit Test for WebView animating in and out of screen  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1002013003:
  Unit Test for WebView animating in and out of screen  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/public/browser/draw_gl.h" | |
| 9 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" | 
| 10 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" | 
| 11 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" | 
| 12 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" | 
| 13 | 12 | 
| 14 namespace android_webview { | 13 namespace android_webview { | 
| 15 | 14 | 
| 16 class FakeWindow::ScopedMakeCurrent { | 15 class FakeWindow::ScopedMakeCurrent { | 
| 17 public: | 16 public: | 
| 18 ScopedMakeCurrent(FakeWindow* view_root) : view_root_(view_root) { | 17 ScopedMakeCurrent(FakeWindow* view_root) : view_root_(view_root) { | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 33 EGL_NO_SURFACE, EGL_NO_CONTEXT); | 32 EGL_NO_SURFACE, EGL_NO_CONTEXT); | 
| 34 view_root_->context_->ReleaseCurrent(view_root_->surface_.get()); | 33 view_root_->context_->ReleaseCurrent(view_root_->surface_.get()); | 
| 35 } | 34 } | 
| 36 | 35 | 
| 37 private: | 36 private: | 
| 38 FakeWindow* view_root_; | 37 FakeWindow* view_root_; | 
| 39 }; | 38 }; | 
| 40 | 39 | 
| 41 FakeWindow::FakeWindow(BrowserViewRenderer* view, | 40 FakeWindow::FakeWindow(BrowserViewRenderer* view, | 
| 42 WindowHooks* hooks, | 41 WindowHooks* hooks, | 
| 43 gfx::Rect location) | 42 gfx::Rect location, | 
| 43 bool will_wait_for_mode_draw_to_finish) | |
| 44 : view_(view), | 44 : view_(view), | 
| 45 hooks_(hooks), | 45 hooks_(hooks), | 
| 46 surface_size_(100, 100), | 46 surface_size_(100, 100), | 
| 47 will_wait_for_mode_draw_to_finish_(will_wait_for_mode_draw_to_finish), | |
| 47 location_(location), | 48 location_(location), | 
| 48 on_draw_hardware_pending_(false), | 49 on_draw_hardware_pending_(false), | 
| 49 functor_(nullptr), | 50 functor_(nullptr), | 
| 50 context_current_(false), | 51 context_current_(false), | 
| 51 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { | 
| 52 CheckCurrentlyOnUIThread(); | 53 CheckCurrentlyOnUIThread(); | 
| 53 DCHECK(view_); | 54 DCHECK(view_); | 
| 54 view_->OnAttachedToWindow(location_.width(), location_.height()); | 55 view_->OnAttachedToWindow(location_.width(), location_.height()); | 
| 55 view_->SetWindowVisibility(true); | 56 view_->SetWindowVisibility(true); | 
| 56 view_->SetViewVisibility(true); | 57 view_->SetViewVisibility(true); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 functor_->DrawGL(&process_info); | 100 functor_->DrawGL(&process_info); | 
| 100 } | 101 } | 
| 101 hooks_->DidProcessOnRT(functor_); | 102 hooks_->DidProcessOnRT(functor_); | 
| 102 | 103 | 
| 103 if (sync) | 104 if (sync) | 
| 104 sync->Signal(); | 105 sync->Signal(); | 
| 105 } | 106 } | 
| 106 | 107 | 
| 107 void FakeWindow::PostInvalidate() { | 108 void FakeWindow::PostInvalidate() { | 
| 108 CheckCurrentlyOnUIThread(); | 109 CheckCurrentlyOnUIThread(); | 
| 109 if (on_draw_hardware_pending_) | 110 if (on_draw_hardware_pending_) { | 
| 111 if (will_wait_for_mode_draw_to_finish_) { | |
| 
boliu
2015/03/16 20:25:08
Oh this is what you meant... please no :(
We need
 | |
| 112 base::MessageLoopProxy::current()->PostTask( | |
| 113 FROM_HERE, base::Bind(&FakeWindow::PostInvalidate, | |
| 114 weak_ptr_factory_.GetWeakPtr())); | |
| 115 } | |
| 110 return; | 116 return; | 
| 117 } | |
| 111 on_draw_hardware_pending_ = true; | 118 on_draw_hardware_pending_ = true; | 
| 112 base::MessageLoopProxy::current()->PostTask( | 119 base::MessageLoopProxy::current()->PostTask( | 
| 113 FROM_HERE, | 120 FROM_HERE, | 
| 114 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); | 121 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); | 
| 115 } | 122 } | 
| 116 | 123 | 
| 117 void FakeWindow::OnDrawHardware() { | 124 void FakeWindow::OnDrawHardware() { | 
| 118 CheckCurrentlyOnUIThread(); | 125 CheckCurrentlyOnUIThread(); | 
| 119 DCHECK(on_draw_hardware_pending_); | 126 DCHECK(on_draw_hardware_pending_); | 
| 120 on_draw_hardware_pending_ = false; | 127 if (!will_wait_for_mode_draw_to_finish_) | 
| 128 on_draw_hardware_pending_ = false; | |
| 121 | 129 | 
| 130 view_->PrepareToDraw(gfx::Vector2d(), location_); | |
| 122 hooks_->WillOnDraw(); | 131 hooks_->WillOnDraw(); | 
| 123 view_->PrepareToDraw(gfx::Vector2d(), location_); | |
| 124 bool success = view_->OnDrawHardware(); | 132 bool success = view_->OnDrawHardware(); | 
| 125 hooks_->DidOnDraw(success); | 133 hooks_->DidOnDraw(success); | 
| 126 if (success) { | 134 if (success) { | 
| 127 CreateRenderThreadIfNeeded(); | 135 CreateRenderThreadIfNeeded(); | 
| 128 | 136 | 
| 129 base::WaitableEvent completion(true, false); | 137 base::WaitableEvent completion(true, false); | 
| 130 render_thread_loop_->PostTask( | 138 render_thread_loop_->PostTask( | 
| 131 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, | 139 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, | 
| 132 base::Unretained(this), &completion)); | 140 base::Unretained(this), &completion)); | 
| 133 completion.Wait(); | 141 completion.Wait(); | 
| 134 } | 142 } | 
| 143 | |
| 144 if (will_wait_for_mode_draw_to_finish_) | |
| 145 on_draw_hardware_pending_ = false; | |
| 135 } | 146 } | 
| 136 | 147 | 
| 137 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { | 148 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { | 
| 138 CheckCurrentlyOnRT(); | 149 CheckCurrentlyOnRT(); | 
| 139 // Ok to access UI functions until sync is signalled. | 150 // Ok to access UI functions until sync is signalled. | 
| 140 gfx::Rect location = location_; | 151 gfx::Rect location = location_; | 
| 141 { | 152 { | 
| 142 AwDrawGLInfo process_info; | 153 AwDrawGLInfo process_info; | 
| 143 process_info.version = kAwDrawGLInfoVersion; | 154 process_info.version = kAwDrawGLInfoVersion; | 
| 144 process_info.mode = AwDrawGLInfo::kModeSync; | 155 process_info.mode = AwDrawGLInfo::kModeSync; | 
| 145 | 156 | 
| 146 hooks_->WillSyncOnRT(functor_); | 157 hooks_->WillSyncOnRT(functor_); | 
| 147 functor_->DrawGL(&process_info); | 158 functor_->DrawGL(&process_info); | 
| 148 hooks_->DidSyncOnRT(functor_); | 159 hooks_->DidSyncOnRT(functor_); | 
| 149 } | 160 } | 
| 150 sync->Signal(); | 161 | 
| 162 if (!will_wait_for_mode_draw_to_finish_) { | |
| 163 sync->Signal(); | |
| 164 } | |
| 151 | 165 | 
| 152 AwDrawGLInfo draw_info; | 166 AwDrawGLInfo draw_info; | 
| 153 draw_info.version = kAwDrawGLInfoVersion; | 167 draw_info.version = kAwDrawGLInfoVersion; | 
| 154 draw_info.mode = AwDrawGLInfo::kModeDraw; | 168 draw_info.mode = AwDrawGLInfo::kModeDraw; | 
| 155 draw_info.clip_left = location.x(); | 169 draw_info.clip_left = location.x(); | 
| 156 draw_info.clip_top = location.y(); | 170 draw_info.clip_top = location.y(); | 
| 157 draw_info.clip_right = location.x() + location.width(); | 171 draw_info.clip_right = location.x() + location.width(); | 
| 158 draw_info.clip_bottom = location.y() + location.height(); | 172 draw_info.clip_bottom = location.y() + location.height(); | 
| 159 draw_info.width = surface_size_.width(); | |
| 160 draw_info.height = surface_size_.height(); | |
| 161 draw_info.is_layer = false; | |
| 162 | 173 | 
| 163 draw_info.transform[0] = 1.0; | 174 hooks_->SetParentDrawConstraints(draw_info); | 
| 164 draw_info.transform[1] = 0.0; | |
| 165 draw_info.transform[2] = 0.0; | |
| 166 draw_info.transform[3] = 0.0; | |
| 167 | 175 | 
| 168 draw_info.transform[4] = 0.0; | 176 if (!hooks_->WillDrawOnRT(functor_)) { | 
| 169 draw_info.transform[5] = 1.0; | 177 if (will_wait_for_mode_draw_to_finish_) { | 
| 170 draw_info.transform[6] = 0.0; | 178 sync->Signal(); | 
| 171 draw_info.transform[7] = 0.0; | 179 } | 
| 180 return; | |
| 181 } | |
| 172 | 182 | 
| 173 draw_info.transform[8] = 0.0; | |
| 174 draw_info.transform[9] = 0.0; | |
| 175 draw_info.transform[10] = 1.0; | |
| 176 draw_info.transform[11] = 0.0; | |
| 177 | |
| 178 draw_info.transform[12] = 0.0; | |
| 179 draw_info.transform[13] = 0.0; | |
| 180 draw_info.transform[14] = 0.0; | |
| 181 draw_info.transform[15] = 1.0; | |
| 182 | |
| 183 hooks_->WillDrawOnRT(functor_); | |
| 184 { | 183 { | 
| 185 ScopedMakeCurrent make_current(this); | 184 ScopedMakeCurrent make_current(this); | 
| 186 functor_->DrawGL(&draw_info); | 185 functor_->DrawGL(&draw_info); | 
| 187 } | 186 } | 
| 188 hooks_->DidDrawOnRT(functor_); | 187 hooks_->DidDrawOnRT(functor_); | 
| 188 if (will_wait_for_mode_draw_to_finish_) { | |
| 189 sync->Signal(); | |
| 190 } | |
| 189 } | 191 } | 
| 190 | 192 | 
| 191 void FakeWindow::CheckCurrentlyOnUIThread() { | 193 void FakeWindow::CheckCurrentlyOnUIThread() { | 
| 192 DCHECK(ui_checker_.CalledOnValidSequencedThread()); | 194 DCHECK(ui_checker_.CalledOnValidSequencedThread()); | 
| 193 } | 195 } | 
| 194 | 196 | 
| 195 void FakeWindow::CreateRenderThreadIfNeeded() { | 197 void FakeWindow::CreateRenderThreadIfNeeded() { | 
| 196 CheckCurrentlyOnUIThread(); | 198 CheckCurrentlyOnUIThread(); | 
| 197 if (functor_) { | 199 if (functor_) { | 
| 198 DCHECK(render_thread_.get()); | 200 DCHECK(render_thread_.get()); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 surface_ = nullptr; | 233 surface_ = nullptr; | 
| 232 } | 234 } | 
| 233 sync->Signal(); | 235 sync->Signal(); | 
| 234 } | 236 } | 
| 235 | 237 | 
| 236 void FakeWindow::CheckCurrentlyOnRT() { | 238 void FakeWindow::CheckCurrentlyOnRT() { | 
| 237 DCHECK(rt_checker_.CalledOnValidSequencedThread()); | 239 DCHECK(rt_checker_.CalledOnValidSequencedThread()); | 
| 238 } | 240 } | 
| 239 | 241 | 
| 240 } // namespace android_webview | 242 } // namespace android_webview | 
| OLD | NEW |