| 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/service/framebuffer_manager.h" | 5 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 9 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 9 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 10 #include "gpu/command_buffer/service/texture_manager.h" | 10 #include "gpu/command_buffer/service/texture_manager.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 virtual ~TextureAttachment() {} | 191 virtual ~TextureAttachment() {} |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 scoped_refptr<Texture> texture_; | 194 scoped_refptr<Texture> texture_; |
| 195 GLenum target_; | 195 GLenum target_; |
| 196 GLint level_; | 196 GLint level_; |
| 197 | 197 |
| 198 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); | 198 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 FramebufferManager::FramebufferManager() | 201 FramebufferManager::FramebufferManager(uint32 max_draw_buffers) |
| 202 : framebuffer_state_change_count_(1), | 202 : framebuffer_state_change_count_(1), |
| 203 framebuffer_count_(0), | 203 framebuffer_count_(0), |
| 204 have_context_(true) { | 204 have_context_(true), |
| 205 max_draw_buffers_(max_draw_buffers) { |
| 206 if (max_draw_buffers_ < 1) |
| 207 max_draw_buffers_ = 1; |
| 205 } | 208 } |
| 206 | 209 |
| 207 FramebufferManager::~FramebufferManager() { | 210 FramebufferManager::~FramebufferManager() { |
| 208 DCHECK(framebuffers_.empty()); | 211 DCHECK(framebuffers_.empty()); |
| 209 // If this triggers, that means something is keeping a reference to a | 212 // If this triggers, that means something is keeping a reference to a |
| 210 // Framebuffer belonging to this. | 213 // Framebuffer belonging to this. |
| 211 CHECK_EQ(framebuffer_count_, 0u); | 214 CHECK_EQ(framebuffer_count_, 0u); |
| 212 } | 215 } |
| 213 | 216 |
| 214 void Framebuffer::MarkAsDeleted() { | 217 void Framebuffer::MarkAsDeleted() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 250 } |
| 248 | 251 |
| 249 Framebuffer::Framebuffer( | 252 Framebuffer::Framebuffer( |
| 250 FramebufferManager* manager, GLuint service_id) | 253 FramebufferManager* manager, GLuint service_id) |
| 251 : manager_(manager), | 254 : manager_(manager), |
| 252 deleted_(false), | 255 deleted_(false), |
| 253 service_id_(service_id), | 256 service_id_(service_id), |
| 254 has_been_bound_(false), | 257 has_been_bound_(false), |
| 255 framebuffer_complete_state_count_id_(0) { | 258 framebuffer_complete_state_count_id_(0) { |
| 256 manager->StartTracking(this); | 259 manager->StartTracking(this); |
| 260 DCHECK_GT(manager->max_draw_buffers_, 0u); |
| 261 draw_buffers_.reset(new GLenum[manager->max_draw_buffers_]); |
| 262 draw_buffers_[0] = GL_COLOR_ATTACHMENT0; |
| 263 for (uint32 i = 1; i < manager->max_draw_buffers_; ++i) |
| 264 draw_buffers_[i] = GL_NONE; |
| 257 } | 265 } |
| 258 | 266 |
| 259 Framebuffer::~Framebuffer() { | 267 Framebuffer::~Framebuffer() { |
| 260 if (manager_) { | 268 if (manager_) { |
| 261 if (manager_->have_context_) { | 269 if (manager_->have_context_) { |
| 262 GLuint id = service_id(); | 270 GLuint id = service_id(); |
| 263 glDeleteFramebuffersEXT(1, &id); | 271 glDeleteFramebuffersEXT(1, &id); |
| 264 } | 272 } |
| 265 manager_->StopTracking(this); | 273 manager_->StopTracking(this); |
| 266 manager_ = NULL; | 274 manager_ = NULL; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 for (AttachmentMap::const_iterator it = attachments_.begin(); | 403 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 396 it != attachments_.end(); ++it) { | 404 it != attachments_.end(); ++it) { |
| 397 Attachment* attachment = it->second; | 405 Attachment* attachment = it->second; |
| 398 if (!attachment->cleared()) { | 406 if (!attachment->cleared()) { |
| 399 return false; | 407 return false; |
| 400 } | 408 } |
| 401 } | 409 } |
| 402 return true; | 410 return true; |
| 403 } | 411 } |
| 404 | 412 |
| 413 GLenum Framebuffer::GetDrawBuffer(GLenum draw_buffer) const { |
| 414 GLsizei index = static_cast<GLsizei>( |
| 415 draw_buffer - GL_DRAW_BUFFER0_ARB); |
| 416 CHECK(index >= 0 && |
| 417 index < static_cast<GLsizei>(manager_->max_draw_buffers_)); |
| 418 return draw_buffers_[index]; |
| 419 } |
| 420 |
| 421 void Framebuffer::SetDrawBuffers(GLsizei n, const GLenum* bufs) { |
| 422 DCHECK(n <= static_cast<GLsizei>(manager_->max_draw_buffers_)); |
| 423 for (GLsizei i = 0; i < n; ++i) |
| 424 draw_buffers_[i] = bufs[i]; |
| 425 } |
| 426 |
| 405 void Framebuffer::UnbindRenderbuffer( | 427 void Framebuffer::UnbindRenderbuffer( |
| 406 GLenum target, Renderbuffer* renderbuffer) { | 428 GLenum target, Renderbuffer* renderbuffer) { |
| 407 bool done; | 429 bool done; |
| 408 do { | 430 do { |
| 409 done = true; | 431 done = true; |
| 410 for (AttachmentMap::const_iterator it = attachments_.begin(); | 432 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 411 it != attachments_.end(); ++it) { | 433 it != attachments_.end(); ++it) { |
| 412 Attachment* attachment = it->second; | 434 Attachment* attachment = it->second; |
| 413 if (attachment->IsRenderbuffer(renderbuffer)) { | 435 if (attachment->IsRenderbuffer(renderbuffer)) { |
| 414 // TODO(gman): manually detach renderbuffer. | 436 // TODO(gman): manually detach renderbuffer. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { | 471 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { |
| 450 FramebufferMap::iterator it = framebuffers_.find(client_id); | 472 FramebufferMap::iterator it = framebuffers_.find(client_id); |
| 451 if (it != framebuffers_.end()) { | 473 if (it != framebuffers_.end()) { |
| 452 it->second->MarkAsDeleted(); | 474 it->second->MarkAsDeleted(); |
| 453 framebuffers_.erase(it); | 475 framebuffers_.erase(it); |
| 454 } | 476 } |
| 455 } | 477 } |
| 456 | 478 |
| 457 void Framebuffer::AttachRenderbuffer( | 479 void Framebuffer::AttachRenderbuffer( |
| 458 GLenum attachment, Renderbuffer* renderbuffer) { | 480 GLenum attachment, Renderbuffer* renderbuffer) { |
| 459 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | |
| 460 attachment == GL_DEPTH_ATTACHMENT || | |
| 461 attachment == GL_STENCIL_ATTACHMENT || | |
| 462 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | |
| 463 const Attachment* a = GetAttachment(attachment); | 481 const Attachment* a = GetAttachment(attachment); |
| 464 if (a) | 482 if (a) |
| 465 a->DetachFromFramebuffer(); | 483 a->DetachFromFramebuffer(); |
| 466 if (renderbuffer) { | 484 if (renderbuffer) { |
| 467 attachments_[attachment] = scoped_refptr<Attachment>( | 485 attachments_[attachment] = scoped_refptr<Attachment>( |
| 468 new RenderbufferAttachment(renderbuffer)); | 486 new RenderbufferAttachment(renderbuffer)); |
| 469 } else { | 487 } else { |
| 470 attachments_.erase(attachment); | 488 attachments_.erase(attachment); |
| 471 } | 489 } |
| 472 framebuffer_complete_state_count_id_ = 0; | 490 framebuffer_complete_state_count_id_ = 0; |
| 473 } | 491 } |
| 474 | 492 |
| 475 void Framebuffer::AttachTexture( | 493 void Framebuffer::AttachTexture( |
| 476 GLenum attachment, Texture* texture, GLenum target, | 494 GLenum attachment, Texture* texture, GLenum target, |
| 477 GLint level) { | 495 GLint level) { |
| 478 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | |
| 479 attachment == GL_DEPTH_ATTACHMENT || | |
| 480 attachment == GL_STENCIL_ATTACHMENT || | |
| 481 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | |
| 482 const Attachment* a = GetAttachment(attachment); | 496 const Attachment* a = GetAttachment(attachment); |
| 483 if (a) | 497 if (a) |
| 484 a->DetachFromFramebuffer(); | 498 a->DetachFromFramebuffer(); |
| 485 if (texture) { | 499 if (texture) { |
| 486 attachments_[attachment] = scoped_refptr<Attachment>( | 500 attachments_[attachment] = scoped_refptr<Attachment>( |
| 487 new TextureAttachment(texture, target, level)); | 501 new TextureAttachment(texture, target, level)); |
| 488 texture->AttachToFramebuffer(); | 502 texture->AttachToFramebuffer(); |
| 489 } else { | 503 } else { |
| 490 attachments_.erase(attachment); | 504 attachments_.erase(attachment); |
| 491 } | 505 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 Framebuffer* framebuffer) { | 550 Framebuffer* framebuffer) { |
| 537 DCHECK(framebuffer); | 551 DCHECK(framebuffer); |
| 538 return framebuffer->framebuffer_complete_state_count_id() == | 552 return framebuffer->framebuffer_complete_state_count_id() == |
| 539 framebuffer_state_change_count_; | 553 framebuffer_state_change_count_; |
| 540 } | 554 } |
| 541 | 555 |
| 542 } // namespace gles2 | 556 } // namespace gles2 |
| 543 } // namespace gpu | 557 } // namespace gpu |
| 544 | 558 |
| 545 | 559 |
| OLD | NEW |