| 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 "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 | 10 |
| 11 namespace gpu { | 11 namespace gpu { |
| 12 namespace gles2 { | 12 namespace gles2 { |
| 13 | 13 |
| 14 FramebufferManager::FramebufferInfo::FramebufferComboCompleteMap* | 14 Framebuffer::FramebufferComboCompleteMap* |
| 15 FramebufferManager::FramebufferInfo::framebuffer_combo_complete_map_; | 15 Framebuffer::framebuffer_combo_complete_map_; |
| 16 | 16 |
| 17 void FramebufferManager::FramebufferInfo::ClearFramebufferCompleteComboMap() { | 17 void Framebuffer::ClearFramebufferCompleteComboMap() { |
| 18 if (framebuffer_combo_complete_map_) { | 18 if (framebuffer_combo_complete_map_) { |
| 19 framebuffer_combo_complete_map_->clear(); | 19 framebuffer_combo_complete_map_->clear(); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 class RenderbufferAttachment | 23 class RenderbufferAttachment |
| 24 : public FramebufferManager::FramebufferInfo::Attachment { | 24 : public Framebuffer::Attachment { |
| 25 public: | 25 public: |
| 26 explicit RenderbufferAttachment( | 26 explicit RenderbufferAttachment( |
| 27 RenderbufferManager::RenderbufferInfo* renderbuffer) | 27 Renderbuffer* renderbuffer) |
| 28 : renderbuffer_(renderbuffer) { | 28 : renderbuffer_(renderbuffer) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual GLsizei width() const OVERRIDE { | 31 virtual GLsizei width() const OVERRIDE { |
| 32 return renderbuffer_->width(); | 32 return renderbuffer_->width(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual GLsizei height() const OVERRIDE { | 35 virtual GLsizei height() const OVERRIDE { |
| 36 return renderbuffer_->height(); | 36 return renderbuffer_->height(); |
| 37 } | 37 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual void SetCleared( | 51 virtual void SetCleared( |
| 52 RenderbufferManager* renderbuffer_manager, | 52 RenderbufferManager* renderbuffer_manager, |
| 53 TextureManager* /* texture_manager */, | 53 TextureManager* /* texture_manager */, |
| 54 bool cleared) OVERRIDE { | 54 bool cleared) OVERRIDE { |
| 55 renderbuffer_manager->SetCleared(renderbuffer_, cleared); | 55 renderbuffer_manager->SetCleared(renderbuffer_, cleared); |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual bool IsTexture( | 58 virtual bool IsTexture( |
| 59 TextureManager::TextureInfo* /* texture */) const OVERRIDE { | 59 Texture* /* texture */) const OVERRIDE { |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual bool IsRenderbuffer( | 63 virtual bool IsRenderbuffer( |
| 64 RenderbufferManager::RenderbufferInfo* renderbuffer) const OVERRIDE { | 64 Renderbuffer* renderbuffer) const OVERRIDE { |
| 65 return renderbuffer_ == renderbuffer; | 65 return renderbuffer_ == renderbuffer; |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual bool CanRenderTo() const OVERRIDE { | 68 virtual bool CanRenderTo() const OVERRIDE { |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual void DetachFromFramebuffer() const OVERRIDE { | 72 virtual void DetachFromFramebuffer() const OVERRIDE { |
| 73 // Nothing to do for renderbuffers. | 73 // Nothing to do for renderbuffers. |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual bool ValidForAttachmentType(GLenum attachment_type) OVERRIDE { | 76 virtual bool ValidForAttachmentType(GLenum attachment_type) OVERRIDE { |
| 77 uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( | 77 uint32 need = GLES2Util::GetChannelsNeededForAttachmentType( |
| 78 attachment_type); | 78 attachment_type); |
| 79 uint32 have = GLES2Util::GetChannelsForFormat(internal_format()); | 79 uint32 have = GLES2Util::GetChannelsForFormat(internal_format()); |
| 80 return (need & have) != 0; | 80 return (need & have) != 0; |
| 81 } | 81 } |
| 82 | 82 |
| 83 RenderbufferManager::RenderbufferInfo* renderbuffer() const { | 83 Renderbuffer* renderbuffer() const { |
| 84 return renderbuffer_.get(); | 84 return renderbuffer_.get(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void AddToSignature( | 87 virtual void AddToSignature( |
| 88 TextureManager* texture_manager, std::string* signature) const OVERRIDE { | 88 TextureManager* texture_manager, std::string* signature) const OVERRIDE { |
| 89 DCHECK(signature); | 89 DCHECK(signature); |
| 90 renderbuffer_->AddToSignature(signature); | 90 renderbuffer_->AddToSignature(signature); |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 virtual ~RenderbufferAttachment() { } | 94 virtual ~RenderbufferAttachment() { } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 RenderbufferManager::RenderbufferInfo::Ref renderbuffer_; | 97 scoped_refptr<Renderbuffer> renderbuffer_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment); | 99 DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 class TextureAttachment | 102 class TextureAttachment |
| 103 : public FramebufferManager::FramebufferInfo::Attachment { | 103 : public Framebuffer::Attachment { |
| 104 public: | 104 public: |
| 105 TextureAttachment( | 105 TextureAttachment( |
| 106 TextureManager::TextureInfo* texture, GLenum target, GLint level) | 106 Texture* texture, GLenum target, GLint level) |
| 107 : texture_(texture), | 107 : texture_(texture), |
| 108 target_(target), | 108 target_(target), |
| 109 level_(level) { | 109 level_(level) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 virtual GLsizei width() const OVERRIDE { | 112 virtual GLsizei width() const OVERRIDE { |
| 113 GLsizei temp_width = 0; | 113 GLsizei temp_width = 0; |
| 114 GLsizei temp_height = 0; | 114 GLsizei temp_height = 0; |
| 115 texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); | 115 texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); |
| 116 return temp_width; | 116 return temp_width; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 return texture_->IsLevelCleared(target_, level_); | 138 return texture_->IsLevelCleared(target_, level_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 virtual void SetCleared( | 141 virtual void SetCleared( |
| 142 RenderbufferManager* /* renderbuffer_manager */, | 142 RenderbufferManager* /* renderbuffer_manager */, |
| 143 TextureManager* texture_manager, | 143 TextureManager* texture_manager, |
| 144 bool cleared) OVERRIDE { | 144 bool cleared) OVERRIDE { |
| 145 texture_manager->SetLevelCleared(texture_, target_, level_, cleared); | 145 texture_manager->SetLevelCleared(texture_, target_, level_, cleared); |
| 146 } | 146 } |
| 147 | 147 |
| 148 virtual bool IsTexture(TextureManager::TextureInfo* texture) const OVERRIDE { | 148 virtual bool IsTexture(Texture* texture) const OVERRIDE { |
| 149 return texture == texture_.get(); | 149 return texture == texture_.get(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 virtual bool IsRenderbuffer( | 152 virtual bool IsRenderbuffer( |
| 153 RenderbufferManager::RenderbufferInfo* /* renderbuffer */) | 153 Renderbuffer* /* renderbuffer */) |
| 154 const OVERRIDE { | 154 const OVERRIDE { |
| 155 return false; | 155 return false; |
| 156 } | 156 } |
| 157 | 157 |
| 158 TextureManager::TextureInfo* texture() const { | 158 Texture* texture() const { |
| 159 return texture_.get(); | 159 return texture_.get(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 virtual bool CanRenderTo() const OVERRIDE { | 162 virtual bool CanRenderTo() const OVERRIDE { |
| 163 return texture_->CanRenderTo(); | 163 return texture_->CanRenderTo(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 virtual void DetachFromFramebuffer() const OVERRIDE { | 166 virtual void DetachFromFramebuffer() const OVERRIDE { |
| 167 texture_->DetachFromFramebuffer(); | 167 texture_->DetachFromFramebuffer(); |
| 168 } | 168 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 182 virtual void AddToSignature( | 182 virtual void AddToSignature( |
| 183 TextureManager* texture_manager, std::string* signature) const OVERRIDE { | 183 TextureManager* texture_manager, std::string* signature) const OVERRIDE { |
| 184 DCHECK(signature); | 184 DCHECK(signature); |
| 185 texture_manager->AddToSignature(texture_, target_, level_, signature); | 185 texture_manager->AddToSignature(texture_, target_, level_, signature); |
| 186 } | 186 } |
| 187 | 187 |
| 188 protected: | 188 protected: |
| 189 virtual ~TextureAttachment() {} | 189 virtual ~TextureAttachment() {} |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 TextureManager::TextureInfo::Ref texture_; | 192 scoped_refptr<Texture> texture_; |
| 193 GLenum target_; | 193 GLenum target_; |
| 194 GLint level_; | 194 GLint level_; |
| 195 | 195 |
| 196 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); | 196 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 FramebufferManager::FramebufferManager() | 199 FramebufferManager::FramebufferManager() |
| 200 : framebuffer_state_change_count_(1), | 200 : framebuffer_state_change_count_(1), |
| 201 framebuffer_info_count_(0), | 201 framebuffer_info_count_(0), |
| 202 have_context_(true) { | 202 have_context_(true) { |
| 203 } | 203 } |
| 204 | 204 |
| 205 FramebufferManager::~FramebufferManager() { | 205 FramebufferManager::~FramebufferManager() { |
| 206 DCHECK(framebuffer_infos_.empty()); | 206 DCHECK(framebuffer_infos_.empty()); |
| 207 // If this triggers, that means something is keeping a reference to a | 207 // If this triggers, that means something is keeping a reference to a |
| 208 // FramebufferInfo belonging to this. | 208 // Framebuffer belonging to this. |
| 209 CHECK_EQ(framebuffer_info_count_, 0u); | 209 CHECK_EQ(framebuffer_info_count_, 0u); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void FramebufferManager::FramebufferInfo::MarkAsDeleted() { | 212 void Framebuffer::MarkAsDeleted() { |
| 213 deleted_ = true; | 213 deleted_ = true; |
| 214 while (!attachments_.empty()) { | 214 while (!attachments_.empty()) { |
| 215 Attachment* attachment = attachments_.begin()->second.get(); | 215 Attachment* attachment = attachments_.begin()->second.get(); |
| 216 attachment->DetachFromFramebuffer(); | 216 attachment->DetachFromFramebuffer(); |
| 217 attachments_.erase(attachments_.begin()); | 217 attachments_.erase(attachments_.begin()); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void FramebufferManager::Destroy(bool have_context) { | 221 void FramebufferManager::Destroy(bool have_context) { |
| 222 have_context_ = have_context; | 222 have_context_ = have_context; |
| 223 framebuffer_infos_.clear(); | 223 framebuffer_infos_.clear(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void FramebufferManager::StartTracking( | 226 void FramebufferManager::StartTracking( |
| 227 FramebufferManager::FramebufferInfo* /* framebuffer */) { | 227 Framebuffer* /* framebuffer */) { |
| 228 ++framebuffer_info_count_; | 228 ++framebuffer_info_count_; |
| 229 } | 229 } |
| 230 | 230 |
| 231 void FramebufferManager::StopTracking( | 231 void FramebufferManager::StopTracking( |
| 232 FramebufferManager::FramebufferInfo* /* framebuffer */) { | 232 Framebuffer* /* framebuffer */) { |
| 233 --framebuffer_info_count_; | 233 --framebuffer_info_count_; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void FramebufferManager::CreateFramebufferInfo( | 236 void FramebufferManager::CreateFramebuffer( |
| 237 GLuint client_id, GLuint service_id) { | 237 GLuint client_id, GLuint service_id) { |
| 238 std::pair<FramebufferInfoMap::iterator, bool> result = | 238 std::pair<FramebufferInfoMap::iterator, bool> result = |
| 239 framebuffer_infos_.insert( | 239 framebuffer_infos_.insert( |
| 240 std::make_pair( | 240 std::make_pair( |
| 241 client_id, | 241 client_id, |
| 242 FramebufferInfo::Ref(new FramebufferInfo(this, service_id)))); | 242 scoped_refptr<Framebuffer>( |
| 243 new Framebuffer(this, service_id)))); |
| 243 DCHECK(result.second); | 244 DCHECK(result.second); |
| 244 } | 245 } |
| 245 | 246 |
| 246 FramebufferManager::FramebufferInfo::FramebufferInfo( | 247 Framebuffer::Framebuffer( |
| 247 FramebufferManager* manager, GLuint service_id) | 248 FramebufferManager* manager, GLuint service_id) |
| 248 : manager_(manager), | 249 : manager_(manager), |
| 249 deleted_(false), | 250 deleted_(false), |
| 250 service_id_(service_id), | 251 service_id_(service_id), |
| 251 has_been_bound_(false), | 252 has_been_bound_(false), |
| 252 framebuffer_complete_state_count_id_(0) { | 253 framebuffer_complete_state_count_id_(0) { |
| 253 manager->StartTracking(this); | 254 manager->StartTracking(this); |
| 254 } | 255 } |
| 255 | 256 |
| 256 FramebufferManager::FramebufferInfo::~FramebufferInfo() { | 257 Framebuffer::~Framebuffer() { |
| 257 if (manager_) { | 258 if (manager_) { |
| 258 if (manager_->have_context_) { | 259 if (manager_->have_context_) { |
| 259 GLuint id = service_id(); | 260 GLuint id = service_id(); |
| 260 glDeleteFramebuffersEXT(1, &id); | 261 glDeleteFramebuffersEXT(1, &id); |
| 261 } | 262 } |
| 262 manager_->StopTracking(this); | 263 manager_->StopTracking(this); |
| 263 manager_ = NULL; | 264 manager_ = NULL; |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 bool FramebufferManager::FramebufferInfo::HasUnclearedAttachment( | 268 bool Framebuffer::HasUnclearedAttachment( |
| 268 GLenum attachment) const { | 269 GLenum attachment) const { |
| 269 AttachmentMap::const_iterator it = | 270 AttachmentMap::const_iterator it = |
| 270 attachments_.find(attachment); | 271 attachments_.find(attachment); |
| 271 if (it != attachments_.end()) { | 272 if (it != attachments_.end()) { |
| 272 const Attachment* attachment = it->second; | 273 const Attachment* attachment = it->second; |
| 273 return !attachment->cleared(); | 274 return !attachment->cleared(); |
| 274 } | 275 } |
| 275 return false; | 276 return false; |
| 276 } | 277 } |
| 277 | 278 |
| 278 void FramebufferManager::FramebufferInfo::MarkAttachmentAsCleared( | 279 void Framebuffer::MarkAttachmentAsCleared( |
| 279 RenderbufferManager* renderbuffer_manager, | 280 RenderbufferManager* renderbuffer_manager, |
| 280 TextureManager* texture_manager, | 281 TextureManager* texture_manager, |
| 281 GLenum attachment, | 282 GLenum attachment, |
| 282 bool cleared) { | 283 bool cleared) { |
| 283 AttachmentMap::iterator it = attachments_.find(attachment); | 284 AttachmentMap::iterator it = attachments_.find(attachment); |
| 284 if (it != attachments_.end()) { | 285 if (it != attachments_.end()) { |
| 285 Attachment* a = it->second; | 286 Attachment* a = it->second; |
| 286 if (a->cleared() != cleared) { | 287 if (a->cleared() != cleared) { |
| 287 a->SetCleared(renderbuffer_manager, | 288 a->SetCleared(renderbuffer_manager, |
| 288 texture_manager, | 289 texture_manager, |
| 289 cleared); | 290 cleared); |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 | 294 |
| 294 void FramebufferManager::FramebufferInfo::MarkAttachmentsAsCleared( | 295 void Framebuffer::MarkAttachmentsAsCleared( |
| 295 RenderbufferManager* renderbuffer_manager, | 296 RenderbufferManager* renderbuffer_manager, |
| 296 TextureManager* texture_manager, | 297 TextureManager* texture_manager, |
| 297 bool cleared) { | 298 bool cleared) { |
| 298 for (AttachmentMap::iterator it = attachments_.begin(); | 299 for (AttachmentMap::iterator it = attachments_.begin(); |
| 299 it != attachments_.end(); ++it) { | 300 it != attachments_.end(); ++it) { |
| 300 Attachment* attachment = it->second; | 301 Attachment* attachment = it->second; |
| 301 if (attachment->cleared() != cleared) { | 302 if (attachment->cleared() != cleared) { |
| 302 attachment->SetCleared(renderbuffer_manager, texture_manager, cleared); | 303 attachment->SetCleared(renderbuffer_manager, texture_manager, cleared); |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 } | 306 } |
| 306 | 307 |
| 307 bool FramebufferManager::FramebufferInfo::HasDepthAttachment() const { | 308 bool Framebuffer::HasDepthAttachment() const { |
| 308 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || | 309 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || |
| 309 attachments_.find(GL_DEPTH_ATTACHMENT) != attachments_.end(); | 310 attachments_.find(GL_DEPTH_ATTACHMENT) != attachments_.end(); |
| 310 } | 311 } |
| 311 | 312 |
| 312 bool FramebufferManager::FramebufferInfo::HasStencilAttachment() const { | 313 bool Framebuffer::HasStencilAttachment() const { |
| 313 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || | 314 return attachments_.find(GL_DEPTH_STENCIL_ATTACHMENT) != attachments_.end() || |
| 314 attachments_.find(GL_STENCIL_ATTACHMENT) != attachments_.end(); | 315 attachments_.find(GL_STENCIL_ATTACHMENT) != attachments_.end(); |
| 315 } | 316 } |
| 316 | 317 |
| 317 GLenum FramebufferManager::FramebufferInfo::GetColorAttachmentFormat() const { | 318 GLenum Framebuffer::GetColorAttachmentFormat() const { |
| 318 AttachmentMap::const_iterator it = attachments_.find(GL_COLOR_ATTACHMENT0); | 319 AttachmentMap::const_iterator it = attachments_.find(GL_COLOR_ATTACHMENT0); |
| 319 if (it == attachments_.end()) { | 320 if (it == attachments_.end()) { |
| 320 return 0; | 321 return 0; |
| 321 } | 322 } |
| 322 const Attachment* attachment = it->second; | 323 const Attachment* attachment = it->second; |
| 323 return attachment->internal_format(); | 324 return attachment->internal_format(); |
| 324 } | 325 } |
| 325 | 326 |
| 326 GLenum FramebufferManager::FramebufferInfo::IsPossiblyComplete() const { | 327 GLenum Framebuffer::IsPossiblyComplete() const { |
| 327 if (attachments_.empty()) { | 328 if (attachments_.empty()) { |
| 328 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; | 329 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
| 329 } | 330 } |
| 330 | 331 |
| 331 GLsizei width = -1; | 332 GLsizei width = -1; |
| 332 GLsizei height = -1; | 333 GLsizei height = -1; |
| 333 for (AttachmentMap::const_iterator it = attachments_.begin(); | 334 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 334 it != attachments_.end(); ++it) { | 335 it != attachments_.end(); ++it) { |
| 335 GLenum attachment_type = it->first; | 336 GLenum attachment_type = it->first; |
| 336 Attachment* attachment = it->second; | 337 Attachment* attachment = it->second; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 352 if (!attachment->CanRenderTo()) { | 353 if (!attachment->CanRenderTo()) { |
| 353 return GL_FRAMEBUFFER_UNSUPPORTED; | 354 return GL_FRAMEBUFFER_UNSUPPORTED; |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 | 357 |
| 357 // This does not mean the framebuffer is actually complete. It just means our | 358 // This does not mean the framebuffer is actually complete. It just means our |
| 358 // checks passed. | 359 // checks passed. |
| 359 return GL_FRAMEBUFFER_COMPLETE; | 360 return GL_FRAMEBUFFER_COMPLETE; |
| 360 } | 361 } |
| 361 | 362 |
| 362 GLenum FramebufferManager::FramebufferInfo::GetStatus( | 363 GLenum Framebuffer::GetStatus( |
| 363 TextureManager* texture_manager, GLenum target) const { | 364 TextureManager* texture_manager, GLenum target) const { |
| 364 // Check if we have this combo already. | 365 // Check if we have this combo already. |
| 365 std::string signature(base::StringPrintf("|FBO|target=%04x", target)); | 366 std::string signature(base::StringPrintf("|FBO|target=%04x", target)); |
| 366 for (AttachmentMap::const_iterator it = attachments_.begin(); | 367 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 367 it != attachments_.end(); ++it) { | 368 it != attachments_.end(); ++it) { |
| 368 Attachment* attachment = it->second; | 369 Attachment* attachment = it->second; |
| 369 signature += base::StringPrintf( | 370 signature += base::StringPrintf( |
| 370 "|Attachment|attachmentpoint=%04x", it->first); | 371 "|Attachment|attachmentpoint=%04x", it->first); |
| 371 attachment->AddToSignature(texture_manager, &signature); | 372 attachment->AddToSignature(texture_manager, &signature); |
| 372 } | 373 } |
| 373 | 374 |
| 374 if (!framebuffer_combo_complete_map_) { | 375 if (!framebuffer_combo_complete_map_) { |
| 375 framebuffer_combo_complete_map_ = new FramebufferComboCompleteMap(); | 376 framebuffer_combo_complete_map_ = new FramebufferComboCompleteMap(); |
| 376 } | 377 } |
| 377 | 378 |
| 378 FramebufferComboCompleteMap::const_iterator it = | 379 FramebufferComboCompleteMap::const_iterator it = |
| 379 framebuffer_combo_complete_map_->find(signature); | 380 framebuffer_combo_complete_map_->find(signature); |
| 380 if (it != framebuffer_combo_complete_map_->end()) { | 381 if (it != framebuffer_combo_complete_map_->end()) { |
| 381 return GL_FRAMEBUFFER_COMPLETE; | 382 return GL_FRAMEBUFFER_COMPLETE; |
| 382 } | 383 } |
| 383 GLenum result = glCheckFramebufferStatusEXT(target); | 384 GLenum result = glCheckFramebufferStatusEXT(target); |
| 384 if (result == GL_FRAMEBUFFER_COMPLETE) { | 385 if (result == GL_FRAMEBUFFER_COMPLETE) { |
| 385 framebuffer_combo_complete_map_->insert(std::make_pair(signature, true)); | 386 framebuffer_combo_complete_map_->insert(std::make_pair(signature, true)); |
| 386 } | 387 } |
| 387 return result; | 388 return result; |
| 388 } | 389 } |
| 389 | 390 |
| 390 bool FramebufferManager::FramebufferInfo::IsCleared() const { | 391 bool Framebuffer::IsCleared() const { |
| 391 // are all the attachments cleaared? | 392 // are all the attachments cleaared? |
| 392 for (AttachmentMap::const_iterator it = attachments_.begin(); | 393 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 393 it != attachments_.end(); ++it) { | 394 it != attachments_.end(); ++it) { |
| 394 Attachment* attachment = it->second; | 395 Attachment* attachment = it->second; |
| 395 if (!attachment->cleared()) { | 396 if (!attachment->cleared()) { |
| 396 return false; | 397 return false; |
| 397 } | 398 } |
| 398 } | 399 } |
| 399 return true; | 400 return true; |
| 400 } | 401 } |
| 401 | 402 |
| 402 void FramebufferManager::FramebufferInfo::UnbindRenderbuffer( | 403 void Framebuffer::UnbindRenderbuffer( |
| 403 GLenum target, RenderbufferManager::RenderbufferInfo* renderbuffer) { | 404 GLenum target, Renderbuffer* renderbuffer) { |
| 404 bool done; | 405 bool done; |
| 405 do { | 406 do { |
| 406 done = true; | 407 done = true; |
| 407 for (AttachmentMap::const_iterator it = attachments_.begin(); | 408 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 408 it != attachments_.end(); ++it) { | 409 it != attachments_.end(); ++it) { |
| 409 Attachment* attachment = it->second; | 410 Attachment* attachment = it->second; |
| 410 if (attachment->IsRenderbuffer(renderbuffer)) { | 411 if (attachment->IsRenderbuffer(renderbuffer)) { |
| 411 // TODO(gman): manually detach renderbuffer. | 412 // TODO(gman): manually detach renderbuffer. |
| 412 // glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); | 413 // glFramebufferRenderbufferEXT(target, it->first, GL_RENDERBUFFER, 0); |
| 413 AttachRenderbuffer(it->first, NULL); | 414 AttachRenderbuffer(it->first, NULL); |
| 414 done = false; | 415 done = false; |
| 415 break; | 416 break; |
| 416 } | 417 } |
| 417 } | 418 } |
| 418 } while (!done); | 419 } while (!done); |
| 419 } | 420 } |
| 420 | 421 |
| 421 void FramebufferManager::FramebufferInfo::UnbindTexture( | 422 void Framebuffer::UnbindTexture( |
| 422 GLenum target, TextureManager::TextureInfo* texture) { | 423 GLenum target, Texture* texture) { |
| 423 bool done; | 424 bool done; |
| 424 do { | 425 do { |
| 425 done = true; | 426 done = true; |
| 426 for (AttachmentMap::const_iterator it = attachments_.begin(); | 427 for (AttachmentMap::const_iterator it = attachments_.begin(); |
| 427 it != attachments_.end(); ++it) { | 428 it != attachments_.end(); ++it) { |
| 428 Attachment* attachment = it->second; | 429 Attachment* attachment = it->second; |
| 429 if (attachment->IsTexture(texture)) { | 430 if (attachment->IsTexture(texture)) { |
| 430 // TODO(gman): manually detach texture. | 431 // TODO(gman): manually detach texture. |
| 431 // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0); | 432 // glFramebufferTexture2DEXT(target, it->first, GL_TEXTURE_2D, 0, 0); |
| 432 AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0); | 433 AttachTexture(it->first, NULL, GL_TEXTURE_2D, 0); |
| 433 done = false; | 434 done = false; |
| 434 break; | 435 break; |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 } while (!done); | 438 } while (!done); |
| 438 } | 439 } |
| 439 | 440 |
| 440 FramebufferManager::FramebufferInfo* FramebufferManager::GetFramebufferInfo( | 441 Framebuffer* FramebufferManager::GetFramebuffer( |
| 441 GLuint client_id) { | 442 GLuint client_id) { |
| 442 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); | 443 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); |
| 443 return it != framebuffer_infos_.end() ? it->second : NULL; | 444 return it != framebuffer_infos_.end() ? it->second : NULL; |
| 444 } | 445 } |
| 445 | 446 |
| 446 void FramebufferManager::RemoveFramebufferInfo(GLuint client_id) { | 447 void FramebufferManager::RemoveFramebuffer(GLuint client_id) { |
| 447 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); | 448 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); |
| 448 if (it != framebuffer_infos_.end()) { | 449 if (it != framebuffer_infos_.end()) { |
| 449 it->second->MarkAsDeleted(); | 450 it->second->MarkAsDeleted(); |
| 450 framebuffer_infos_.erase(it); | 451 framebuffer_infos_.erase(it); |
| 451 } | 452 } |
| 452 } | 453 } |
| 453 | 454 |
| 454 void FramebufferManager::FramebufferInfo::AttachRenderbuffer( | 455 void Framebuffer::AttachRenderbuffer( |
| 455 GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer) { | 456 GLenum attachment, Renderbuffer* renderbuffer) { |
| 456 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | 457 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || |
| 457 attachment == GL_DEPTH_ATTACHMENT || | 458 attachment == GL_DEPTH_ATTACHMENT || |
| 458 attachment == GL_STENCIL_ATTACHMENT || | 459 attachment == GL_STENCIL_ATTACHMENT || |
| 459 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | 460 attachment == GL_DEPTH_STENCIL_ATTACHMENT); |
| 460 const Attachment* a = GetAttachment(attachment); | 461 const Attachment* a = GetAttachment(attachment); |
| 461 if (a) | 462 if (a) |
| 462 a->DetachFromFramebuffer(); | 463 a->DetachFromFramebuffer(); |
| 463 if (renderbuffer) { | 464 if (renderbuffer) { |
| 464 attachments_[attachment] = Attachment::Ref( | 465 attachments_[attachment] = scoped_refptr<Attachment>( |
| 465 new RenderbufferAttachment(renderbuffer)); | 466 new RenderbufferAttachment(renderbuffer)); |
| 466 } else { | 467 } else { |
| 467 attachments_.erase(attachment); | 468 attachments_.erase(attachment); |
| 468 } | 469 } |
| 469 framebuffer_complete_state_count_id_ = 0; | 470 framebuffer_complete_state_count_id_ = 0; |
| 470 } | 471 } |
| 471 | 472 |
| 472 void FramebufferManager::FramebufferInfo::AttachTexture( | 473 void Framebuffer::AttachTexture( |
| 473 GLenum attachment, TextureManager::TextureInfo* texture, GLenum target, | 474 GLenum attachment, Texture* texture, GLenum target, |
| 474 GLint level) { | 475 GLint level) { |
| 475 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | 476 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || |
| 476 attachment == GL_DEPTH_ATTACHMENT || | 477 attachment == GL_DEPTH_ATTACHMENT || |
| 477 attachment == GL_STENCIL_ATTACHMENT || | 478 attachment == GL_STENCIL_ATTACHMENT || |
| 478 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | 479 attachment == GL_DEPTH_STENCIL_ATTACHMENT); |
| 479 const Attachment* a = GetAttachment(attachment); | 480 const Attachment* a = GetAttachment(attachment); |
| 480 if (a) | 481 if (a) |
| 481 a->DetachFromFramebuffer(); | 482 a->DetachFromFramebuffer(); |
| 482 if (texture) { | 483 if (texture) { |
| 483 attachments_[attachment] = Attachment::Ref( | 484 attachments_[attachment] = scoped_refptr<Attachment>( |
| 484 new TextureAttachment(texture, target, level)); | 485 new TextureAttachment(texture, target, level)); |
| 485 texture->AttachToFramebuffer(); | 486 texture->AttachToFramebuffer(); |
| 486 } else { | 487 } else { |
| 487 attachments_.erase(attachment); | 488 attachments_.erase(attachment); |
| 488 } | 489 } |
| 489 framebuffer_complete_state_count_id_ = 0; | 490 framebuffer_complete_state_count_id_ = 0; |
| 490 } | 491 } |
| 491 | 492 |
| 492 const FramebufferManager::FramebufferInfo::Attachment* | 493 const Framebuffer::Attachment* |
| 493 FramebufferManager::FramebufferInfo::GetAttachment( | 494 Framebuffer::GetAttachment( |
| 494 GLenum attachment) const { | 495 GLenum attachment) const { |
| 495 AttachmentMap::const_iterator it = attachments_.find(attachment); | 496 AttachmentMap::const_iterator it = attachments_.find(attachment); |
| 496 if (it != attachments_.end()) { | 497 if (it != attachments_.end()) { |
| 497 return it->second; | 498 return it->second; |
| 498 } | 499 } |
| 499 return NULL; | 500 return NULL; |
| 500 } | 501 } |
| 501 | 502 |
| 502 bool FramebufferManager::GetClientId( | 503 bool FramebufferManager::GetClientId( |
| 503 GLuint service_id, GLuint* client_id) const { | 504 GLuint service_id, GLuint* client_id) const { |
| 504 // This doesn't need to be fast. It's only used during slow queries. | 505 // This doesn't need to be fast. It's only used during slow queries. |
| 505 for (FramebufferInfoMap::const_iterator it = framebuffer_infos_.begin(); | 506 for (FramebufferInfoMap::const_iterator it = framebuffer_infos_.begin(); |
| 506 it != framebuffer_infos_.end(); ++it) { | 507 it != framebuffer_infos_.end(); ++it) { |
| 507 if (it->second->service_id() == service_id) { | 508 if (it->second->service_id() == service_id) { |
| 508 *client_id = it->first; | 509 *client_id = it->first; |
| 509 return true; | 510 return true; |
| 510 } | 511 } |
| 511 } | 512 } |
| 512 return false; | 513 return false; |
| 513 } | 514 } |
| 514 | 515 |
| 515 void FramebufferManager::MarkAttachmentsAsCleared( | 516 void FramebufferManager::MarkAttachmentsAsCleared( |
| 516 FramebufferManager::FramebufferInfo* framebuffer, | 517 Framebuffer* framebuffer, |
| 517 RenderbufferManager* renderbuffer_manager, | 518 RenderbufferManager* renderbuffer_manager, |
| 518 TextureManager* texture_manager) { | 519 TextureManager* texture_manager) { |
| 519 DCHECK(framebuffer); | 520 DCHECK(framebuffer); |
| 520 framebuffer->MarkAttachmentsAsCleared(renderbuffer_manager, | 521 framebuffer->MarkAttachmentsAsCleared(renderbuffer_manager, |
| 521 texture_manager, | 522 texture_manager, |
| 522 true); | 523 true); |
| 523 MarkAsComplete(framebuffer); | 524 MarkAsComplete(framebuffer); |
| 524 } | 525 } |
| 525 | 526 |
| 526 void FramebufferManager::MarkAsComplete( | 527 void FramebufferManager::MarkAsComplete( |
| 527 FramebufferManager::FramebufferInfo* framebuffer) { | 528 Framebuffer* framebuffer) { |
| 528 DCHECK(framebuffer); | 529 DCHECK(framebuffer); |
| 529 framebuffer->MarkAsComplete(framebuffer_state_change_count_); | 530 framebuffer->MarkAsComplete(framebuffer_state_change_count_); |
| 530 } | 531 } |
| 531 | 532 |
| 532 bool FramebufferManager::IsComplete( | 533 bool FramebufferManager::IsComplete( |
| 533 FramebufferManager::FramebufferInfo* framebuffer) { | 534 Framebuffer* framebuffer) { |
| 534 DCHECK(framebuffer); | 535 DCHECK(framebuffer); |
| 535 return framebuffer->framebuffer_complete_state_count_id() == | 536 return framebuffer->framebuffer_complete_state_count_id() == |
| 536 framebuffer_state_change_count_; | 537 framebuffer_state_change_count_; |
| 537 } | 538 } |
| 538 | 539 |
| 539 } // namespace gles2 | 540 } // namespace gles2 |
| 540 } // namespace gpu | 541 } // namespace gpu |
| 541 | 542 |
| 542 | 543 |
| OLD | NEW |