| 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 27 matching lines...) Expand all Loading... |
| 38 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > | 38 static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> > |
| 39 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 39 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 void ClearSharedContexts() { | 43 void ClearSharedContexts() { |
| 44 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 44 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 45 g_all_shared_contexts.Pointer()->clear(); | 45 g_all_shared_contexts.Pointer()->clear(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ClearSharedContextsIfInShareSet( |
| 49 WebGraphicsContext3DCommandBufferImpl* context) { |
| 50 // If the given context isn't in the share set, that means that it |
| 51 // or another context it was previously sharing with already |
| 52 // provoked a lost context. Other contexts might have since been |
| 53 // successfully created and added to the share set, so do not clear |
| 54 // out the share set unless we know that all the contexts in there |
| 55 // are supposed to be lost simultaneously. |
| 56 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 57 std::set<WebGraphicsContext3DCommandBufferImpl*>* share_set = |
| 58 g_all_shared_contexts.Pointer(); |
| 59 for (std::set<WebGraphicsContext3DCommandBufferImpl*>::iterator iter = |
| 60 share_set->begin(); iter != share_set->end(); ++iter) { |
| 61 if (context == *iter) { |
| 62 share_set->clear(); |
| 63 return; |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 48 const int32 kCommandBufferSize = 1024 * 1024; | 68 const int32 kCommandBufferSize = 1024 * 1024; |
| 49 // TODO(kbr): make the transfer buffer size configurable via context | 69 // TODO(kbr): make the transfer buffer size configurable via context |
| 50 // creation attributes. | 70 // creation attributes. |
| 51 const size_t kStartTransferBufferSize = 1 * 1024 * 1024; | 71 const size_t kStartTransferBufferSize = 1 * 1024 * 1024; |
| 52 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 72 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
| 53 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; | 73 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
| 54 | 74 |
| 55 // Singleton used to initialize and terminate the gles2 library. | 75 // Singleton used to initialize and terminate the gles2 library. |
| 56 class GLES2Initializer { | 76 class GLES2Initializer { |
| 57 public: | 77 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 153 |
| 134 WebGraphicsContext3DCommandBufferImpl:: | 154 WebGraphicsContext3DCommandBufferImpl:: |
| 135 ~WebGraphicsContext3DCommandBufferImpl() { | 155 ~WebGraphicsContext3DCommandBufferImpl() { |
| 136 if (gl_) { | 156 if (gl_) { |
| 137 gl_->SetErrorMessageCallback(NULL); | 157 gl_->SetErrorMessageCallback(NULL); |
| 138 } | 158 } |
| 139 | 159 |
| 140 if (host_) { | 160 if (host_) { |
| 141 if (host_->WillGpuSwitchOccur(false, gpu_preference_)) { | 161 if (host_->WillGpuSwitchOccur(false, gpu_preference_)) { |
| 142 host_->ForciblyCloseChannel(); | 162 host_->ForciblyCloseChannel(); |
| 163 TRACE_EVENT0( |
| 164 "gpu", |
| 165 "WebGfxCtx3DCmdBfrImpl::~WebGfxCtx3DCmdBfrImpl closed channel"); |
| 143 ClearSharedContexts(); | 166 ClearSharedContexts(); |
| 144 } | 167 } |
| 145 } | 168 } |
| 146 | 169 |
| 147 { | 170 { |
| 148 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 171 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 149 g_all_shared_contexts.Pointer()->erase(this); | 172 g_all_shared_contexts.Pointer()->erase(this); |
| 150 } | 173 } |
| 151 Destroy(); | 174 Destroy(); |
| 152 } | 175 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (!host_) | 208 if (!host_) |
| 186 return false; | 209 return false; |
| 187 DCHECK(host_->state() == GpuChannelHost::kConnected); | 210 DCHECK(host_->state() == GpuChannelHost::kConnected); |
| 188 | 211 |
| 189 if (!retry) { | 212 if (!retry) { |
| 190 // If the creation of this context requires all contexts for this | 213 // If the creation of this context requires all contexts for this |
| 191 // client to be destroyed on the GPU process side, then drop the | 214 // client to be destroyed on the GPU process side, then drop the |
| 192 // channel and recreate it. | 215 // channel and recreate it. |
| 193 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) { | 216 if (host_->WillGpuSwitchOccur(true, gpu_preference_)) { |
| 194 host_->ForciblyCloseChannel(); | 217 host_->ForciblyCloseChannel(); |
| 218 TRACE_EVENT0( |
| 219 "gpu", |
| 220 "WebGfxCtx3DCmdBfrImpl::Initialize closed channel"); |
| 195 ClearSharedContexts(); | 221 ClearSharedContexts(); |
| 196 retry = true; | 222 retry = true; |
| 197 } | 223 } |
| 198 } else { | 224 } else { |
| 199 retry = false; | 225 retry = false; |
| 200 } | 226 } |
| 201 } while (retry); | 227 } while (retry); |
| 202 | 228 |
| 203 return true; | 229 return true; |
| 204 } | 230 } |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 | 1533 |
| 1508 } // anonymous namespace | 1534 } // anonymous namespace |
| 1509 | 1535 |
| 1510 void WebGraphicsContext3DCommandBufferImpl::OnContextLost() { | 1536 void WebGraphicsContext3DCommandBufferImpl::OnContextLost() { |
| 1511 context_lost_reason_ = convertReason( | 1537 context_lost_reason_ = convertReason( |
| 1512 command_buffer_->GetLastState().context_lost_reason); | 1538 command_buffer_->GetLastState().context_lost_reason); |
| 1513 if (context_lost_callback_) { | 1539 if (context_lost_callback_) { |
| 1514 context_lost_callback_->onContextLost(); | 1540 context_lost_callback_->onContextLost(); |
| 1515 } | 1541 } |
| 1516 if (attributes_.shareResources) | 1542 if (attributes_.shareResources) |
| 1517 ClearSharedContexts(); | 1543 ClearSharedContextsIfInShareSet(this); |
| 1518 if (ShouldUseSwapClient()) | 1544 if (ShouldUseSwapClient()) |
| 1519 swap_client_->OnViewContextSwapBuffersAborted(); | 1545 swap_client_->OnViewContextSwapBuffersAborted(); |
| 1520 } | 1546 } |
| 1521 | 1547 |
| 1522 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1548 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
| 1523 const std::string& message, int id) { | 1549 const std::string& message, int id) { |
| 1524 if (error_message_callback_) { | 1550 if (error_message_callback_) { |
| 1525 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | 1551 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); |
| 1526 error_message_callback_->onErrorMessage(str, id); | 1552 error_message_callback_->onErrorMessage(str, id); |
| 1527 } | 1553 } |
| 1528 } | 1554 } |
| OLD | NEW |