| 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/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | 5 #include "webkit/common/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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 window_(window), | 111 window_(window), |
| 112 context_(context.Pass()) { | 112 context_(context.Pass()) { |
| 113 ConvertAttributes(attributes, &attribs_); | 113 ConvertAttributes(attributes, &attribs_); |
| 114 attribs_.lose_context_when_out_of_memory = lose_context_when_out_of_memory; | 114 attribs_.lose_context_when_out_of_memory = lose_context_when_out_of_memory; |
| 115 } | 115 } |
| 116 | 116 |
| 117 WebGraphicsContext3DInProcessCommandBufferImpl:: | 117 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 118 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 118 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
| 119 } | 119 } |
| 120 | 120 |
| 121 size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() { |
| 122 return context_->GetMappedMemoryLimit(); |
| 123 } |
| 124 |
| 121 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { | 125 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { |
| 122 if (initialized_) | 126 if (initialized_) |
| 123 return true; | 127 return true; |
| 124 | 128 |
| 125 if (initialize_failed_) | 129 if (initialize_failed_) |
| 126 return false; | 130 return false; |
| 127 | 131 |
| 128 // Ensure the gles2 library is initialized first in a thread safe way. | 132 // Ensure the gles2 library is initialized first in a thread safe way. |
| 129 g_gles2_initializer.Get(); | 133 g_gles2_initializer.Get(); |
| 130 | 134 |
| 131 if (!context_) { | 135 if (!context_) { |
| 132 // TODO(kbr): More work will be needed in this implementation to | 136 // TODO(kbr): More work will be needed in this implementation to |
| 133 // properly support GPU switching. Like in the out-of-process | 137 // properly support GPU switching. Like in the out-of-process |
| 134 // command buffer implementation, all previously created contexts | 138 // command buffer implementation, all previously created contexts |
| 135 // will need to be lost either when the first context requesting the | 139 // will need to be lost either when the first context requesting the |
| 136 // discrete GPU is created, or the last one is destroyed. | 140 // discrete GPU is created, or the last one is destroyed. |
| 137 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 141 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 138 context_.reset(GLInProcessContext::Create(NULL, /* service */ | 142 context_.reset(GLInProcessContext::Create( |
| 139 NULL, /* surface */ | 143 NULL, /* service */ |
| 140 is_offscreen_, | 144 NULL, /* surface */ |
| 141 window_, | 145 is_offscreen_, |
| 142 gfx::Size(1, 1), | 146 window_, |
| 143 NULL, /* share_context */ | 147 gfx::Size(1, 1), |
| 144 share_resources_, | 148 NULL, /* share_context */ |
| 145 attribs_, | 149 share_resources_, |
| 146 gpu_preference)); | 150 attribs_, |
| 151 gpu_preference, |
| 152 ::gpu::GLInProcessContextSharedMemoryLimits())); |
| 147 } | 153 } |
| 148 | 154 |
| 149 if (context_) { | 155 if (context_) { |
| 150 base::Closure context_lost_callback = base::Bind( | 156 base::Closure context_lost_callback = base::Bind( |
| 151 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | 157 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, |
| 152 base::Unretained(this)); | 158 base::Unretained(this)); |
| 153 context_->SetContextLostCallback(context_lost_callback); | 159 context_->SetContextLostCallback(context_lost_callback); |
| 154 } else { | 160 } else { |
| 155 initialize_failed_ = true; | 161 initialize_failed_ = true; |
| 156 return false; | 162 return false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 196 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
| 191 // TODO(kbr): improve the precision here. | 197 // TODO(kbr): improve the precision here. |
| 192 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 198 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 193 if (context_lost_callback_) { | 199 if (context_lost_callback_) { |
| 194 context_lost_callback_->onContextLost(); | 200 context_lost_callback_->onContextLost(); |
| 195 } | 201 } |
| 196 } | 202 } |
| 197 | 203 |
| 198 } // namespace gpu | 204 } // namespace gpu |
| 199 } // namespace webkit | 205 } // namespace webkit |
| OLD | NEW |