diff options
author | Brian Osman <brianosman@google.com> | 2017-11-16 22:31:30 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-16 22:31:39 +0000 |
commit | 1e09e461d2ffcf8b07242cfe93dd7d12c4d75866 (patch) | |
tree | 59ecb8a613b8a958522036043ed6e5a4c4e329ca /src | |
parent | 8dca18ac7b8af9a945abe4ae0d9190a1d2bff3d6 (diff) |
Revert "Add method to sk_gpu_test::TestContext to automatically restore the previous context."
This reverts commit 5627d65146cb92624b682389e017d488872228c7.
Reason for revert: Google3
Original change's description:
> Add method to sk_gpu_test::TestContext to automatically restore the previous context.
>
> The motivation for this is to allow a GM to create a GL context, do some some work in it, and then return to the context that was set when it was invoked.
>
> Change-Id: Ie8496072a10f8f3ff36a08889e593a6ca961b61a
> Reviewed-on: https://skia-review.googlesource.com/70720
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
TBR=bsalomon@google.com,brianosman@google.com
Change-Id: Ifb79638c9d4500ca3be9a5be39a5ad78b20247c1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/72981
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/SkScopeExit.h (renamed from src/core/SkScopeExit.h) | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/core/SkScopeExit.h b/src/pdf/SkScopeExit.h index 95804e637a..5b7bcdc076 100644 --- a/src/core/SkScopeExit.h +++ b/src/pdf/SkScopeExit.h @@ -10,30 +10,6 @@ #include "SkTypes.h" -/** SkScopeExit calls a std:::function<void()> in its destructor. */ -class SkScopeExit { -public: - SkScopeExit(std::function<void()> f) : fFn(std::move(f)) {} - SkScopeExit(SkScopeExit&& that) : fFn(std::move(that.fFn)) {} - - ~SkScopeExit() { - if (fFn) { - fFn(); - } - } - - SkScopeExit& operator=(SkScopeExit&& that) { - fFn = std::move(that.fFn); - return *this; - } - -private: - std::function<void()> fFn; - - SkScopeExit( const SkScopeExit& ) = delete; - SkScopeExit& operator=(const SkScopeExit& ) = delete; -}; - /** * SK_AT_SCOPE_EXIT(stmt) evaluates stmt when the current scope ends. * @@ -47,7 +23,28 @@ private: * SkASSERT(x == 4); * } */ +template <typename Fn> +class SkScopeExit { +public: + SkScopeExit(Fn f) : fFn(std::move(f)) {} + ~SkScopeExit() { fFn(); } + +private: + Fn fFn; + + SkScopeExit( const SkScopeExit& ) = delete; + SkScopeExit& operator=(const SkScopeExit& ) = delete; + SkScopeExit( SkScopeExit&&) = delete; + SkScopeExit& operator=( SkScopeExit&&) = delete; +}; + +template <typename Fn> +inline SkScopeExit<Fn> SkMakeScopeExit(Fn&& fn) { + return {std::move(fn)}; +} + #define SK_AT_SCOPE_EXIT(stmt) \ - SkScopeExit SK_MACRO_APPEND_LINE(at_scope_exit_)([&]() { stmt; }) + SK_UNUSED auto&& SK_MACRO_APPEND_LINE(at_scope_exit_) = \ + SkMakeScopeExit([&]() { stmt; }); #endif // SkScopeExit_DEFINED |