Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: gpu/command_buffer/service/mailbox_manager_sync.cc

Issue 2783393002: Revert of Assert sequence validity on non-thread-safe RefCount manipulations (2) (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/gpu/gpu_data_manager_impl.cc ('k') | ppapi/shared_impl/proxy_lock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
202 TextureGroup* group = TextureGroup::FromName(mailbox); 198 TextureGroup* group = TextureGroup::FromName(mailbox);
203 if (!group) 199 if (!group)
204 return NULL; 200 return NULL;
205 201
206 // Check if a texture already exists in this share group. 202 // Check if a texture already exists in this share group.
207 Texture* texture = group->FindTexture(this); 203 Texture* texture = group->FindTexture(this);
208 if (texture) 204 if (texture)
209 return texture; 205 return texture;
210 206
211 // Otherwise create a new texture. 207 // Otherwise create a new texture.
212 texture = group->GetDefinition().CreateTexture(); 208 texture = group->GetDefinition().CreateTexture();
213 if (texture) { 209 if (texture) {
214 DCHECK(!SkipTextureWorkarounds(texture)); 210 DCHECK(!SkipTextureWorkarounds(texture));
215 texture->SetMailboxManager(this); 211 texture->SetMailboxManager(this);
216 group->AddTexture(this, texture); 212 group->AddTexture(this, texture);
217 213
218 TextureGroupRef new_ref = 214 TextureGroupRef new_ref =
219 TextureGroupRef(group->GetDefinition().version(), group); 215 TextureGroupRef(group->GetDefinition().version(), group);
220 texture_to_group_.insert(std::make_pair(texture, new_ref)); 216 texture_to_group_.insert(std::make_pair(texture, new_ref));
221 } 217 }
222 218
223 return texture; 219 return texture;
224 } 220 }
225 221
226 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, 222 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox,
227 TextureBase* texture_base) { 223 TextureBase* texture_base) {
228 base::AutoLock lock(g_lock.Get()); 224 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;
233 225
234 Texture* texture = static_cast<Texture*>(texture_base); 226 Texture* texture = static_cast<Texture*>(texture_base);
235 DCHECK(texture != nullptr); 227 DCHECK(texture != nullptr);
236 228
237 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); 229 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture);
238 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); 230 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox);
239 TextureGroup* group_for_texture = NULL; 231 TextureGroup* group_for_texture = NULL;
240 232
241 if (tex_it != texture_to_group_.end()) { 233 if (tex_it != texture_to_group_.end()) {
242 group_for_texture = tex_it->second.group.get(); 234 group_for_texture = tex_it->second.group.get();
(...skipping 27 matching lines...) Expand all
270 group_for_texture->AddName(mailbox); 262 group_for_texture->AddName(mailbox);
271 texture_to_group_.insert(std::make_pair( 263 texture_to_group_.insert(std::make_pair(
272 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); 264 texture, TextureGroupRef(kNewTextureVersion, group_for_texture)));
273 } 265 }
274 266
275 DCHECK(texture->mailbox_manager_ == this); 267 DCHECK(texture->mailbox_manager_ == this);
276 } 268 }
277 269
278 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { 270 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) {
279 base::AutoLock lock(g_lock.Get()); 271 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;
284 272
285 Texture* texture = static_cast<Texture*>(texture_base); 273 Texture* texture = static_cast<Texture*>(texture_base);
286 DCHECK(texture != nullptr); 274 DCHECK(texture != nullptr);
287 275
288 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); 276 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture);
289 DCHECK(tex_it != texture_to_group_.end()); 277 DCHECK(tex_it != texture_to_group_.end());
290 TextureGroup* group_for_texture = tex_it->second.group.get(); 278 TextureGroup* group_for_texture = tex_it->second.group.get();
291 if (group_for_texture->RemoveTexture(this, texture)) 279 if (group_for_texture->RemoveTexture(this, texture))
292 UpdateDefinitionLocked(texture, &tex_it->second); 280 UpdateDefinitionLocked(texture, &tex_it->second);
293 texture_to_group_.erase(tex_it); 281 texture_to_group_.erase(tex_it);
(...skipping 27 matching lines...) Expand all
321 LOG(ERROR) << "MailboxSync: Incompatible attachment"; 309 LOG(ERROR) << "MailboxSync: Incompatible attachment";
322 return; 310 return;
323 } 311 }
324 312
325 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, 313 group->SetDefinition(TextureDefinition(texture, ++group_ref->version,
326 image ? image_buffer : NULL)); 314 image ? image_buffer : NULL));
327 } 315 }
328 316
329 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { 317 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) {
330 base::AutoLock lock(g_lock.Get()); 318 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;
335 319
336 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); 320 for (TextureToGroupMap::iterator it = texture_to_group_.begin();
337 it != texture_to_group_.end(); it++) { 321 it != texture_to_group_.end(); it++) {
338 UpdateDefinitionLocked(it->first, &it->second); 322 UpdateDefinitionLocked(it->first, &it->second);
339 } 323 }
340 CreateFenceLocked(token); 324 CreateFenceLocked(token);
341 } 325 }
342 326
343 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { 327 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) {
344 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; 328 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>;
345 std::vector<TextureUpdatePair> needs_update; 329 std::vector<TextureUpdatePair> needs_update;
346 { 330 {
347 base::AutoLock lock(g_lock.Get()); 331 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;
352 AcquireFenceLocked(token); 332 AcquireFenceLocked(token);
353 333
354 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); 334 for (TextureToGroupMap::iterator it = texture_to_group_.begin();
355 it != texture_to_group_.end(); it++) { 335 it != texture_to_group_.end(); it++) {
356 const TextureDefinition& definition = it->second.group->GetDefinition(); 336 const TextureDefinition& definition = it->second.group->GetDefinition();
357 Texture* texture = it->first; 337 Texture* texture = it->first;
358 unsigned& texture_version = it->second.version; 338 unsigned& texture_version = it->second.version;
359 if (texture_version == definition.version() || 339 if (texture_version == definition.version() ||
360 definition.IsOlderThan(texture_version)) 340 definition.IsOlderThan(texture_version))
361 continue; 341 continue;
362 texture_version = definition.version(); 342 texture_version = definition.version();
363 needs_update.push_back(TextureUpdatePair(texture, definition)); 343 needs_update.push_back(TextureUpdatePair(texture, definition));
364 } 344 }
365 } 345 }
366 346
367 if (!needs_update.empty()) { 347 if (!needs_update.empty()) {
368 for (const TextureUpdatePair& pair : needs_update) { 348 for (const TextureUpdatePair& pair : needs_update) {
369 pair.second.UpdateTexture(pair.first); 349 pair.second.UpdateTexture(pair.first);
370 } 350 }
371 } 351 }
372 } 352 }
373 353
374 } // namespace gles2 354 } // namespace gles2
375 } // namespace gpu 355 } // namespace gpu
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_data_manager_impl.cc ('k') | ppapi/shared_impl/proxy_lock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698