Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: webkit/common/gpu/context_provider_in_process.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: don't access Context3d() in OutputSurface contructors, it's not bound yet Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "webkit/common/gpu/context_provider_in_process.h" 5 #include "webkit/common/gpu/context_provider_in_process.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "cc/output/managed_memory_policy.h"
9 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" 10 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
10 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 11 #include "webkit/common/gpu/managed_memory_policy_convert.h"
11 12
12 namespace webkit { 13 namespace webkit {
13 namespace gpu { 14 namespace gpu {
14 15
15 class ContextProviderInProcess::LostContextCallbackProxy 16 class ContextProviderInProcess::LostContextCallbackProxy
16 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 17 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
17 public: 18 public:
18 explicit LostContextCallbackProxy(ContextProviderInProcess* provider) 19 explicit LostContextCallbackProxy(ContextProviderInProcess* provider)
19 : provider_(provider) { 20 : provider_(provider) {
20 provider_->context3d_->setContextLostCallback(this); 21 provider_->context3d_->setContextLostCallback(this);
21 } 22 }
22 23
23 virtual ~LostContextCallbackProxy() { 24 virtual ~LostContextCallbackProxy() {
24 provider_->context3d_->setContextLostCallback(NULL); 25 provider_->context3d_->setContextLostCallback(NULL);
25 } 26 }
26 27
27 virtual void onContextLost() { 28 virtual void onContextLost() {
28 provider_->OnLostContext(); 29 provider_->OnLostContext();
29 } 30 }
30 31
31 private: 32 private:
32 ContextProviderInProcess* provider_; 33 ContextProviderInProcess* provider_;
33 }; 34 };
34 35
36 class ContextProviderInProcess::SwapBuffersCompleteCallbackProxy
37 : public WebKit::WebGraphicsContext3D::
38 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
39 public:
40 explicit SwapBuffersCompleteCallbackProxy(ContextProviderInProcess* provider)
41 : provider_(provider) {
42 provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this);
43 }
44
45 virtual ~SwapBuffersCompleteCallbackProxy() {
46 provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
47 }
48
49 virtual void onSwapBuffersComplete() {
50 provider_->OnSwapBuffersComplete();
51 }
52
53 private:
54 ContextProviderInProcess* provider_;
55 };
56
35 class ContextProviderInProcess::MemoryAllocationCallbackProxy 57 class ContextProviderInProcess::MemoryAllocationCallbackProxy
36 : public WebKit::WebGraphicsContext3D:: 58 : public WebKit::WebGraphicsContext3D::
37 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { 59 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
38 public: 60 public:
39 explicit MemoryAllocationCallbackProxy(ContextProviderInProcess* provider) 61 explicit MemoryAllocationCallbackProxy(ContextProviderInProcess* provider)
40 : provider_(provider) { 62 : provider_(provider) {
41 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); 63 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
42 } 64 }
43 65
44 virtual ~MemoryAllocationCallbackProxy() { 66 virtual ~MemoryAllocationCallbackProxy() {
45 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); 67 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
46 } 68 }
47 69
48 virtual void onMemoryAllocationChanged( 70 virtual void onMemoryAllocationChanged(
49 WebKit::WebGraphicsMemoryAllocation alloc) { 71 WebKit::WebGraphicsMemoryAllocation allocation) {
50 provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes); 72 provider_->OnMemoryAllocationChanged(allocation);
51 } 73 }
52 74
53 private: 75 private:
54 ContextProviderInProcess* provider_; 76 ContextProviderInProcess* provider_;
55 }; 77 };
56 78
57 // static 79 // static
58 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( 80 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create(
59 const CreateCallback& create_callback) { 81 const CreateCallback& create_callback) {
60 scoped_refptr<ContextProviderInProcess> provider = 82 scoped_refptr<ContextProviderInProcess> provider =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // This is called on the thread the context will be used. 132 // This is called on the thread the context will be used.
111 DCHECK(context_thread_checker_.CalledOnValidThread()); 133 DCHECK(context_thread_checker_.CalledOnValidThread());
112 134
113 if (lost_context_callback_proxy_) 135 if (lost_context_callback_proxy_)
114 return true; 136 return true;
115 137
116 if (!context3d_->makeContextCurrent()) 138 if (!context3d_->makeContextCurrent())
117 return false; 139 return false;
118 140
119 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); 141 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
142 swap_buffers_complete_callback_proxy_.reset(
143 new SwapBuffersCompleteCallbackProxy(this));
144 memory_allocation_callback_proxy_.reset(
145 new MemoryAllocationCallbackProxy(this));
120 return true; 146 return true;
121 } 147 }
122 148
123 WebKit::WebGraphicsContext3D* ContextProviderInProcess::Context3d() { 149 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl*
150 ContextProviderInProcess::Context3d() {
124 DCHECK(context3d_); 151 DCHECK(context3d_);
125 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 152 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
126 DCHECK(context_thread_checker_.CalledOnValidThread()); 153 DCHECK(context_thread_checker_.CalledOnValidThread());
127 154
128 return context3d_.get(); 155 return context3d_.get();
129 } 156 }
130 157
131 class GrContext* ContextProviderInProcess::GrContext() { 158 class GrContext* ContextProviderInProcess::GrContext() {
132 DCHECK(context3d_); 159 DCHECK(context3d_);
133 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 160 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
134 DCHECK(context_thread_checker_.CalledOnValidThread()); 161 DCHECK(context_thread_checker_.CalledOnValidThread());
135 162
136 if (gr_context_) 163 if (gr_context_)
137 return gr_context_->get(); 164 return gr_context_->get();
138 165
139 gr_context_.reset( 166 gr_context_.reset(
140 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); 167 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
141 memory_allocation_callback_proxy_.reset(
142 new MemoryAllocationCallbackProxy(this));
143 return gr_context_->get(); 168 return gr_context_->get();
144 } 169 }
145 170
146 void ContextProviderInProcess::VerifyContexts() { 171 void ContextProviderInProcess::VerifyContexts() {
147 DCHECK(context3d_); 172 DCHECK(context3d_);
148 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 173 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
149 DCHECK(context_thread_checker_.CalledOnValidThread()); 174 DCHECK(context_thread_checker_.CalledOnValidThread());
150 175
151 if (context3d_->isContextLost()) 176 if (context3d_->isContextLost())
152 OnLostContext(); 177 OnLostContext();
153 } 178 }
154 179
155 void ContextProviderInProcess::OnLostContext() { 180 void ContextProviderInProcess::OnLostContext() {
156 DCHECK(context_thread_checker_.CalledOnValidThread()); 181 DCHECK(context_thread_checker_.CalledOnValidThread());
157 { 182 {
158 base::AutoLock lock(destroyed_lock_); 183 base::AutoLock lock(destroyed_lock_);
159 if (destroyed_) 184 if (destroyed_)
160 return; 185 return;
161 destroyed_ = true; 186 destroyed_ = true;
162 } 187 }
163 if (!lost_context_callback_.is_null()) 188 if (!lost_context_callback_.is_null())
164 base::ResetAndReturn(&lost_context_callback_).Run(); 189 base::ResetAndReturn(&lost_context_callback_).Run();
165 } 190 }
166 191
192 void ContextProviderInProcess::OnSwapBuffersComplete() {
193 DCHECK(context_thread_checker_.CalledOnValidThread());
194 if (!swap_buffers_complete_callback_.is_null())
195 swap_buffers_complete_callback_.Run();
196 }
197
198 void ContextProviderInProcess::OnMemoryAllocationChanged(
199 const WebKit::WebGraphicsMemoryAllocation& allocation) {
200 DCHECK(context_thread_checker_.CalledOnValidThread());
201
202 if (gr_context_) {
203 bool nonzero_allocation = !!allocation.gpuResourceSizeInBytes;
204 gr_context_->SetMemoryLimit(nonzero_allocation);
205 }
206
207 if (memory_policy_changed_callback_.is_null())
208 return;
209
210 bool discard_backbuffer_when_not_visible;
211 cc::ManagedMemoryPolicy policy =
212 ManagedMemoryPolicyConvert::Convert(allocation,
213 &discard_backbuffer_when_not_visible);
214
215 memory_policy_changed_callback_.Run(
216 policy, discard_backbuffer_when_not_visible);
217 }
218
167 bool ContextProviderInProcess::DestroyedOnMainThread() { 219 bool ContextProviderInProcess::DestroyedOnMainThread() {
168 DCHECK(main_thread_checker_.CalledOnValidThread()); 220 DCHECK(main_thread_checker_.CalledOnValidThread());
169 221
170 base::AutoLock lock(destroyed_lock_); 222 base::AutoLock lock(destroyed_lock_);
171 return destroyed_; 223 return destroyed_;
172 } 224 }
173 225
174 void ContextProviderInProcess::SetLostContextCallback( 226 void ContextProviderInProcess::SetLostContextCallback(
175 const LostContextCallback& lost_context_callback) { 227 const LostContextCallback& lost_context_callback) {
176 DCHECK(context_thread_checker_.CalledOnValidThread()); 228 DCHECK(context_thread_checker_.CalledOnValidThread());
177 DCHECK(lost_context_callback_.is_null()); 229 DCHECK(lost_context_callback_.is_null() ||
230 lost_context_callback.is_null());
178 lost_context_callback_ = lost_context_callback; 231 lost_context_callback_ = lost_context_callback;
179 } 232 }
180 233
181 void ContextProviderInProcess::OnMemoryAllocationChanged( 234 void ContextProviderInProcess::SetSwapBuffersCompleteCallback(
182 bool nonzero_allocation) { 235 const SwapBuffersCompleteCallback& swap_buffers_complete_callback) {
183 DCHECK(context_thread_checker_.CalledOnValidThread()); 236 DCHECK(context_thread_checker_.CalledOnValidThread());
184 if (gr_context_) 237 DCHECK(swap_buffers_complete_callback_.is_null() ||
185 gr_context_->SetMemoryLimit(nonzero_allocation); 238 swap_buffers_complete_callback.is_null());
239 swap_buffers_complete_callback_ = swap_buffers_complete_callback;
240 }
241
242 void ContextProviderInProcess::SetMemoryPolicyChangedCallback(
243 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
244 DCHECK(context_thread_checker_.CalledOnValidThread());
245 DCHECK(memory_policy_changed_callback_.is_null() ||
246 memory_policy_changed_callback.is_null());
247 memory_policy_changed_callback_ = memory_policy_changed_callback;
186 } 248 }
187 249
188 } // namespace gpu 250 } // namespace gpu
189 } // namespace webkit 251 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/common/gpu/context_provider_in_process.h ('k') | webkit/common/gpu/managed_memory_policy_convert.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698