| 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/command_buffer/client/gl_in_process_context.h" | 5 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 explicit GLInProcessContextImpl(); | 51 explicit GLInProcessContextImpl(); |
| 52 virtual ~GLInProcessContextImpl(); | 52 virtual ~GLInProcessContextImpl(); |
| 53 | 53 |
| 54 bool Initialize( | 54 bool Initialize( |
| 55 scoped_refptr<gfx::GLSurface> surface, | 55 scoped_refptr<gfx::GLSurface> surface, |
| 56 bool is_offscreen, | 56 bool is_offscreen, |
| 57 bool use_global_share_group, | 57 bool use_global_share_group, |
| 58 GLInProcessContext* share_context, | 58 GLInProcessContext* share_context, |
| 59 gfx::AcceleratedWidget window, | 59 gfx::AcceleratedWidget window, |
| 60 const gfx::Size& size, | 60 const gfx::Size& size, |
| 61 const GLInProcessContextAttribs& attribs, | 61 const gpu::gles2::ContextCreationAttribHelper& attribs, |
| 62 gfx::GpuPreference gpu_preference, | 62 gfx::GpuPreference gpu_preference, |
| 63 const scoped_refptr<InProcessCommandBuffer::Service>& service); | 63 const scoped_refptr<InProcessCommandBuffer::Service>& service); |
| 64 | 64 |
| 65 // GLInProcessContext implementation: | 65 // GLInProcessContext implementation: |
| 66 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; | 66 virtual void SetContextLostCallback(const base::Closure& callback) OVERRIDE; |
| 67 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; | 67 virtual gles2::GLES2Implementation* GetImplementation() OVERRIDE; |
| 68 | 68 |
| 69 #if defined(OS_ANDROID) | 69 #if defined(OS_ANDROID) |
| 70 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 70 virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
| 71 uint32 stream_id) OVERRIDE; | 71 uint32 stream_id) OVERRIDE; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool GLInProcessContextImpl::Initialize( | 122 bool GLInProcessContextImpl::Initialize( |
| 123 scoped_refptr<gfx::GLSurface> surface, | 123 scoped_refptr<gfx::GLSurface> surface, |
| 124 bool is_offscreen, | 124 bool is_offscreen, |
| 125 bool use_global_share_group, | 125 bool use_global_share_group, |
| 126 GLInProcessContext* share_context, | 126 GLInProcessContext* share_context, |
| 127 gfx::AcceleratedWidget window, | 127 gfx::AcceleratedWidget window, |
| 128 const gfx::Size& size, | 128 const gfx::Size& size, |
| 129 const GLInProcessContextAttribs& attribs, | 129 const gles2::ContextCreationAttribHelper& attribs, |
| 130 gfx::GpuPreference gpu_preference, | 130 gfx::GpuPreference gpu_preference, |
| 131 const scoped_refptr<InProcessCommandBuffer::Service>& service) { | 131 const scoped_refptr<InProcessCommandBuffer::Service>& service) { |
| 132 DCHECK(!use_global_share_group || !share_context); | 132 DCHECK(!use_global_share_group || !share_context); |
| 133 DCHECK(size.width() >= 0 && size.height() >= 0); | 133 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 134 | 134 |
| 135 // Changes to these values should also be copied to | |
| 136 // gpu/command_buffer/client/gl_in_process_context.cc and to | |
| 137 // content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h | |
| 138 const int32 ALPHA_SIZE = 0x3021; | |
| 139 const int32 BLUE_SIZE = 0x3022; | |
| 140 const int32 GREEN_SIZE = 0x3023; | |
| 141 const int32 RED_SIZE = 0x3024; | |
| 142 const int32 DEPTH_SIZE = 0x3025; | |
| 143 const int32 STENCIL_SIZE = 0x3026; | |
| 144 const int32 SAMPLES = 0x3031; | |
| 145 const int32 SAMPLE_BUFFERS = 0x3032; | |
| 146 const int32 NONE = 0x3038; | |
| 147 | |
| 148 // Chromium-specific attributes | |
| 149 const int32 FAIL_IF_MAJOR_PERF_CAVEAT = 0x10002; | |
| 150 const int32 LOSE_CONTEXT_WHEN_OUT_OF_MEMORY = 0x10003; | |
| 151 | |
| 152 std::vector<int32> attrib_vector; | 135 std::vector<int32> attrib_vector; |
| 153 if (attribs.alpha_size >= 0) { | 136 attribs.Serialize(&attrib_vector); |
| 154 attrib_vector.push_back(ALPHA_SIZE); | |
| 155 attrib_vector.push_back(attribs.alpha_size); | |
| 156 } | |
| 157 if (attribs.blue_size >= 0) { | |
| 158 attrib_vector.push_back(BLUE_SIZE); | |
| 159 attrib_vector.push_back(attribs.blue_size); | |
| 160 } | |
| 161 if (attribs.green_size >= 0) { | |
| 162 attrib_vector.push_back(GREEN_SIZE); | |
| 163 attrib_vector.push_back(attribs.green_size); | |
| 164 } | |
| 165 if (attribs.red_size >= 0) { | |
| 166 attrib_vector.push_back(RED_SIZE); | |
| 167 attrib_vector.push_back(attribs.red_size); | |
| 168 } | |
| 169 if (attribs.depth_size >= 0) { | |
| 170 attrib_vector.push_back(DEPTH_SIZE); | |
| 171 attrib_vector.push_back(attribs.depth_size); | |
| 172 } | |
| 173 if (attribs.stencil_size >= 0) { | |
| 174 attrib_vector.push_back(STENCIL_SIZE); | |
| 175 attrib_vector.push_back(attribs.stencil_size); | |
| 176 } | |
| 177 if (attribs.samples >= 0) { | |
| 178 attrib_vector.push_back(SAMPLES); | |
| 179 attrib_vector.push_back(attribs.samples); | |
| 180 } | |
| 181 if (attribs.sample_buffers >= 0) { | |
| 182 attrib_vector.push_back(SAMPLE_BUFFERS); | |
| 183 attrib_vector.push_back(attribs.sample_buffers); | |
| 184 } | |
| 185 if (attribs.fail_if_major_perf_caveat > 0) { | |
| 186 attrib_vector.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); | |
| 187 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); | |
| 188 } | |
| 189 if (attribs.lose_context_when_out_of_memory > 0) { | |
| 190 attrib_vector.push_back(LOSE_CONTEXT_WHEN_OUT_OF_MEMORY); | |
| 191 attrib_vector.push_back(attribs.lose_context_when_out_of_memory); | |
| 192 } | |
| 193 attrib_vector.push_back(NONE); | |
| 194 | 137 |
| 195 base::Closure wrapped_callback = | 138 base::Closure wrapped_callback = |
| 196 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); | 139 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); |
| 197 command_buffer_.reset(new InProcessCommandBuffer(service)); | 140 command_buffer_.reset(new InProcessCommandBuffer(service)); |
| 198 | 141 |
| 199 scoped_ptr<base::AutoLock> scoped_shared_context_lock; | 142 scoped_ptr<base::AutoLock> scoped_shared_context_lock; |
| 200 scoped_refptr<gles2::ShareGroup> share_group; | 143 scoped_refptr<gles2::ShareGroup> share_group; |
| 201 InProcessCommandBuffer* share_command_buffer = NULL; | 144 InProcessCommandBuffer* share_command_buffer = NULL; |
| 202 if (use_global_share_group) { | 145 if (use_global_share_group) { |
| 203 scoped_shared_context_lock.reset( | 146 scoped_shared_context_lock.reset( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 183 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
| 241 if (!gles2_helper_->Initialize(kCommandBufferSize)) { | 184 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
| 242 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; | 185 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; |
| 243 Destroy(); | 186 Destroy(); |
| 244 return false; | 187 return false; |
| 245 } | 188 } |
| 246 | 189 |
| 247 // Create a transfer buffer. | 190 // Create a transfer buffer. |
| 248 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 191 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
| 249 | 192 |
| 250 bool bind_generates_resources = false; | 193 // Check for consistency. |
| 194 DCHECK(!attribs.bind_generates_resource); |
| 195 bool bind_generates_resource = false; |
| 251 | 196 |
| 252 // Create the object exposing the OpenGL API. | 197 // Create the object exposing the OpenGL API. |
| 253 gles2_implementation_.reset(new gles2::GLES2Implementation( | 198 gles2_implementation_.reset(new gles2::GLES2Implementation( |
| 254 gles2_helper_.get(), | 199 gles2_helper_.get(), |
| 255 share_group, | 200 share_group, |
| 256 transfer_buffer_.get(), | 201 transfer_buffer_.get(), |
| 257 bind_generates_resources, | 202 bind_generates_resource, |
| 258 attribs.lose_context_when_out_of_memory > 0, | 203 attribs.lose_context_when_out_of_memory, |
| 259 command_buffer_.get())); | 204 command_buffer_.get())); |
| 260 | 205 |
| 261 if (use_global_share_group) { | 206 if (use_global_share_group) { |
| 262 g_all_shared_contexts.Get().insert(this); | 207 g_all_shared_contexts.Get().insert(this); |
| 263 scoped_shared_context_lock.reset(); | 208 scoped_shared_context_lock.reset(); |
| 264 } | 209 } |
| 265 | 210 |
| 266 if (!gles2_implementation_->Initialize( | 211 if (!gles2_implementation_->Initialize( |
| 267 kStartTransferBufferSize, | 212 kStartTransferBufferSize, |
| 268 kMinTransferBufferSize, | 213 kMinTransferBufferSize, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 293 | 238 |
| 294 #if defined(OS_ANDROID) | 239 #if defined(OS_ANDROID) |
| 295 scoped_refptr<gfx::SurfaceTexture> | 240 scoped_refptr<gfx::SurfaceTexture> |
| 296 GLInProcessContextImpl::GetSurfaceTexture(uint32 stream_id) { | 241 GLInProcessContextImpl::GetSurfaceTexture(uint32 stream_id) { |
| 297 return command_buffer_->GetSurfaceTexture(stream_id); | 242 return command_buffer_->GetSurfaceTexture(stream_id); |
| 298 } | 243 } |
| 299 #endif | 244 #endif |
| 300 | 245 |
| 301 } // anonymous namespace | 246 } // anonymous namespace |
| 302 | 247 |
| 303 GLInProcessContextAttribs::GLInProcessContextAttribs() | |
| 304 : alpha_size(-1), | |
| 305 blue_size(-1), | |
| 306 green_size(-1), | |
| 307 red_size(-1), | |
| 308 depth_size(-1), | |
| 309 stencil_size(-1), | |
| 310 samples(-1), | |
| 311 sample_buffers(-1), | |
| 312 fail_if_major_perf_caveat(-1), | |
| 313 lose_context_when_out_of_memory(-1) {} | |
| 314 | |
| 315 GLInProcessContext* GLInProcessContext::Create( | 248 GLInProcessContext* GLInProcessContext::Create( |
| 316 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | 249 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, |
| 317 scoped_refptr<gfx::GLSurface> surface, | 250 scoped_refptr<gfx::GLSurface> surface, |
| 318 bool is_offscreen, | 251 bool is_offscreen, |
| 319 gfx::AcceleratedWidget window, | 252 gfx::AcceleratedWidget window, |
| 320 const gfx::Size& size, | 253 const gfx::Size& size, |
| 321 GLInProcessContext* share_context, | 254 GLInProcessContext* share_context, |
| 322 bool use_global_share_group, | 255 bool use_global_share_group, |
| 323 const GLInProcessContextAttribs& attribs, | 256 const ::gpu::gles2::ContextCreationAttribHelper& attribs, |
| 324 gfx::GpuPreference gpu_preference) { | 257 gfx::GpuPreference gpu_preference) { |
| 325 DCHECK(!use_global_share_group || !share_context); | 258 DCHECK(!use_global_share_group || !share_context); |
| 326 if (surface.get()) { | 259 if (surface.get()) { |
| 327 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); | 260 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); |
| 328 DCHECK(surface->GetSize() == size); | 261 DCHECK(surface->GetSize() == size); |
| 329 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); | 262 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); |
| 330 } | 263 } |
| 331 | 264 |
| 332 scoped_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl()); | 265 scoped_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl()); |
| 333 if (!context->Initialize(surface, | 266 if (!context->Initialize(surface, |
| 334 is_offscreen, | 267 is_offscreen, |
| 335 use_global_share_group, | 268 use_global_share_group, |
| 336 share_context, | 269 share_context, |
| 337 window, | 270 window, |
| 338 size, | 271 size, |
| 339 attribs, | 272 attribs, |
| 340 gpu_preference, | 273 gpu_preference, |
| 341 service)) | 274 service)) |
| 342 return NULL; | 275 return NULL; |
| 343 | 276 |
| 344 return context.release(); | 277 return context.release(); |
| 345 } | 278 } |
| 346 | 279 |
| 347 } // namespace gpu | 280 } // namespace gpu |
| OLD | NEW |