| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service/texture_definition.h" | 5 #include "gpu/command_buffer/service/texture_definition.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 TextureDefinition::LevelInfo::~LevelInfo() {} | 310 TextureDefinition::LevelInfo::~LevelInfo() {} |
| 311 | 311 |
| 312 TextureDefinition::TextureDefinition() | 312 TextureDefinition::TextureDefinition() |
| 313 : version_(0), | 313 : version_(0), |
| 314 target_(0), | 314 target_(0), |
| 315 min_filter_(0), | 315 min_filter_(0), |
| 316 mag_filter_(0), | 316 mag_filter_(0), |
| 317 wrap_s_(0), | 317 wrap_s_(0), |
| 318 wrap_t_(0), | 318 wrap_t_(0), |
| 319 usage_(0), | 319 usage_(0), |
| 320 immutable_(true) { | 320 immutable_(true), |
| 321 is_es3_enabled_(false) { |
| 321 } | 322 } |
| 322 | 323 |
| 323 TextureDefinition::TextureDefinition( | 324 TextureDefinition::TextureDefinition( |
| 324 Texture* texture, | 325 Texture* texture, |
| 325 unsigned int version, | 326 unsigned int version, |
| 326 const scoped_refptr<NativeImageBuffer>& image_buffer) | 327 const scoped_refptr<NativeImageBuffer>& image_buffer) |
| 327 : version_(version), | 328 : version_(version), |
| 328 target_(texture->target()), | 329 target_(texture->target()), |
| 329 image_buffer_(image_buffer), | 330 image_buffer_(image_buffer), |
| 330 min_filter_(texture->min_filter()), | 331 min_filter_(texture->min_filter()), |
| 331 mag_filter_(texture->mag_filter()), | 332 mag_filter_(texture->mag_filter()), |
| 332 wrap_s_(texture->wrap_s()), | 333 wrap_s_(texture->wrap_s()), |
| 333 wrap_t_(texture->wrap_t()), | 334 wrap_t_(texture->wrap_t()), |
| 334 usage_(texture->usage()), | 335 usage_(texture->usage()), |
| 335 immutable_(texture->IsImmutable()), | 336 immutable_(texture->IsImmutable()), |
| 336 defined_(texture->IsDefined()) { | 337 defined_(texture->IsDefined()), |
| 338 is_es3_enabled_(texture->IsES3Enabled()) { |
| 337 DCHECK(!image_buffer_.get() || defined_); | 339 DCHECK(!image_buffer_.get() || defined_); |
| 338 if (!image_buffer_.get() && defined_) { | 340 if (!image_buffer_.get() && defined_) { |
| 339 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); | 341 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); |
| 340 DCHECK(image_buffer_.get()); | 342 DCHECK(image_buffer_.get()); |
| 341 } | 343 } |
| 342 | 344 |
| 343 const Texture::FaceInfo& first_face = texture->face_infos_[0]; | 345 const Texture::FaceInfo& first_face = texture->face_infos_[0]; |
| 344 if (image_buffer_.get()) { | 346 if (image_buffer_.get()) { |
| 345 scoped_refptr<gl::GLImage> gl_image(new GLImageSync( | 347 scoped_refptr<gl::GLImage> gl_image(new GLImageSync( |
| 346 image_buffer_, gfx::Size(first_face.level_infos[0].width, | 348 image_buffer_, gfx::Size(first_face.level_infos[0].width, |
| 347 first_face.level_infos[0].height))); | 349 first_face.level_infos[0].height))); |
| 348 texture->SetLevelImage(target_, 0, gl_image.get(), Texture::BOUND); | 350 texture->SetLevelImage(target_, 0, gl_image.get(), Texture::BOUND); |
| 349 } | 351 } |
| 350 | 352 |
| 351 const Texture::LevelInfo& level = first_face.level_infos[0]; | 353 const Texture::LevelInfo& level = first_face.level_infos[0]; |
| 352 level_info_ = LevelInfo(level.target, level.internal_format, level.width, | 354 level_info_ = LevelInfo(level.target, level.internal_format, level.width, |
| 353 level.height, level.depth, level.border, level.format, | 355 level.height, level.depth, level.border, level.format, |
| 354 level.type, level.cleared_rect); | 356 level.type, level.cleared_rect); |
| 355 } | 357 } |
| 356 | 358 |
| 357 TextureDefinition::~TextureDefinition() { | 359 TextureDefinition::~TextureDefinition() { |
| 358 } | 360 } |
| 359 | 361 |
| 360 Texture* TextureDefinition::CreateTexture() const { | 362 Texture* TextureDefinition::CreateTexture() const { |
| 361 GLuint texture_id; | 363 GLuint texture_id; |
| 362 glGenTextures(1, &texture_id); | 364 glGenTextures(1, &texture_id); |
| 363 | 365 |
| 364 Texture* texture(new Texture(texture_id)); | 366 Texture* texture(new Texture(texture_id, is_es3_enabled_)); |
| 365 UpdateTextureInternal(texture); | 367 UpdateTextureInternal(texture); |
| 366 | 368 |
| 367 return texture; | 369 return texture; |
| 368 } | 370 } |
| 369 | 371 |
| 370 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { | 372 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { |
| 371 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); | 373 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); |
| 372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); | 374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); |
| 373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); | 375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); |
| 374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); | 376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 395 if (image_buffer_.get()) { | 397 if (image_buffer_.get()) { |
| 396 texture->SetLevelImage( | 398 texture->SetLevelImage( |
| 397 target_, 0, | 399 target_, 0, |
| 398 new GLImageSync(image_buffer_, | 400 new GLImageSync(image_buffer_, |
| 399 gfx::Size(level_info_.width, level_info_.height)), | 401 gfx::Size(level_info_.width, level_info_.height)), |
| 400 Texture::BOUND); | 402 Texture::BOUND); |
| 401 } | 403 } |
| 402 | 404 |
| 403 texture->target_ = target_; | 405 texture->target_ = target_; |
| 404 texture->SetImmutable(immutable_); | 406 texture->SetImmutable(immutable_); |
| 405 texture->min_filter_ = min_filter_; | 407 texture->sampler_state_.min_filter = min_filter_; |
| 406 texture->mag_filter_ = mag_filter_; | 408 texture->sampler_state_.mag_filter = mag_filter_; |
| 407 texture->wrap_s_ = wrap_s_; | 409 texture->sampler_state_.wrap_s = wrap_s_; |
| 408 texture->wrap_t_ = wrap_t_; | 410 texture->sampler_state_.wrap_t = wrap_t_; |
| 409 texture->usage_ = usage_; | 411 texture->usage_ = usage_; |
| 410 } | 412 } |
| 411 | 413 |
| 412 void TextureDefinition::UpdateTexture(Texture* texture) const { | 414 void TextureDefinition::UpdateTexture(Texture* texture) const { |
| 413 GLuint old_service_id = 0u; | 415 GLuint old_service_id = 0u; |
| 414 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { | 416 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { |
| 415 GLuint service_id = 0u; | 417 GLuint service_id = 0u; |
| 416 glGenTextures(1, &service_id); | 418 glGenTextures(1, &service_id); |
| 417 old_service_id = texture->service_id(); | 419 old_service_id = texture->service_id(); |
| 418 texture->SetServiceId(service_id); | 420 texture->SetServiceId(service_id); |
| 419 | 421 |
| 420 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); | 422 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); |
| 421 GLint bound_id = 0; | 423 GLint bound_id = 0; |
| 422 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); | 424 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); |
| 423 if (bound_id == static_cast<GLint>(old_service_id)) { | 425 if (bound_id == static_cast<GLint>(old_service_id)) { |
| 424 glBindTexture(target_, service_id); | 426 glBindTexture(target_, service_id); |
| 425 } | 427 } |
| 426 texture->SetLevelImage(target_, 0, NULL, Texture::UNBOUND); | 428 texture->SetLevelImage(target_, 0, NULL, Texture::UNBOUND); |
| 427 } | 429 } |
| 428 | 430 |
| 429 UpdateTextureInternal(texture); | 431 UpdateTextureInternal(texture); |
| 430 | 432 |
| 431 if (old_service_id) { | 433 if (old_service_id) { |
| 432 glDeleteTextures(1, &old_service_id); | 434 glDeleteTextures(1, &old_service_id); |
| 433 } | 435 } |
| 434 } | 436 } |
| 435 | 437 |
| 436 bool TextureDefinition::Matches(const Texture* texture) const { | 438 bool TextureDefinition::Matches(const Texture* texture) const { |
| 437 DCHECK(target_ == texture->target()); | 439 DCHECK(target_ == texture->target()); |
| 438 if (texture->min_filter_ != min_filter_ || | 440 if (texture->sampler_state_.min_filter != min_filter_ || |
| 439 texture->mag_filter_ != mag_filter_ || | 441 texture->sampler_state_.mag_filter != mag_filter_ || |
| 440 texture->wrap_s_ != wrap_s_ || | 442 texture->sampler_state_.wrap_s != wrap_s_ || |
| 441 texture->wrap_t_ != wrap_t_ || | 443 texture->sampler_state_.wrap_t != wrap_t_ || |
| 442 texture->SafeToRenderFrom() != SafeToRenderFrom()) { | 444 texture->SafeToRenderFrom() != SafeToRenderFrom()) { |
| 443 return false; | 445 return false; |
| 444 } | 446 } |
| 445 | 447 |
| 446 // Texture became defined. | 448 // Texture became defined. |
| 447 if (!image_buffer_.get() && texture->IsDefined()) | 449 if (!image_buffer_.get() && texture->IsDefined()) |
| 448 return false; | 450 return false; |
| 449 | 451 |
| 450 // All structural changes should have orphaned the texture. | 452 // All structural changes should have orphaned the texture. |
| 451 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) | 453 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) |
| 452 return false; | 454 return false; |
| 453 | 455 |
| 454 return true; | 456 return true; |
| 455 } | 457 } |
| 456 | 458 |
| 457 bool TextureDefinition::SafeToRenderFrom() const { | 459 bool TextureDefinition::SafeToRenderFrom() const { |
| 458 return level_info_.cleared_rect.Contains( | 460 return level_info_.cleared_rect.Contains( |
| 459 gfx::Rect(level_info_.width, level_info_.height)); | 461 gfx::Rect(level_info_.width, level_info_.height)); |
| 460 } | 462 } |
| 461 | 463 |
| 462 } // namespace gles2 | 464 } // namespace gles2 |
| 463 } // namespace gpu | 465 } // namespace gpu |
| OLD | NEW |