Chromium Code Reviews| Index: content/browser/android/scoped_surface_request_manager.h |
| diff --git a/content/browser/android/scoped_surface_request_manager.h b/content/browser/android/scoped_surface_request_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6755b7d25d3ac7d1727498b78435897ca31a6a20 |
| --- /dev/null |
| +++ b/content/browser/android/scoped_surface_request_manager.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |
| +#define CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |
| + |
| +#include <unordered_map> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/singleton.h" |
| +#include "content/common/content_export.h" |
| +#include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
| +#include "ui/gl/android/scoped_java_surface.h" |
| + |
| +namespace content { |
| + |
| +class CONTENT_EXPORT ScopedSurfaceRequestManager |
| + : public gpu::ScopedSurfaceRequestConduit { |
| + public: |
| + static ScopedSurfaceRequestManager* GetInstance(); |
| + |
| + using ScopedSurfaceRequestCB = base::Callback<void(gl::ScopedJavaSurface)>; |
| + |
| + // Registers a request, and returns the |request_token| that should be used to |
| + // call Fulfill at a later time. The caller is responsible for unregistering |
| + // the request, if it is destroyed before the request is fulfilled. |
| + // 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.
|
| + // ScopedJavaSurface (as passing an empty surface is a valid operation). |
| + // Must be called on the UI thread. |
| + uint64_t RegisterScopedSurfaceRequest(ScopedSurfaceRequestCB request_cb); |
| + |
| + // Unregisters a request registered under |request_token| if it exists, |
| + // no-ops otherwise. |
| + // Must be called on the UI thread. |
| + void UnregisterScopedSurfaceRequest(uint64_t request_token); |
| + |
| + // Unregisters and runs the request callback identified by |request_token| if |
| + // one exists, no-ops otherwise. |
| + // Passing an empty |surface| is a valid operation that will complete the |
| + // request. |
| + // Can be called from any thread. The request will be run synchonously on the |
| + // UI thread. |
| + void FulfillScopedSurfaceRequest(uint64_t request_token, |
| + gl::ScopedJavaSurface surface); |
| + |
| + // Implementation of ScopedSurfaceRequestConduit. |
| + // To be used in the single process case. |
| + // Can be called from any thread. |
| + void ForwardSurfaceTextureForSurfaceRequest( |
| + uint64_t request_token, |
| + gl::SurfaceTexture* surface_texture) override; |
| + |
| + void clear_callbacks_for_testing() { request_callbacks_.clear(); } |
| + |
| + 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.
|
| + |
| + private: |
| + friend struct base::DefaultSingletonTraits<ScopedSurfaceRequestManager>; |
| + |
| + // Unregisters and returns the request identified by |request_token|. |
| + // Does not acquire |lock_|. |
| + ScopedSurfaceRequestCB GetAndUnregisterInternal(uint64_t request_token); |
| + |
| + // Map used to hold references to the registered callbacks. |
| + std::unordered_map<uint64_t, ScopedSurfaceRequestCB> request_callbacks_; |
| + |
| + ScopedSurfaceRequestManager(); |
| + ~ScopedSurfaceRequestManager() override; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedSurfaceRequestManager); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |