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

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

Issue 1816283005: Move SharedRendererState ownership to AwContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: All tests passing Created 4 years, 8 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"
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
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();
boliu 2016/03/30 16:12:13 this is wrong order compared to aw_contents
Tobias Sargeant 2016/03/30 17:17:17 It isn't possible to match the old AwContents orde
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; 80 functor_ = nullptr;
boliu 2016/03/30 16:12:13 Can't do this anymore. Window can attach/detach ma
Tobias Sargeant 2016/03/30 17:17:17 Done.
77 } 81 }
78 82
79 void FakeWindow::RequestDrawGL(bool wait_for_completion) { 83 void FakeWindow::RequestDrawGL(bool wait_for_completion) {
80 CheckCurrentlyOnUIThread(); 84 CheckCurrentlyOnUIThread();
81 base::WaitableEvent completion(true, false); 85 base::WaitableEvent completion(true, false);
82 render_thread_loop_->PostTask( 86 render_thread_loop_->PostTask(
83 FROM_HERE, 87 FROM_HERE,
84 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this), 88 base::Bind(&FakeWindow::ProcessFunctorOnRT, base::Unretained(this),
85 wait_for_completion ? &completion : nullptr)); 89 wait_for_completion ? &completion : nullptr));
86 if (wait_for_completion) 90 if (wait_for_completion)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 170 }
167 hooks_->DidDrawOnRT(functor_); 171 hooks_->DidDrawOnRT(functor_);
168 } 172 }
169 173
170 void FakeWindow::CheckCurrentlyOnUIThread() { 174 void FakeWindow::CheckCurrentlyOnUIThread() {
171 DCHECK(ui_checker_.CalledOnValidSequencedThread()); 175 DCHECK(ui_checker_.CalledOnValidSequencedThread());
172 } 176 }
173 177
174 void FakeWindow::CreateRenderThreadIfNeeded() { 178 void FakeWindow::CreateRenderThreadIfNeeded() {
175 CheckCurrentlyOnUIThread(); 179 CheckCurrentlyOnUIThread();
176 if (functor_) { 180 if (render_thread_.get()) {
boliu 2016/03/30 16:12:13 .get() not needed, can remove them from DCHECKs to
Tobias Sargeant 2016/03/30 17:17:17 Done.
177 DCHECK(render_thread_.get());
178 DCHECK(render_thread_loop_.get()); 181 DCHECK(render_thread_loop_.get());
179 return; 182 return;
180 } 183 }
181 functor_ = view_->GetAwDrawGLViewContext();
182 render_thread_.reset(new base::Thread("TestRenderThread")); 184 render_thread_.reset(new base::Thread("TestRenderThread"));
183 render_thread_->Start(); 185 render_thread_->Start();
184 render_thread_loop_ = render_thread_->task_runner(); 186 render_thread_loop_ = render_thread_->task_runner();
185 rt_checker_.DetachFromSequence(); 187 rt_checker_.DetachFromSequence();
186 188
187 base::WaitableEvent completion(true, false); 189 base::WaitableEvent completion(true, false);
188 render_thread_loop_->PostTask( 190 render_thread_loop_->PostTask(
189 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this), 191 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this),
190 &completion)); 192 &completion));
191 completion.Wait(); 193 completion.Wait();
(...skipping 18 matching lines...) Expand all
210 surface_ = nullptr; 212 surface_ = nullptr;
211 } 213 }
212 sync->Signal(); 214 sync->Signal();
213 } 215 }
214 216
215 void FakeWindow::CheckCurrentlyOnRT() { 217 void FakeWindow::CheckCurrentlyOnRT() {
216 DCHECK(rt_checker_.CalledOnValidSequencedThread()); 218 DCHECK(rt_checker_.CalledOnValidSequencedThread());
217 } 219 }
218 220
219 } // namespace android_webview 221 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698