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

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: 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_client.h"
10 #include "android_webview/public/browser/draw_gl.h" 11 #include "android_webview/public/browser/draw_gl.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/sequence_checker.h" 14 #include "base/sequence_checker.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gl/gl_context.h" 17 #include "ui/gl/gl_context.h"
17 #include "ui/gl/gl_surface.h" 18 #include "ui/gl/gl_surface.h"
18 19
19 namespace base { 20 namespace base {
20 class Thread; 21 class Thread;
21 class WaitableEvent; 22 class WaitableEvent;
22 } 23 }
23 24
24 namespace android_webview { 25 namespace android_webview {
25 26
26 class BrowserViewRenderer; 27 class BrowserViewRenderer;
28 class CompositorFrameConsumer;
29 class FakeFunctor;
30 class RenderThreadManager;
27 31
28 class WindowHooks { 32 class WindowHooks {
29 public: 33 public:
30 virtual ~WindowHooks() {} 34 virtual ~WindowHooks() {}
31 35
32 virtual void WillOnDraw() = 0; 36 virtual void WillOnDraw() = 0;
33 virtual void DidOnDraw(bool success) = 0; 37 virtual void DidOnDraw(bool success) = 0;
38 virtual FakeFunctor* GetFunctorForView(BrowserViewRenderer* view) = 0;
boliu 2016/05/13 16:09:02 nothing uses the parameter afaict, or maybe the ne
34 39
35 virtual void WillSyncOnRT() = 0; 40 virtual void WillSyncOnRT() = 0;
36 virtual void DidSyncOnRT() = 0; 41 virtual void DidSyncOnRT() = 0;
37 virtual void WillProcessOnRT() = 0; 42 virtual void WillProcessOnRT() = 0;
38 virtual void DidProcessOnRT() = 0; 43 virtual void DidProcessOnRT() = 0;
39 virtual bool WillDrawOnRT(AwDrawGLInfo* draw_info) = 0; 44 virtual bool WillDrawOnRT(AwDrawGLInfo* draw_info) = 0;
40 virtual void DidDrawOnRT() = 0; 45 virtual void DidDrawOnRT() = 0;
41 }; 46 };
42 47
43 class FakeWindow { 48 class FakeWindow {
44 public: 49 public:
45 using DrawGLCallback = base::Callback<void(AwDrawGLInfo*)>; 50 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(); 51 ~FakeWindow();
52 52
53 void Detach(); 53 void Detach();
54 54
55 // BrowserViewRendererClient methods. 55 void RequestInvokeGL(FakeFunctor* functor, bool wait_for_completion);
56 void RequestInvokeGL(bool wait_for_completion);
57 void PostInvalidate(); 56 void PostInvalidate();
58 const gfx::Size& surface_size() { return surface_size_; } 57 const gfx::Size& surface_size() { return surface_size_; }
59 58
59 void SetDrawFunctor(FakeFunctor* functor);
60 void RequestDrawGL(FakeFunctor* functor);
61
60 private: 62 private:
61 class ScopedMakeCurrent; 63 class ScopedMakeCurrent;
62 64
63 void OnDrawHardware(); 65 void OnDrawHardware();
64 void CheckCurrentlyOnUIThread(); 66 void CheckCurrentlyOnUIThread();
65 void CreateRenderThreadIfNeeded(); 67 void CreateRenderThreadIfNeeded();
66 68
67 void InitializeOnRT(base::WaitableEvent* sync); 69 void InitializeOnRT(base::WaitableEvent* sync);
68 void DestroyOnRT(base::WaitableEvent* sync); 70 void DestroyOnRT(base::WaitableEvent* sync);
69 void ProcessFunctorOnRT(base::WaitableEvent* sync); 71 void InvokeFunctorOnRT(FakeFunctor* functor, base::WaitableEvent* sync);
70 void DrawFunctorOnRT(base::WaitableEvent* sync); 72 void ProcessSyncOnRT(FakeFunctor* functor, base::WaitableEvent* sync);
73 void ProcessDrawOnRT(FakeFunctor* functor);
74 void DrawFunctorOnRT(FakeFunctor* functor, base::WaitableEvent* sync);
71 void CheckCurrentlyOnRT(); 75 void CheckCurrentlyOnRT();
72 76
73 // const so can be used on both threads. 77 // const so can be used on both threads.
74 BrowserViewRenderer* const view_; 78 BrowserViewRenderer* const view_;
75 WindowHooks* const hooks_; 79 WindowHooks* const hooks_;
76 const gfx::Size surface_size_; 80 const gfx::Size surface_size_;
77 81
78 // UI thread members. 82 // UI thread members.
79 gfx::Rect location_; 83 gfx::Rect location_;
80 bool on_draw_hardware_pending_; 84 bool on_draw_hardware_pending_;
81 base::SequenceChecker ui_checker_; 85 base::SequenceChecker ui_checker_;
82 86
83 // Render thread members. 87 // Render thread members.
84 std::unique_ptr<base::Thread> render_thread_; 88 std::unique_ptr<base::Thread> render_thread_;
85 base::SequenceChecker rt_checker_; 89 base::SequenceChecker rt_checker_;
86 DrawGLCallback draw_gl_;
87 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_; 90 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_;
88 scoped_refptr<gfx::GLSurface> surface_; 91 scoped_refptr<gfx::GLSurface> surface_;
89 scoped_refptr<gfx::GLContext> context_; 92 scoped_refptr<gfx::GLContext> context_;
90 bool context_current_; 93 bool context_current_;
94 FakeFunctor* functor_;
91 95
92 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_; 96 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_;
93 97
94 DISALLOW_COPY_AND_ASSIGN(FakeWindow); 98 DISALLOW_COPY_AND_ASSIGN(FakeWindow);
95 }; 99 };
96 100
101 class FakeFunctor : public RenderThreadManagerClient {
102 public:
103 using DrawGLCallback = base::Callback<void(AwDrawGLInfo*)>;
104 using RenderThreadManagerFactory =
boliu 2016/05/13 16:09:02 remove
Tobias Sargeant 2016/05/13 17:02:37 Done.
105 base::Callback<RenderThreadManager*(RenderThreadManagerClient*)>;
106
107 FakeFunctor();
108 ~FakeFunctor() override;
109
110 CompositorFrameConsumer* GetCompositorFrameConsumer();
111 void Init(FakeWindow* window,
boliu 2016/05/13 16:09:02 nit: Move Init up
Tobias Sargeant 2016/05/13 17:02:37 Done.
112 std::unique_ptr<RenderThreadManager> render_thread_manager);
113 void Sync(const gfx::Rect& location,
114 base::WaitableEvent* sync,
115 WindowHooks* hooks);
116 void Draw(WindowHooks* hooks);
117 void Invoke(base::WaitableEvent* sync, WindowHooks* hooks);
118
119 // RenderThreadManagerClient overrides
120 bool RequestInvokeGL(bool wait_for_completion) override;
121 void DetachFunctorFromView() override;
122
123 private:
124 FakeWindow* window_;
125 DrawGLCallback callback_;
126 std::unique_ptr<RenderThreadManager> render_thread_manager_;
127 gfx::Rect committed_location_;
128 };
129
97 } // namespace android_webview 130 } // namespace android_webview
98 131
99 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ 132 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698