Chromium Code Reviews| 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/mailbox_manager_sync.h" | 5 #include "gpu/command_buffer/service/mailbox_manager_sync.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 // EGL_KHR_gl_texture_2D_image and glEGLImageTargetTexture2DOES for | 184 // EGL_KHR_gl_texture_2D_image and glEGLImageTargetTexture2DOES for |
| 185 // texture levels. | 185 // texture levels. |
| 186 bool has_mips = texture->NeedsMips() && texture->texture_complete(); | 186 bool has_mips = texture->NeedsMips() && texture->texture_complete(); |
| 187 return texture->target() != GL_TEXTURE_2D || has_mips; | 187 return texture->target() != GL_TEXTURE_2D || has_mips; |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool MailboxManagerSync::UsesSync() { | 190 bool MailboxManagerSync::UsesSync() { |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 Texture* MailboxManagerSync::ConsumeTexture(const Mailbox& mailbox) { | 194 TextureBase* MailboxManagerSync::ConsumeTexture(const Mailbox& mailbox) { |
|
piman
2016/09/07 17:38:31
nit: you can use covariant returns and return Text
Geoff Lang
2016/09/07 18:14:49
Done.
| |
| 195 base::AutoLock lock(g_lock.Get()); | 195 base::AutoLock lock(g_lock.Get()); |
| 196 TextureGroup* group = TextureGroup::FromName(mailbox); | 196 TextureGroup* group = TextureGroup::FromName(mailbox); |
| 197 if (!group) | 197 if (!group) |
| 198 return NULL; | 198 return NULL; |
| 199 | 199 |
| 200 // Check if a texture already exists in this share group. | 200 // Check if a texture already exists in this share group. |
| 201 Texture* texture = group->FindTexture(this); | 201 Texture* texture = group->FindTexture(this); |
| 202 if (texture) | 202 if (texture) |
| 203 return texture; | 203 return texture; |
| 204 | 204 |
| 205 // Otherwise create a new texture. | 205 // Otherwise create a new texture. |
| 206 texture = group->GetDefinition().CreateTexture(); | 206 texture = group->GetDefinition().CreateTexture(); |
| 207 if (texture) { | 207 if (texture) { |
| 208 DCHECK(!SkipTextureWorkarounds(texture)); | 208 DCHECK(!SkipTextureWorkarounds(texture)); |
| 209 texture->SetMailboxManager(this); | 209 texture->SetMailboxManager(this); |
| 210 group->AddTexture(this, texture); | 210 group->AddTexture(this, texture); |
| 211 | 211 |
| 212 TextureGroupRef new_ref = | 212 TextureGroupRef new_ref = |
| 213 TextureGroupRef(group->GetDefinition().version(), group); | 213 TextureGroupRef(group->GetDefinition().version(), group); |
| 214 texture_to_group_.insert(std::make_pair(texture, new_ref)); | 214 texture_to_group_.insert(std::make_pair(texture, new_ref)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 return texture; | 217 return texture; |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, | 220 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, |
| 221 Texture* texture) { | 221 TextureBase* texture_base) { |
| 222 base::AutoLock lock(g_lock.Get()); | 222 base::AutoLock lock(g_lock.Get()); |
| 223 | 223 |
| 224 Texture* texture = texture_base->AsTexture(); | |
| 225 DCHECK(texture != nullptr); | |
| 226 | |
| 224 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 227 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
| 225 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); | 228 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); |
| 226 TextureGroup* group_for_texture = NULL; | 229 TextureGroup* group_for_texture = NULL; |
| 227 | 230 |
| 228 if (tex_it != texture_to_group_.end()) { | 231 if (tex_it != texture_to_group_.end()) { |
| 229 group_for_texture = tex_it->second.group.get(); | 232 group_for_texture = tex_it->second.group.get(); |
| 230 DCHECK(group_for_texture); | 233 DCHECK(group_for_texture); |
| 231 if (group_for_mailbox == group_for_texture) { | 234 if (group_for_mailbox == group_for_texture) { |
| 232 // The texture is already known under this name. | 235 // The texture is already known under this name. |
| 233 return; | 236 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 255 group_for_texture = new TextureGroup(definition); | 258 group_for_texture = new TextureGroup(definition); |
| 256 group_for_texture->AddTexture(this, texture); | 259 group_for_texture->AddTexture(this, texture); |
| 257 group_for_texture->AddName(mailbox); | 260 group_for_texture->AddName(mailbox); |
| 258 texture_to_group_.insert(std::make_pair( | 261 texture_to_group_.insert(std::make_pair( |
| 259 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); | 262 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); |
| 260 } | 263 } |
| 261 | 264 |
| 262 DCHECK(texture->mailbox_manager_ == this); | 265 DCHECK(texture->mailbox_manager_ == this); |
| 263 } | 266 } |
| 264 | 267 |
| 265 void MailboxManagerSync::TextureDeleted(Texture* texture) { | 268 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { |
| 266 base::AutoLock lock(g_lock.Get()); | 269 base::AutoLock lock(g_lock.Get()); |
| 270 | |
| 271 Texture* texture = texture_base->AsTexture(); | |
| 272 DCHECK(texture != nullptr); | |
| 273 | |
| 267 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 274 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
| 268 DCHECK(tex_it != texture_to_group_.end()); | 275 DCHECK(tex_it != texture_to_group_.end()); |
| 269 TextureGroup* group_for_texture = tex_it->second.group.get(); | 276 TextureGroup* group_for_texture = tex_it->second.group.get(); |
| 270 if (group_for_texture->RemoveTexture(this, texture)) | 277 if (group_for_texture->RemoveTexture(this, texture)) |
| 271 UpdateDefinitionLocked(texture, &tex_it->second); | 278 UpdateDefinitionLocked(texture, &tex_it->second); |
| 272 texture_to_group_.erase(tex_it); | 279 texture_to_group_.erase(tex_it); |
| 273 } | 280 } |
| 274 | 281 |
| 275 void MailboxManagerSync::UpdateDefinitionLocked( | 282 void MailboxManagerSync::UpdateDefinitionLocked(TextureBase* texture_base, |
| 276 Texture* texture, | 283 TextureGroupRef* group_ref) { |
| 277 TextureGroupRef* group_ref) { | |
| 278 g_lock.Get().AssertAcquired(); | 284 g_lock.Get().AssertAcquired(); |
| 279 | 285 |
| 286 Texture* texture = texture_base->AsTexture(); | |
| 287 DCHECK(texture != nullptr); | |
| 288 | |
| 280 if (SkipTextureWorkarounds(texture)) | 289 if (SkipTextureWorkarounds(texture)) |
| 281 return; | 290 return; |
| 282 | 291 |
| 283 gl::GLImage* image = texture->GetLevelImage(texture->target(), 0); | 292 gl::GLImage* image = texture->GetLevelImage(texture->target(), 0); |
| 284 TextureGroup* group = group_ref->group.get(); | 293 TextureGroup* group = group_ref->group.get(); |
| 285 const TextureDefinition& definition = group->GetDefinition(); | 294 const TextureDefinition& definition = group->GetDefinition(); |
| 286 scoped_refptr<NativeImageBuffer> image_buffer = definition.image(); | 295 scoped_refptr<NativeImageBuffer> image_buffer = definition.image(); |
| 287 | 296 |
| 288 // Make sure we don't clobber with an older version | 297 // Make sure we don't clobber with an older version |
| 289 if (!definition.IsOlderThan(group_ref->version)) | 298 if (!definition.IsOlderThan(group_ref->version)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 344 |
| 336 if (!needs_update.empty()) { | 345 if (!needs_update.empty()) { |
| 337 for (const TextureUpdatePair& pair : needs_update) { | 346 for (const TextureUpdatePair& pair : needs_update) { |
| 338 pair.second.UpdateTexture(pair.first); | 347 pair.second.UpdateTexture(pair.first); |
| 339 } | 348 } |
| 340 } | 349 } |
| 341 } | 350 } |
| 342 | 351 |
| 343 } // namespace gles2 | 352 } // namespace gles2 |
| 344 } // namespace gpu | 353 } // namespace gpu |
| OLD | NEW |