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 #ifndef CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ | |
6 #define CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 #include <unordered_map> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/singleton.h" | |
13 #include "base/nonce.h" | |
14 #include "content/common/content_export.h" | |
15 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" | |
16 #include "ui/gl/android/scoped_java_surface.h" | |
17 | |
18 namespace content { | |
19 | |
20 class CONTENT_EXPORT ScopedSurfaceRequestManager | |
21 : public gpu::ScopedSurfaceRequestConduit { | |
22 public: | |
23 static ScopedSurfaceRequestManager* GetInstance(); | |
24 | |
25 using ScopedSurfaceRequestCB = base::Callback<void(gl::ScopedJavaSurface)>; | |
26 | |
27 // Registers a request, and returns the |request_token| that should be used to | |
28 // call Fulfill at a later time. The caller is responsible for unregistering | |
29 // the request, if it is destroyed before the request is fulfilled. | |
30 // It is the requester's responsability to check the validity of the final | |
no sievers
2016/09/13 23:25:56
nit: s/responsability/responsibility
tguilbert
2016/09/20 03:08:40
Done.
| |
31 // ScopedJavaSurface (as passing an empty surface is a valid operation). | |
32 // Must be called on the UI thread. | |
33 base::Nonce RegisterScopedSurfaceRequest(ScopedSurfaceRequestCB request_cb); | |
34 | |
35 // Unregisters a request registered under |request_token| if it exists, | |
36 // no-ops otherwise. | |
37 // Must be called on the UI thread. | |
38 void UnregisterScopedSurfaceRequest(base::Nonce request_token); | |
39 | |
40 // Unregisters and runs the request callback identified by |request_token| if | |
41 // one exists, no-ops otherwise. | |
42 // Passing an empty |surface| is a valid operation that will complete the | |
43 // request. | |
44 // Can be called from any thread. The request will be run synchonously on the | |
no sievers
2016/09/13 23:25:56
see comment in implementation
no sievers
2016/09/13 23:25:56
nit: s/synchonously/synchronously
tguilbert
2016/09/20 03:08:40
Done.
| |
45 // UI thread. | |
46 void FulfillScopedSurfaceRequest(base::Nonce request_token, | |
47 gl::ScopedJavaSurface surface); | |
48 | |
49 // Implementation of ScopedSurfaceRequestConduit. | |
50 // To be used in the single process case. | |
51 // Can be called from any thread. | |
52 void ForwardSurfaceTextureForSurfaceRequest( | |
53 base::Nonce request_token, | |
54 gl::SurfaceTexture* surface_texture) override; | |
55 | |
56 void clear_requests_for_testing() { request_callbacks_.clear(); } | |
57 | |
58 int request_count_for_testing() { return request_callbacks_.size(); } | |
59 | |
60 private: | |
61 friend struct base::DefaultSingletonTraits<ScopedSurfaceRequestManager>; | |
62 | |
63 // Unregisters and returns the request identified by |request_token|. | |
64 // Does not acquire |lock_|. | |
65 ScopedSurfaceRequestCB GetAndUnregisterInternal(base::Nonce request_token); | |
66 | |
67 // Map used to hold references to the registered callbacks. | |
68 std::unordered_map<base::Nonce, ScopedSurfaceRequestCB, base::NonceHash> | |
69 request_callbacks_; | |
70 | |
71 ScopedSurfaceRequestManager(); | |
72 ~ScopedSurfaceRequestManager() override; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(ScopedSurfaceRequestManager); | |
75 }; | |
76 | |
77 } // namespace content | |
78 | |
79 #endif // CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ | |
OLD | NEW |