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> | 8 #include <queue> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/output/compositor_frame_ack.h" |
13 #include "content/public/browser/android/synchronous_compositor.h" | 15 #include "content/public/browser/android/synchronous_compositor.h" |
14 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/vector2d.h" | 17 #include "ui/gfx/geometry/vector2d.h" |
16 | 18 |
| 19 namespace cc { |
| 20 class CompositorFrameAck; |
| 21 } |
| 22 |
17 namespace android_webview { | 23 namespace android_webview { |
18 | 24 |
19 class BrowserViewRendererClient; | 25 class BrowserViewRendererClient; |
20 | 26 |
21 // Set by BrowserViewRenderer and read by HardwareRenderer. | 27 // Set by BrowserViewRenderer and read by HardwareRenderer. |
22 struct DrawGLInput { | 28 struct DrawGLInput { |
23 unsigned int frame_id; | 29 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; | 42 unsigned int frame_id; |
35 bool clip_contains_visible_rect; | 43 bool clip_contains_visible_rect; |
36 | 44 |
37 DrawGLResult(); | 45 DrawGLResult(); |
| 46 ~DrawGLResult(); |
38 }; | 47 }; |
39 | 48 |
40 // This class holds renderer state that is shared between UI and RT threads. | 49 // 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 | 50 // 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 | 51 // 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 | 52 // thread hopping that should eventually be removed once RT support work is |
44 // complete. | 53 // complete. |
45 class SharedRendererState { | 54 class SharedRendererState { |
46 public: | 55 public: |
47 SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop, | 56 SharedRendererState(scoped_refptr<base::MessageLoopProxy> ui_loop, |
48 BrowserViewRendererClient* client); | 57 BrowserViewRendererClient* client); |
49 ~SharedRendererState(); | 58 ~SharedRendererState(); |
50 | 59 |
51 void ClientRequestDrawGL(); | 60 void ClientRequestDrawGL(); |
52 | 61 |
53 // This function should only be called on UI thread. | 62 // This function should only be called on UI thread. |
54 void SetCompositorOnUiThread(content::SynchronousCompositor* compositor); | 63 void SetCompositorOnUiThread(content::SynchronousCompositor* compositor); |
55 | 64 |
56 // This function can be called on both UI and RT thread. | 65 // This function can be called on both UI and RT thread. |
57 content::SynchronousCompositor* GetCompositor(); | 66 content::SynchronousCompositor* GetCompositor(); |
58 | 67 |
59 void SetMemoryPolicy(const content::SynchronousCompositorMemoryPolicy policy); | 68 void SetMemoryPolicy(const content::SynchronousCompositorMemoryPolicy policy); |
60 content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() const; | 69 content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() const; |
61 | 70 |
62 void SetMemoryPolicyDirty(bool is_dirty); | 71 void SetMemoryPolicyDirty(bool is_dirty); |
63 bool IsMemoryPolicyDirty() const; | 72 bool IsMemoryPolicyDirty() const; |
64 void SetDrawGLInput(const DrawGLInput& input); | 73 scoped_ptr<DrawGLInput> SetDrawGLInput(scoped_ptr<DrawGLInput> input); |
65 DrawGLInput GetDrawGLInput() const; | 74 scoped_ptr<DrawGLInput> PassDrawGLInput(); |
66 | 75 |
67 void ClearClosureQueue(); | 76 void ClearClosureQueue(); |
68 void AppendClosure(const base::Closure& closure); | 77 void AppendClosure(const base::Closure& closure); |
69 // Will return empty closure if queue empty. | 78 // Will return empty closure if queue empty. |
70 base::Closure PopFrontClosure(); | 79 base::Closure PopFrontClosure(); |
71 | 80 |
72 void SetHardwareInitialized(bool initialized); | 81 void SetHardwareInitialized(bool initialized); |
73 bool IsHardwareInitialized() const; | 82 bool IsHardwareInitialized() const; |
74 | 83 |
| 84 // TODO(boliu): Remove this. |
| 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 std::queue<base::Closure> closure_queue_; |
93 bool hardware_initialized_; | 108 bool hardware_initialized_; |
| 109 cc::ReturnedResourceArray returned_resources_; |
94 }; | 110 }; |
95 | 111 |
96 } // namespace android_webview | 112 } // namespace android_webview |
97 | 113 |
98 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 114 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ |
OLD | NEW |