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 19 matching lines...) Expand all Loading... |
30 #include "content/public/common/content_constants.h" | 30 #include "content/public/common/content_constants.h" |
31 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
32 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 32 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
33 #include "gpu/command_buffer/client/gles2_implementation.h" | 33 #include "gpu/command_buffer/client/gles2_implementation.h" |
34 #include "gpu/command_buffer/client/gles2_lib.h" | 34 #include "gpu/command_buffer/client/gles2_lib.h" |
35 #include "gpu/command_buffer/client/transfer_buffer.h" | 35 #include "gpu/command_buffer/client/transfer_buffer.h" |
36 #include "gpu/command_buffer/common/constants.h" | 36 #include "gpu/command_buffer/common/constants.h" |
37 #include "gpu/ipc/command_buffer_proxy.h" | 37 #include "gpu/ipc/command_buffer_proxy.h" |
38 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" | 38 #include "webkit/glue/gl_bindings_skia_cmd_buffer.h" |
39 | 39 |
| 40 namespace content { |
40 static base::LazyInstance<base::Lock>::Leaky | 41 static base::LazyInstance<base::Lock>::Leaky |
41 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; | 42 g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; |
42 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > | 43 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > |
43 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 44 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 void ClearSharedContextsIfInShareSet( | 48 void ClearSharedContextsIfInShareSet( |
48 WebGraphicsContext3DCommandBufferImpl* context) { | 49 WebGraphicsContext3DCommandBufferImpl* context) { |
49 // If the given context isn't in the share set, that means that it | 50 // If the given context isn't in the share set, that means that it |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 parent_texture_id_(0), | 145 parent_texture_id_(0), |
145 command_buffer_(NULL), | 146 command_buffer_(NULL), |
146 gles2_helper_(NULL), | 147 gles2_helper_(NULL), |
147 transfer_buffer_(NULL), | 148 transfer_buffer_(NULL), |
148 gl_(NULL), | 149 gl_(NULL), |
149 frame_number_(0), | 150 frame_number_(0), |
150 bind_generates_resources_(false), | 151 bind_generates_resources_(false), |
151 use_echo_for_swap_ack_(true) { | 152 use_echo_for_swap_ack_(true) { |
152 #if defined(OS_MACOSX) || defined(OS_WIN) | 153 #if defined(OS_MACOSX) || defined(OS_WIN) |
153 // Get ViewMsg_SwapBuffers_ACK from browser for single-threaded path. | 154 // Get ViewMsg_SwapBuffers_ACK from browser for single-threaded path. |
154 use_echo_for_swap_ack_ = content::IsThreadedCompositingEnabled(); | 155 use_echo_for_swap_ack_ = IsThreadedCompositingEnabled(); |
155 #endif | 156 #endif |
156 } | 157 } |
157 | 158 |
158 WebGraphicsContext3DCommandBufferImpl:: | 159 WebGraphicsContext3DCommandBufferImpl:: |
159 ~WebGraphicsContext3DCommandBufferImpl() { | 160 ~WebGraphicsContext3DCommandBufferImpl() { |
160 if (gl_) { | 161 if (gl_) { |
161 gl_->SetErrorMessageCallback(NULL); | 162 gl_->SetErrorMessageCallback(NULL); |
162 } | 163 } |
163 | 164 |
164 { | 165 { |
165 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 166 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
166 g_all_shared_contexts.Pointer()->erase(this); | 167 g_all_shared_contexts.Pointer()->erase(this); |
167 } | 168 } |
168 Destroy(); | 169 Destroy(); |
169 } | 170 } |
170 | 171 |
171 void WebGraphicsContext3DCommandBufferImpl::InitializeWithCommandBuffer( | 172 void WebGraphicsContext3DCommandBufferImpl::InitializeWithCommandBuffer( |
172 CommandBufferProxy* command_buffer, | 173 CommandBufferProxy* command_buffer, |
173 const WebGraphicsContext3D::Attributes& attributes, | 174 const WebGraphicsContext3D::Attributes& attributes, |
174 bool bind_generates_resources) { | 175 bool bind_generates_resources) { |
175 DCHECK(command_buffer); | 176 DCHECK(command_buffer); |
176 command_buffer_ = command_buffer; | 177 command_buffer_ = command_buffer; |
177 attributes_ = attributes; | 178 attributes_ = attributes; |
178 bind_generates_resources_ = bind_generates_resources; | 179 bind_generates_resources_ = bind_generates_resources; |
179 } | 180 } |
180 | 181 |
181 bool WebGraphicsContext3DCommandBufferImpl::Initialize( | 182 bool WebGraphicsContext3DCommandBufferImpl::Initialize( |
182 const WebGraphicsContext3D::Attributes& attributes, | 183 const WebGraphicsContext3D::Attributes& attributes, |
183 bool bind_generates_resources, | 184 bool bind_generates_resources, |
184 content::CauseForGpuLaunch cause) { | 185 CauseForGpuLaunch cause) { |
185 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); | 186 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::initialize"); |
186 | 187 |
187 attributes_ = attributes; | 188 attributes_ = attributes; |
188 bind_generates_resources_ = bind_generates_resources; | 189 bind_generates_resources_ = bind_generates_resources; |
189 DCHECK(!command_buffer_); | 190 DCHECK(!command_buffer_); |
190 | 191 |
191 if (!factory_) | 192 if (!factory_) |
192 return false; | 193 return false; |
193 | 194 |
194 if (attributes.preferDiscreteGPU) | 195 if (attributes.preferDiscreteGPU) |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 | 1447 |
1447 // static | 1448 // static |
1448 WebGraphicsContext3DCommandBufferImpl* | 1449 WebGraphicsContext3DCommandBufferImpl* |
1449 WebGraphicsContext3DCommandBufferImpl::CreateViewContext( | 1450 WebGraphicsContext3DCommandBufferImpl::CreateViewContext( |
1450 GpuChannelHostFactory* factory, | 1451 GpuChannelHostFactory* factory, |
1451 int32 surface_id, | 1452 int32 surface_id, |
1452 const char* allowed_extensions, | 1453 const char* allowed_extensions, |
1453 const WebGraphicsContext3D::Attributes& attributes, | 1454 const WebGraphicsContext3D::Attributes& attributes, |
1454 bool bind_generates_resources, | 1455 bool bind_generates_resources, |
1455 const GURL& active_url, | 1456 const GURL& active_url, |
1456 content::CauseForGpuLaunch cause) { | 1457 CauseForGpuLaunch cause) { |
1457 WebGraphicsContext3DCommandBufferImpl* context = | 1458 WebGraphicsContext3DCommandBufferImpl* context = |
1458 new WebGraphicsContext3DCommandBufferImpl( | 1459 new WebGraphicsContext3DCommandBufferImpl( |
1459 surface_id, | 1460 surface_id, |
1460 active_url, | 1461 active_url, |
1461 factory, | 1462 factory, |
1462 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>()); | 1463 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>()); |
1463 if (!context->Initialize(attributes, bind_generates_resources, cause) || | 1464 if (!context->Initialize(attributes, bind_generates_resources, cause) || |
1464 !context->MaybeInitializeGL(allowed_extensions)) { | 1465 !context->MaybeInitializeGL(allowed_extensions)) { |
1465 delete context; | 1466 delete context; |
1466 return NULL; | 1467 return NULL; |
1467 } | 1468 } |
1468 return context; | 1469 return context; |
1469 } | 1470 } |
1470 | 1471 |
1471 // static | 1472 // static |
1472 WebGraphicsContext3DCommandBufferImpl* | 1473 WebGraphicsContext3DCommandBufferImpl* |
1473 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 1474 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
1474 GpuChannelHostFactory* factory, | 1475 GpuChannelHostFactory* factory, |
1475 const WebGraphicsContext3D::Attributes& attributes, | 1476 const WebGraphicsContext3D::Attributes& attributes, |
1476 const GURL& active_url) { | 1477 const GURL& active_url) { |
1477 if (!factory) | 1478 if (!factory) |
1478 return NULL; | 1479 return NULL; |
1479 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> null_client; | 1480 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> null_client; |
1480 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 1481 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
1481 new WebGraphicsContext3DCommandBufferImpl( | 1482 new WebGraphicsContext3DCommandBufferImpl( |
1482 0, active_url, factory, null_client)); | 1483 0, active_url, factory, null_client)); |
1483 content::CauseForGpuLaunch cause = | 1484 CauseForGpuLaunch cause = |
1484 content::CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIA
LIZE; | 1485 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
1485 if (context->Initialize(attributes, false, cause)) | 1486 if (context->Initialize(attributes, false, cause)) |
1486 return context.release(); | 1487 return context.release(); |
1487 return NULL; | 1488 return NULL; |
1488 } | 1489 } |
1489 | 1490 |
1490 void WebGraphicsContext3DCommandBufferImpl:: | 1491 void WebGraphicsContext3DCommandBufferImpl:: |
1491 setSwapBuffersCompleteCallbackCHROMIUM( | 1492 setSwapBuffersCompleteCallbackCHROMIUM( |
1492 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) { | 1493 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) { |
1493 swapbuffers_complete_callback_ = cb; | 1494 swapbuffers_complete_callback_ = cb; |
1494 } | 1495 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 swap_client_->OnViewContextSwapBuffersAborted(); | 1597 swap_client_->OnViewContextSwapBuffersAborted(); |
1597 } | 1598 } |
1598 | 1599 |
1599 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1600 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
1600 const std::string& message, int id) { | 1601 const std::string& message, int id) { |
1601 if (error_message_callback_) { | 1602 if (error_message_callback_) { |
1602 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | 1603 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); |
1603 error_message_callback_->onErrorMessage(str, id); | 1604 error_message_callback_->onErrorMessage(str, id); |
1604 } | 1605 } |
1605 } | 1606 } |
| 1607 |
| 1608 } // namespace content |
OLD | NEW |