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

Side by Side Diff: content/common/gpu/client/context_provider_command_buffer.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 "content/common/gpu/client/context_provider_command_buffer.h" 5 #include "content/common/gpu/client/context_provider_command_buffer.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "cc/output/managed_memory_policy.h"
8 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" 9 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
10 #include "webkit/common/gpu/managed_memory_policy_convert.h"
9 11
10 namespace content { 12 namespace content {
11 13
12 class ContextProviderCommandBuffer::LostContextCallbackProxy 14 class ContextProviderCommandBuffer::LostContextCallbackProxy
13 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 15 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
14 public: 16 public:
15 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider) 17 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider)
16 : provider_(provider) { 18 : provider_(provider) {
17 provider_->context3d_->setContextLostCallback(this); 19 provider_->context3d_->setContextLostCallback(this);
18 } 20 }
19 21
20 virtual ~LostContextCallbackProxy() { 22 virtual ~LostContextCallbackProxy() {
21 provider_->context3d_->setContextLostCallback(NULL); 23 provider_->context3d_->setContextLostCallback(NULL);
22 } 24 }
23 25
24 virtual void onContextLost() { 26 virtual void onContextLost() {
25 provider_->OnLostContext(); 27 provider_->OnLostContext();
26 } 28 }
27 29
28 private: 30 private:
29 ContextProviderCommandBuffer* provider_; 31 ContextProviderCommandBuffer* provider_;
30 }; 32 };
31 33
34 class ContextProviderCommandBuffer::SwapBuffersCompleteCallbackProxy
35 : public WebKit::WebGraphicsContext3D::
36 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
37 public:
38 explicit SwapBuffersCompleteCallbackProxy(
39 ContextProviderCommandBuffer* provider)
40 : provider_(provider) {
41 provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this);
42 }
43
44 virtual ~SwapBuffersCompleteCallbackProxy() {
45 provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
46 }
47
48 virtual void onSwapBuffersComplete() {
49 provider_->OnSwapBuffersComplete();
50 }
51
52 private:
53 ContextProviderCommandBuffer* provider_;
54 };
55
32 class ContextProviderCommandBuffer::MemoryAllocationCallbackProxy 56 class ContextProviderCommandBuffer::MemoryAllocationCallbackProxy
33 : public WebKit::WebGraphicsContext3D:: 57 : public WebKit::WebGraphicsContext3D::
34 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { 58 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
35 public: 59 public:
36 explicit MemoryAllocationCallbackProxy(ContextProviderCommandBuffer* provider) 60 explicit MemoryAllocationCallbackProxy(ContextProviderCommandBuffer* provider)
37 : provider_(provider) { 61 : provider_(provider) {
38 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); 62 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
39 } 63 }
40 64
41 virtual ~MemoryAllocationCallbackProxy() { 65 virtual ~MemoryAllocationCallbackProxy() {
42 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); 66 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL);
43 } 67 }
44 68
45 virtual void onMemoryAllocationChanged( 69 virtual void onMemoryAllocationChanged(
46 WebKit::WebGraphicsMemoryAllocation alloc) { 70 WebKit::WebGraphicsMemoryAllocation allocation) {
47 provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes); 71 provider_->OnMemoryAllocationChanged(allocation);
48 } 72 }
49 73
50 private: 74 private:
51 ContextProviderCommandBuffer* provider_; 75 ContextProviderCommandBuffer* provider_;
52 }; 76 };
53 77
54 scoped_refptr<ContextProviderCommandBuffer> 78 scoped_refptr<ContextProviderCommandBuffer>
55 ContextProviderCommandBuffer::Create(const CreateCallback& create_callback) { 79 ContextProviderCommandBuffer::Create(const CreateCallback& create_callback) {
56 scoped_refptr<ContextProviderCommandBuffer> provider = 80 scoped_refptr<ContextProviderCommandBuffer> provider =
57 new ContextProviderCommandBuffer; 81 new ContextProviderCommandBuffer;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // This is called on the thread the context will be used. 120 // This is called on the thread the context will be used.
97 DCHECK(context_thread_checker_.CalledOnValidThread()); 121 DCHECK(context_thread_checker_.CalledOnValidThread());
98 122
99 if (lost_context_callback_proxy_) 123 if (lost_context_callback_proxy_)
100 return true; 124 return true;
101 125
102 if (!context3d_->makeContextCurrent()) 126 if (!context3d_->makeContextCurrent())
103 return false; 127 return false;
104 128
105 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); 129 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
130 swap_buffers_complete_callback_proxy_.reset(
131 new SwapBuffersCompleteCallbackProxy(this));
132 memory_allocation_callback_proxy_.reset(
133 new MemoryAllocationCallbackProxy(this));
106 return true; 134 return true;
107 } 135 }
108 136
109 WebGraphicsContext3DCommandBufferImpl* 137 WebGraphicsContext3DCommandBufferImpl*
110 ContextProviderCommandBuffer::Context3d() { 138 ContextProviderCommandBuffer::Context3d() {
111 DCHECK(context3d_); 139 DCHECK(context3d_);
112 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 140 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
113 DCHECK(context_thread_checker_.CalledOnValidThread()); 141 DCHECK(context_thread_checker_.CalledOnValidThread());
114 142
115 return context3d_.get(); 143 return context3d_.get();
116 } 144 }
117 145
118 class GrContext* ContextProviderCommandBuffer::GrContext() { 146 class GrContext* ContextProviderCommandBuffer::GrContext() {
119 DCHECK(context3d_); 147 DCHECK(context3d_);
120 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 148 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
121 DCHECK(context_thread_checker_.CalledOnValidThread()); 149 DCHECK(context_thread_checker_.CalledOnValidThread());
122 150
123 if (gr_context_) 151 if (gr_context_)
124 return gr_context_->get(); 152 return gr_context_->get();
125 153
126 gr_context_.reset( 154 gr_context_.reset(
127 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); 155 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
128 memory_allocation_callback_proxy_.reset(
129 new MemoryAllocationCallbackProxy(this));
130 return gr_context_->get(); 156 return gr_context_->get();
131 } 157 }
132 158
133 void ContextProviderCommandBuffer::VerifyContexts() { 159 void ContextProviderCommandBuffer::VerifyContexts() {
134 DCHECK(context3d_); 160 DCHECK(context3d_);
135 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 161 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
136 DCHECK(context_thread_checker_.CalledOnValidThread()); 162 DCHECK(context_thread_checker_.CalledOnValidThread());
137 163
138 if (context3d_->isContextLost()) 164 if (context3d_->isContextLost())
139 OnLostContext(); 165 OnLostContext();
140 } 166 }
141 167
142 void ContextProviderCommandBuffer::OnLostContext() { 168 void ContextProviderCommandBuffer::OnLostContext() {
143 DCHECK(context_thread_checker_.CalledOnValidThread()); 169 DCHECK(context_thread_checker_.CalledOnValidThread());
144 { 170 {
145 base::AutoLock lock(main_thread_lock_); 171 base::AutoLock lock(main_thread_lock_);
146 if (destroyed_) 172 if (destroyed_)
147 return; 173 return;
148 destroyed_ = true; 174 destroyed_ = true;
149 } 175 }
150 if (!lost_context_callback_.is_null()) 176 if (!lost_context_callback_.is_null())
151 base::ResetAndReturn(&lost_context_callback_).Run(); 177 base::ResetAndReturn(&lost_context_callback_).Run();
152 } 178 }
153 179
180 void ContextProviderCommandBuffer::OnSwapBuffersComplete() {
181 DCHECK(context_thread_checker_.CalledOnValidThread());
182 if (!swap_buffers_complete_callback_.is_null())
183 swap_buffers_complete_callback_.Run();
184 }
185
186 void ContextProviderCommandBuffer::OnMemoryAllocationChanged(
187 const WebKit::WebGraphicsMemoryAllocation& allocation) {
188 DCHECK(context_thread_checker_.CalledOnValidThread());
189
190 if (gr_context_) {
191 bool nonzero_allocation = !!allocation.gpuResourceSizeInBytes;
192 gr_context_->SetMemoryLimit(nonzero_allocation);
193 }
194
195 if (memory_policy_changed_callback_.is_null())
196 return;
197
198 bool discard_backbuffer_when_not_visible;
199 cc::ManagedMemoryPolicy policy =
200 webkit::gpu::ManagedMemoryPolicyConvert::Convert(
201 allocation,
202 &discard_backbuffer_when_not_visible);
203
204 memory_policy_changed_callback_.Run(
205 policy, discard_backbuffer_when_not_visible);
206 }
207
154 bool ContextProviderCommandBuffer::DestroyedOnMainThread() { 208 bool ContextProviderCommandBuffer::DestroyedOnMainThread() {
155 DCHECK(main_thread_checker_.CalledOnValidThread()); 209 DCHECK(main_thread_checker_.CalledOnValidThread());
156 210
157 base::AutoLock lock(main_thread_lock_); 211 base::AutoLock lock(main_thread_lock_);
158 return destroyed_; 212 return destroyed_;
159 } 213 }
160 214
161 void ContextProviderCommandBuffer::SetLostContextCallback( 215 void ContextProviderCommandBuffer::SetLostContextCallback(
162 const LostContextCallback& lost_context_callback) { 216 const LostContextCallback& lost_context_callback) {
163 DCHECK(context_thread_checker_.CalledOnValidThread()); 217 DCHECK(context_thread_checker_.CalledOnValidThread());
164 DCHECK(lost_context_callback_.is_null()); 218 DCHECK(lost_context_callback_.is_null() ||
219 lost_context_callback.is_null());
165 lost_context_callback_ = lost_context_callback; 220 lost_context_callback_ = lost_context_callback;
166 } 221 }
167 222
168 void ContextProviderCommandBuffer::OnMemoryAllocationChanged( 223 void ContextProviderCommandBuffer::SetSwapBuffersCompleteCallback(
169 bool nonzero_allocation) { 224 const SwapBuffersCompleteCallback& swap_buffers_complete_callback) {
170 DCHECK(context_thread_checker_.CalledOnValidThread()); 225 DCHECK(context_thread_checker_.CalledOnValidThread());
171 if (gr_context_) 226 DCHECK(swap_buffers_complete_callback_.is_null() ||
172 gr_context_->SetMemoryLimit(nonzero_allocation); 227 swap_buffers_complete_callback.is_null());
228 swap_buffers_complete_callback_ = swap_buffers_complete_callback;
229 }
230
231 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback(
232 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
233 DCHECK(context_thread_checker_.CalledOnValidThread());
234 DCHECK(memory_policy_changed_callback_.is_null() ||
235 memory_policy_changed_callback.is_null());
236 memory_policy_changed_callback_ = memory_policy_changed_callback;
173 } 237 }
174 238
175 } // namespace content 239 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/context_provider_command_buffer.h ('k') | content/renderer/gpu/compositor_output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698