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_SHARED_RENDERER_STATE_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ |
6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ |
7 | 7 |
8 #include <queue> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/compositor_frame_ack.h" |
13 #include "content/public/browser/android/synchronous_compositor.h" | 12 #include "content/public/browser/android/synchronous_compositor.h" |
14 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/vector2d.h" | 14 #include "ui/gfx/geometry/vector2d.h" |
16 | 15 |
| 16 namespace cc { |
| 17 class CompositorFrameAck; |
| 18 } |
| 19 |
| 20 namespace gpu { |
| 21 class GLInProcessContext; |
| 22 } |
| 23 |
17 namespace android_webview { | 24 namespace android_webview { |
18 | 25 |
19 class BrowserViewRendererClient; | 26 class BrowserViewRendererClient; |
20 | 27 |
21 // Set by BrowserViewRenderer and read by HardwareRenderer. | 28 // Set by BrowserViewRenderer and read by HardwareRenderer. |
22 struct DrawGLInput { | 29 struct DrawGLInput { |
23 unsigned int frame_id; | |
24 gfx::Rect global_visible_rect; | 30 gfx::Rect global_visible_rect; |
25 gfx::Vector2d scroll_offset; | 31 gfx::Vector2d scroll_offset; |
26 int width; | 32 int width; |
27 int height; | 33 int height; |
| 34 cc::CompositorFrame frame; |
28 | 35 |
29 DrawGLInput(); | 36 DrawGLInput(); |
| 37 ~DrawGLInput(); |
30 }; | 38 }; |
31 | 39 |
32 // Set by HardwareRenderer and read by BrowserViewRenderer. | 40 // Set by HardwareRenderer and read by BrowserViewRenderer. |
33 struct DrawGLResult { | 41 struct DrawGLResult { |
34 unsigned int frame_id; | |
35 bool clip_contains_visible_rect; | 42 bool clip_contains_visible_rect; |
36 | 43 |
37 DrawGLResult(); | 44 DrawGLResult(); |
38 }; | 45 }; |
39 | 46 |
40 // This class holds renderer state that is shared between UI and RT threads. | 47 // This class holds renderer state that is shared between UI and RT threads. |
41 // Android framework will block the UI thread when RT is drawing, so no locking | 48 // Android framework will block the UI thread when RT is drawing, so no locking |
42 // is needed in this class. In the interim, this class is also responsible for | 49 // is needed in this class. In the interim, this class is also responsible for |
43 // thread hopping that should eventually be removed once RT support work is | 50 // thread hopping that should eventually be removed once RT support work is |
44 // complete. | 51 // complete. |
45 class SharedRendererState { | 52 class SharedRendererState { |
46 public: | 53 public: |
47 SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop, | 54 SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop, |
48 BrowserViewRendererClient* client); | 55 BrowserViewRendererClient* client); |
49 ~SharedRendererState(); | 56 ~SharedRendererState(); |
50 | 57 |
51 void ClientRequestDrawGL(); | 58 void ClientRequestDrawGL(); |
52 | 59 |
53 // This function should only be called on UI thread. | 60 // This function should only be called on UI thread. |
54 void SetCompositorOnUiThread(content::SynchronousCompositor* compositor); | 61 void SetCompositorOnUiThread(content::SynchronousCompositor* compositor); |
55 | 62 |
56 // This function can be called on both UI and RT thread. | 63 // This function can be called on both UI and RT thread. |
57 content::SynchronousCompositor* GetCompositor(); | 64 content::SynchronousCompositor* GetCompositor(); |
58 | 65 |
59 void SetMemoryPolicy(const content::SynchronousCompositorMemoryPolicy policy); | 66 void SetMemoryPolicy(const content::SynchronousCompositorMemoryPolicy policy); |
60 content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() const; | 67 content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() const; |
61 | 68 |
62 void SetMemoryPolicyDirty(bool is_dirty); | 69 void SetMemoryPolicyDirty(bool is_dirty); |
63 bool IsMemoryPolicyDirty() const; | 70 bool IsMemoryPolicyDirty() const; |
64 void SetDrawGLInput(const DrawGLInput& input); | 71 void SetDrawGLInput(scoped_ptr<DrawGLInput> input); |
65 DrawGLInput GetDrawGLInput() const; | 72 scoped_ptr<DrawGLInput> PassDrawGLInput(); |
66 | 73 |
67 void ClearClosureQueue(); | 74 // Set by UI and read by RT. |
68 void AppendClosure(const base::Closure& closure); | 75 void SetInsideTeardown(bool inside); |
69 // Will return empty closure if queue empty. | 76 bool IsInsideTeardown() const; |
70 base::Closure PopFrontClosure(); | |
71 | 77 |
| 78 // Set by RT and read by UI. |
72 void SetHardwareInitialized(bool initialized); | 79 void SetHardwareInitialized(bool initialized); |
73 bool IsHardwareInitialized() const; | 80 bool IsHardwareInitialized() const; |
74 | 81 |
| 82 void SetSharedContext(gpu::GLInProcessContext* context); |
| 83 gpu::GLInProcessContext* GetSharedContext() const; |
| 84 |
| 85 void ReturnResources(const cc::TransferableResourceArray& input); |
| 86 void InsertReturnedResources(const cc::ReturnedResourceArray& resources); |
| 87 void SwapReturnedResources(cc::ReturnedResourceArray* resources); |
| 88 bool ReturnedResourcesEmpty() const; |
| 89 |
75 private: | 90 private: |
76 void ClientRequestDrawGLOnUIThread(); | 91 void ClientRequestDrawGLOnUIThread(); |
77 | 92 |
78 scoped_refptr<base::MessageLoopProxy> ui_loop_; | 93 scoped_refptr<base::MessageLoopProxy> ui_loop_; |
79 // TODO(boliu): Remove |client_on_ui_| from shared state. | 94 // TODO(boliu): Remove |client_on_ui_| from shared state. |
80 BrowserViewRendererClient* client_on_ui_; | 95 BrowserViewRendererClient* client_on_ui_; |
81 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; | 96 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; |
82 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; | 97 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; |
83 | 98 |
84 // Accessed by both UI and RT thread. | 99 // Accessed by both UI and RT thread. |
85 mutable base::Lock lock_; | 100 mutable base::Lock lock_; |
86 content::SynchronousCompositor* compositor_; | 101 content::SynchronousCompositor* compositor_; |
87 content::SynchronousCompositorMemoryPolicy memory_policy_; | 102 content::SynchronousCompositorMemoryPolicy memory_policy_; |
88 // Set to true when SetMemoryPolicy called with a different memory policy. | 103 // Set to true when SetMemoryPolicy called with a different memory policy. |
89 // Set to false when memory policy is read and enforced to compositor. | 104 // Set to false when memory policy is read and enforced to compositor. |
90 bool memory_policy_dirty_; | 105 bool memory_policy_dirty_; |
91 DrawGLInput draw_gl_input_; | 106 scoped_ptr<DrawGLInput> draw_gl_input_; |
92 std::queue<base::Closure> closure_queue_; | 107 bool inside_tear_down_; |
93 bool hardware_initialized_; | 108 bool hardware_initialized_; |
| 109 gpu::GLInProcessContext* share_context_; |
| 110 cc::ReturnedResourceArray returned_resources_; |
94 }; | 111 }; |
95 | 112 |
96 } // namespace android_webview | 113 } // namespace android_webview |
97 | 114 |
98 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 115 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ |
OLD | NEW |