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

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

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

Powered by Google App Engine
This is Rietveld 408576698