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 base::ScopedAllowCrossThreadRefCountAccess a; | |
197 TextureGroup* group = TextureGroup::FromName(mailbox); | 198 TextureGroup* group = TextureGroup::FromName(mailbox); |
198 if (!group) | 199 if (!group) |
199 return NULL; | 200 return NULL; |
200 | 201 |
201 // Check if a texture already exists in this share group. | 202 // Check if a texture already exists in this share group. |
202 Texture* texture = group->FindTexture(this); | 203 Texture* texture = group->FindTexture(this); |
203 if (texture) | 204 if (texture) |
204 return texture; | 205 return texture; |
205 | 206 |
206 // Otherwise create a new texture. | 207 // Otherwise create a new texture. |
207 texture = group->GetDefinition().CreateTexture(); | 208 texture = group->GetDefinition().CreateTexture(); |
208 if (texture) { | 209 if (texture) { |
209 DCHECK(!SkipTextureWorkarounds(texture)); | 210 DCHECK(!SkipTextureWorkarounds(texture)); |
210 texture->SetMailboxManager(this); | 211 texture->SetMailboxManager(this); |
211 group->AddTexture(this, texture); | 212 group->AddTexture(this, texture); |
212 | 213 |
213 TextureGroupRef new_ref = | 214 TextureGroupRef new_ref = |
214 TextureGroupRef(group->GetDefinition().version(), group); | 215 TextureGroupRef(group->GetDefinition().version(), group); |
215 texture_to_group_.insert(std::make_pair(texture, new_ref)); | 216 texture_to_group_.insert(std::make_pair(texture, new_ref)); |
216 } | 217 } |
217 | 218 |
218 return texture; | 219 return texture; |
219 } | 220 } |
220 | 221 |
221 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, | 222 void MailboxManagerSync::ProduceTexture(const Mailbox& mailbox, |
222 TextureBase* texture_base) { | 223 TextureBase* texture_base) { |
223 base::AutoLock lock(g_lock.Get()); | 224 base::AutoLock lock(g_lock.Get()); |
225 base::ScopedAllowCrossThreadRefCountAccess a; | |
224 | 226 |
225 Texture* texture = static_cast<Texture*>(texture_base); | 227 Texture* texture = static_cast<Texture*>(texture_base); |
226 DCHECK(texture != nullptr); | 228 DCHECK(texture != nullptr); |
227 | 229 |
228 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 230 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
229 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); | 231 TextureGroup* group_for_mailbox = TextureGroup::FromName(mailbox); |
230 TextureGroup* group_for_texture = NULL; | 232 TextureGroup* group_for_texture = NULL; |
231 | 233 |
232 if (tex_it != texture_to_group_.end()) { | 234 if (tex_it != texture_to_group_.end()) { |
233 group_for_texture = tex_it->second.group.get(); | 235 group_for_texture = tex_it->second.group.get(); |
(...skipping 27 matching lines...) Expand all Loading... | |
261 group_for_texture->AddName(mailbox); | 263 group_for_texture->AddName(mailbox); |
262 texture_to_group_.insert(std::make_pair( | 264 texture_to_group_.insert(std::make_pair( |
263 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); | 265 texture, TextureGroupRef(kNewTextureVersion, group_for_texture))); |
264 } | 266 } |
265 | 267 |
266 DCHECK(texture->mailbox_manager_ == this); | 268 DCHECK(texture->mailbox_manager_ == this); |
267 } | 269 } |
268 | 270 |
269 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { | 271 void MailboxManagerSync::TextureDeleted(TextureBase* texture_base) { |
270 base::AutoLock lock(g_lock.Get()); | 272 base::AutoLock lock(g_lock.Get()); |
273 base::ScopedAllowCrossThreadRefCountAccess a; | |
271 | 274 |
272 Texture* texture = static_cast<Texture*>(texture_base); | 275 Texture* texture = static_cast<Texture*>(texture_base); |
273 DCHECK(texture != nullptr); | 276 DCHECK(texture != nullptr); |
274 | 277 |
275 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); | 278 TextureToGroupMap::iterator tex_it = texture_to_group_.find(texture); |
276 DCHECK(tex_it != texture_to_group_.end()); | 279 DCHECK(tex_it != texture_to_group_.end()); |
277 TextureGroup* group_for_texture = tex_it->second.group.get(); | 280 TextureGroup* group_for_texture = tex_it->second.group.get(); |
278 if (group_for_texture->RemoveTexture(this, texture)) | 281 if (group_for_texture->RemoveTexture(this, texture)) |
279 UpdateDefinitionLocked(texture, &tex_it->second); | 282 UpdateDefinitionLocked(texture, &tex_it->second); |
280 texture_to_group_.erase(tex_it); | 283 texture_to_group_.erase(tex_it); |
(...skipping 27 matching lines...) Expand all Loading... | |
308 LOG(ERROR) << "MailboxSync: Incompatible attachment"; | 311 LOG(ERROR) << "MailboxSync: Incompatible attachment"; |
309 return; | 312 return; |
310 } | 313 } |
311 | 314 |
312 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, | 315 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, |
313 image ? image_buffer : NULL)); | 316 image ? image_buffer : NULL)); |
314 } | 317 } |
315 | 318 |
316 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { | 319 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { |
317 base::AutoLock lock(g_lock.Get()); | 320 base::AutoLock lock(g_lock.Get()); |
321 base::ScopedAllowCrossThreadRefCountAccess a; | |
gab
2017/02/17 21:10:41
Comment and full variable name everywhere.
tzik
2017/02/21 06:15:03
Done.
| |
318 | 322 |
319 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 323 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
320 it != texture_to_group_.end(); it++) { | 324 it != texture_to_group_.end(); it++) { |
321 UpdateDefinitionLocked(it->first, &it->second); | 325 UpdateDefinitionLocked(it->first, &it->second); |
322 } | 326 } |
323 CreateFenceLocked(token); | 327 CreateFenceLocked(token); |
324 } | 328 } |
325 | 329 |
326 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { | 330 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { |
327 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; | 331 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; |
328 std::vector<TextureUpdatePair> needs_update; | 332 std::vector<TextureUpdatePair> needs_update; |
329 { | 333 { |
330 base::AutoLock lock(g_lock.Get()); | 334 base::AutoLock lock(g_lock.Get()); |
335 base::ScopedAllowCrossThreadRefCountAccess a; | |
331 AcquireFenceLocked(token); | 336 AcquireFenceLocked(token); |
332 | 337 |
333 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 338 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
334 it != texture_to_group_.end(); it++) { | 339 it != texture_to_group_.end(); it++) { |
335 const TextureDefinition& definition = it->second.group->GetDefinition(); | 340 const TextureDefinition& definition = it->second.group->GetDefinition(); |
336 Texture* texture = it->first; | 341 Texture* texture = it->first; |
337 unsigned& texture_version = it->second.version; | 342 unsigned& texture_version = it->second.version; |
338 if (texture_version == definition.version() || | 343 if (texture_version == definition.version() || |
339 definition.IsOlderThan(texture_version)) | 344 definition.IsOlderThan(texture_version)) |
340 continue; | 345 continue; |
341 texture_version = definition.version(); | 346 texture_version = definition.version(); |
342 needs_update.push_back(TextureUpdatePair(texture, definition)); | 347 needs_update.push_back(TextureUpdatePair(texture, definition)); |
343 } | 348 } |
344 } | 349 } |
345 | 350 |
346 if (!needs_update.empty()) { | 351 if (!needs_update.empty()) { |
347 for (const TextureUpdatePair& pair : needs_update) { | 352 for (const TextureUpdatePair& pair : needs_update) { |
348 pair.second.UpdateTexture(pair.first); | 353 pair.second.UpdateTexture(pair.first); |
349 } | 354 } |
350 } | 355 } |
351 } | 356 } |
352 | 357 |
353 } // namespace gles2 | 358 } // namespace gles2 |
354 } // namespace gpu | 359 } // namespace gpu |
OLD | NEW |