| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 12 #include "gpu/command_buffer/service/texture_manager.h" | 13 #include "gpu/command_buffer/service/texture_manager.h" |
| 13 #include "ui/gl/gl_fence.h" | 14 #include "ui/gl/gl_fence.h" |
| 14 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
| 15 | 16 |
| 16 #if !defined(OS_MACOSX) | 17 #if !defined(OS_MACOSX) |
| 17 #include "ui/gl/gl_fence_egl.h" | 18 #include "ui/gl/gl_fence_egl.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace gpu { | 21 namespace gpu { |
| 21 namespace gles2 { | 22 namespace gles2 { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER; | 26 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER; |
| 26 | 27 |
| 27 typedef std::map<uint32, linked_ptr<gfx::GLFence>> SyncPointToFenceMap; | 28 #if !defined(OS_MACOSX) |
| 28 base::LazyInstance<SyncPointToFenceMap> g_sync_point_to_fence = | 29 typedef std::map<SyncToken, linked_ptr<gfx::GLFence>> SyncTokenToFenceMap; |
| 30 base::LazyInstance<SyncTokenToFenceMap> g_sync_point_to_fence = |
| 29 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 30 #if !defined(OS_MACOSX) | 32 base::LazyInstance<std::queue<SyncTokenToFenceMap::iterator>> g_sync_points = |
| 31 base::LazyInstance<std::queue<SyncPointToFenceMap::iterator>> g_sync_points = | |
| 32 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 void CreateFenceLocked(uint32 sync_point) { | 36 void CreateFenceLocked(const SyncToken& sync_token) { |
| 37 #if !defined(OS_MACOSX) |
| 36 g_lock.Get().AssertAcquired(); | 38 g_lock.Get().AssertAcquired(); |
| 37 if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) | 39 if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) |
| 38 return; | 40 return; |
| 39 | 41 |
| 40 #if !defined(OS_MACOSX) | 42 std::queue<SyncTokenToFenceMap::iterator>& sync_points = g_sync_points.Get(); |
| 41 std::queue<SyncPointToFenceMap::iterator>& sync_points = g_sync_points.Get(); | 43 SyncTokenToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get(); |
| 42 SyncPointToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get(); | 44 if (sync_token.release_count) { |
| 43 if (sync_point) { | |
| 44 while (!sync_points.empty() && | 45 while (!sync_points.empty() && |
| 45 sync_points.front()->second->HasCompleted()) { | 46 sync_points.front()->second->HasCompleted()) { |
| 46 sync_point_to_fence.erase(sync_points.front()); | 47 sync_point_to_fence.erase(sync_points.front()); |
| 47 sync_points.pop(); | 48 sync_points.pop(); |
| 48 } | 49 } |
| 49 // Need to use EGL fences since we are likely not in a single share group. | 50 // Need to use EGL fences since we are likely not in a single share group. |
| 50 linked_ptr<gfx::GLFence> fence(make_linked_ptr(new gfx::GLFenceEGL)); | 51 linked_ptr<gfx::GLFence> fence(make_linked_ptr(new gfx::GLFenceEGL)); |
| 51 if (fence.get()) { | 52 if (fence.get()) { |
| 52 std::pair<SyncPointToFenceMap::iterator, bool> result = | 53 std::pair<SyncTokenToFenceMap::iterator, bool> result = |
| 53 sync_point_to_fence.insert(std::make_pair(sync_point, fence)); | 54 sync_point_to_fence.insert(std::make_pair(sync_token, fence)); |
| 54 DCHECK(result.second); | 55 DCHECK(result.second); |
| 55 sync_points.push(result.first); | 56 sync_points.push(result.first); |
| 56 } | 57 } |
| 57 DCHECK(sync_points.size() == sync_point_to_fence.size()); | 58 DCHECK(sync_points.size() == sync_point_to_fence.size()); |
| 58 } | 59 } |
| 59 #endif | 60 #endif |
| 60 } | 61 } |
| 61 | 62 |
| 62 void AcquireFenceLocked(uint32 sync_point) { | 63 void AcquireFenceLocked(const SyncToken& sync_token) { |
| 64 #if !defined(OS_MACOSX) |
| 63 g_lock.Get().AssertAcquired(); | 65 g_lock.Get().AssertAcquired(); |
| 64 SyncPointToFenceMap::iterator fence_it = | 66 SyncTokenToFenceMap::iterator fence_it = |
| 65 g_sync_point_to_fence.Get().find(sync_point); | 67 g_sync_point_to_fence.Get().find(sync_token); |
| 66 if (fence_it != g_sync_point_to_fence.Get().end()) { | 68 if (fence_it != g_sync_point_to_fence.Get().end()) { |
| 67 fence_it->second->ServerWait(); | 69 fence_it->second->ServerWait(); |
| 68 } | 70 } |
| 71 #endif |
| 69 } | 72 } |
| 70 | 73 |
| 71 static const unsigned kNewTextureVersion = 1; | 74 static const unsigned kNewTextureVersion = 1; |
| 72 | 75 |
| 73 } // anonymous namespace | 76 } // anonymous namespace |
| 74 | 77 |
| 75 base::LazyInstance<MailboxManagerSync::TextureGroup::MailboxToGroupMap> | 78 base::LazyInstance<MailboxManagerSync::TextureGroup::MailboxToGroupMap> |
| 76 MailboxManagerSync::TextureGroup::mailbox_to_group_ = | 79 MailboxManagerSync::TextureGroup::mailbox_to_group_ = |
| 77 LAZY_INSTANCE_INITIALIZER; | 80 LAZY_INSTANCE_INITIALIZER; |
| 78 | 81 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 DCHECK_IMPLIES(gl_image, image_buffer.get()); | 290 DCHECK_IMPLIES(gl_image, image_buffer.get()); |
| 288 if (gl_image && !image_buffer->IsClient(gl_image)) { | 291 if (gl_image && !image_buffer->IsClient(gl_image)) { |
| 289 LOG(ERROR) << "MailboxSync: Incompatible attachment"; | 292 LOG(ERROR) << "MailboxSync: Incompatible attachment"; |
| 290 return; | 293 return; |
| 291 } | 294 } |
| 292 | 295 |
| 293 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, | 296 group->SetDefinition(TextureDefinition(texture, ++group_ref->version, |
| 294 gl_image ? image_buffer : NULL)); | 297 gl_image ? image_buffer : NULL)); |
| 295 } | 298 } |
| 296 | 299 |
| 297 void MailboxManagerSync::PushTextureUpdates(uint32 sync_point) { | 300 void MailboxManagerSync::PushTextureUpdates(const SyncToken& token) { |
| 298 base::AutoLock lock(g_lock.Get()); | 301 base::AutoLock lock(g_lock.Get()); |
| 299 | 302 |
| 300 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 303 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
| 301 it != texture_to_group_.end(); it++) { | 304 it != texture_to_group_.end(); it++) { |
| 302 UpdateDefinitionLocked(it->first, &it->second); | 305 UpdateDefinitionLocked(it->first, &it->second); |
| 303 } | 306 } |
| 304 CreateFenceLocked(sync_point); | 307 CreateFenceLocked(token); |
| 305 } | 308 } |
| 306 | 309 |
| 307 void MailboxManagerSync::PullTextureUpdates(uint32 sync_point) { | 310 void MailboxManagerSync::PullTextureUpdates(const SyncToken& token) { |
| 308 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; | 311 using TextureUpdatePair = std::pair<Texture*, TextureDefinition>; |
| 309 std::vector<TextureUpdatePair> needs_update; | 312 std::vector<TextureUpdatePair> needs_update; |
| 310 { | 313 { |
| 311 base::AutoLock lock(g_lock.Get()); | 314 base::AutoLock lock(g_lock.Get()); |
| 312 AcquireFenceLocked(sync_point); | 315 AcquireFenceLocked(token); |
| 313 | 316 |
| 314 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); | 317 for (TextureToGroupMap::iterator it = texture_to_group_.begin(); |
| 315 it != texture_to_group_.end(); it++) { | 318 it != texture_to_group_.end(); it++) { |
| 316 const TextureDefinition& definition = it->second.group->GetDefinition(); | 319 const TextureDefinition& definition = it->second.group->GetDefinition(); |
| 317 Texture* texture = it->first; | 320 Texture* texture = it->first; |
| 318 unsigned& texture_version = it->second.version; | 321 unsigned& texture_version = it->second.version; |
| 319 if (texture_version == definition.version() || | 322 if (texture_version == definition.version() || |
| 320 definition.IsOlderThan(texture_version)) | 323 definition.IsOlderThan(texture_version)) |
| 321 continue; | 324 continue; |
| 322 texture_version = definition.version(); | 325 texture_version = definition.version(); |
| 323 needs_update.push_back(TextureUpdatePair(texture, definition)); | 326 needs_update.push_back(TextureUpdatePair(texture, definition)); |
| 324 } | 327 } |
| 325 } | 328 } |
| 326 | 329 |
| 327 if (!needs_update.empty()) { | 330 if (!needs_update.empty()) { |
| 328 for (const TextureUpdatePair& pair : needs_update) { | 331 for (const TextureUpdatePair& pair : needs_update) { |
| 329 pair.second.UpdateTexture(pair.first); | 332 pair.second.UpdateTexture(pair.first); |
| 330 } | 333 } |
| 331 } | 334 } |
| 332 } | 335 } |
| 333 | 336 |
| 334 } // namespace gles2 | 337 } // namespace gles2 |
| 335 } // namespace gpu | 338 } // namespace gpu |
| OLD | NEW |