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_initialized_(false) { | 31 inside_tear_down_(false), |
| 32 hardware_initialized_(false), |
| 33 share_context_(NULL) { |
27 DCHECK(ui_loop_->BelongsToCurrentThread()); | 34 DCHECK(ui_loop_->BelongsToCurrentThread()); |
28 DCHECK(client_on_ui_); | 35 DCHECK(client_on_ui_); |
29 } | 36 } |
30 | 37 |
31 SharedRendererState::~SharedRendererState() {} | 38 SharedRendererState::~SharedRendererState() {} |
32 | 39 |
33 void SharedRendererState::ClientRequestDrawGL() { | 40 void SharedRendererState::ClientRequestDrawGL() { |
34 if (ui_loop_->BelongsToCurrentThread()) { | 41 if (ui_loop_->BelongsToCurrentThread()) { |
35 ClientRequestDrawGLOnUIThread(); | 42 ClientRequestDrawGLOnUIThread(); |
36 } else { | 43 } else { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 memory_policy_dirty_ = true; | 76 memory_policy_dirty_ = true; |
70 } | 77 } |
71 } | 78 } |
72 | 79 |
73 content::SynchronousCompositorMemoryPolicy | 80 content::SynchronousCompositorMemoryPolicy |
74 SharedRendererState::GetMemoryPolicy() const { | 81 SharedRendererState::GetMemoryPolicy() const { |
75 base::AutoLock lock(lock_); | 82 base::AutoLock lock(lock_); |
76 return memory_policy_; | 83 return memory_policy_; |
77 } | 84 } |
78 | 85 |
79 void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) { | 86 void SharedRendererState::SetDrawGLInput(scoped_ptr<DrawGLInput> input) { |
80 base::AutoLock lock(lock_); | 87 base::AutoLock lock(lock_); |
81 draw_gl_input_ = input; | 88 DCHECK(!draw_gl_input_.get()); |
| 89 draw_gl_input_ = input.Pass(); |
82 } | 90 } |
83 | 91 |
84 DrawGLInput SharedRendererState::GetDrawGLInput() const { | 92 scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() { |
85 base::AutoLock lock(lock_); | 93 base::AutoLock lock(lock_); |
86 return draw_gl_input_; | 94 return draw_gl_input_.Pass(); |
87 } | 95 } |
88 | 96 |
89 void SharedRendererState::ClearClosureQueue() { | 97 void SharedRendererState::SetInsideTeardown(bool inside_tear_down) { |
90 base::AutoLock lock(lock_); | 98 base::AutoLock lock(lock_); |
91 std::queue<base::Closure> empty; | 99 inside_tear_down_ = inside_tear_down; |
92 std::swap(closure_queue_, empty); | |
93 } | 100 } |
94 | 101 |
95 void SharedRendererState::AppendClosure(const base::Closure& closure) { | 102 bool SharedRendererState::IsInsideTeardown() const { |
96 base::AutoLock lock(lock_); | 103 base::AutoLock lock(lock_); |
97 closure_queue_.push(closure); | 104 return inside_tear_down_; |
98 } | |
99 | |
100 base::Closure SharedRendererState::PopFrontClosure() { | |
101 base::Closure closure; | |
102 | |
103 base::AutoLock lock(lock_); | |
104 if (!closure_queue_.empty()) { | |
105 closure = closure_queue_.front(); | |
106 closure_queue_.pop(); | |
107 } | |
108 | |
109 return closure; | |
110 } | 105 } |
111 | 106 |
112 void SharedRendererState::SetHardwareInitialized(bool initialized) { | 107 void SharedRendererState::SetHardwareInitialized(bool initialized) { |
113 base::AutoLock lock(lock_); | 108 base::AutoLock lock(lock_); |
114 hardware_initialized_ = initialized; | 109 hardware_initialized_ = initialized; |
115 } | 110 } |
116 | 111 |
117 bool SharedRendererState::IsHardwareInitialized() const { | 112 bool SharedRendererState::IsHardwareInitialized() const { |
118 base::AutoLock lock(lock_); | 113 base::AutoLock lock(lock_); |
119 return hardware_initialized_; | 114 return hardware_initialized_; |
120 } | 115 } |
121 | 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 |
122 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { | 129 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { |
123 base::AutoLock lock(lock_); | 130 base::AutoLock lock(lock_); |
124 memory_policy_dirty_ = is_dirty; | 131 memory_policy_dirty_ = is_dirty; |
125 } | 132 } |
126 | 133 |
127 bool SharedRendererState::IsMemoryPolicyDirty() const { | 134 bool SharedRendererState::IsMemoryPolicyDirty() const { |
128 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
129 return memory_policy_dirty_; | 136 return memory_policy_dirty_; |
130 } | 137 } |
131 | 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 |
132 } // namespace android_webview | 163 } // namespace android_webview |
OLD | NEW |