| 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 "webkit/common/gpu/context_provider_in_process.h" | 5 #include "webkit/common/gpu/context_provider_in_process.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 8 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | 9 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" |
| 9 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 10 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" |
| 10 | 11 |
| 11 namespace webkit { | 12 namespace webkit { |
| 12 namespace gpu { | 13 namespace gpu { |
| 13 | 14 |
| 14 class ContextProviderInProcess::LostContextCallbackProxy | 15 class ContextProviderInProcess::LostContextCallbackProxy |
| 15 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 16 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 16 public: | 17 public: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 | 47 |
| 47 virtual void onMemoryAllocationChanged( | 48 virtual void onMemoryAllocationChanged( |
| 48 WebKit::WebGraphicsMemoryAllocation alloc) { | 49 WebKit::WebGraphicsMemoryAllocation alloc) { |
| 49 provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes); | 50 provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes); |
| 50 } | 51 } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 ContextProviderInProcess* provider_; | 54 ContextProviderInProcess* provider_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 57 // static |
| 58 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( |
| 59 const CreateCallback& create_callback) { |
| 60 scoped_refptr<ContextProviderInProcess> provider = |
| 61 new ContextProviderInProcess; |
| 62 if (!provider->InitializeOnMainThread(create_callback)) |
| 63 return NULL; |
| 64 return provider; |
| 65 } |
| 66 |
| 67 static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> |
| 68 CreateOffscreenContext() { |
| 69 WebKit::WebGraphicsContext3D::Attributes attributes; |
| 70 attributes.depth = false; |
| 71 attributes.stencil = true; |
| 72 attributes.antialias = false; |
| 73 attributes.shareResources = true; |
| 74 attributes.noAutomaticFlushes = true; |
| 75 |
| 76 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( |
| 77 attributes).Pass(); |
| 78 } |
| 79 |
| 80 // static |
| 81 scoped_refptr<ContextProviderInProcess> |
| 82 ContextProviderInProcess::CreateOffscreen() { |
| 83 return Create(base::Bind(&CreateOffscreenContext)); |
| 84 } |
| 85 |
| 56 ContextProviderInProcess::ContextProviderInProcess() | 86 ContextProviderInProcess::ContextProviderInProcess() |
| 57 : destroyed_(false) { | 87 : destroyed_(false) { |
| 58 DCHECK(main_thread_checker_.CalledOnValidThread()); | 88 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 59 context_thread_checker_.DetachFromThread(); | 89 context_thread_checker_.DetachFromThread(); |
| 60 } | 90 } |
| 61 | 91 |
| 62 ContextProviderInProcess::~ContextProviderInProcess() { | 92 ContextProviderInProcess::~ContextProviderInProcess() { |
| 63 DCHECK(main_thread_checker_.CalledOnValidThread() || | 93 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 64 context_thread_checker_.CalledOnValidThread()); | 94 context_thread_checker_.CalledOnValidThread()); |
| 65 } | 95 } |
| 66 | 96 |
| 67 bool ContextProviderInProcess::InitializeOnMainThread() { | 97 bool ContextProviderInProcess::InitializeOnMainThread( |
| 98 const CreateCallback& create_callback) { |
| 68 DCHECK(!context3d_); | 99 DCHECK(!context3d_); |
| 69 DCHECK(main_thread_checker_.CalledOnValidThread()); | 100 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 101 DCHECK(!create_callback.is_null()); |
| 70 | 102 |
| 71 WebKit::WebGraphicsContext3D::Attributes attributes; | 103 context3d_ = create_callback.Run(); |
| 72 attributes.depth = false; | |
| 73 attributes.stencil = true; | |
| 74 attributes.antialias = false; | |
| 75 attributes.shareResources = true; | |
| 76 attributes.noAutomaticFlushes = true; | |
| 77 | |
| 78 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
| 79 context3d_ = | |
| 80 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | |
| 81 attributes); | |
| 82 | |
| 83 return context3d_; | 104 return context3d_; |
| 84 } | 105 } |
| 85 | 106 |
| 86 bool ContextProviderInProcess::BindToCurrentThread() { | 107 bool ContextProviderInProcess::BindToCurrentThread() { |
| 87 DCHECK(context3d_); | 108 DCHECK(context3d_); |
| 88 | 109 |
| 89 // This is called on the thread the context will be used. | 110 // This is called on the thread the context will be used. |
| 90 DCHECK(context_thread_checker_.CalledOnValidThread()); | 111 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 91 | 112 |
| 92 if (lost_context_callback_proxy_) | 113 if (lost_context_callback_proxy_) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 180 |
| 160 void ContextProviderInProcess::OnMemoryAllocationChanged( | 181 void ContextProviderInProcess::OnMemoryAllocationChanged( |
| 161 bool nonzero_allocation) { | 182 bool nonzero_allocation) { |
| 162 DCHECK(context_thread_checker_.CalledOnValidThread()); | 183 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 163 if (gr_context_) | 184 if (gr_context_) |
| 164 gr_context_->SetMemoryLimit(nonzero_allocation); | 185 gr_context_->SetMemoryLimit(nonzero_allocation); |
| 165 } | 186 } |
| 166 | 187 |
| 167 } // namespace gpu | 188 } // namespace gpu |
| 168 } // namespace webkit | 189 } // namespace webkit |
| OLD | NEW |