Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: content/browser/android/scoped_surface_request_manager.h

Issue 2285593002: Add ScopedSurfaceRequestManager (Closed)
Patch Set: Update to UnguessableToken. Addressed comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/unguessable_token.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 responsibility to check the validity of the final
31 // ScopedJavaSurface (as passing an empty surface is a valid operation).
32 // Must be called on the UI thread.
33 base::UnguessableToken RegisterScopedSurfaceRequest(
34 ScopedSurfaceRequestCB request_cb);
dcheng 2016/09/20 06:50:35 The original guidance was to pass callbacks as con
tguilbert 2016/09/20 20:59:19 Good to know. Updated.
35
36 // Unregisters a request registered under |request_token| if it exists,
37 // no-ops otherwise.
38 // Must be called on the UI thread.
39 void UnregisterScopedSurfaceRequest(
40 const base::UnguessableToken& request_token);
41
42 // Unregisters and runs the request callback identified by |request_token| if
43 // one exists, no-ops otherwise.
44 // Passing an empty |surface| is a valid operation that will complete the
45 // request.
46 // Can be called from any thread. The request will be posted to the UI thread.
47 void FulfillScopedSurfaceRequest(const base::UnguessableToken& request_token,
48 gl::ScopedJavaSurface surface);
49
50 // Implementation of ScopedSurfaceRequestConduit.
51 // To be used in the single process case.
52 // Can be called from any thread.
53 void ForwardSurfaceTextureForSurfaceRequest(
54 const base::UnguessableToken& request_token,
55 const gl::SurfaceTexture* surface_texture) override;
56
57 void clear_requests_for_testing() { request_callbacks_.clear(); }
58
59 int request_count_for_testing() { return request_callbacks_.size(); }
60
61 private:
62 friend struct base::DefaultSingletonTraits<ScopedSurfaceRequestManager>;
63
64 // Unregisters and returns the request identified by |request_token|.
65 ScopedSurfaceRequestCB GetAndUnregisterInternal(
66 const base::UnguessableToken& request_token);
67
68 void CompleteRequestOnUiThread(const base::UnguessableToken& request_token,
69 gl::ScopedJavaSurface surface);
70
71 // Map used to hold references to the registered callbacks.
72 std::unordered_map<base::UnguessableToken,
73 ScopedSurfaceRequestCB,
74 base::UnguessableTokenHash>
75 request_callbacks_;
76
77 ScopedSurfaceRequestManager();
78 ~ScopedSurfaceRequestManager() override;
79
80 DISALLOW_COPY_AND_ASSIGN(ScopedSurfaceRequestManager);
81 };
82
83 } // namespace content
84
85 #endif // CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698