-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Destroy textures on raster thread (#427)
* Destroy textures on raster thread Signed-off-by: Bari Rao <[email protected]> * Fix format Signed-off-by: Bari Rao <[email protected]> --------- Signed-off-by: Bari Rao <[email protected]>
- Loading branch information
1 parent
9dc1156
commit 9d0ff07
Showing
11 changed files
with
219 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2013 The Flutter 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 FLUTTER_FML_CLOSURE_H_ | ||
#define FLUTTER_FML_CLOSURE_H_ | ||
|
||
#include <functional> | ||
|
||
#include "flutter/fml/macros.h" | ||
|
||
namespace fml { | ||
|
||
using closure = std::function<void()>; | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Wraps a closure that is invoked in the destructor unless | ||
/// released by the caller. | ||
/// | ||
/// This is especially useful in dealing with APIs that return a | ||
/// resource by accepting ownership of a sub-resource and a closure | ||
/// that releases that resource. When such APIs are chained, each | ||
/// link in the chain must check that the next member in the chain | ||
/// has accepted the resource. If not, it must invoke the closure | ||
/// eagerly. Not doing this results in a resource leak in the | ||
/// erroneous case. Using this wrapper, the closure can be released | ||
/// once the next call in the chain has successfully accepted | ||
/// ownership of the resource. If not, the closure gets invoked | ||
/// automatically at the end of the scope. This covers the cases | ||
/// where there are early returns as well. | ||
/// | ||
class ScopedCleanupClosure final { | ||
public: | ||
ScopedCleanupClosure() = default; | ||
|
||
ScopedCleanupClosure(ScopedCleanupClosure&& other) { | ||
closure_ = other.Release(); | ||
} | ||
|
||
ScopedCleanupClosure& operator=(ScopedCleanupClosure&& other) { | ||
closure_ = other.Release(); | ||
return *this; | ||
} | ||
|
||
explicit ScopedCleanupClosure(const fml::closure& closure) | ||
: closure_(closure) {} | ||
|
||
~ScopedCleanupClosure() { Reset(); } | ||
|
||
fml::closure SetClosure(const fml::closure& closure) { | ||
auto old_closure = closure_; | ||
closure_ = closure; | ||
return old_closure; | ||
} | ||
|
||
fml::closure Release() { | ||
fml::closure closure = closure_; | ||
closure_ = nullptr; | ||
return closure; | ||
} | ||
|
||
void Reset() { | ||
if (closure_) { | ||
closure_(); | ||
closure_ = nullptr; | ||
} | ||
} | ||
|
||
private: | ||
fml::closure closure_; | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(ScopedCleanupClosure); | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_CLOSURE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2013 The Flutter 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 FLUTTER_FML_MACROS_H_ | ||
#define FLUTTER_FML_MACROS_H_ | ||
|
||
#ifndef FML_USED_ON_EMBEDDER | ||
|
||
#define FML_EMBEDDER_ONLY [[deprecated]] | ||
|
||
#else // FML_USED_ON_EMBEDDER | ||
|
||
#define FML_EMBEDDER_ONLY | ||
|
||
#endif // FML_USED_ON_EMBEDDER | ||
|
||
#define FML_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete | ||
|
||
#define FML_DISALLOW_ASSIGN(TypeName) \ | ||
TypeName& operator=(const TypeName&) = delete | ||
|
||
#define FML_DISALLOW_MOVE(TypeName) \ | ||
TypeName(TypeName&&) = delete; \ | ||
TypeName& operator=(TypeName&&) = delete | ||
|
||
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName) \ | ||
TypeName(const TypeName&) = delete; \ | ||
TypeName& operator=(const TypeName&) = delete | ||
|
||
#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) \ | ||
TypeName(const TypeName&) = delete; \ | ||
TypeName(TypeName&&) = delete; \ | ||
TypeName& operator=(const TypeName&) = delete; \ | ||
TypeName& operator=(TypeName&&) = delete | ||
|
||
#define FML_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ | ||
TypeName() = delete; \ | ||
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) | ||
|
||
#define FML_FRIEND_TEST(test_case_name, test_name) \ | ||
friend class test_case_name##_##test_name##_Test | ||
|
||
#endif // FLUTTER_FML_MACROS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters