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

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

Issue 1943963003: WIP Handle AwContents needing multiple live functors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Testing framework changes to support testing multiple RenderThreadManager instances. Created 4 years, 7 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 #ifndef ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ 5 #ifndef ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_
6 #define ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ 6 #define ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "android_webview/browser/render_thread_manager.h"
boliu 2016/05/10 15:18:19 forward declare?
Tobias Sargeant 2016/05/13 13:23:57 Done.
11 #include "android_webview/browser/render_thread_manager_client.h"
10 #include "android_webview/public/browser/draw_gl.h" 12 #include "android_webview/public/browser/draw_gl.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
13 #include "base/sequence_checker.h" 15 #include "base/sequence_checker.h"
14 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
15 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gl/gl_context.h" 18 #include "ui/gl/gl_context.h"
17 #include "ui/gl/gl_surface.h" 19 #include "ui/gl/gl_surface.h"
18 20
19 namespace base { 21 namespace base {
20 class Thread; 22 class Thread;
21 class WaitableEvent; 23 class WaitableEvent;
22 } 24 }
23 25
24 namespace android_webview { 26 namespace android_webview {
25 27
26 class BrowserViewRenderer; 28 class BrowserViewRenderer;
29 class Functor;
27 30
28 class WindowHooks { 31 class WindowHooks {
29 public: 32 public:
30 virtual ~WindowHooks() {} 33 virtual ~WindowHooks() {}
31 34
32 virtual void WillOnDraw() = 0; 35 virtual void WillOnDraw() = 0;
33 virtual void DidOnDraw(bool success) = 0; 36 virtual void DidOnDraw(bool success) = 0;
34 37
35 virtual void WillSyncOnRT() = 0; 38 virtual void WillSyncOnRT() = 0;
36 virtual void DidSyncOnRT() = 0; 39 virtual void DidSyncOnRT() = 0;
37 virtual void WillProcessOnRT() = 0; 40 virtual void WillProcessOnRT() = 0;
38 virtual void DidProcessOnRT() = 0; 41 virtual void DidProcessOnRT() = 0;
39 virtual bool WillDrawOnRT(AwDrawGLInfo* draw_info) = 0; 42 virtual bool WillDrawOnRT(AwDrawGLInfo* draw_info) = 0;
40 virtual void DidDrawOnRT() = 0; 43 virtual void DidDrawOnRT() = 0;
41 }; 44 };
42 45
43 class FakeWindow { 46 class FakeWindow {
44 public: 47 public:
45 using DrawGLCallback = base::Callback<void(AwDrawGLInfo*)>; 48 FakeWindow(BrowserViewRenderer* view, WindowHooks* hooks, gfx::Rect location);
46
47 FakeWindow(BrowserViewRenderer* view,
48 const DrawGLCallback& draw_gl,
49 WindowHooks* hooks,
50 gfx::Rect location);
51 ~FakeWindow(); 49 ~FakeWindow();
52 50
53 void Detach(); 51 void Detach();
54 52
55 // BrowserViewRendererClient methods. 53 void RequestInvokeGL(Functor* functor, bool wait_for_completion);
56 void RequestInvokeGL(bool wait_for_completion);
57 void PostInvalidate(); 54 void PostInvalidate();
58 const gfx::Size& surface_size() { return surface_size_; } 55 const gfx::Size& surface_size() { return surface_size_; }
59 56
57 void SetDrawFunctor(Functor* functor);
58 void RequestDrawGL(Functor* functor);
59
60 private: 60 private:
61 class ScopedMakeCurrent; 61 class ScopedMakeCurrent;
62 62
63 void OnDrawHardware(); 63 void OnDrawHardware();
64 void CheckCurrentlyOnUIThread(); 64 void CheckCurrentlyOnUIThread();
65 void CreateRenderThreadIfNeeded(); 65 void CreateRenderThreadIfNeeded();
66 66
67 void InitializeOnRT(base::WaitableEvent* sync); 67 void InitializeOnRT(base::WaitableEvent* sync);
68 void DestroyOnRT(base::WaitableEvent* sync); 68 void DestroyOnRT(base::WaitableEvent* sync);
69 void ProcessFunctorOnRT(base::WaitableEvent* sync); 69 void InvokeFunctorOnRT(Functor* functor, base::WaitableEvent* sync);
70 void DrawFunctorOnRT(base::WaitableEvent* sync); 70 void ProcessSyncOnRT(Functor* functor, base::WaitableEvent* sync);
71 void ProcessDrawOnRT(Functor* functor);
72 void DrawFunctorOnRT(Functor* functor, base::WaitableEvent* sync);
71 void CheckCurrentlyOnRT(); 73 void CheckCurrentlyOnRT();
boliu 2016/05/10 15:18:19 style: keep blank line below
Tobias Sargeant 2016/05/13 13:23:56 Done.
72
73 // const so can be used on both threads. 74 // const so can be used on both threads.
74 BrowserViewRenderer* const view_; 75 BrowserViewRenderer* const view_;
75 WindowHooks* const hooks_; 76 WindowHooks* const hooks_;
76 const gfx::Size surface_size_; 77 const gfx::Size surface_size_;
77 78
78 // UI thread members. 79 // UI thread members.
79 gfx::Rect location_; 80 gfx::Rect location_;
80 bool on_draw_hardware_pending_; 81 bool on_draw_hardware_pending_;
81 base::SequenceChecker ui_checker_; 82 base::SequenceChecker ui_checker_;
82 83
83 // Render thread members. 84 // Render thread members.
84 std::unique_ptr<base::Thread> render_thread_; 85 std::unique_ptr<base::Thread> render_thread_;
85 base::SequenceChecker rt_checker_; 86 base::SequenceChecker rt_checker_;
86 DrawGLCallback draw_gl_;
87 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_; 87 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_;
88 scoped_refptr<gfx::GLSurface> surface_; 88 scoped_refptr<gfx::GLSurface> surface_;
89 scoped_refptr<gfx::GLContext> context_; 89 scoped_refptr<gfx::GLContext> context_;
90 bool context_current_; 90 bool context_current_;
91 Functor* functor_;
boliu 2016/05/10 15:18:19 there is nothing really guaranteeing lifetime betw
Tobias Sargeant 2016/05/13 13:23:57 True. It's slightly better now that FakeWindow doe
91 92
92 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_; 93 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(FakeWindow); 95 DISALLOW_COPY_AND_ASSIGN(FakeWindow);
95 }; 96 };
96 97
98 class Functor : public RenderThreadManagerClient {
boliu 2016/05/10 15:18:19 TestFunctor or something that implies it's not a p
Tobias Sargeant 2016/05/13 13:23:57 Done.
99 public:
100 using DrawGLCallback = base::Callback<void(AwDrawGLInfo*)>;
101 using RenderThreadManagerFactory =
102 base::Callback<RenderThreadManager*(RenderThreadManagerClient*)>;
103
104 Functor(RenderThreadManagerFactory render_thread_manager_factory);
boliu 2016/05/10 15:18:19 explicit, const&
Tobias Sargeant 2016/05/13 13:23:57 Took your Init suggestion, no need for this constr
105 ~Functor() override;
106
107 CompositorFrameConsumer* GetCompositorFrameConsumer();
108 void Attach(FakeWindow* window);
109 void Sync(const gfx::Rect& location,
110 base::WaitableEvent* sync,
111 WindowHooks* hooks);
112 void Draw(WindowHooks* hooks);
113 void Invoke(base::WaitableEvent* sync, WindowHooks* hooks);
114
115 // RenderThreadManagerClient overrides
116 bool RequestInvokeGL(bool wait_for_completion) override;
117 void DetachFunctorFromView() override;
118
119 private:
120 FakeWindow* window_;
121 DrawGLCallback callback_;
122 std::unique_ptr<RenderThreadManager> render_thread_manager_;
123 gfx::Rect committed_location_;
124 };
125
97 } // namespace android_webview 126 } // namespace android_webview
98 127
99 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ 128 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698