| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (!image_buffer_.get() && defined_) { | 345 if (!image_buffer_.get() && defined_) { |
| 346 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); | 346 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); |
| 347 DCHECK(image_buffer_.get()); | 347 DCHECK(image_buffer_.get()); |
| 348 } | 348 } |
| 349 | 349 |
| 350 const Texture::FaceInfo& first_face = texture->face_infos_[0]; | 350 const Texture::FaceInfo& first_face = texture->face_infos_[0]; |
| 351 if (image_buffer_.get()) { | 351 if (image_buffer_.get()) { |
| 352 scoped_refptr<gl::GLImage> gl_image(new GLImageSync( | 352 scoped_refptr<gl::GLImage> gl_image(new GLImageSync( |
| 353 image_buffer_, gfx::Size(first_face.level_infos[0].width, | 353 image_buffer_, gfx::Size(first_face.level_infos[0].width, |
| 354 first_face.level_infos[0].height))); | 354 first_face.level_infos[0].height))); |
| 355 texture->SetLevelImage(target_, 0, gl_image.get(), Texture::BOUND); | 355 texture->SetLevelImage(target_, 0, 0, gl_image.get(), Texture::BOUND); |
| 356 } | 356 } |
| 357 | 357 |
| 358 const Texture::LevelInfo& level = first_face.level_infos[0]; | 358 const Texture::LevelInfo& level = first_face.level_infos[0]; |
| 359 level_info_ = LevelInfo(level.target, level.internal_format, level.width, | 359 level_info_ = LevelInfo(level.target, level.internal_format, level.width, |
| 360 level.height, level.depth, level.border, level.format, | 360 level.height, level.depth, level.border, level.format, |
| 361 level.type, level.cleared_rect); | 361 level.type, level.layer_infos[0].cleared_rect); |
| 362 } | 362 } |
| 363 | 363 |
| 364 TextureDefinition::TextureDefinition(const TextureDefinition& other) = default; | 364 TextureDefinition::TextureDefinition(const TextureDefinition& other) = default; |
| 365 | 365 |
| 366 TextureDefinition::~TextureDefinition() { | 366 TextureDefinition::~TextureDefinition() { |
| 367 } | 367 } |
| 368 | 368 |
| 369 Texture* TextureDefinition::CreateTexture() const { | 369 Texture* TextureDefinition::CreateTexture() const { |
| 370 GLuint texture_id; | 370 GLuint texture_id; |
| 371 glGenTextures(1, &texture_id); | 371 glGenTextures(1, &texture_id); |
| 372 | 372 |
| 373 Texture* texture(new Texture(texture_id)); | 373 Texture* texture(new Texture(texture_id)); |
| 374 UpdateTextureInternal(texture); | 374 UpdateTextureInternal(texture); |
| 375 | 375 |
| 376 return texture; | 376 return texture; |
| 377 } | 377 } |
| 378 | 378 |
| 379 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { | 379 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { |
| 380 gl::ScopedTextureBinder texture_binder(target_, texture->service_id()); | 380 gl::ScopedTextureBinder texture_binder(target_, texture->service_id()); |
| 381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); | 381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); |
| 382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); | 382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); |
| 383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); | 383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); |
| 384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); | 384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); |
| 385 | 385 |
| 386 if (image_buffer_.get()) { | 386 if (image_buffer_.get()) { |
| 387 gl::GLImage* existing_image = texture->GetLevelImage(target_, 0); | 387 gl::GLImage* existing_image = texture->GetLevelImage(target_, 0, 0); |
| 388 // Don't need to re-bind if already bound before. | 388 // Don't need to re-bind if already bound before. |
| 389 if (!existing_image || !image_buffer_->IsClient(existing_image)) { | 389 if (!existing_image || !image_buffer_->IsClient(existing_image)) { |
| 390 image_buffer_->BindToTexture(target_); | 390 image_buffer_->BindToTexture(target_); |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 | 393 |
| 394 if (defined_) { | 394 if (defined_) { |
| 395 texture->face_infos_.resize(1); | 395 texture->face_infos_.resize(1); |
| 396 texture->face_infos_[0].level_infos.resize(1); | 396 texture->face_infos_[0].level_infos.resize(1); |
| 397 texture->face_infos_[0].level_infos[0].layer_infos.resize(1); |
| 397 texture->SetLevelInfo(level_info_.target, 0, | 398 texture->SetLevelInfo(level_info_.target, 0, |
| 398 level_info_.internal_format, level_info_.width, | 399 level_info_.internal_format, level_info_.width, |
| 399 level_info_.height, level_info_.depth, | 400 level_info_.height, level_info_.depth, |
| 400 level_info_.border, level_info_.format, | 401 level_info_.border, level_info_.format, |
| 401 level_info_.type, level_info_.cleared_rect); | 402 level_info_.type, level_info_.cleared_rect); |
| 402 texture->face_infos_[0].level_infos.resize( | 403 texture->face_infos_[0].level_infos.resize( |
| 403 texture->face_infos_[0].num_mip_levels); | 404 texture->face_infos_[0].num_mip_levels); |
| 405 for (int i = 0; i < texture->face_infos_[0].num_mip_levels; ++i) |
| 406 texture->face_infos_[0].level_infos[i].layer_infos.resize(1); |
| 404 } | 407 } |
| 405 | 408 |
| 406 if (image_buffer_.get()) { | 409 if (image_buffer_.get()) { |
| 407 texture->SetLevelImage( | 410 texture->SetLevelImage( |
| 408 target_, 0, | 411 target_, 0, 0, |
| 409 new GLImageSync(image_buffer_, | 412 new GLImageSync(image_buffer_, |
| 410 gfx::Size(level_info_.width, level_info_.height)), | 413 gfx::Size(level_info_.width, level_info_.height)), |
| 411 Texture::BOUND); | 414 Texture::BOUND); |
| 412 } | 415 } |
| 413 | 416 |
| 414 texture->target_ = target_; | 417 texture->target_ = target_; |
| 415 texture->SetImmutable(immutable_); | 418 texture->SetImmutable(immutable_); |
| 416 texture->sampler_state_.min_filter = min_filter_; | 419 texture->sampler_state_.min_filter = min_filter_; |
| 417 texture->sampler_state_.mag_filter = mag_filter_; | 420 texture->sampler_state_.mag_filter = mag_filter_; |
| 418 texture->sampler_state_.wrap_s = wrap_s_; | 421 texture->sampler_state_.wrap_s = wrap_s_; |
| 419 texture->sampler_state_.wrap_t = wrap_t_; | 422 texture->sampler_state_.wrap_t = wrap_t_; |
| 420 texture->usage_ = usage_; | 423 texture->usage_ = usage_; |
| 421 } | 424 } |
| 422 | 425 |
| 423 void TextureDefinition::UpdateTexture(Texture* texture) const { | 426 void TextureDefinition::UpdateTexture(Texture* texture) const { |
| 424 GLuint old_service_id = 0u; | 427 GLuint old_service_id = 0u; |
| 425 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { | 428 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { |
| 426 GLuint service_id = 0u; | 429 GLuint service_id = 0u; |
| 427 glGenTextures(1, &service_id); | 430 glGenTextures(1, &service_id); |
| 428 old_service_id = texture->service_id(); | 431 old_service_id = texture->service_id(); |
| 429 texture->SetServiceId(service_id); | 432 texture->SetServiceId(service_id); |
| 430 | 433 |
| 431 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); | 434 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); |
| 432 GLint bound_id = 0; | 435 GLint bound_id = 0; |
| 433 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); | 436 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); |
| 434 if (bound_id == static_cast<GLint>(old_service_id)) { | 437 if (bound_id == static_cast<GLint>(old_service_id)) { |
| 435 glBindTexture(target_, service_id); | 438 glBindTexture(target_, service_id); |
| 436 } | 439 } |
| 437 texture->SetLevelImage(target_, 0, NULL, Texture::UNBOUND); | 440 texture->SetLevelImage(target_, 0, 0, NULL, Texture::UNBOUND); |
| 438 } | 441 } |
| 439 | 442 |
| 440 UpdateTextureInternal(texture); | 443 UpdateTextureInternal(texture); |
| 441 | 444 |
| 442 if (old_service_id) { | 445 if (old_service_id) { |
| 443 glDeleteTextures(1, &old_service_id); | 446 glDeleteTextures(1, &old_service_id); |
| 444 } | 447 } |
| 445 } | 448 } |
| 446 | 449 |
| 447 bool TextureDefinition::Matches(const Texture* texture) const { | 450 bool TextureDefinition::Matches(const Texture* texture) const { |
| 448 DCHECK(target_ == texture->target()); | 451 DCHECK(target_ == texture->target()); |
| 449 if (texture->sampler_state_.min_filter != min_filter_ || | 452 if (texture->sampler_state_.min_filter != min_filter_ || |
| 450 texture->sampler_state_.mag_filter != mag_filter_ || | 453 texture->sampler_state_.mag_filter != mag_filter_ || |
| 451 texture->sampler_state_.wrap_s != wrap_s_ || | 454 texture->sampler_state_.wrap_s != wrap_s_ || |
| 452 texture->sampler_state_.wrap_t != wrap_t_ || | 455 texture->sampler_state_.wrap_t != wrap_t_ || |
| 453 texture->SafeToRenderFrom() != SafeToRenderFrom()) { | 456 texture->SafeToRenderFrom() != SafeToRenderFrom()) { |
| 454 return false; | 457 return false; |
| 455 } | 458 } |
| 456 | 459 |
| 457 // Texture became defined. | 460 // Texture became defined. |
| 458 if (!image_buffer_.get() && texture->IsDefined()) | 461 if (!image_buffer_.get() && texture->IsDefined()) |
| 459 return false; | 462 return false; |
| 460 | 463 |
| 461 // All structural changes should have orphaned the texture. | 464 // All structural changes should have orphaned the texture. |
| 462 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) | 465 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0, 0)) |
| 463 return false; | 466 return false; |
| 464 | 467 |
| 465 return true; | 468 return true; |
| 466 } | 469 } |
| 467 | 470 |
| 468 bool TextureDefinition::SafeToRenderFrom() const { | 471 bool TextureDefinition::SafeToRenderFrom() const { |
| 469 return level_info_.cleared_rect.Contains( | 472 return level_info_.cleared_rect.Contains( |
| 470 gfx::Rect(level_info_.width, level_info_.height)); | 473 gfx::Rect(level_info_.width, level_info_.height)); |
| 471 } | 474 } |
| 472 | 475 |
| 473 } // namespace gles2 | 476 } // namespace gles2 |
| 474 } // namespace gpu | 477 } // namespace gpu |
| OLD | NEW |