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 "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #ifndef GL_GLEXT_PROTOTYPES | 9 #ifndef GL_GLEXT_PROTOTYPES |
| 10 #define GL_GLEXT_PROTOTYPES 1 | 10 #define GL_GLEXT_PROTOTYPES 1 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 bool is_offscreen, | 61 bool is_offscreen, |
| 62 gfx::AcceleratedWidget window) | 62 gfx::AcceleratedWidget window) |
| 63 : attributes_(attributes), | 63 : attributes_(attributes), |
| 64 share_resources_(share_resources), | 64 share_resources_(share_resources), |
| 65 is_offscreen_(is_offscreen), | 65 is_offscreen_(is_offscreen), |
| 66 window_(window), | 66 window_(window), |
| 67 context_(std::move(context)) {} | 67 context_(std::move(context)) {} |
| 68 | 68 |
| 69 WebGraphicsContext3DInProcessCommandBufferImpl:: | 69 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 70 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 70 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
| 71 if (real_gl_) { | |
| 72 real_gl_->SetErrorMessageCallback( | |
| 73 base::Callback<void(const char*, int32_t)>()); | |
| 74 real_gl_->SetLostContextCallback(base::Closure()); | |
| 75 } | |
| 71 } | 76 } |
| 72 | 77 |
| 73 size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { | 78 size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { |
| 74 return context_->GetMappedMemoryLimit(); | 79 return context_->GetMappedMemoryLimit(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { | 82 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { |
| 78 if (initialized_) | 83 if (initialized_) |
| 79 return true; | 84 return true; |
| 80 | 85 |
| 81 if (initialize_failed_) | 86 if (initialize_failed_) |
| 82 return false; | 87 return false; |
| 83 | 88 |
| 84 if (!context_) { | 89 if (!context_) { |
| 85 // TODO(kbr): More work will be needed in this implementation to | 90 // TODO(kbr): More work will be needed in this implementation to |
| 86 // properly support GPU switching. Like in the out-of-process | 91 // properly support GPU switching. Like in the out-of-process |
| 87 // command buffer implementation, all previously created contexts | 92 // command buffer implementation, all previously created contexts |
| 88 // will need to be lost either when the first context requesting the | 93 // will need to be lost either when the first context requesting the |
| 89 // discrete GPU is created, or the last one is destroyed. | 94 // discrete GPU is created, or the last one is destroyed. |
| 90 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 95 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 91 context_.reset(GLInProcessContext::Create( | 96 context_.reset(GLInProcessContext::Create( |
| 92 NULL, /* service */ | 97 NULL, /* service */ |
| 93 NULL, /* surface */ | 98 NULL, /* surface */ |
| 94 is_offscreen_, window_, gfx::Size(1, 1), NULL, /* share_context */ | 99 is_offscreen_, window_, gfx::Size(1, 1), NULL, /* share_context */ |
| 95 share_resources_, attributes_, gpu_preference, | 100 share_resources_, attributes_, gpu_preference, |
| 96 ::gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr)); | 101 ::gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr)); |
| 97 } | 102 } |
| 98 | 103 |
| 99 if (context_) { | 104 if (!context_) { |
| 100 base::Closure context_lost_callback = base::Bind( | |
| 101 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | |
| 102 base::Unretained(this)); | |
| 103 context_->SetContextLostCallback(context_lost_callback); | |
| 104 } else { | |
| 105 initialize_failed_ = true; | 105 initialize_failed_ = true; |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 real_gl_ = context_->GetImplementation(); | 109 real_gl_ = context_->GetImplementation(); |
| 110 SetGLInterface(real_gl_); | 110 SetGLInterface(real_gl_); |
| 111 | 111 |
| 112 real_gl_->SetErrorMessageCallback(base::Bind( | |
| 113 // This method is in WebGraphicsContext3DImpl. | |
| 114 &WebGraphicsContext3DInProcessCommandBufferImpl::OnErrorMessage, | |
|
danakj
2016/04/06 02:14:15
I started setting this here, but I don't think thi
| |
| 115 // The callback is unset in the destructor. | |
| 116 base::Unretained(this))); | |
| 117 real_gl_->SetLostContextCallback( | |
| 118 base::Bind(&WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | |
| 119 // The callback is unset in the destructor. | |
| 120 base::Unretained(this))); | |
| 121 | |
| 112 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", | 122 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", |
| 113 "InProcessContext"); | 123 "InProcessContext"); |
| 114 | 124 |
| 115 initialized_ = true; | 125 initialized_ = true; |
| 116 return true; | 126 return true; |
| 117 } | 127 } |
| 118 | 128 |
| 119 bool | 129 bool |
| 120 WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() { | 130 WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() { |
| 121 if (!MaybeInitializeGL()) | 131 if (!MaybeInitializeGL()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 134 return real_gl_; | 144 return real_gl_; |
| 135 } | 145 } |
| 136 | 146 |
| 137 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 147 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
| 138 if (context_lost_callback_) { | 148 if (context_lost_callback_) { |
| 139 context_lost_callback_->onContextLost(); | 149 context_lost_callback_->onContextLost(); |
| 140 } | 150 } |
| 141 } | 151 } |
| 142 | 152 |
| 143 } // namespace gpu_blink | 153 } // namespace gpu_blink |
| OLD | NEW |