This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Use hint freed specifically for image disposal #20754
Merged
Merged
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fa3cce8
Use hint freed specifically for image disposal
dnfield 7b35fb3
update tests, license file
dnfield eee1b33
test that is hopefully not flaky!
dnfield 3666025
Update image_dispose_unittests.cc
dnfield d9a6a8d
Deflake?
dnfield 44330c5
Merge branch 'image_dispose' of github.com:dnfield/engine into image_…
dnfield 8b19c6c
deflaked
dnfield e972933
merge
dnfield c154c46
Fix windows?
dnfield 68b3151
Deflake by adding .. a timeout :(
dnfield b82af7b
Deflake by adding .. a timeout :(
dnfield d09f46b
make it safer
dnfield 35e376b
..
dnfield c8a52b7
merge
dnfield c6ee6f3
Merge branch 'image_dispose' of github.com:dnfield/engine into image_…
dnfield fd59059
Merge remote-tracking branch 'upstream/master' into image_dispose
dnfield fcf2217
split changees to new pr
dnfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
// 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_LIB_UI_HINT_FREED_DELEGATE_H_ | ||
#define FLUTTER_LIB_UI_HINT_FREED_DELEGATE_H_ | ||
|
||
namespace flutter { | ||
|
||
class HintFreedDelegate { | ||
public: | ||
//---------------------------------------------------------------------------- | ||
/// @brief Notifies the engine that native bytes might be freed if a | ||
/// garbage collection ran at the next NotifyIdle period. | ||
/// | ||
/// @param[in] size The number of bytes freed. This size adds to any | ||
/// previously supplied value, rather than replacing. | ||
/// | ||
virtual void HintFreed(size_t size) = 0; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_LIB_UI_HINT_FREED_DELEGATE_H_ |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,121 @@ | ||
// 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. | ||
|
||
#define FML_USED_ON_EMBEDDER | ||
|
||
#include "flutter/common/task_runners.h" | ||
#include "flutter/fml/synchronization/waitable_event.h" | ||
#include "flutter/lib/ui/painting/image.h" | ||
#include "flutter/lib/ui/painting/picture.h" | ||
#include "flutter/runtime/dart_vm.h" | ||
#include "flutter/shell/common/shell_test.h" | ||
#include "flutter/shell/common/thread_host.h" | ||
#include "flutter/testing/testing.h" | ||
|
||
namespace flutter { | ||
namespace testing { | ||
|
||
class ImageDisposeTest : public ShellTest { | ||
public: | ||
template <class T> | ||
T* GetNativePeer(Dart_NativeArguments args, int index) { | ||
auto handle = Dart_GetNativeArgument(args, index); | ||
intptr_t peer = 0; | ||
EXPECT_FALSE(Dart_IsError(Dart_GetNativeInstanceField( | ||
handle, tonic::DartWrappable::kPeerIndex, &peer))); | ||
return reinterpret_cast<T*>(peer); | ||
} | ||
|
||
// Used to wait on Dart callbacks or Shell task runner flushing | ||
fml::AutoResetWaitableEvent message_latch_; | ||
|
||
fml::AutoResetWaitableEvent picture_finalizer_latch_; | ||
static void picture_finalizer(void* isolate_callback_data, void* peer) { | ||
auto latch = reinterpret_cast<fml::AutoResetWaitableEvent*>(peer); | ||
latch->Signal(); | ||
} | ||
|
||
sk_sp<SkPicture> current_picture_; | ||
sk_sp<SkImage> current_image_; | ||
}; | ||
|
||
TEST_F(ImageDisposeTest, ImageReleasedAfterFrame) { | ||
auto native_capture_image_and_picture = [&](Dart_NativeArguments args) { | ||
CanvasImage* image = GetNativePeer<CanvasImage>(args, 0); | ||
Picture* picture = GetNativePeer<Picture>(args, 1); | ||
ASSERT_FALSE(image->image()->unique()); | ||
ASSERT_FALSE(picture->picture()->unique()); | ||
current_image_ = image->image(); | ||
current_picture_ = picture->picture(); | ||
|
||
Dart_NewFinalizableHandle(Dart_GetNativeArgument(args, 1), | ||
&picture_finalizer_latch_, 0, &picture_finalizer); | ||
}; | ||
|
||
auto native_on_begin_frame_done = [&](Dart_NativeArguments args) { | ||
message_latch_.Signal(); | ||
}; | ||
|
||
Settings settings = CreateSettingsForFixture(); | ||
auto task_runner = CreateNewThread(); | ||
TaskRunners task_runners("test", // label | ||
GetCurrentTaskRunner(), // platform | ||
task_runner, // raster | ||
task_runner, // ui | ||
task_runner // io | ||
); | ||
|
||
AddNativeCallback("CaptureImageAndPicture", | ||
CREATE_NATIVE_ENTRY(native_capture_image_and_picture)); | ||
AddNativeCallback("OnBeginFrameDone", | ||
CREATE_NATIVE_ENTRY(native_on_begin_frame_done)); | ||
|
||
std::unique_ptr<Shell> shell = CreateShell(std::move(settings), task_runners); | ||
|
||
ASSERT_TRUE(shell->IsSetup()); | ||
|
||
SetViewportMetrics(shell.get(), 800, 600); | ||
|
||
shell->GetPlatformView()->NotifyCreated(); | ||
|
||
auto configuration = RunConfiguration::InferFromSettings(settings); | ||
configuration.SetEntrypoint("pumpImage"); | ||
|
||
shell->RunEngine(std::move(configuration), [&](auto result) { | ||
ASSERT_EQ(result, Engine::RunStatus::Success); | ||
}); | ||
|
||
message_latch_.Wait(); | ||
|
||
ASSERT_TRUE(current_picture_); | ||
ASSERT_TRUE(current_image_); | ||
|
||
// Make sure we wait longer than the animator's notify idle. | ||
// which is 51ms in animator.cc. | ||
message_latch_.Reset(); | ||
task_runner->PostDelayedTask([&]() { message_latch_.Signal(); }, | ||
fml::TimeDelta::FromMilliseconds(60)); | ||
dnfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message_latch_.Wait(); | ||
picture_finalizer_latch_.Wait(); | ||
|
||
// Force a drain the SkiaUnrefQueue. | ||
message_latch_.Reset(); | ||
task_runner->PostTask([&, io_manager = shell->GetIOManager()]() { | ||
io_manager->GetSkiaUnrefQueue()->Drain(); | ||
message_latch_.Signal(); | ||
}); | ||
message_latch_.Wait(); | ||
|
||
EXPECT_TRUE(current_picture_->unique()); | ||
current_picture_.reset(); | ||
|
||
EXPECT_TRUE(current_image_->unique()); | ||
current_image_.reset(); | ||
|
||
shell->GetPlatformView()->NotifyDestroyed(); | ||
DestroyShell(std::move(shell), std::move(task_runners)); | ||
} | ||
|
||
} // namespace testing | ||
} // namespace flutter |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the engine no longer be reporting these sizes as the external allocation size for Dart objects with native fields? Or does this only affect HintFreed? (Same question here and below.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I can split this into another patch, but basically this seems like it was a mistake. We've already moved the reporting of images for this.
The basic problem is that from scene to scene, we might be reusing these things, and end up reporting vastly inflated numbers to the VM, and then that creates lots of wasteful garbage collections.