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