OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 void onContextLost() override { provider_->OnLostContext(); } | 35 void onContextLost() override { provider_->OnLostContext(); } |
36 | 36 |
37 private: | 37 private: |
38 ContextProviderCommandBuffer* provider_; | 38 ContextProviderCommandBuffer* provider_; |
39 }; | 39 }; |
40 | 40 |
41 ContextProviderCommandBuffer::ContextProviderCommandBuffer( | 41 ContextProviderCommandBuffer::ContextProviderCommandBuffer( |
42 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, | 42 std::unique_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, |
| 43 const gpu::SharedMemoryLimits& memory_limits, |
43 CommandBufferContextType type) | 44 CommandBufferContextType type) |
44 : context3d_(std::move(context3d)), | 45 : context3d_(std::move(context3d)), |
| 46 memory_limits_(memory_limits), |
45 context_type_(type), | 47 context_type_(type), |
46 debug_name_(CommandBufferContextTypeToString(type)) { | 48 debug_name_(CommandBufferContextTypeToString(type)) { |
47 DCHECK(main_thread_checker_.CalledOnValidThread()); | 49 DCHECK(main_thread_checker_.CalledOnValidThread()); |
48 DCHECK(context3d_); | 50 DCHECK(context3d_); |
49 context_thread_checker_.DetachFromThread(); | 51 context_thread_checker_.DetachFromThread(); |
50 } | 52 } |
51 | 53 |
52 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { | 54 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
53 DCHECK(main_thread_checker_.CalledOnValidThread() || | 55 DCHECK(main_thread_checker_.CalledOnValidThread() || |
54 context_thread_checker_.CalledOnValidThread()); | 56 context_thread_checker_.CalledOnValidThread()); |
(...skipping 19 matching lines...) Expand all Loading... |
74 } | 76 } |
75 | 77 |
76 bool ContextProviderCommandBuffer::BindToCurrentThread() { | 78 bool ContextProviderCommandBuffer::BindToCurrentThread() { |
77 // This is called on the thread the context will be used. | 79 // This is called on the thread the context will be used. |
78 DCHECK(context_thread_checker_.CalledOnValidThread()); | 80 DCHECK(context_thread_checker_.CalledOnValidThread()); |
79 | 81 |
80 if (lost_context_callback_proxy_) | 82 if (lost_context_callback_proxy_) |
81 return true; | 83 return true; |
82 | 84 |
83 context3d_->SetContextType(context_type_); | 85 context3d_->SetContextType(context_type_); |
84 if (!context3d_->InitializeOnCurrentThread()) | 86 if (!context3d_->InitializeOnCurrentThread(memory_limits_)) |
85 return false; | 87 return false; |
86 | 88 |
87 InitializeCapabilities(); | |
88 | |
89 std::string unique_context_name = | 89 std::string unique_context_name = |
90 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); | 90 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); |
91 context3d_->GetGLInterface()->TraceBeginCHROMIUM("gpu_toplevel", | 91 context3d_->GetGLInterface()->TraceBeginCHROMIUM("gpu_toplevel", |
92 unique_context_name.c_str()); | 92 unique_context_name.c_str()); |
93 | 93 |
94 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); | 94 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 void ContextProviderCommandBuffer::DetachFromThread() { | 98 void ContextProviderCommandBuffer::DetachFromThread() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 void ContextProviderCommandBuffer::SetupLock() { | 140 void ContextProviderCommandBuffer::SetupLock() { |
141 DCHECK(context3d_); | 141 DCHECK(context3d_); |
142 context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); | 142 context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); |
143 } | 143 } |
144 | 144 |
145 base::Lock* ContextProviderCommandBuffer::GetLock() { | 145 base::Lock* ContextProviderCommandBuffer::GetLock() { |
146 return &context_lock_; | 146 return &context_lock_; |
147 } | 147 } |
148 | 148 |
149 cc::ContextProvider::Capabilities | 149 gpu::Capabilities ContextProviderCommandBuffer::ContextCapabilities() { |
150 ContextProviderCommandBuffer::ContextCapabilities() { | |
151 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 150 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
152 DCHECK(context_thread_checker_.CalledOnValidThread()); | 151 DCHECK(context_thread_checker_.CalledOnValidThread()); |
153 | 152 return context3d_->GetImplementation()->capabilities(); |
154 return capabilities_; | |
155 } | 153 } |
156 | 154 |
157 void ContextProviderCommandBuffer::DeleteCachedResources() { | 155 void ContextProviderCommandBuffer::DeleteCachedResources() { |
158 DCHECK(context_thread_checker_.CalledOnValidThread()); | 156 DCHECK(context_thread_checker_.CalledOnValidThread()); |
159 | 157 |
160 if (gr_context_) | 158 if (gr_context_) |
161 gr_context_->FreeGpuResources(); | 159 gr_context_->FreeGpuResources(); |
162 } | 160 } |
163 | 161 |
164 void ContextProviderCommandBuffer::OnLostContext() { | 162 void ContextProviderCommandBuffer::OnLostContext() { |
165 DCHECK(context_thread_checker_.CalledOnValidThread()); | 163 DCHECK(context_thread_checker_.CalledOnValidThread()); |
166 | 164 |
167 if (!lost_context_callback_.is_null()) | 165 if (!lost_context_callback_.is_null()) |
168 lost_context_callback_.Run(); | 166 lost_context_callback_.Run(); |
169 if (gr_context_) | 167 if (gr_context_) |
170 gr_context_->OnLostContext(); | 168 gr_context_->OnLostContext(); |
171 } | 169 } |
172 | 170 |
173 void ContextProviderCommandBuffer::InitializeCapabilities() { | |
174 Capabilities caps; | |
175 caps.gpu = context3d_->GetImplementation()->capabilities(); | |
176 | |
177 size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit(); | |
178 caps.max_transfer_buffer_usage_bytes = | |
179 mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit | |
180 ? std::numeric_limits<size_t>::max() : mapped_memory_limit; | |
181 | |
182 capabilities_ = caps; | |
183 } | |
184 | |
185 void ContextProviderCommandBuffer::SetLostContextCallback( | 171 void ContextProviderCommandBuffer::SetLostContextCallback( |
186 const LostContextCallback& lost_context_callback) { | 172 const LostContextCallback& lost_context_callback) { |
187 DCHECK(context_thread_checker_.CalledOnValidThread()); | 173 DCHECK(context_thread_checker_.CalledOnValidThread()); |
188 DCHECK(lost_context_callback_.is_null() || | 174 DCHECK(lost_context_callback_.is_null() || |
189 lost_context_callback.is_null()); | 175 lost_context_callback.is_null()); |
190 lost_context_callback_ = lost_context_callback; | 176 lost_context_callback_ = lost_context_callback; |
191 } | 177 } |
192 | 178 |
193 } // namespace content | 179 } // namespace content |
OLD | NEW |