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 <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 ContextProviderCommandBuffer* provider_; | 36 ContextProviderCommandBuffer* provider_; |
37 }; | 37 }; |
38 | 38 |
39 scoped_refptr<ContextProviderCommandBuffer> | 39 scoped_refptr<ContextProviderCommandBuffer> |
40 ContextProviderCommandBuffer::Create( | 40 ContextProviderCommandBuffer::Create( |
41 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, | 41 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, |
42 CommandBufferContextType type) { | 42 CommandBufferContextType type) { |
43 if (!context3d) | 43 if (!context3d) |
44 return NULL; | 44 return NULL; |
45 | 45 |
46 return new ContextProviderCommandBuffer(context3d.Pass(), type); | 46 const bool enable_memory_allocation_callback = true; |
47 return new ContextProviderCommandBuffer(context3d.Pass(), type, | |
48 enable_memory_allocation_callback); | |
47 } | 49 } |
48 | 50 |
49 ContextProviderCommandBuffer::ContextProviderCommandBuffer( | 51 ContextProviderCommandBuffer::ContextProviderCommandBuffer( |
50 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, | 52 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, |
51 CommandBufferContextType type) | 53 CommandBufferContextType type, |
54 bool enable_memory_allocation_callback) | |
52 : context3d_(context3d.Pass()), | 55 : context3d_(context3d.Pass()), |
53 context_type_(type), | 56 context_type_(type), |
54 debug_name_(CommandBufferContextTypeToString(type)), | 57 debug_name_(CommandBufferContextTypeToString(type)), |
58 enable_memory_allocation_callback_(enable_memory_allocation_callback), | |
55 destroyed_(false) { | 59 destroyed_(false) { |
56 DCHECK(main_thread_checker_.CalledOnValidThread()); | 60 DCHECK(main_thread_checker_.CalledOnValidThread()); |
57 DCHECK(context3d_); | 61 DCHECK(context3d_); |
58 context_thread_checker_.DetachFromThread(); | 62 context_thread_checker_.DetachFromThread(); |
59 } | 63 } |
60 | 64 |
61 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { | 65 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
62 DCHECK(main_thread_checker_.CalledOnValidThread() || | 66 DCHECK(main_thread_checker_.CalledOnValidThread() || |
63 context_thread_checker_.CalledOnValidThread()); | 67 context_thread_checker_.CalledOnValidThread()); |
64 | 68 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 if (!context3d_->InitializeOnCurrentThread()) | 102 if (!context3d_->InitializeOnCurrentThread()) |
99 return false; | 103 return false; |
100 | 104 |
101 InitializeCapabilities(); | 105 InitializeCapabilities(); |
102 | 106 |
103 std::string unique_context_name = | 107 std::string unique_context_name = |
104 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); | 108 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); |
105 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); | 109 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); |
106 | 110 |
107 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); | 111 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); |
108 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | 112 |
109 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, | 113 if (enable_memory_allocation_callback_) { |
110 base::Unretained(this))); | 114 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
no sievers
2015/08/05 22:50:32
Wait, can you just move this code to SetMemoryPoli
boliu
2015/08/06 01:30:33
Totally thought about that!
But... enabling callb
boliu
2015/08/06 01:41:37
And then I realize these two things actually happe
| |
115 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, | |
116 base::Unretained(this))); | |
117 } | |
111 return true; | 118 return true; |
112 } | 119 } |
113 | 120 |
114 void ContextProviderCommandBuffer::DetachFromThread() { | 121 void ContextProviderCommandBuffer::DetachFromThread() { |
115 context_thread_checker_.DetachFromThread(); | 122 context_thread_checker_.DetachFromThread(); |
116 } | 123 } |
117 | 124 |
118 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { | 125 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { |
119 DCHECK(context3d_); | 126 DCHECK(context3d_); |
120 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 127 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 | 244 |
238 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( | 245 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( |
239 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 246 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
240 DCHECK(context_thread_checker_.CalledOnValidThread()); | 247 DCHECK(context_thread_checker_.CalledOnValidThread()); |
241 DCHECK(memory_policy_changed_callback_.is_null() || | 248 DCHECK(memory_policy_changed_callback_.is_null() || |
242 memory_policy_changed_callback.is_null()); | 249 memory_policy_changed_callback.is_null()); |
243 memory_policy_changed_callback_ = memory_policy_changed_callback; | 250 memory_policy_changed_callback_ = memory_policy_changed_callback; |
244 } | 251 } |
245 | 252 |
246 } // namespace content | 253 } // namespace content |
OLD | NEW |