Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/browser_scoped_surface_request_manager.h" | |
| 6 | |
| 7 #include "ui/gl/android/scoped_java_surface.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 // static | |
| 12 BrowserScopedSurfaceRequestManager* | |
| 13 BrowserScopedSurfaceRequestManager::GetInstance() { | |
| 14 return base::Singleton< | |
| 15 BrowserScopedSurfaceRequestManager, | |
| 16 base::LeakySingletonTraits<BrowserScopedSurfaceRequestManager>>::get(); | |
| 17 } | |
| 18 | |
| 19 void BrowserScopedSurfaceRequestManager::RegisterScopedSurfaceRequest( | |
| 20 uint64_t request_id, | |
| 21 ScopedSurfaceRequestCB request_cb) { | |
| 22 base::AutoLock lock(lock_); | |
| 23 | |
| 24 DCHECK(request_callbacks_.find(request_id) == request_callbacks_.end()); | |
|
watk
2016/08/26 22:01:32
Can use .count() for this
tguilbert
2016/08/29 18:30:46
Done.
| |
| 25 request_callbacks_.insert(std::make_pair(request_id, request_cb)); | |
| 26 } | |
| 27 | |
| 28 gpu::ScopedSurfaceRequestManager::ScopedSurfaceRequestCB | |
| 29 BrowserScopedSurfaceRequestManager::GetAndUnregisterScopedSurfaceRequest( | |
|
watk
2016/08/26 22:01:32
I don't see the need for both this one and the int
tguilbert
2016/08/29 18:30:46
I added an internal one, so I could lock in the en
watk
2016/08/29 19:42:25
Ah, gotcha. Yeah, then I think what you have is be
tguilbert
2016/08/30 22:53:09
Ah! Yes, good call on the _Locked suffix. Although
| |
| 30 uint64_t request_id) { | |
| 31 base::AutoLock lock(lock_); | |
| 32 | |
| 33 return GetAndUnregisterInternal(request_id); | |
| 34 } | |
| 35 | |
| 36 gpu::ScopedSurfaceRequestManager::ScopedSurfaceRequestCB | |
| 37 BrowserScopedSurfaceRequestManager::GetAndUnregisterInternal( | |
| 38 uint64_t request_id) { | |
| 39 gpu::ScopedSurfaceRequestManager::ScopedSurfaceRequestCB request; | |
| 40 | |
| 41 auto it = request_callbacks_.find(request_id); | |
| 42 | |
| 43 if (it != request_callbacks_.end()) { | |
| 44 request = it->second; | |
| 45 request_callbacks_.erase(it); | |
| 46 } | |
| 47 | |
| 48 return request; | |
| 49 } | |
| 50 | |
| 51 void BrowserScopedSurfaceRequestManager::FulfillScopedSurfaceRequest( | |
| 52 uint64_t request_id, | |
| 53 gl::SurfaceTexture* surface_texture) { | |
| 54 base::AutoLock lock(lock_); | |
| 55 | |
| 56 gpu::ScopedSurfaceRequestManager::ScopedSurfaceRequestCB request = | |
| 57 GetAndUnregisterInternal(request_id); | |
| 58 | |
| 59 if (!request.is_null()) { | |
| 60 gl::ScopedJavaSurface surface(surface_texture); | |
| 61 request.Run(std::move(surface)); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 BrowserScopedSurfaceRequestManager::BrowserScopedSurfaceRequestManager() {} | |
| 66 | |
| 67 BrowserScopedSurfaceRequestManager::~BrowserScopedSurfaceRequestManager() {} | |
| 68 | |
| 69 } // namespace content | |
| OLD | NEW |