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

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

Issue 2285593002: Add ScopedSurfaceRequestManager (Closed)
Patch Set: Added RunUntilIdle() to 2 UTs 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 <unordered_map>
9
10 #include "base/macros.h"
11 #include "base/memory/singleton.h"
12 #include "base/unguessable_token.h"
13 #include "content/common/content_export.h"
14 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h"
15 #include "ui/gl/android/scoped_java_surface.h"
16
17 namespace content {
18
19 class CONTENT_EXPORT ScopedSurfaceRequestManager
20 : public gpu::ScopedSurfaceRequestConduit {
21 public:
22 static ScopedSurfaceRequestManager* GetInstance();
23
24 using ScopedSurfaceRequestCB = base::Callback<void(gl::ScopedJavaSurface)>;
25
26 // Registers a request, and returns the |request_token| that should be used to
27 // call Fulfill at a later time. The caller is responsible for unregistering
28 // the request, if it is destroyed before the request is fulfilled.
29 // It is the requester's responsibility to check the validity of the final
30 // ScopedJavaSurface (as passing an empty surface is a valid operation).
31 // Must be called on the UI thread.
32 base::UnguessableToken RegisterScopedSurfaceRequest(
33 const 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(
39 const base::UnguessableToken& request_token);
40
41 // Unregisters and runs the request callback identified by |request_token| if
42 // one exists, no-ops otherwise.
43 // Passing an empty |surface| is a valid operation that will complete the
44 // request.
45 // Can be called from any thread. The request will be posted to the UI thread.
46 void FulfillScopedSurfaceRequest(const base::UnguessableToken& 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 const base::UnguessableToken& request_token,
54 const 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 ScopedSurfaceRequestCB GetAndUnregisterInternal(
65 const base::UnguessableToken& request_token);
66
67 void CompleteRequestOnUiThread(const base::UnguessableToken& request_token,
68 gl::ScopedJavaSurface surface);
69
70 // Map used to hold references to the registered callbacks.
71 std::unordered_map<base::UnguessableToken,
72 ScopedSurfaceRequestCB,
73 base::UnguessableTokenHash>
74 request_callbacks_;
75
76 ScopedSurfaceRequestManager();
77 ~ScopedSurfaceRequestManager() override;
78
79 DISALLOW_COPY_AND_ASSIGN(ScopedSurfaceRequestManager);
80 };
81
82 } // namespace content
83
84 #endif // CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/android/child_process_launcher_android.cc ('k') | content/browser/android/scoped_surface_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698