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