| OLD | NEW |
| 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* GetFunctor() = 0; |
| 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 RequestDrawGL(FakeFunctor* functor); |
| 60 |
| 60 private: | 61 private: |
| 61 class ScopedMakeCurrent; | 62 class ScopedMakeCurrent; |
| 62 | 63 |
| 63 void OnDrawHardware(); | 64 void OnDrawHardware(); |
| 64 void CheckCurrentlyOnUIThread(); | 65 void CheckCurrentlyOnUIThread(); |
| 65 void CreateRenderThreadIfNeeded(); | 66 void CreateRenderThreadIfNeeded(); |
| 66 | 67 |
| 67 void InitializeOnRT(base::WaitableEvent* sync); | 68 void InitializeOnRT(base::WaitableEvent* sync); |
| 68 void DestroyOnRT(base::WaitableEvent* sync); | 69 void DestroyOnRT(base::WaitableEvent* sync); |
| 69 void ProcessFunctorOnRT(base::WaitableEvent* sync); | 70 void InvokeFunctorOnRT(FakeFunctor* functor, base::WaitableEvent* sync); |
| 70 void DrawFunctorOnRT(base::WaitableEvent* sync); | 71 void ProcessSyncOnRT(FakeFunctor* functor, base::WaitableEvent* sync); |
| 72 void ProcessDrawOnRT(FakeFunctor* functor); |
| 73 void DrawFunctorOnRT(FakeFunctor* functor, base::WaitableEvent* sync); |
| 71 void CheckCurrentlyOnRT(); | 74 void CheckCurrentlyOnRT(); |
| 72 | 75 |
| 73 // const so can be used on both threads. | 76 // const so can be used on both threads. |
| 74 BrowserViewRenderer* const view_; | 77 BrowserViewRenderer* const view_; |
| 75 WindowHooks* const hooks_; | 78 WindowHooks* const hooks_; |
| 76 const gfx::Size surface_size_; | 79 const gfx::Size surface_size_; |
| 77 | 80 |
| 78 // UI thread members. | 81 // UI thread members. |
| 79 gfx::Rect location_; | 82 gfx::Rect location_; |
| 80 bool on_draw_hardware_pending_; | 83 bool on_draw_hardware_pending_; |
| 81 base::SequenceChecker ui_checker_; | 84 base::SequenceChecker ui_checker_; |
| 82 | 85 |
| 83 // Render thread members. | 86 // Render thread members. |
| 84 std::unique_ptr<base::Thread> render_thread_; | 87 std::unique_ptr<base::Thread> render_thread_; |
| 85 base::SequenceChecker rt_checker_; | 88 base::SequenceChecker rt_checker_; |
| 86 DrawGLCallback draw_gl_; | |
| 87 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_; | 89 scoped_refptr<base::SingleThreadTaskRunner> render_thread_loop_; |
| 88 scoped_refptr<gfx::GLSurface> surface_; | 90 scoped_refptr<gfx::GLSurface> surface_; |
| 89 scoped_refptr<gfx::GLContext> context_; | 91 scoped_refptr<gfx::GLContext> context_; |
| 90 bool context_current_; | 92 bool context_current_; |
| 91 | 93 |
| 92 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_; | 94 base::WeakPtrFactory<FakeWindow> weak_ptr_factory_; |
| 93 | 95 |
| 94 DISALLOW_COPY_AND_ASSIGN(FakeWindow); | 96 DISALLOW_COPY_AND_ASSIGN(FakeWindow); |
| 95 }; | 97 }; |
| 96 | 98 |
| 99 class FakeFunctor : public RenderThreadManagerClient { |
| 100 public: |
| 101 using DrawGLCallback = base::Callback<void(AwDrawGLInfo*)>; |
| 102 |
| 103 FakeFunctor(); |
| 104 ~FakeFunctor() override; |
| 105 |
| 106 void Init(FakeWindow* window, |
| 107 std::unique_ptr<RenderThreadManager> render_thread_manager); |
| 108 void Sync(const gfx::Rect& location, WindowHooks* hooks); |
| 109 void Draw(WindowHooks* hooks); |
| 110 void Invoke(WindowHooks* hooks); |
| 111 |
| 112 CompositorFrameConsumer* GetCompositorFrameConsumer(); |
| 113 |
| 114 // RenderThreadManagerClient overrides |
| 115 bool RequestInvokeGL(bool wait_for_completion) override; |
| 116 void DetachFunctorFromView() override; |
| 117 |
| 118 private: |
| 119 FakeWindow* window_; |
| 120 DrawGLCallback callback_; |
| 121 std::unique_ptr<RenderThreadManager> render_thread_manager_; |
| 122 gfx::Rect committed_location_; |
| 123 }; |
| 124 |
| 97 } // namespace android_webview | 125 } // namespace android_webview |
| 98 | 126 |
| 99 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ | 127 #endif // ANDROID_WEBVIEW_BROWSER_TEST_FAKE_WINDOW_H_ |
| OLD | NEW |