OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/compositor/blimp_context_provider.h" | 5 #include "blimp/client/compositor/blimp_context_provider.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 "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "gpu/command_buffer/client/gl_in_process_context.h" | 10 #include "gpu/command_buffer/client/gl_in_process_context.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 namespace blimp { | 42 namespace blimp { |
43 | 43 |
44 // static | 44 // static |
45 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create( | 45 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create( |
46 gfx::AcceleratedWidget widget) { | 46 gfx::AcceleratedWidget widget) { |
47 return new BlimpContextProvider(widget); | 47 return new BlimpContextProvider(widget); |
48 } | 48 } |
49 | 49 |
50 BlimpContextProvider::BlimpContextProvider(gfx::AcceleratedWidget widget) { | 50 BlimpContextProvider::BlimpContextProvider(gfx::AcceleratedWidget widget) |
| 51 : lost_(false) { |
51 context_thread_checker_.DetachFromThread(); | 52 context_thread_checker_.DetachFromThread(); |
52 | 53 |
53 gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; | 54 gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; |
54 attribs_for_gles2.alpha_size = 8; | 55 attribs_for_gles2.alpha_size = 8; |
55 attribs_for_gles2.depth_size = 0; | 56 attribs_for_gles2.depth_size = 0; |
56 attribs_for_gles2.stencil_size = 0; | 57 attribs_for_gles2.stencil_size = 0; |
57 attribs_for_gles2.samples = 0; | 58 attribs_for_gles2.samples = 0; |
58 attribs_for_gles2.sample_buffers = 0; | 59 attribs_for_gles2.sample_buffers = 0; |
59 attribs_for_gles2.fail_if_major_perf_caveat = false; | 60 attribs_for_gles2.fail_if_major_perf_caveat = false; |
60 attribs_for_gles2.bind_generates_resource = false; | 61 attribs_for_gles2.bind_generates_resource = false; |
61 attribs_for_gles2.webgl_version = 0; | 62 attribs_for_gles2.webgl_version = 0; |
62 attribs_for_gles2.lose_context_when_out_of_memory = true; | 63 attribs_for_gles2.lose_context_when_out_of_memory = true; |
63 | 64 |
64 context_.reset(gpu::GLInProcessContext::Create( | 65 context_.reset(gpu::GLInProcessContext::Create( |
65 nullptr /* service */, nullptr /* surface */, false /* is_offscreen */, | 66 nullptr /* service */, nullptr /* surface */, false /* is_offscreen */, |
66 widget, gfx::Size(1, 1), nullptr /* share_context */, | 67 widget, gfx::Size(1, 1), nullptr /* share_context */, |
67 false /* share_resources */, attribs_for_gles2, gfx::PreferDiscreteGpu, | 68 false /* share_resources */, attribs_for_gles2, gfx::PreferDiscreteGpu, |
68 gpu::GLInProcessContextSharedMemoryLimits(), | 69 gpu::GLInProcessContextSharedMemoryLimits(), |
69 nullptr /* gpu_memory_buffer_manager */, nullptr /* memory_limits */)); | 70 nullptr /* gpu_memory_buffer_manager */, nullptr /* memory_limits */)); |
70 context_->SetContextLostCallback( | 71 context_->SetContextLostCallback( |
71 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); | 72 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); |
72 } | 73 } |
73 | 74 |
74 BlimpContextProvider::~BlimpContextProvider() { | 75 BlimpContextProvider::~BlimpContextProvider() { |
75 DCHECK(main_thread_checker_.CalledOnValidThread() || | |
76 context_thread_checker_.CalledOnValidThread()); | |
77 } | 76 } |
78 | 77 |
79 bool BlimpContextProvider::BindToCurrentThread() { | 78 bool BlimpContextProvider::BindToCurrentThread() { |
80 DCHECK(context_thread_checker_.CalledOnValidThread()); | 79 DCHECK(context_thread_checker_.CalledOnValidThread()); |
81 capabilities_.gpu = context_->GetImplementation()->capabilities(); | 80 capabilities_.gpu = context_->GetImplementation()->capabilities(); |
82 capabilities_.gpu.image = true; | 81 capabilities_.gpu.image = true; |
83 return true; | 82 return true; |
84 } | 83 } |
85 | 84 |
86 void BlimpContextProvider::DetachFromThread() { | 85 void BlimpContextProvider::DetachFromThread() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 DCHECK(context_thread_checker_.CalledOnValidThread()); | 142 DCHECK(context_thread_checker_.CalledOnValidThread()); |
144 } | 143 } |
145 | 144 |
146 void BlimpContextProvider::DeleteCachedResources() { | 145 void BlimpContextProvider::DeleteCachedResources() { |
147 DCHECK(context_thread_checker_.CalledOnValidThread()); | 146 DCHECK(context_thread_checker_.CalledOnValidThread()); |
148 | 147 |
149 if (gr_context_) | 148 if (gr_context_) |
150 gr_context_->freeGpuResources(); | 149 gr_context_->freeGpuResources(); |
151 } | 150 } |
152 | 151 |
153 bool BlimpContextProvider::DestroyedOnMainThread() { | 152 bool BlimpContextProvider::HasBeenLostOnMainThread() { |
154 DCHECK(main_thread_checker_.CalledOnValidThread()); | 153 DCHECK(main_thread_checker_.CalledOnValidThread()); |
155 | 154 |
156 base::AutoLock lock(destroyed_lock_); | 155 base::AutoLock lock(lost_lock_); |
157 return destroyed_; | 156 return lost_; |
158 } | 157 } |
159 | 158 |
160 void BlimpContextProvider::SetLostContextCallback( | 159 void BlimpContextProvider::SetLostContextCallback( |
161 const LostContextCallback& lost_context_callback) { | 160 const LostContextCallback& lost_context_callback) { |
162 DCHECK(context_thread_checker_.CalledOnValidThread()); | 161 DCHECK(context_thread_checker_.CalledOnValidThread()); |
163 lost_context_callback_ = lost_context_callback; | 162 lost_context_callback_ = lost_context_callback; |
164 } | 163 } |
165 | 164 |
166 void BlimpContextProvider::SetMemoryPolicyChangedCallback( | 165 void BlimpContextProvider::SetMemoryPolicyChangedCallback( |
167 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 166 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
168 // There's no memory manager for the in-process implementation. | 167 // There's no memory manager for the in-process implementation. |
169 // TODO(dtrainor): Figure out if we need a memory manager for Blimp. | 168 // TODO(dtrainor): Figure out if we need a memory manager for Blimp. |
170 } | 169 } |
171 | 170 |
172 void BlimpContextProvider::OnLostContext() { | 171 void BlimpContextProvider::OnLostContext() { |
173 DCHECK(context_thread_checker_.CalledOnValidThread()); | 172 DCHECK(context_thread_checker_.CalledOnValidThread()); |
174 | 173 |
175 { | 174 { |
176 base::AutoLock lock(destroyed_lock_); | 175 base::AutoLock lock(lost_lock_); |
177 if (destroyed_) | 176 if (lost_) |
178 return; | 177 return; |
179 destroyed_ = true; | 178 lost_ = true; |
180 } | 179 } |
181 | 180 |
182 if (!lost_context_callback_.is_null()) | 181 if (!lost_context_callback_.is_null()) |
183 base::ResetAndReturn(&lost_context_callback_).Run(); | 182 base::ResetAndReturn(&lost_context_callback_).Run(); |
184 if (gr_context_) | 183 if (gr_context_) |
185 gr_context_->abandonContext(); | 184 gr_context_->abandonContext(); |
186 } | 185 } |
187 | 186 |
| 187 bool BlimpContextProvider::HasBeenDestroyed() { |
| 188 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 189 return false; |
| 190 } |
| 191 |
188 } // namespace blimp | 192 } // namespace blimp |
OLD | NEW |