Chromium Code Reviews| 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 "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 // Return the current error. | 138 // Return the current error. |
| 139 Error GetError(); | 139 Error GetError(); |
| 140 | 140 |
| 141 // Return true if GPU process reported GLInProcessContext lost or there was a | 141 // Return true if GPU process reported GLInProcessContext lost or there was a |
| 142 // problem communicating with the GPU process. | 142 // problem communicating with the GPU process. |
| 143 bool IsCommandBufferContextLost(); | 143 bool IsCommandBufferContextLost(); |
| 144 | 144 |
| 145 CommandBufferService* GetCommandBufferService(); | 145 CommandBufferService* GetCommandBufferService(); |
| 146 | 146 |
| 147 void set_context_lost_reason(WGC3Denum reason) { | |
| 148 context_lost_reason_ = reason; | |
| 149 } | |
| 150 | |
| 147 private: | 151 private: |
| 148 explicit GLInProcessContext(GLInProcessContext* parent); | 152 explicit GLInProcessContext(GLInProcessContext* parent); |
| 149 | 153 |
| 150 bool Initialize(const gfx::Size& size, | 154 bool Initialize(const gfx::Size& size, |
| 151 GLInProcessContext* context_group, | 155 GLInProcessContext* context_group, |
| 152 const char* allowed_extensions, | 156 const char* allowed_extensions, |
| 153 const int32* attrib_list, | 157 const int32* attrib_list, |
| 154 gfx::GpuPreference gpu_preference); | 158 gfx::GpuPreference gpu_preference); |
| 155 void Destroy(); | 159 void Destroy(); |
| 156 | 160 |
| 157 void OnContextLost(); | 161 void OnContextLost(); |
| 158 | 162 |
| 159 base::WeakPtr<GLInProcessContext> parent_; | 163 base::WeakPtr<GLInProcessContext> parent_; |
| 160 base::Closure context_lost_callback_; | 164 base::Closure context_lost_callback_; |
| 161 uint32 parent_texture_id_; | 165 uint32 parent_texture_id_; |
| 162 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 163 scoped_ptr<CommandBufferService> command_buffer_; | 167 scoped_ptr<CommandBufferService> command_buffer_; |
| 164 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 165 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 166 scoped_refptr<gfx::GLContext> context_; | 170 scoped_refptr<gfx::GLContext> context_; |
| 167 scoped_refptr<gfx::GLSurface> surface_; | 171 scoped_refptr<gfx::GLSurface> surface_; |
| 168 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 172 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
| 169 scoped_ptr<TransferBuffer> transfer_buffer_; | 173 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 170 scoped_ptr<GLES2Implementation> gles2_implementation_; | 174 scoped_ptr<GLES2Implementation> gles2_implementation_; |
| 171 Error last_error_; | 175 Error last_error_; |
| 176 WGC3Denum context_lost_reason_; | |
| 172 | 177 |
| 173 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); | 178 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); |
| 174 }; | 179 }; |
| 175 | 180 |
| 176 namespace { | 181 namespace { |
| 177 | 182 |
| 178 const int32 kCommandBufferSize = 1024 * 1024; | 183 const int32 kCommandBufferSize = 1024 * 1024; |
| 179 // TODO(kbr): make the transfer buffer size configurable via context | 184 // TODO(kbr): make the transfer buffer size configurable via context |
| 180 // creation attributes. | 185 // creation attributes. |
| 181 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 186 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 // and in particular the GL implementations behind it, are not generally | 244 // and in particular the GL implementations behind it, are not generally |
| 240 // threadsafe, so we guard entry points with a mutex. | 245 // threadsafe, so we guard entry points with a mutex. |
| 241 static base::LazyInstance<base::Lock> g_decoder_lock = | 246 static base::LazyInstance<base::Lock> g_decoder_lock = |
| 242 LAZY_INSTANCE_INITIALIZER; | 247 LAZY_INSTANCE_INITIALIZER; |
| 243 | 248 |
| 244 void GLInProcessContext::PumpCommands() { | 249 void GLInProcessContext::PumpCommands() { |
| 245 base::AutoLock lock(g_decoder_lock.Get()); | 250 base::AutoLock lock(g_decoder_lock.Get()); |
| 246 decoder_->MakeCurrent(); | 251 decoder_->MakeCurrent(); |
| 247 gpu_scheduler_->PutChanged(); | 252 gpu_scheduler_->PutChanged(); |
| 248 ::gpu::CommandBuffer::State state = command_buffer_->GetState(); | 253 ::gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 249 CHECK(state.error == ::gpu::error::kNoError); | 254 if (!context_lost_reason_) |
| 255 CHECK(state.error == ::gpu::error::kNoError); | |
| 250 } | 256 } |
| 251 | 257 |
| 252 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { | 258 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { |
| 253 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); | 259 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); |
| 254 } | 260 } |
| 255 | 261 |
| 256 uint32 GLInProcessContext::GetParentTextureId() { | 262 uint32 GLInProcessContext::GetParentTextureId() { |
| 257 return parent_texture_id_; | 263 return parent_texture_id_; |
| 258 } | 264 } |
| 259 | 265 |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 ClearContext(); | 1656 ClearContext(); |
| 1651 return gl_->MapBufferCHROMIUM(target, access); | 1657 return gl_->MapBufferCHROMIUM(target, access); |
| 1652 } | 1658 } |
| 1653 | 1659 |
| 1654 WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl:: | 1660 WGC3Dboolean WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 1655 unmapBufferCHROMIUM(WGC3Denum target) { | 1661 unmapBufferCHROMIUM(WGC3Denum target) { |
| 1656 ClearContext(); | 1662 ClearContext(); |
| 1657 return gl_->UnmapBufferCHROMIUM(target); | 1663 return gl_->UnmapBufferCHROMIUM(target); |
| 1658 } | 1664 } |
| 1659 | 1665 |
| 1666 void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM( | |
| 1667 WGC3Denum current, WGC3Denum other) { | |
| 1668 ClearContext(); | |
| 1669 gl_->LoseContextCHROMIUM(current, other); | |
| 1670 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | |
| 1671 context_->set_context_lost_reason(context_lost_reason_); | |
|
jamesr
2012/12/18 05:40:11
why do we need to store the context loss reason on
danakj
2012/12/18 21:26:59
Done.
| |
| 1672 } | |
| 1673 | |
| 1660 GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl:: | 1674 GrGLInterface* WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 1661 onCreateGrGLInterface() { | 1675 onCreateGrGLInterface() { |
| 1662 return CreateCommandBufferSkiaGLBinding(); | 1676 return CreateCommandBufferSkiaGLBinding(); |
| 1663 } | 1677 } |
| 1664 | 1678 |
| 1665 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1679 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
| 1666 // TODO(kbr): improve the precision here. | 1680 // TODO(kbr): improve the precision here. |
| 1667 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1681 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1668 if (context_lost_callback_) { | 1682 if (context_lost_callback_) { |
| 1669 context_lost_callback_->onContextLost(); | 1683 context_lost_callback_->onContextLost(); |
| 1670 } | 1684 } |
| 1671 } | 1685 } |
| 1672 | 1686 |
| 1673 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1687 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
| 1674 WebGLId, WGC3Dint, const WGC3Dchar*) | 1688 WebGLId, WGC3Dint, const WGC3Dchar*) |
| 1675 | 1689 |
| 1676 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1690 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) |
| 1677 | 1691 |
| 1678 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1692 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
| 1679 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1693 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
| 1680 WGC3Denum, const WGC3Dbyte*) | 1694 WGC3Denum, const WGC3Dbyte*) |
| 1681 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1695 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
| 1682 WGC3Denum, const WGC3Dbyte*) | 1696 WGC3Denum, const WGC3Dbyte*) |
| 1683 | 1697 |
| 1684 } // namespace gpu | 1698 } // namespace gpu |
| 1685 } // namespace webkit | 1699 } // namespace webkit |
| OLD | NEW |