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

Side by Side Diff: android_webview/browser/test/fake_window.cc

Issue 1002013003: Unit Test for WebView animating in and out of screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new test Created 5 years, 9 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/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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 base::MessageLoopProxy::current()->PostTask( 111 base::MessageLoopProxy::current()->PostTask(
113 FROM_HERE, 112 FROM_HERE,
114 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); 113 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr()));
115 } 114 }
116 115
117 void FakeWindow::OnDrawHardware() { 116 void FakeWindow::OnDrawHardware() {
118 CheckCurrentlyOnUIThread(); 117 CheckCurrentlyOnUIThread();
119 DCHECK(on_draw_hardware_pending_); 118 DCHECK(on_draw_hardware_pending_);
120 on_draw_hardware_pending_ = false; 119 on_draw_hardware_pending_ = false;
121 120
121 view_->PrepareToDraw(gfx::Vector2d(), location_);
122 hooks_->WillOnDraw(); 122 hooks_->WillOnDraw();
123 view_->PrepareToDraw(gfx::Vector2d(), location_);
124 bool success = view_->OnDrawHardware(); 123 bool success = view_->OnDrawHardware();
125 hooks_->DidOnDraw(success); 124 hooks_->DidOnDraw(success);
126 if (success) { 125 if (success) {
127 CreateRenderThreadIfNeeded(); 126 CreateRenderThreadIfNeeded();
128 127
129 base::WaitableEvent completion(true, false); 128 base::WaitableEvent completion(true, false);
130 render_thread_loop_->PostTask( 129 render_thread_loop_->PostTask(
131 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, 130 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT,
132 base::Unretained(this), &completion)); 131 base::Unretained(this), &completion));
133 completion.Wait(); 132 completion.Wait();
134 } 133 }
135 } 134 }
136 135
137 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) { 136 void FakeWindow::DrawFunctorOnRT(base::WaitableEvent* sync) {
138 CheckCurrentlyOnRT(); 137 CheckCurrentlyOnRT();
139 // Ok to access UI functions until sync is signalled. 138 // Ok to access UI functions until sync is signalled.
140 gfx::Rect location = location_; 139 gfx::Rect location = location_;
141 { 140 {
142 AwDrawGLInfo process_info; 141 AwDrawGLInfo process_info;
143 process_info.version = kAwDrawGLInfoVersion; 142 process_info.version = kAwDrawGLInfoVersion;
144 process_info.mode = AwDrawGLInfo::kModeSync; 143 process_info.mode = AwDrawGLInfo::kModeSync;
145 144
146 hooks_->WillSyncOnRT(functor_); 145 hooks_->WillSyncOnRT(functor_);
147 functor_->DrawGL(&process_info); 146 functor_->DrawGL(&process_info);
148 hooks_->DidSyncOnRT(functor_); 147 hooks_->DidSyncOnRT(functor_);
149 } 148 }
150 sync->Signal(); 149
150 if (!hooks_->WillWaitForModeDrawToFinish()) {
151 sync->Signal();
152 }
151 153
152 AwDrawGLInfo draw_info; 154 AwDrawGLInfo draw_info;
153 draw_info.version = kAwDrawGLInfoVersion; 155 draw_info.version = kAwDrawGLInfoVersion;
154 draw_info.mode = AwDrawGLInfo::kModeDraw; 156 draw_info.mode = AwDrawGLInfo::kModeDraw;
155 draw_info.clip_left = location.x(); 157 draw_info.clip_left = location.x();
156 draw_info.clip_top = location.y(); 158 draw_info.clip_top = location.y();
157 draw_info.clip_right = location.x() + location.width(); 159 draw_info.clip_right = location.x() + location.width();
158 draw_info.clip_bottom = location.y() + location.height(); 160 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 161
163 draw_info.transform[0] = 1.0; 162 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 163
168 draw_info.transform[4] = 0.0; 164 if (!hooks_->WillDrawOnRT(functor_)) {
169 draw_info.transform[5] = 1.0; 165 if (hooks_->WillWaitForModeDrawToFinish()) {
boliu 2015/03/13 23:51:55 Save the value from above. Don't call it twice. M
hush (inactive) 2015/03/16 18:19:21 I put it as a private member in the class.
170 draw_info.transform[6] = 0.0; 166 sync->Signal();
171 draw_info.transform[7] = 0.0; 167 }
168 return;
169 }
172 170
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 { 171 {
185 ScopedMakeCurrent make_current(this); 172 ScopedMakeCurrent make_current(this);
186 functor_->DrawGL(&draw_info); 173 functor_->DrawGL(&draw_info);
187 } 174 }
188 hooks_->DidDrawOnRT(functor_); 175 hooks_->DidDrawOnRT(functor_);
176 if (hooks_->WillWaitForModeDrawToFinish()) {
boliu 2015/03/13 23:51:55 ditto
hush (inactive) 2015/03/16 18:19:21 Done.
177 sync->Signal();
178 }
189 } 179 }
190 180
191 void FakeWindow::CheckCurrentlyOnUIThread() { 181 void FakeWindow::CheckCurrentlyOnUIThread() {
192 DCHECK(ui_checker_.CalledOnValidSequencedThread()); 182 DCHECK(ui_checker_.CalledOnValidSequencedThread());
193 } 183 }
194 184
195 void FakeWindow::CreateRenderThreadIfNeeded() { 185 void FakeWindow::CreateRenderThreadIfNeeded() {
196 CheckCurrentlyOnUIThread(); 186 CheckCurrentlyOnUIThread();
197 if (functor_) { 187 if (functor_) {
198 DCHECK(render_thread_.get()); 188 DCHECK(render_thread_.get());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 surface_ = nullptr; 221 surface_ = nullptr;
232 } 222 }
233 sync->Signal(); 223 sync->Signal();
234 } 224 }
235 225
236 void FakeWindow::CheckCurrentlyOnRT() { 226 void FakeWindow::CheckCurrentlyOnRT() {
237 DCHECK(rt_checker_.CalledOnValidSequencedThread()); 227 DCHECK(rt_checker_.CalledOnValidSequencedThread());
238 } 228 }
239 229
240 } // namespace android_webview 230 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698