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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bool has_mips = texture->NeedsMips() && texture->texture_complete(); | 188 bool has_mips = texture->NeedsMips() && texture->texture_complete(); |
189 return texture->target() != GL_TEXTURE_2D || has_mips; | 189 return texture->target() != GL_TEXTURE_2D || has_mips; |
190 } | 190 } |
191 | 191 |
192 bool MailboxManagerSync::UsesSync() { | 192 bool MailboxManagerSync::UsesSync() { |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 Texture* MailboxManagerSync::ConsumeTexture(const Mailbox& mailbox) { | 196 Texture* MailboxManagerSync::ConsumeTexture(const Mailbox& mailbox) { |
197 base::AutoLock lock(g_lock.Get()); | 197 base::AutoLock lock(g_lock.Get()); |
| 198 // Relax the cross-thread access restriction to non-thread-safe RefCount. |
| 199 // The lock above protects non-thread-safe RefCount in TextureGroup. |
| 200 base::ScopedAllowCrossThreadRefCountAccess |
| 201 scoped_allow_cross_thread_ref_count_access; |
198 TextureGroup* group = TextureGroup::FromName(mailbox); | 202 TextureGroup* group = TextureGroup::FromName(mailbox); |
199 if (!group) | 203 if (!group) |
200 return NULL; | 204 return NULL; |
201 | 205 |
202 // Check if a texture already exists in this share group. | 206 // Check if a texture already exists in this share group. |
203 Texture* texture = group->FindTexture(this); | 207 Texture* texture = group->FindTexture(this); |
204 if (texture) | 208 if (texture) |
205 return texture; | 209 return texture; |
206 | 210 |
207 // Otherwise create a new texture. | 211 // Otherwise create a new texture. |
208 texture = group->GetDefinition().CreateTexture(); | 212 texture = group->GetDefinition().CreateTexture(); |
209 if (texture) { | 213 if (texture) { |
210 DCHECK(!SkipTextureWorkarounds(texture)); | 214 DCHECK(!SkipTextureWorkarounds(texture)); |
211 texture->SetMailboxManager(this); | 215 texture->SetMailboxManager(this); |
212 group->AddTexture(this, texture); | 216 group->AddTexture(this, texture); |
213 | 217 |
214 TextureGroupRef new_ref = | 218 TextureGroupRef new_ref = |
215 TextureGroupRef(group->GetDefinition().version(), group); | 219 TextureGroupRef(group->GetDefinition().version(), group); |
216 texture_to_group_.insert(std::make_pair(texture, new_ref)); | 220 texture_to_group_.insert(std::make_pair(texture, new_ref)); |
217 } | 221 } |
218 | 222 |
219 return texture; | 223 return texture; |
220 } | 224 } |
221 | 225 |
222 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, | 226 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, |
223 TextureBase* texture_base) { | 227 TextureBase* texture_base) { |
224 base::AutoLock lock(g_lock.Get()); | 228 base::AutoLock lock(g_lock.Get()); |
| 229 // Relax the cross-thread access restriction to non-thread-safe RefCount. |
| 230 // The lock above protects non-thread-safe RefCount in TextureGroup. |
| 231 base::ScopedAllowCrossThreadRefCountAccess |
| 232 scoped_allow_cross_thread_ref_count_access; |
225 | 233 |
226 Texture* texture = static_cast<Texture*>(texture_base); | 234 Texture* texture = static_cast<Texture*>(texture_base); |
227 DCHECK(texture != nullptr); | 235 DCHECK(texture != nullptr); |
228 | 236 |
229 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 237 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
230 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); | 238 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); |
231 TextureGroup* group_for_texture = NULL; | 239 TextureGroup* group_for_texture = NULL; |
232 | 240 |
233 if (tex_it != texture_to_group_.end()) { | 241 if (tex_it != texture_to_group_.end()) { |
234 group_for_texture = tex_it->second.group.get(); | 242 group_for_texture = tex_it->second.group.get(); |
(...skipping 27 matching lines...) Expand all Loading... |
262 group_for_texture->AddName(mailbox); | 270 group_for_texture->AddName(mailbox); |
263 texture_to_group_.insert(std::make_pair( | 271 texture_to_group_.insert(std::make_pair( |
264 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); | 272 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); |
265 } | 273 } |
266 | 274 |
267 DCHECK(texture->mailbox_manager_ == this); | 275 DCHECK(texture->mailbox_manager_ == this); |
268 } | 276 } |
269 | 277 |
270 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { | 278 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { |
271 base::AutoLock lock(g_lock.Get()); | 279 base::AutoLock lock(g_lock.Get()); |
| 280 // Relax the cross-thread access restriction to non-thread-safe RefCount. |
| 281 // The lock above protects non-thread-safe RefCount in TextureGroup. |
| 282 base::ScopedAllowCrossThreadRefCountAccess |
| 283 scoped_allow_cross_thread_ref_count_access; |
272 | 284 |
273 Texture* texture = static_cast<Texture*>(texture_base); | 285 Texture* texture = static_cast<Texture*>(texture_base); |
274 DCHECK(texture != nullptr); | 286 DCHECK(texture != nullptr); |
275 | 287 |
276 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 288 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
277 DCHECK(tex_it != texture_to_group_.end()); | 289 DCHECK(tex_it != texture_to_group_.end()); |
278 TextureGroup* group_for_texture = tex_it->second.group.get(); | 290 TextureGroup* group_for_texture = tex_it->second.group.get(); |
279 if (group_for_texture->RemoveTexture(this, texture)) | 291 if (group_for_texture->RemoveTexture(this, texture)) |
280 UpdateDefinitionLocked(texture, &tex_it->second); | 292 UpdateDefinitionLocked(texture, &tex_it->second); |
281 texture_to_group_.erase(tex_it); | 293 texture_to_group_.erase(tex_it); |
(...skipping 27 matching lines...) Expand all Loading... |
309 LOG(ERROR) << "MailboxSync: Incompatible attachment"; | 321 LOG(ERROR) << "MailboxSync: Incompatible attachment"; |
310 return; | 322 return; |
311 } | 323 } |
312 | 324 |
313 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, | 325 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, |
314 image ? image_buffer : NULL)); | 326 image ? image_buffer : NULL)); |
315 } | 327 } |
316 | 328 |
317 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { | 329 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { |
318 base::AutoLock lock(g_lock.Get()); | 330 base::AutoLock lock(g_lock.Get()); |
| 331 // Relax the cross-thread access restriction to non-thread-safe RefCount. |
| 332 // The lock above protects non-thread-safe RefCount in TextureGroup. |
| 333 base::ScopedAllowCrossThreadRefCountAccess |
| 334 scoped_allow_cross_thread_ref_count_access; |
319 | 335 |
320 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 336 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
321 it != texture_to_group_.end(); it++) { | 337 it != texture_to_group_.end(); it++) { |
322 UpdateDefinitionLocked(it->first, &it->second); | 338 UpdateDefinitionLocked(it->first, &it->second); |
323 } | 339 } |
324 CreateFenceLocked(token); | 340 CreateFenceLocked(token); |
325 } | 341 } |
326 | 342 |
327 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { | 343 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { |
328 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; | 344 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; |
329 std::vector<TextureUpdatePair> needs_update; | 345 std::vector<TextureUpdatePair> needs_update; |
330 { | 346 { |
331 base::AutoLock lock(g_lock.Get()); | 347 base::AutoLock lock(g_lock.Get()); |
| 348 // Relax the cross-thread access restriction to non-thread-safe RefCount. |
| 349 // The lock above protects non-thread-safe RefCount in TextureGroup. |
| 350 base::ScopedAllowCrossThreadRefCountAccess |
| 351 scoped_allow_cross_thread_ref_count_access; |
332 AcquireFenceLocked(token); | 352 AcquireFenceLocked(token); |
333 | 353 |
334 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 354 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
335 it != texture_to_group_.end(); it++) { | 355 it != texture_to_group_.end(); it++) { |
336 const TextureDefinition& definition = it->second.group->GetDefinition(); | 356 const TextureDefinition& definition = it->second.group->GetDefinition(); |
337 Texture* texture = it->first; | 357 Texture* texture = it->first; |
338 unsigned& texture_version = it->second.version; | 358 unsigned& texture_version = it->second.version; |
339 if (texture_version == definition.version() || | 359 if (texture_version == definition.version() || |
340 definition.IsOlderThan(texture_version)) | 360 definition.IsOlderThan(texture_version)) |
341 continue; | 361 continue; |
342 texture_version = definition.version(); | 362 texture_version = definition.version(); |
343 needs_update.push_back(TextureUpdatePair(texture, definition)); | 363 needs_update.push_back(TextureUpdatePair(texture, definition)); |
344 } | 364 } |
345 } | 365 } |
346 | 366 |
347 if (!needs_update.empty()) { | 367 if (!needs_update.empty()) { |
348 for (const TextureUpdatePair& pair : needs_update) { | 368 for (const TextureUpdatePair& pair : needs_update) { |
349 pair.second.UpdateTexture(pair.first); | 369 pair.second.UpdateTexture(pair.first); |
350 } | 370 } |
351 } | 371 } |
352 } | 372 } |
353 | 373 |
354 } // namespace gles2 | 374 } // namespace gles2 |
355 } // namespace gpu | 375 } // namespace gpu |
OLD | NEW |