| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 41 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 42 g_all_shared_contexts.Pointer()->clear(); | 42 g_all_shared_contexts.Pointer()->clear(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace anonymous | 45 } // namespace anonymous |
| 46 | 46 |
| 47 | 47 |
| 48 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 48 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( |
| 49 int surface_id, | 49 int surface_id, |
| 50 const GURL& active_url, | 50 const GURL& active_url, |
| 51 GpuChannelHostFactory* factory, |
| 51 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client) | 52 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client) |
| 52 : initialize_failed_(false), | 53 : initialize_failed_(false), |
| 54 factory_(factory), |
| 53 context_(NULL), | 55 context_(NULL), |
| 54 gl_(NULL), | 56 gl_(NULL), |
| 55 host_(NULL), | 57 host_(NULL), |
| 56 surface_id_(surface_id), | 58 surface_id_(surface_id), |
| 57 active_url_(active_url), | 59 active_url_(active_url), |
| 58 swap_client_(swap_client), | 60 swap_client_(swap_client), |
| 59 memory_allocation_changed_callback_(0), | 61 memory_allocation_changed_callback_(0), |
| 60 context_lost_callback_(0), | 62 context_lost_callback_(0), |
| 61 context_lost_reason_(GL_NO_ERROR), | 63 context_lost_reason_(GL_NO_ERROR), |
| 62 error_message_callback_(0), | 64 error_message_callback_(0), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 81 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 83 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 82 g_all_shared_contexts.Pointer()->erase(this); | 84 g_all_shared_contexts.Pointer()->erase(this); |
| 83 } | 85 } |
| 84 delete context_; | 86 delete context_; |
| 85 } | 87 } |
| 86 | 88 |
| 87 bool WebGraphicsContext3DCommandBufferImpl::Initialize( | 89 bool WebGraphicsContext3DCommandBufferImpl::Initialize( |
| 88 const WebGraphicsContext3D::Attributes& attributes) { | 90 const WebGraphicsContext3D::Attributes& attributes) { |
| 89 DCHECK(!context_); | 91 DCHECK(!context_); |
| 90 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); | 92 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); |
| 91 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); | 93 if (!factory_) |
| 92 if (!factory) | |
| 93 return false; | 94 return false; |
| 94 | 95 |
| 95 // The noExtensions and canRecoverFromContextLoss flags are | 96 // The noExtensions and canRecoverFromContextLoss flags are |
| 96 // currently used as hints that we are creating a context on | 97 // currently used as hints that we are creating a context on |
| 97 // behalf of WebGL or accelerated 2D canvas, respectively. | 98 // behalf of WebGL or accelerated 2D canvas, respectively. |
| 98 if (attributes.noExtensions || !attributes.canRecoverFromContextLoss) | 99 if (attributes.noExtensions || !attributes.canRecoverFromContextLoss) |
| 99 gpu_preference_ = gfx::PreferDiscreteGpu; | 100 gpu_preference_ = gfx::PreferDiscreteGpu; |
| 100 | 101 |
| 101 bool retry = false; | 102 bool retry = false; |
| 102 | 103 |
| 103 // Note similar code in Pepper PlatformContext3DImpl::Init. | 104 // Note similar code in Pepper PlatformContext3DImpl::Init. |
| 104 do { | 105 do { |
| 105 host_ = factory->EstablishGpuChannelSync( | 106 host_ = factory_->EstablishGpuChannelSync( |
| 106 content:: | 107 content:: |
| 107 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); | 108 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); |
| 108 if (!host_) | 109 if (!host_) |
| 109 return false; | 110 return false; |
| 110 DCHECK(host_->state() == GpuChannelHost::kConnected); | 111 DCHECK(host_->state() == GpuChannelHost::kConnected); |
| 111 | 112 |
| 112 if (!retry) { | 113 if (!retry) { |
| 113 // If the creation of this context requires all contexts for this | 114 // If the creation of this context requires all contexts for this |
| 114 // client to be destroyed on the GPU process side, then drop the | 115 // client to be destroyed on the GPU process side, then drop the |
| 115 // channel and recreate it. | 116 // channel and recreate it. |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 | 1110 |
| 1110 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) { | 1111 void WebGraphicsContext3DCommandBufferImpl::deleteShader(WebGLId shader) { |
| 1111 gl_->DeleteShader(shader); | 1112 gl_->DeleteShader(shader); |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { | 1115 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { |
| 1115 gl_->DeleteTextures(1, &texture); | 1116 gl_->DeleteTextures(1, &texture); |
| 1116 } | 1117 } |
| 1117 | 1118 |
| 1118 bool WebGraphicsContext3DCommandBufferImpl::ShouldUseSwapClient() { | 1119 bool WebGraphicsContext3DCommandBufferImpl::ShouldUseSwapClient() { |
| 1119 GpuChannelHostFactory* factory = GpuChannelHostFactory::instance(); | 1120 return factory_ && factory_->IsMainThread() && swap_client_.get(); |
| 1120 return factory && factory->IsMainThread() && swap_client_.get(); | |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { | 1123 void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { |
| 1124 typedef WebGraphicsContext3DSwapBuffersClient WGC3DSwapClient; | 1124 typedef WebGraphicsContext3DSwapBuffersClient WGC3DSwapClient; |
| 1125 // This may be called after tear-down of the RenderView. | 1125 // This may be called after tear-down of the RenderView. |
| 1126 if (ShouldUseSwapClient()) { | 1126 if (ShouldUseSwapClient()) { |
| 1127 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 1127 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 1128 &WGC3DSwapClient::OnViewContextSwapBuffersComplete, swap_client_)); | 1128 &WGC3DSwapClient::OnViewContextSwapBuffersComplete, swap_client_)); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1209 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
| 1210 const std::string& message, int id) { | 1210 const std::string& message, int id) { |
| 1211 if (error_message_callback_) { | 1211 if (error_message_callback_) { |
| 1212 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | 1212 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); |
| 1213 error_message_callback_->onErrorMessage(str, id); | 1213 error_message_callback_->onErrorMessage(str, id); |
| 1214 } | 1214 } |
| 1215 } | 1215 } |
| 1216 | 1216 |
| OLD | NEW |