| Index: ui/ozone/platform/drm/gpu/proxy_helpers.h
|
| diff --git a/ui/ozone/platform/drm/gpu/proxy_helpers.h b/ui/ozone/platform/drm/gpu/proxy_helpers.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..156ba9a8fff51b577e78ce24299e3485e34b4fb9
|
| --- /dev/null
|
| +++ b/ui/ozone/platform/drm/gpu/proxy_helpers.h
|
| @@ -0,0 +1,73 @@
|
| +// Copyright 2015 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 UI_OZONE_PLATFORM_DRM_GPU_PROXY_HELPERS_H_
|
| +#define UI_OZONE_PLATFORM_DRM_GPU_PROXY_HELPERS_H_
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/location.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace internal {
|
| +
|
| +template <typename... Args>
|
| +void PostAsyncTask(
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
|
| + const base::Callback<void(Args...)>& callback,
|
| + Args... args) {
|
| + task_runner->PostTask(FROM_HERE, base::Bind(callback, args...));
|
| +}
|
| +
|
| +template <typename Functor, typename Type, typename Return, typename... Args>
|
| +void RunWeakPtrMethod(Functor func,
|
| + base::WeakPtr<Type> type,
|
| + Return* ret,
|
| + const Args&... args) {
|
| + if (type)
|
| + *ret = ((*type.get()).*func)(args...);
|
| +}
|
| +
|
| +} // namespace internal
|
| +
|
| +// Posts a task to a different thread and blocks waiting for the task to finish
|
| +// executing.
|
| +void PostSyncTask(
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
|
| + const base::Closure& callback);
|
| +
|
| +// Creates a callback that will run |callback| on the calling thread. Useful
|
| +// when posting a task on a different thread and expecting a callback when the
|
| +// task finished (and the callback needs to run on the original thread).
|
| +template <typename... Args>
|
| +base::Callback<void(Args...)> CreateSafeCallback(
|
| + const base::Callback<void(Args...)>& callback) {
|
| + return base::Bind(&internal::PostAsyncTask<Args...>,
|
| + base::ThreadTaskRunnerHandle::Get(), callback);
|
| +}
|
| +
|
| +// Helper function allowing the caller to post a task to a different thread and
|
| +// calling a base::WeakPtr with a method that returns a value. Since a weak
|
| +// pointer may have expired, this function checks the pointer before attemping
|
| +// to run the method.
|
| +//
|
| +// base::Bind doesn't allow us to do this since the base::WeakPtr specialization
|
| +// allows weak pointers only when the method has a void return.
|
| +//
|
| +// If the weak pointer is valid, |ret| will contain the returned value from
|
| +// type->func(args), otherwise |ret| will not be modified.
|
| +template <typename Functor, typename Type, typename Return, typename... Args>
|
| +base::Closure CreateWeakPtrCallback(Functor func,
|
| + base::WeakPtr<Type> type,
|
| + Return* ret,
|
| + const Args&... args) {
|
| + return base::Bind(&internal::RunWeakPtrMethod<Functor, Type, Return, Args...>,
|
| + func, type, ret, args...);
|
| +}
|
| +
|
| +} // namespace ui
|
| +
|
| +#endif // UI_OZONE_PLATFORM_DRM_GPU_PROXY_HELPERS_H_
|
|
|