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