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 #include "android_webview/browser/shared_renderer_state.h" | 5 #include "android_webview/browser/shared_renderer_state.h" |
6 | 6 |
7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 | 10 |
11 namespace android_webview { | 11 namespace android_webview { |
12 | 12 |
13 DrawGLInput::DrawGLInput() : frame_id(0), width(0), height(0) {} | 13 DrawGLInput::DrawGLInput() : width(0), height(0) { |
| 14 } |
14 | 15 |
15 DrawGLResult::DrawGLResult() : frame_id(0), clip_contains_visible_rect(false) {} | 16 DrawGLInput::~DrawGLInput() { |
| 17 } |
| 18 |
| 19 DrawGLResult::DrawGLResult() : clip_contains_visible_rect(false) { |
| 20 } |
16 | 21 |
17 SharedRendererState::SharedRendererState( | 22 SharedRendererState::SharedRendererState( |
18 scoped_refptr<base::MessageLoopProxy> ui_loop, | 23 scoped_refptr<base::MessageLoopProxy> ui_loop, |
19 BrowserViewRendererClient* client) | 24 BrowserViewRendererClient* client) |
20 : ui_loop_(ui_loop), | 25 : ui_loop_(ui_loop), |
21 client_on_ui_(client), | 26 client_on_ui_(client), |
22 weak_factory_on_ui_thread_(this), | 27 weak_factory_on_ui_thread_(this), |
23 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), | 28 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), |
24 compositor_(NULL), | 29 compositor_(NULL), |
25 memory_policy_dirty_(false), | 30 memory_policy_dirty_(false), |
26 hardware_allowed_(false), | 31 hardware_allowed_(false), |
27 hardware_initialized_(false) { | 32 hardware_initialized_(false), |
| 33 share_context_(NULL) { |
28 DCHECK(ui_loop_->BelongsToCurrentThread()); | 34 DCHECK(ui_loop_->BelongsToCurrentThread()); |
29 DCHECK(client_on_ui_); | 35 DCHECK(client_on_ui_); |
30 } | 36 } |
31 | 37 |
32 SharedRendererState::~SharedRendererState() {} | 38 SharedRendererState::~SharedRendererState() {} |
33 | 39 |
34 void SharedRendererState::ClientRequestDrawGL() { | 40 void SharedRendererState::ClientRequestDrawGL() { |
35 if (ui_loop_->BelongsToCurrentThread()) { | 41 if (ui_loop_->BelongsToCurrentThread()) { |
36 ClientRequestDrawGLOnUIThread(); | 42 ClientRequestDrawGLOnUIThread(); |
37 } else { | 43 } else { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 memory_policy_dirty_ = true; | 76 memory_policy_dirty_ = true; |
71 } | 77 } |
72 } | 78 } |
73 | 79 |
74 content::SynchronousCompositorMemoryPolicy | 80 content::SynchronousCompositorMemoryPolicy |
75 SharedRendererState::GetMemoryPolicy() const { | 81 SharedRendererState::GetMemoryPolicy() const { |
76 base::AutoLock lock(lock_); | 82 base::AutoLock lock(lock_); |
77 return memory_policy_; | 83 return memory_policy_; |
78 } | 84 } |
79 | 85 |
80 void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) { | 86 void SharedRendererState::SetDrawGLInput(scoped_ptr<DrawGLInput> input) { |
81 base::AutoLock lock(lock_); | 87 base::AutoLock lock(lock_); |
82 draw_gl_input_ = input; | 88 DCHECK(!draw_gl_input_.get()); |
| 89 draw_gl_input_ = input.Pass(); |
83 } | 90 } |
84 | 91 |
85 DrawGLInput SharedRendererState::GetDrawGLInput() const { | 92 scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() { |
86 base::AutoLock lock(lock_); | 93 base::AutoLock lock(lock_); |
87 return draw_gl_input_; | 94 return draw_gl_input_.Pass(); |
88 } | 95 } |
89 | 96 |
90 void SharedRendererState::SetHardwareAllowed(bool allowed) { | 97 void SharedRendererState::SetHardwareAllowed(bool allowed) { |
91 base::AutoLock lock(lock_); | 98 base::AutoLock lock(lock_); |
92 hardware_allowed_ = allowed; | 99 hardware_allowed_ = allowed; |
93 } | 100 } |
94 | 101 |
95 bool SharedRendererState::IsHardwareAllowed() const { | 102 bool SharedRendererState::IsHardwareAllowed() const { |
96 base::AutoLock lock(lock_); | 103 base::AutoLock lock(lock_); |
97 return hardware_allowed_; | 104 return hardware_allowed_; |
98 } | 105 } |
99 | 106 |
100 void SharedRendererState::SetHardwareInitialized(bool initialized) { | 107 void SharedRendererState::SetHardwareInitialized(bool initialized) { |
101 base::AutoLock lock(lock_); | 108 base::AutoLock lock(lock_); |
102 hardware_initialized_ = initialized; | 109 hardware_initialized_ = initialized; |
103 } | 110 } |
104 | 111 |
105 bool SharedRendererState::IsHardwareInitialized() const { | 112 bool SharedRendererState::IsHardwareInitialized() const { |
106 base::AutoLock lock(lock_); | 113 base::AutoLock lock(lock_); |
107 return hardware_initialized_; | 114 return hardware_initialized_; |
108 } | 115 } |
109 | 116 |
| 117 void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) { |
| 118 base::AutoLock lock(lock_); |
| 119 DCHECK(!share_context_ || !context); |
| 120 share_context_ = context; |
| 121 } |
| 122 |
| 123 gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const { |
| 124 base::AutoLock lock(lock_); |
| 125 DCHECK(share_context_); |
| 126 return share_context_; |
| 127 } |
| 128 |
110 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { | 129 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { |
111 base::AutoLock lock(lock_); | 130 base::AutoLock lock(lock_); |
112 memory_policy_dirty_ = is_dirty; | 131 memory_policy_dirty_ = is_dirty; |
113 } | 132 } |
114 | 133 |
115 bool SharedRendererState::IsMemoryPolicyDirty() const { | 134 bool SharedRendererState::IsMemoryPolicyDirty() const { |
116 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
117 return memory_policy_dirty_; | 136 return memory_policy_dirty_; |
118 } | 137 } |
119 | 138 |
| 139 void SharedRendererState::ReturnResources( |
| 140 const cc::TransferableResourceArray& input) { |
| 141 base::AutoLock lock(lock_); |
| 142 cc::TransferableResource::ReturnResources(input, &returned_resources_); |
| 143 } |
| 144 |
| 145 void SharedRendererState::InsertReturnedResources( |
| 146 const cc::ReturnedResourceArray& resources) { |
| 147 base::AutoLock lock(lock_); |
| 148 returned_resources_.insert( |
| 149 returned_resources_.end(), resources.begin(), resources.end()); |
| 150 } |
| 151 |
| 152 void SharedRendererState::SwapReturnedResources( |
| 153 cc::ReturnedResourceArray* resources) { |
| 154 base::AutoLock lock(lock_); |
| 155 resources->swap(returned_resources_); |
| 156 } |
| 157 |
| 158 bool SharedRendererState::ReturnedResourcesEmpty() const { |
| 159 base::AutoLock lock(lock_); |
| 160 return returned_resources_.empty(); |
| 161 } |
| 162 |
120 } // namespace android_webview | 163 } // namespace android_webview |
OLD | NEW |