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