| 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/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 private: | 51 private: |
| 52 scoped_refptr<NativeImageBuffer> buffer_; | 52 scoped_refptr<NativeImageBuffer> buffer_; |
| 53 gfx::Size size_; | 53 gfx::Size size_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(GLImageSync); | 55 DISALLOW_COPY_AND_ASSIGN(GLImageSync); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 GLImageSync::GLImageSync(const scoped_refptr<NativeImageBuffer>& buffer, | 58 GLImageSync::GLImageSync(const scoped_refptr<NativeImageBuffer>& buffer, |
| 59 const gfx::Size& size) | 59 const gfx::Size& size) |
| 60 : buffer_(buffer), size_(size) { | 60 : buffer_(buffer), size_(size) { |
| 61 if (buffer) | 61 if (buffer.get()) |
| 62 buffer->AddClient(this); | 62 buffer->AddClient(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 GLImageSync::~GLImageSync() { | 65 GLImageSync::~GLImageSync() { |
| 66 if (buffer_) | 66 if (buffer_.get()) |
| 67 buffer_->RemoveClient(this); | 67 buffer_->RemoveClient(this); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void GLImageSync::Destroy(bool have_context) { | 70 void GLImageSync::Destroy(bool have_context) { |
| 71 } | 71 } |
| 72 | 72 |
| 73 gfx::Size GLImageSync::GetSize() { | 73 gfx::Size GLImageSync::GetSize() { |
| 74 return size_; | 74 return size_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool GLImageSync::BindTexImage(unsigned target) { | 77 bool GLImageSync::BindTexImage(unsigned target) { |
| 78 NOTREACHED(); | 78 NOTREACHED(); |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void GLImageSync::ReleaseTexImage(unsigned target) { | 82 void GLImageSync::ReleaseTexImage(unsigned target) { |
| 83 NOTREACHED(); | 83 NOTREACHED(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void GLImageSync::WillUseTexImage() { | 86 void GLImageSync::WillUseTexImage() { |
| 87 if (buffer_) | 87 if (buffer_.get()) |
| 88 buffer_->WillRead(this); | 88 buffer_->WillRead(this); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void GLImageSync::DidUseTexImage() { | 91 void GLImageSync::DidUseTexImage() { |
| 92 if (buffer_) | 92 if (buffer_.get()) |
| 93 buffer_->DidRead(this); | 93 buffer_->DidRead(this); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GLImageSync::WillModifyTexImage() { | 96 void GLImageSync::WillModifyTexImage() { |
| 97 if (buffer_) | 97 if (buffer_.get()) |
| 98 buffer_->WillWrite(this); | 98 buffer_->WillWrite(this); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void GLImageSync::DidModifyTexImage() { | 101 void GLImageSync::DidModifyTexImage() { |
| 102 if (buffer_) | 102 if (buffer_.get()) |
| 103 buffer_->DidWrite(this); | 103 buffer_->DidWrite(this); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool GLImageSync::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 106 bool GLImageSync::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 107 int z_order, | 107 int z_order, |
| 108 gfx::OverlayTransform transform, | 108 gfx::OverlayTransform transform, |
| 109 const gfx::Rect& bounds_rect, | 109 const gfx::Rect& bounds_rect, |
| 110 const gfx::RectF& crop_rect) { | 110 const gfx::RectF& crop_rect) { |
| 111 NOTREACHED(); | 111 NOTREACHED(); |
| 112 return false; | 112 return false; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 TextureDefinition::LevelInfo::~LevelInfo() {} | 358 TextureDefinition::LevelInfo::~LevelInfo() {} |
| 359 | 359 |
| 360 TextureDefinition::TextureDefinition( | 360 TextureDefinition::TextureDefinition( |
| 361 GLenum target, | 361 GLenum target, |
| 362 Texture* texture, | 362 Texture* texture, |
| 363 unsigned int version, | 363 unsigned int version, |
| 364 const scoped_refptr<NativeImageBuffer>& image_buffer) | 364 const scoped_refptr<NativeImageBuffer>& image_buffer) |
| 365 : version_(version), | 365 : version_(version), |
| 366 target_(target), | 366 target_(target), |
| 367 image_buffer_(image_buffer ? image_buffer : NativeImageBuffer::Create( | 367 image_buffer_(image_buffer.get() |
| 368 texture->service_id())), | 368 ? image_buffer |
| 369 : NativeImageBuffer::Create(texture->service_id())), |
| 369 min_filter_(texture->min_filter()), | 370 min_filter_(texture->min_filter()), |
| 370 mag_filter_(texture->mag_filter()), | 371 mag_filter_(texture->mag_filter()), |
| 371 wrap_s_(texture->wrap_s()), | 372 wrap_s_(texture->wrap_s()), |
| 372 wrap_t_(texture->wrap_t()), | 373 wrap_t_(texture->wrap_t()), |
| 373 usage_(texture->usage()), | 374 usage_(texture->usage()), |
| 374 immutable_(texture->IsImmutable()) { | 375 immutable_(texture->IsImmutable()) { |
| 375 | |
| 376 // TODO | 376 // TODO |
| 377 DCHECK(!texture->level_infos_.empty()); | 377 DCHECK(!texture->level_infos_.empty()); |
| 378 DCHECK(!texture->level_infos_[0].empty()); | 378 DCHECK(!texture->level_infos_[0].empty()); |
| 379 DCHECK(!texture->NeedsMips()); | 379 DCHECK(!texture->NeedsMips()); |
| 380 DCHECK(texture->level_infos_[0][0].width); | 380 DCHECK(texture->level_infos_[0][0].width); |
| 381 DCHECK(texture->level_infos_[0][0].height); | 381 DCHECK(texture->level_infos_[0][0].height); |
| 382 | 382 |
| 383 scoped_refptr<gfx::GLImage> gl_image( | 383 scoped_refptr<gfx::GLImage> gl_image( |
| 384 new GLImageSync(image_buffer_, | 384 new GLImageSync(image_buffer_, |
| 385 gfx::Size(texture->level_infos_[0][0].width, | 385 gfx::Size(texture->level_infos_[0][0].width, |
| 386 texture->level_infos_[0][0].height))); | 386 texture->level_infos_[0][0].height))); |
| 387 texture->SetLevelImage(NULL, target, 0, gl_image); | 387 texture->SetLevelImage(NULL, target, 0, gl_image.get()); |
| 388 | 388 |
| 389 // TODO: all levels | 389 // TODO: all levels |
| 390 level_infos_.clear(); | 390 level_infos_.clear(); |
| 391 const Texture::LevelInfo& level = texture->level_infos_[0][0]; | 391 const Texture::LevelInfo& level = texture->level_infos_[0][0]; |
| 392 LevelInfo info(level.target, | 392 LevelInfo info(level.target, |
| 393 level.internal_format, | 393 level.internal_format, |
| 394 level.width, | 394 level.width, |
| 395 level.height, | 395 level.height, |
| 396 level.depth, | 396 level.depth, |
| 397 level.border, | 397 level.border, |
| 398 level.format, | 398 level.format, |
| 399 level.type, | 399 level.type, |
| 400 level.cleared); | 400 level.cleared); |
| 401 std::vector<LevelInfo> infos; | 401 std::vector<LevelInfo> infos; |
| 402 infos.push_back(info); | 402 infos.push_back(info); |
| 403 level_infos_.push_back(infos); | 403 level_infos_.push_back(infos); |
| 404 } | 404 } |
| 405 | 405 |
| 406 TextureDefinition::~TextureDefinition() { | 406 TextureDefinition::~TextureDefinition() { |
| 407 } | 407 } |
| 408 | 408 |
| 409 Texture* TextureDefinition::CreateTexture() const { | 409 Texture* TextureDefinition::CreateTexture() const { |
| 410 if (!image_buffer_) | 410 if (!image_buffer_.get()) |
| 411 return NULL; | 411 return NULL; |
| 412 | 412 |
| 413 GLuint texture_id; | 413 GLuint texture_id; |
| 414 glGenTextures(1, &texture_id); | 414 glGenTextures(1, &texture_id); |
| 415 | 415 |
| 416 Texture* texture(new Texture(texture_id)); | 416 Texture* texture(new Texture(texture_id)); |
| 417 UpdateTexture(texture); | 417 UpdateTexture(texture); |
| 418 | 418 |
| 419 return texture; | 419 return texture; |
| 420 } | 420 } |
| 421 | 421 |
| 422 void TextureDefinition::UpdateTexture(Texture* texture) const { | 422 void TextureDefinition::UpdateTexture(Texture* texture) const { |
| 423 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); | 423 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); |
| 424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); | 424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); |
| 425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); | 425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); |
| 426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); | 426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); |
| 427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); | 427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); |
| 428 if (image_buffer_) | 428 if (image_buffer_.get()) |
| 429 image_buffer_->BindToTexture(target_); | 429 image_buffer_->BindToTexture(target_); |
| 430 // We have to make sure the changes are visible to other clients in this share | 430 // We have to make sure the changes are visible to other clients in this share |
| 431 // group. As far as the clients are concerned, the mailbox semantics only | 431 // group. As far as the clients are concerned, the mailbox semantics only |
| 432 // demand a single flush from the client after changes are first made, | 432 // demand a single flush from the client after changes are first made, |
| 433 // and it is not visible to them when another share group boundary is crossed. | 433 // and it is not visible to them when another share group boundary is crossed. |
| 434 // We could probably track this and be a bit smarter about when to flush | 434 // We could probably track this and be a bit smarter about when to flush |
| 435 // though. | 435 // though. |
| 436 glFlush(); | 436 glFlush(); |
| 437 | 437 |
| 438 texture->level_infos_.resize(1); | 438 texture->level_infos_.resize(1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 450 info.internal_format, | 450 info.internal_format, |
| 451 info.width, | 451 info.width, |
| 452 info.height, | 452 info.height, |
| 453 info.depth, | 453 info.depth, |
| 454 info.border, | 454 info.border, |
| 455 info.format, | 455 info.format, |
| 456 info.type, | 456 info.type, |
| 457 info.cleared); | 457 info.cleared); |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 if (image_buffer_) { | 460 if (image_buffer_.get()) { |
| 461 texture->SetLevelImage( | 461 texture->SetLevelImage( |
| 462 NULL, | 462 NULL, |
| 463 target_, | 463 target_, |
| 464 0, | 464 0, |
| 465 new GLImageSync( | 465 new GLImageSync( |
| 466 image_buffer_, | 466 image_buffer_, |
| 467 gfx::Size(level_infos_[0][0].width, level_infos_[0][0].height))); | 467 gfx::Size(level_infos_[0][0].width, level_infos_[0][0].height))); |
| 468 } | 468 } |
| 469 | 469 |
| 470 texture->target_ = target_; | 470 texture->target_ = target_; |
| 471 texture->SetImmutable(immutable_); | 471 texture->SetImmutable(immutable_); |
| 472 texture->min_filter_ = min_filter_; | 472 texture->min_filter_ = min_filter_; |
| 473 texture->mag_filter_ = mag_filter_; | 473 texture->mag_filter_ = mag_filter_; |
| 474 texture->wrap_s_ = wrap_s_; | 474 texture->wrap_s_ = wrap_s_; |
| 475 texture->wrap_t_ = wrap_t_; | 475 texture->wrap_t_ = wrap_t_; |
| 476 texture->usage_ = usage_; | 476 texture->usage_ = usage_; |
| 477 } | 477 } |
| 478 | 478 |
| 479 bool TextureDefinition::Matches(const Texture* texture) const { | 479 bool TextureDefinition::Matches(const Texture* texture) const { |
| 480 DCHECK(target_ == texture->target()); | 480 DCHECK(target_ == texture->target()); |
| 481 if (texture->min_filter_ != min_filter_ || | 481 if (texture->min_filter_ != min_filter_ || |
| 482 texture->mag_filter_ != mag_filter_ || | 482 texture->mag_filter_ != mag_filter_ || |
| 483 texture->wrap_s_ != wrap_s_ || | 483 texture->wrap_s_ != wrap_s_ || |
| 484 texture->wrap_t_ != wrap_t_) { | 484 texture->wrap_t_ != wrap_t_) { |
| 485 return false; | 485 return false; |
| 486 } | 486 } |
| 487 | 487 |
| 488 // All structural changes should have orphaned the texture. | 488 // All structural changes should have orphaned the texture. |
| 489 if (image_buffer_ && !texture->GetLevelImage(texture->target(), 0)) | 489 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) |
| 490 return false; | 490 return false; |
| 491 | 491 |
| 492 return true; | 492 return true; |
| 493 } | 493 } |
| 494 | 494 |
| 495 } // namespace gles2 | 495 } // namespace gles2 |
| 496 } // namespace gpu | 496 } // namespace gpu |
| OLD | NEW |