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