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

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: Created 4 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/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();
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 base::ThreadTaskRunnerHandle::Get()->PostTask( 116 base::ThreadTaskRunnerHandle::Get()->PostTask(
113 FROM_HERE, 117 FROM_HERE,
114 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr())); 118 base::Bind(&FakeWindow::OnDrawHardware, weak_ptr_factory_.GetWeakPtr()));
115 } 119 }
116 120
117 void FakeWindow::OnDrawHardware() { 121 void FakeWindow::OnDrawHardware() {
118 CheckCurrentlyOnUIThread(); 122 CheckCurrentlyOnUIThread();
119 DCHECK(on_draw_hardware_pending_); 123 DCHECK(on_draw_hardware_pending_);
120 on_draw_hardware_pending_ = false; 124 on_draw_hardware_pending_ = false;
121 125
122 view_->PrepareToDraw(gfx::Vector2d(), location_); 126 view_->PrepareToDraw(location_);
123 hooks_->WillOnDraw(); 127 hooks_->WillOnDraw();
124 bool success = view_->OnDrawHardware(); 128 scoped_ptr<ChildFrame> frame = view_->OnDrawHardware();
129 bool success = frame.get() != nullptr;
125 hooks_->DidOnDraw(success); 130 hooks_->DidOnDraw(success);
126 if (success) { 131 if (success) {
132 view_->ReturnUnusedResource(functor_->PassUncommittedFrameOnUI());
133 functor_->SetFrameOnUI(std::move(frame));
127 CreateRenderThreadIfNeeded(); 134 CreateRenderThreadIfNeeded();
128 135
129 base::WaitableEvent completion(true, false); 136 base::WaitableEvent completion(true, false);
130 render_thread_loop_->PostTask( 137 render_thread_loop_->PostTask(
131 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT, 138 FROM_HERE, base::Bind(&FakeWindow::DrawFunctorOnRT,
132 base::Unretained(this), &completion)); 139 base::Unretained(this), &completion));
133 completion.Wait(); 140 completion.Wait();
134 } 141 }
135 } 142 }
136 143
(...skipping 29 matching lines...) Expand all
166 } 173 }
167 hooks_->DidDrawOnRT(functor_); 174 hooks_->DidDrawOnRT(functor_);
168 } 175 }
169 176
170 void FakeWindow::CheckCurrentlyOnUIThread() { 177 void FakeWindow::CheckCurrentlyOnUIThread() {
171 DCHECK(ui_checker_.CalledOnValidSequencedThread()); 178 DCHECK(ui_checker_.CalledOnValidSequencedThread());
172 } 179 }
173 180
174 void FakeWindow::CreateRenderThreadIfNeeded() { 181 void FakeWindow::CreateRenderThreadIfNeeded() {
175 CheckCurrentlyOnUIThread(); 182 CheckCurrentlyOnUIThread();
176 if (functor_) { 183 if (render_thread_.get()) {
177 DCHECK(render_thread_.get());
178 DCHECK(render_thread_loop_.get()); 184 DCHECK(render_thread_loop_.get());
179 return; 185 return;
180 } 186 }
181 functor_ = view_->GetAwDrawGLViewContext();
182 render_thread_.reset(new base::Thread("TestRenderThread")); 187 render_thread_.reset(new base::Thread("TestRenderThread"));
183 render_thread_->Start(); 188 render_thread_->Start();
184 render_thread_loop_ = render_thread_->task_runner(); 189 render_thread_loop_ = render_thread_->task_runner();
185 rt_checker_.DetachFromSequence(); 190 rt_checker_.DetachFromSequence();
186 191
187 base::WaitableEvent completion(true, false); 192 base::WaitableEvent completion(true, false);
188 render_thread_loop_->PostTask( 193 render_thread_loop_->PostTask(
189 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this), 194 FROM_HERE, base::Bind(&FakeWindow::InitializeOnRT, base::Unretained(this),
190 &completion)); 195 &completion));
191 completion.Wait(); 196 completion.Wait();
(...skipping 18 matching lines...) Expand all
210 surface_ = nullptr; 215 surface_ = nullptr;
211 } 216 }
212 sync->Signal(); 217 sync->Signal();
213 } 218 }
214 219
215 void FakeWindow::CheckCurrentlyOnRT() { 220 void FakeWindow::CheckCurrentlyOnRT() {
216 DCHECK(rt_checker_.CalledOnValidSequencedThread()); 221 DCHECK(rt_checker_.CalledOnValidSequencedThread());
217 } 222 }
218 223
219 } // namespace android_webview 224 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698