| 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> |
| 11 | 11 |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "gpu/command_buffer/common/sync_token.h" | 14 #include "gpu/command_buffer/common/sync_token.h" |
| 15 #include "gpu/command_buffer/service/texture_manager.h" | 15 #include "gpu/command_buffer/service/texture_manager.h" |
| 16 #include "ui/gl/gl_fence.h" | 16 #include "ui/gl/gl_fence.h" |
| 17 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
| 18 | 18 |
| 19 #if !defined(OS_MACOSX) | 19 #if !defined(OS_MACOSX) |
| 20 #include "ui/gl/gl_fence_egl.h" | 20 #include "ui/gl/gl_fence_egl.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace gpu { | 23 namespace gpu { |
| 24 namespace gles2 { | 24 namespace gles2 { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER; | 28 base::LazyInstance<base::Lock> g_lock = LAZY_INSTANCE_INITIALIZER; |
| 29 | 29 |
| 30 #if !defined(OS_MACOSX) | 30 #if !defined(OS_MACOSX) |
| 31 typedef std::map<SyncToken, linked_ptr<gl::GLFence>> SyncTokenToFenceMap; | 31 typedef std::map<SyncToken, std::unique_ptr<gl::GLFence>> SyncTokenToFenceMap; |
| 32 base::LazyInstance<SyncTokenToFenceMap> g_sync_point_to_fence = | 32 base::LazyInstance<SyncTokenToFenceMap> g_sync_point_to_fence = |
| 33 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
| 34 base::LazyInstance<std::queue<SyncTokenToFenceMap::iterator>> g_sync_points = | 34 base::LazyInstance<std::queue<SyncTokenToFenceMap::iterator>> g_sync_points = |
| 35 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 void CreateFenceLocked(const SyncToken& sync_token) { | 38 void CreateFenceLocked(const SyncToken& sync_token) { |
| 39 #if !defined(OS_MACOSX) | 39 #if !defined(OS_MACOSX) |
| 40 g_lock.Get().AssertAcquired(); | 40 g_lock.Get().AssertAcquired(); |
| 41 if (gl::GetGLImplementation() == gl::kGLImplementationMockGL) | 41 if (gl::GetGLImplementation() == gl::kGLImplementationMockGL) |
| 42 return; | 42 return; |
| 43 | 43 |
| 44 std::queue<SyncTokenToFenceMap::iterator>& sync_points = g_sync_points.Get(); | 44 std::queue<SyncTokenToFenceMap::iterator>& sync_points = g_sync_points.Get(); |
| 45 SyncTokenToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get(); | 45 SyncTokenToFenceMap& sync_point_to_fence = g_sync_point_to_fence.Get(); |
| 46 if (sync_token.release_count()) { | 46 if (sync_token.release_count()) { |
| 47 while (!sync_points.empty() && | 47 while (!sync_points.empty() && |
| 48 sync_points.front()->second->HasCompleted()) { | 48 sync_points.front()->second->HasCompleted()) { |
| 49 sync_point_to_fence.erase(sync_points.front()); | 49 sync_point_to_fence.erase(sync_points.front()); |
| 50 sync_points.pop(); | 50 sync_points.pop(); |
| 51 } | 51 } |
| 52 // Need to use EGL fences since we are likely not in a single share group. | 52 // Need to use EGL fences since we are likely not in a single share group. |
| 53 linked_ptr<gl::GLFence> fence(make_linked_ptr(new gl::GLFenceEGL)); | 53 auto fence = base::MakeUnique<gl::GLFenceEGL>(); |
| 54 if (fence.get()) { | 54 std::pair<SyncTokenToFenceMap::iterator, bool> result = |
| 55 std::pair<SyncTokenToFenceMap::iterator, bool> result = | 55 sync_point_to_fence.insert( |
| 56 sync_point_to_fence.insert(std::make_pair(sync_token, fence)); | 56 std::make_pair(sync_token, std::move(fence))); |
| 57 DCHECK(result.second); | 57 DCHECK(result.second); |
| 58 sync_points.push(result.first); | 58 sync_points.push(result.first); |
| 59 } | |
| 60 DCHECK(sync_points.size() == sync_point_to_fence.size()); | 59 DCHECK(sync_points.size() == sync_point_to_fence.size()); |
| 61 } | 60 } |
| 62 #endif | 61 #endif |
| 63 } | 62 } |
| 64 | 63 |
| 65 void AcquireFenceLocked(const SyncToken& sync_token) { | 64 void AcquireFenceLocked(const SyncToken& sync_token) { |
| 66 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
| 67 g_lock.Get().AssertAcquired(); | 66 g_lock.Get().AssertAcquired(); |
| 68 SyncTokenToFenceMap::iterator fence_it = | 67 SyncTokenToFenceMap::iterator fence_it = |
| 69 g_sync_point_to_fence.Get().find(sync_token); | 68 g_sync_point_to_fence.Get().find(sync_token); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 332 |
| 334 if (!needs_update.empty()) { | 333 if (!needs_update.empty()) { |
| 335 for (const TextureUpdatePair& pair : needs_update) { | 334 for (const TextureUpdatePair& pair : needs_update) { |
| 336 pair.second.UpdateTexture(pair.first); | 335 pair.second.UpdateTexture(pair.first); |
| 337 } | 336 } |
| 338 } | 337 } |
| 339 } | 338 } |
| 340 | 339 |
| 341 } // namespace gles2 | 340 } // namespace gles2 |
| 342 } // namespace gpu | 341 } // namespace gpu |
| OLD | NEW |