Chromium Code Reviews| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "cc/output/managed_memory_policy.h" | 12 #include "cc/output/managed_memory_policy.h" |
| 13 #include "content/common/gpu/client/grcontext_for_webgraphicscontext3d.h" | 13 #include "content/common/gpu/client/grcontext_for_webgraphicscontext3d.h" |
| 14 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 15 #include "third_party/skia/include/gpu/GrContext.h" | 15 #include "third_party/skia/include/gpu/GrContext.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 class ContextProviderCommandBuffer::LostContextCallbackProxy | 19 class ContextProviderCommandBuffer::LostContextCallbackProxy |
| 20 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 20 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 21 public: | 21 public: |
| 22 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider) | 22 explicit LostContextCallbackProxy(ContextProviderCommandBuffer* provider) |
| 23 : provider_(provider) { | 23 : provider_(provider) { |
| 24 provider_->context3d_->setContextLostCallback(this); | 24 provider_->WebContext3DNoChecks()->setContextLostCallback(this); |
| 25 } | 25 } |
| 26 | 26 |
| 27 ~LostContextCallbackProxy() override { | 27 ~LostContextCallbackProxy() override { |
| 28 provider_->context3d_->setContextLostCallback(NULL); | 28 provider_->WebContext3DNoChecks()->setContextLostCallback(NULL); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void onContextLost() override { provider_->OnLostContext(); } | 31 void onContextLost() override { provider_->OnLostContext(); } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 ContextProviderCommandBuffer* provider_; | 34 ContextProviderCommandBuffer* provider_; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 scoped_refptr<ContextProviderCommandBuffer> | 37 scoped_refptr<ContextProviderCommandBuffer> |
| 38 ContextProviderCommandBuffer::Create( | 38 ContextProviderCommandBuffer::Create( |
| 39 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, | 39 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, |
| 40 CommandBufferContextType type) { | 40 CommandBufferContextType type) { |
| 41 if (!context3d) | 41 if (!context3d) |
| 42 return NULL; | 42 return NULL; |
| 43 | 43 |
| 44 return new ContextProviderCommandBuffer(context3d.Pass(), type); | 44 return new ContextProviderCommandBuffer(context3d.Pass(), type); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ContextProviderCommandBuffer::ContextProviderCommandBuffer( | 47 ContextProviderCommandBuffer::ContextProviderCommandBuffer( |
| 48 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, | 48 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, |
| 49 CommandBufferContextType type) | 49 CommandBufferContextType type) |
| 50 : context3d_(context3d.Pass()), | 50 : context_type_(type), |
| 51 context_type_(type), | |
| 52 debug_name_(CommandBufferContextTypeToString(type)) { | 51 debug_name_(CommandBufferContextTypeToString(type)) { |
| 52 gr_interface_ = skia::AdoptRef(new GrGLInterfaceForWebGraphicsContext3D( | |
| 53 context3d.Pass())); | |
| 53 DCHECK(main_thread_checker_.CalledOnValidThread()); | 54 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 54 DCHECK(context3d_); | 55 DCHECK(gr_interface_->WebContext3D()); |
| 55 context_thread_checker_.DetachFromThread(); | 56 context_thread_checker_.DetachFromThread(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { | 59 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
| 59 DCHECK(main_thread_checker_.CalledOnValidThread() || | 60 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 60 context_thread_checker_.CalledOnValidThread()); | 61 context_thread_checker_.CalledOnValidThread()); |
| 61 | 62 |
| 62 // Destroy references to the context3d_ before leaking it. | 63 // Destroy references to the context3d_ before leaking it. |
| 63 if (context3d_->GetCommandBufferProxy()) | 64 if (WebContext3DNoChecks()->GetCommandBufferProxy()) |
| 64 context3d_->GetCommandBufferProxy()->SetLock(nullptr); | 65 WebContext3DNoChecks()->GetCommandBufferProxy()->SetLock(nullptr); |
| 65 lost_context_callback_proxy_.reset(); | 66 lost_context_callback_proxy_.reset(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 | 69 |
| 69 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { | 70 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { |
| 70 return context3d_->GetCommandBufferProxy(); | 71 return WebContext3D()->GetCommandBufferProxy(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 WebGraphicsContext3DCommandBufferImpl* | 74 WebGraphicsContext3DCommandBufferImpl* |
| 74 ContextProviderCommandBuffer::WebContext3D() { | 75 ContextProviderCommandBuffer::WebContext3D() { |
| 75 DCHECK(context3d_); | 76 DCHECK(gr_interface_); |
| 77 DCHECK(gr_interface_->WebContext3D()); | |
| 76 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 78 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 77 DCHECK(context_thread_checker_.CalledOnValidThread()); | 79 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 78 | 80 |
| 79 return context3d_.get(); | 81 return WebContext3DNoChecks(); |
| 82 } | |
| 83 | |
| 84 WebGraphicsContext3DCommandBufferImpl* | |
| 85 ContextProviderCommandBuffer::WebContext3DNoChecks() { | |
| 86 return static_cast<WebGraphicsContext3DCommandBufferImpl*>( | |
| 87 gr_interface_->WebContext3D()); | |
| 80 } | 88 } |
| 81 | 89 |
| 82 bool ContextProviderCommandBuffer::BindToCurrentThread() { | 90 bool ContextProviderCommandBuffer::BindToCurrentThread() { |
| 83 // This is called on the thread the context will be used. | 91 // This is called on the thread the context will be used. |
| 84 DCHECK(context_thread_checker_.CalledOnValidThread()); | 92 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 93 DCHECK(gr_interface_ && gr_interface_->WebContext3D()); | |
| 85 | 94 |
| 86 if (lost_context_callback_proxy_) | 95 if (lost_context_callback_proxy_) |
| 87 return true; | 96 return true; |
| 88 | 97 |
| 89 context3d_->SetContextType(context_type_); | 98 WebContext3DNoChecks()->SetContextType(context_type_); |
| 90 if (!context3d_->InitializeOnCurrentThread()) | 99 if (!WebContext3DNoChecks()->InitializeOnCurrentThread()) |
| 91 return false; | 100 return false; |
| 92 | 101 |
| 93 InitializeCapabilities(); | 102 InitializeCapabilities(); |
| 94 | 103 |
| 95 std::string unique_context_name = | 104 std::string unique_context_name = |
| 96 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); | 105 base::StringPrintf("%s-%p", debug_name_.c_str(), WebContext3DNoChecks()); |
| 97 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); | 106 WebContext3DNoChecks()->traceBeginCHROMIUM("gpu_toplevel", |
| 107 unique_context_name.c_str()); | |
| 98 | 108 |
| 99 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); | 109 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); |
| 100 return true; | 110 return true; |
| 101 } | 111 } |
| 102 | 112 |
| 103 void ContextProviderCommandBuffer::DetachFromThread() { | 113 void ContextProviderCommandBuffer::DetachFromThread() { |
| 104 context_thread_checker_.DetachFromThread(); | 114 context_thread_checker_.DetachFromThread(); |
| 105 } | 115 } |
| 106 | 116 |
| 107 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { | 117 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { |
| 108 DCHECK(context3d_); | |
| 109 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 118 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 110 DCHECK(context_thread_checker_.CalledOnValidThread()); | 119 DCHECK(context_thread_checker_.CalledOnValidThread()); |
|
piman
2015/11/09 19:29:25
nit: can remove those, since they're covered by We
| |
| 111 | 120 |
| 112 return context3d_->GetImplementation(); | 121 return WebContext3D()->GetImplementation(); |
| 113 } | 122 } |
| 114 | 123 |
| 115 gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() { | 124 gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() { |
| 116 return context3d_->GetContextSupport(); | 125 return WebContext3D()->GetContextSupport(); |
| 117 } | 126 } |
| 118 | 127 |
| 119 class GrContext* ContextProviderCommandBuffer::GrContext() { | 128 class GrContext* ContextProviderCommandBuffer::GrContext() { |
| 120 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 129 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 121 DCHECK(context_thread_checker_.CalledOnValidThread()); | 130 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 122 | 131 |
| 123 if (gr_context_) | 132 if (gr_context_) |
| 124 return gr_context_->get(); | 133 return gr_context_->get(); |
| 125 | 134 |
| 126 gr_context_.reset(new GrContextForWebGraphicsContext3D(context3d_.get())); | 135 gr_context_.reset(new GrContextForWebGraphicsContext3D(gr_interface_)); |
| 127 | 136 |
| 128 // If GlContext is already lost, also abandon the new GrContext. | 137 // If GlContext is already lost, also abandon the new GrContext. |
| 129 if (gr_context_->get() && | 138 if (gr_context_->get() && |
| 130 ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 139 ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR) |
| 131 gr_context_->get()->abandonContext(); | 140 gr_context_->get()->abandonContext(); |
| 132 | 141 |
| 133 return gr_context_->get(); | 142 return gr_context_->get(); |
| 134 } | 143 } |
| 135 | 144 |
| 136 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { | 145 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { |
| 137 if (gr_context_) { | 146 if (gr_context_) { |
| 138 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 147 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 139 DCHECK(context_thread_checker_.CalledOnValidThread()); | 148 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 140 gr_context_->get()->resetContext(state); | 149 gr_context_->get()->resetContext(state); |
| 141 } | 150 } |
| 142 } | 151 } |
| 143 | 152 |
| 144 void ContextProviderCommandBuffer::SetupLock() { | 153 void ContextProviderCommandBuffer::SetupLock() { |
| 145 DCHECK(context3d_); | 154 WebContext3D()->GetCommandBufferProxy()->SetLock(&context_lock_); |
| 146 context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); | |
| 147 } | 155 } |
| 148 | 156 |
| 149 base::Lock* ContextProviderCommandBuffer::GetLock() { | 157 base::Lock* ContextProviderCommandBuffer::GetLock() { |
| 150 return &context_lock_; | 158 return &context_lock_; |
| 151 } | 159 } |
| 152 | 160 |
| 153 cc::ContextProvider::Capabilities | 161 cc::ContextProvider::Capabilities |
| 154 ContextProviderCommandBuffer::ContextCapabilities() { | 162 ContextProviderCommandBuffer::ContextCapabilities() { |
| 155 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 163 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 156 DCHECK(context_thread_checker_.CalledOnValidThread()); | 164 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 169 DCHECK(context_thread_checker_.CalledOnValidThread()); | 177 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 170 | 178 |
| 171 if (!lost_context_callback_.is_null()) | 179 if (!lost_context_callback_.is_null()) |
| 172 base::ResetAndReturn(&lost_context_callback_).Run(); | 180 base::ResetAndReturn(&lost_context_callback_).Run(); |
| 173 if (gr_context_) | 181 if (gr_context_) |
| 174 gr_context_->OnLostContext(); | 182 gr_context_->OnLostContext(); |
| 175 } | 183 } |
| 176 | 184 |
| 177 void ContextProviderCommandBuffer::InitializeCapabilities() { | 185 void ContextProviderCommandBuffer::InitializeCapabilities() { |
| 178 Capabilities caps; | 186 Capabilities caps; |
| 179 caps.gpu = context3d_->GetImplementation()->capabilities(); | 187 caps.gpu = WebContext3DNoChecks()->GetImplementation()->capabilities(); |
| 180 | 188 |
| 181 size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit(); | 189 size_t mapped_memory_limit = WebContext3DNoChecks()->GetMappedMemoryLimit(); |
| 182 caps.max_transfer_buffer_usage_bytes = | 190 caps.max_transfer_buffer_usage_bytes = |
| 183 mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit | 191 mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit |
| 184 ? std::numeric_limits<size_t>::max() : mapped_memory_limit; | 192 ? std::numeric_limits<size_t>::max() : mapped_memory_limit; |
| 185 | 193 |
| 186 capabilities_ = caps; | 194 capabilities_ = caps; |
| 187 } | 195 } |
| 188 | 196 |
| 189 void ContextProviderCommandBuffer::SetLostContextCallback( | 197 void ContextProviderCommandBuffer::SetLostContextCallback( |
| 190 const LostContextCallback& lost_context_callback) { | 198 const LostContextCallback& lost_context_callback) { |
| 191 DCHECK(context_thread_checker_.CalledOnValidThread()); | 199 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 192 DCHECK(lost_context_callback_.is_null() || | 200 DCHECK(lost_context_callback_.is_null() || |
| 193 lost_context_callback.is_null()); | 201 lost_context_callback.is_null()); |
| 194 lost_context_callback_ = lost_context_callback; | 202 lost_context_callback_ = lost_context_callback; |
| 195 } | 203 } |
| 196 | 204 |
| 197 } // namespace content | 205 } // namespace content |
| OLD | NEW |