| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 8 | 8 |
| 9 namespace gpu { | 9 namespace gpu { |
| 10 namespace gles2 { | 10 namespace gles2 { |
| 11 | 11 |
| 12 class RenderbufferAttachment |
| 13 : public FramebufferManager::FramebufferInfo::Attachment { |
| 14 public: |
| 15 explicit RenderbufferAttachment( |
| 16 RenderbufferManager::RenderbufferInfo* render_buffer) |
| 17 : render_buffer_(render_buffer) { |
| 18 } |
| 19 |
| 20 virtual ~RenderbufferAttachment() { } |
| 21 |
| 22 virtual GLsizei width() const { |
| 23 return render_buffer_->width(); |
| 24 } |
| 25 |
| 26 virtual GLsizei height() const { |
| 27 return render_buffer_->height(); |
| 28 } |
| 29 |
| 30 virtual GLenum internal_format() const { |
| 31 return render_buffer_->internal_format(); |
| 32 } |
| 33 |
| 34 virtual GLsizei samples() const { |
| 35 return render_buffer_->samples(); |
| 36 } |
| 37 |
| 38 virtual bool cleared() const { |
| 39 return render_buffer_->cleared(); |
| 40 } |
| 41 |
| 42 virtual void set_cleared() { |
| 43 render_buffer_->set_cleared(); |
| 44 } |
| 45 |
| 46 RenderbufferManager::RenderbufferInfo* render_buffer() const { |
| 47 return render_buffer_.get(); |
| 48 } |
| 49 |
| 50 private: |
| 51 RenderbufferManager::RenderbufferInfo::Ref render_buffer_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment); |
| 54 }; |
| 55 |
| 56 class TextureAttachment |
| 57 : public FramebufferManager::FramebufferInfo::Attachment { |
| 58 public: |
| 59 TextureAttachment( |
| 60 TextureManager::TextureInfo* texture, GLenum target, GLint level) |
| 61 : texture_(texture), |
| 62 target_(target), |
| 63 level_(level) { |
| 64 } |
| 65 |
| 66 virtual ~TextureAttachment() { } |
| 67 |
| 68 virtual GLsizei width() const { |
| 69 GLsizei temp_width = 0; |
| 70 GLsizei temp_height = 0; |
| 71 texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); |
| 72 return temp_width; |
| 73 } |
| 74 |
| 75 virtual GLsizei height() const { |
| 76 GLsizei temp_width = 0; |
| 77 GLsizei temp_height = 0; |
| 78 texture_->GetLevelSize(target_, level_, &temp_width, &temp_height); |
| 79 return temp_height; |
| 80 } |
| 81 |
| 82 virtual GLenum internal_format() const { |
| 83 GLenum temp_type = 0; |
| 84 GLenum temp_internal_format = 0; |
| 85 texture_->GetLevelType(target_, level_, &temp_type, &temp_internal_format); |
| 86 return temp_internal_format; |
| 87 } |
| 88 |
| 89 virtual GLsizei samples() const { |
| 90 return 0; |
| 91 } |
| 92 |
| 93 virtual bool cleared() const { |
| 94 // Textures are cleared on creation. |
| 95 return true; |
| 96 } |
| 97 |
| 98 virtual void set_cleared() { |
| 99 NOTREACHED(); |
| 100 } |
| 101 |
| 102 TextureManager::TextureInfo* texture() const { |
| 103 return texture_.get(); |
| 104 } |
| 105 |
| 106 private: |
| 107 TextureManager::TextureInfo::Ref texture_; |
| 108 GLenum target_; |
| 109 GLint level_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(TextureAttachment); |
| 112 }; |
| 113 |
| 12 FramebufferManager::FramebufferManager() {} | 114 FramebufferManager::FramebufferManager() {} |
| 13 | 115 |
| 14 FramebufferManager::~FramebufferManager() { | 116 FramebufferManager::~FramebufferManager() { |
| 15 DCHECK(framebuffer_infos_.empty()); | 117 DCHECK(framebuffer_infos_.empty()); |
| 16 } | 118 } |
| 17 | 119 |
| 18 void FramebufferManager::Destroy(bool have_context) { | 120 void FramebufferManager::Destroy(bool have_context) { |
| 19 while (!framebuffer_infos_.empty()) { | 121 while (!framebuffer_infos_.empty()) { |
| 20 if (have_context) { | 122 if (have_context) { |
| 21 FramebufferInfo* info = framebuffer_infos_.begin()->second; | 123 FramebufferInfo* info = framebuffer_infos_.begin()->second; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 } | 142 } |
| 41 | 143 |
| 42 FramebufferManager::FramebufferInfo::FramebufferInfo(GLuint service_id) | 144 FramebufferManager::FramebufferInfo::FramebufferInfo(GLuint service_id) |
| 43 : service_id_(service_id) { | 145 : service_id_(service_id) { |
| 44 } | 146 } |
| 45 | 147 |
| 46 FramebufferManager::FramebufferInfo::~FramebufferInfo() {} | 148 FramebufferManager::FramebufferInfo::~FramebufferInfo() {} |
| 47 | 149 |
| 48 bool FramebufferManager::FramebufferInfo::HasUnclearedAttachment( | 150 bool FramebufferManager::FramebufferInfo::HasUnclearedAttachment( |
| 49 GLenum attachment) const { | 151 GLenum attachment) const { |
| 50 AttachmentToRenderbufferMap::const_iterator it = | 152 AttachmentMap::const_iterator it = |
| 51 renderbuffers_.find(attachment); | 153 attachments_.find(attachment); |
| 52 if (it != renderbuffers_.end()) { | 154 if (it != attachments_.end()) { |
| 53 RenderbufferManager::RenderbufferInfo* info = it->second; | 155 const Attachment* attachment = it->second; |
| 54 return !info->cleared(); | 156 return !attachment->cleared(); |
| 55 } | 157 } |
| 56 return false; | 158 return false; |
| 57 } | 159 } |
| 58 | 160 |
| 59 void FramebufferManager::FramebufferInfo::MarkAttachedRenderbuffersAsCleared() { | 161 void FramebufferManager::FramebufferInfo::MarkAttachedRenderbuffersAsCleared() { |
| 60 for (AttachmentToRenderbufferMap::iterator it = renderbuffers_.begin(); | 162 for (AttachmentMap::iterator it = attachments_.begin(); |
| 61 it != renderbuffers_.end(); ++it) { | 163 it != attachments_.end(); ++it) { |
| 62 RenderbufferManager::RenderbufferInfo* info = it->second; | 164 Attachment* attachment = it->second; |
| 63 info->set_cleared(); | 165 if (!attachment->cleared()) { |
| 166 attachment->set_cleared(); |
| 167 } |
| 64 } | 168 } |
| 65 } | 169 } |
| 66 | 170 |
| 67 FramebufferManager::FramebufferInfo* FramebufferManager::GetFramebufferInfo( | 171 FramebufferManager::FramebufferInfo* FramebufferManager::GetFramebufferInfo( |
| 68 GLuint client_id) { | 172 GLuint client_id) { |
| 69 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); | 173 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); |
| 70 return it != framebuffer_infos_.end() ? it->second : NULL; | 174 return it != framebuffer_infos_.end() ? it->second : NULL; |
| 71 } | 175 } |
| 72 | 176 |
| 73 void FramebufferManager::RemoveFramebufferInfo(GLuint client_id) { | 177 void FramebufferManager::RemoveFramebufferInfo(GLuint client_id) { |
| 74 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); | 178 FramebufferInfoMap::iterator it = framebuffer_infos_.find(client_id); |
| 75 if (it != framebuffer_infos_.end()) { | 179 if (it != framebuffer_infos_.end()) { |
| 76 it->second->MarkAsDeleted(); | 180 it->second->MarkAsDeleted(); |
| 77 framebuffer_infos_.erase(it); | 181 framebuffer_infos_.erase(it); |
| 78 } | 182 } |
| 79 } | 183 } |
| 80 | 184 |
| 81 void FramebufferManager::FramebufferInfo::AttachRenderbuffer( | 185 void FramebufferManager::FramebufferInfo::AttachRenderbuffer( |
| 82 GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer) { | 186 GLenum attachment, RenderbufferManager::RenderbufferInfo* renderbuffer) { |
| 83 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || | 187 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || |
| 84 attachment == GL_DEPTH_ATTACHMENT || | 188 attachment == GL_DEPTH_ATTACHMENT || |
| 85 attachment == GL_STENCIL_ATTACHMENT || | 189 attachment == GL_STENCIL_ATTACHMENT || |
| 86 attachment == GL_DEPTH_STENCIL_ATTACHMENT); | 190 attachment == GL_DEPTH_STENCIL_ATTACHMENT); |
| 87 if (renderbuffer) { | 191 if (renderbuffer) { |
| 88 renderbuffers_[attachment] = | 192 attachments_[attachment] = Attachment::Ref( |
| 89 RenderbufferManager::RenderbufferInfo::Ref(renderbuffer); | 193 new RenderbufferAttachment(renderbuffer)); |
| 90 } else { | 194 } else { |
| 91 renderbuffers_.erase(attachment); | 195 attachments_.erase(attachment); |
| 92 } | 196 } |
| 93 } | 197 } |
| 94 | 198 |
| 199 void FramebufferManager::FramebufferInfo::AttachTexture( |
| 200 GLenum attachment, TextureManager::TextureInfo* texture, GLenum target, |
| 201 GLint level) { |
| 202 DCHECK(attachment == GL_COLOR_ATTACHMENT0 || |
| 203 attachment == GL_DEPTH_ATTACHMENT || |
| 204 attachment == GL_STENCIL_ATTACHMENT || |
| 205 attachment == GL_DEPTH_STENCIL_ATTACHMENT); |
| 206 if (texture) { |
| 207 attachments_[attachment] = Attachment::Ref( |
| 208 new TextureAttachment(texture, target, level)); |
| 209 } else { |
| 210 attachments_.erase(attachment); |
| 211 } |
| 212 } |
| 213 |
| 214 const FramebufferManager::FramebufferInfo::Attachment* |
| 215 FramebufferManager::FramebufferInfo::GetAttachment( |
| 216 GLenum attachment) const { |
| 217 AttachmentMap::const_iterator it = attachments_.find(attachment); |
| 218 if (it != attachments_.end()) { |
| 219 return it->second; |
| 220 } |
| 221 return NULL; |
| 222 } |
| 223 |
| 95 bool FramebufferManager::GetClientId( | 224 bool FramebufferManager::GetClientId( |
| 96 GLuint service_id, GLuint* client_id) const { | 225 GLuint service_id, GLuint* client_id) const { |
| 97 // This doesn't need to be fast. It's only used during slow queries. | 226 // This doesn't need to be fast. It's only used during slow queries. |
| 98 for (FramebufferInfoMap::const_iterator it = framebuffer_infos_.begin(); | 227 for (FramebufferInfoMap::const_iterator it = framebuffer_infos_.begin(); |
| 99 it != framebuffer_infos_.end(); ++it) { | 228 it != framebuffer_infos_.end(); ++it) { |
| 100 if (it->second->service_id() == service_id) { | 229 if (it->second->service_id() == service_id) { |
| 101 *client_id = it->first; | 230 *client_id = it->first; |
| 102 return true; | 231 return true; |
| 103 } | 232 } |
| 104 } | 233 } |
| 105 return false; | 234 return false; |
| 106 } | 235 } |
| 107 | 236 |
| 108 } // namespace gles2 | 237 } // namespace gles2 |
| 109 } // namespace gpu | 238 } // namespace gpu |
| 110 | 239 |
| 111 | 240 |
| OLD | NEW |