forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for dynamic thread merging on IOS for embedded view mutations (f…
…lutter#9819) After pre-roll we know if there have been any mutations made to the IOS embedded UIViews. If there are any mutations and the thread configuration is such chat the mutations will be committed on an illegal thread (GPU thread), we merge the threads and keep them merged until the lease expires. The lease is currently set to expire after 10 frames of no mutations. If there are any mutations in the interim we extend the lease. TaskRunnerMerger will ultimately be responsible for enforcing the correct thread configurations. This configuration will be inactive even after this change since still use the same thread when we create the iOS engine. That is slated to change in the coming PRs.
- Loading branch information
1 parent
c92a0d9
commit 971a639
Showing
21 changed files
with
529 additions
and
52 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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/fml/gpu_thread_merger.h" | ||
#include "flutter/fml/message_loop_impl.h" | ||
|
||
namespace fml { | ||
|
||
const int GpuThreadMerger::kLeaseNotSet = -1; | ||
|
||
GpuThreadMerger::GpuThreadMerger(fml::TaskQueueId platform_queue_id, | ||
fml::TaskQueueId gpu_queue_id) | ||
: platform_queue_id_(platform_queue_id), | ||
gpu_queue_id_(gpu_queue_id), | ||
task_queues_(fml::MessageLoopTaskQueues::GetInstance()), | ||
lease_term_(kLeaseNotSet) { | ||
is_merged_ = task_queues_->Owns(platform_queue_id_, gpu_queue_id_); | ||
} | ||
|
||
void GpuThreadMerger::MergeWithLease(size_t lease_term) { | ||
FML_DCHECK(lease_term > 0) << "lease_term should be positive."; | ||
if (!is_merged_) { | ||
is_merged_ = task_queues_->Merge(platform_queue_id_, gpu_queue_id_); | ||
lease_term_ = lease_term; | ||
} | ||
} | ||
|
||
bool GpuThreadMerger::IsOnRasterizingThread() { | ||
const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId(); | ||
if (is_merged_) { | ||
return current_queue_id == platform_queue_id_; | ||
} else { | ||
return current_queue_id == gpu_queue_id_; | ||
} | ||
} | ||
|
||
void GpuThreadMerger::ExtendLeaseTo(size_t lease_term) { | ||
FML_DCHECK(lease_term > 0) << "lease_term should be positive."; | ||
if (lease_term_ != kLeaseNotSet && (int)lease_term > lease_term_) { | ||
lease_term_ = lease_term; | ||
} | ||
} | ||
|
||
bool GpuThreadMerger::IsMerged() const { | ||
return is_merged_; | ||
} | ||
|
||
GpuThreadStatus GpuThreadMerger::DecrementLease() { | ||
if (!is_merged_) { | ||
return GpuThreadStatus::kRemainsUnmerged; | ||
} | ||
|
||
// we haven't been set to merge. | ||
if (lease_term_ == kLeaseNotSet) { | ||
return GpuThreadStatus::kRemainsUnmerged; | ||
} | ||
|
||
FML_DCHECK(lease_term_ > 0) | ||
<< "lease_term should always be positive when merged."; | ||
lease_term_--; | ||
if (lease_term_ == 0) { | ||
bool success = task_queues_->Unmerge(platform_queue_id_); | ||
FML_CHECK(success) << "Unable to un-merge the GPU and platform threads."; | ||
is_merged_ = false; | ||
return GpuThreadStatus::kUnmergedNow; | ||
} | ||
|
||
return GpuThreadStatus::kRemainsMerged; | ||
} | ||
|
||
} // namespace fml |
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,59 @@ | ||
// 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 FML_SHELL_COMMON_TASK_RUNNER_MERGER_H_ | ||
#define FML_SHELL_COMMON_TASK_RUNNER_MERGER_H_ | ||
|
||
#include "flutter/fml/macros.h" | ||
#include "flutter/fml/memory/ref_counted.h" | ||
#include "flutter/fml/message_loop_task_queues.h" | ||
|
||
namespace fml { | ||
|
||
class MessageLoopImpl; | ||
|
||
enum class GpuThreadStatus { kRemainsMerged, kRemainsUnmerged, kUnmergedNow }; | ||
|
||
class GpuThreadMerger : public fml::RefCountedThreadSafe<GpuThreadMerger> { | ||
public: | ||
// Merges the GPU thread into platform thread for the duration of | ||
// the lease term. Lease is managed by the caller by either calling | ||
// |ExtendLeaseTo| or |DecrementLease|. | ||
// When the caller merges with a lease term of say 2. The threads | ||
// are going to remain merged until 2 invocations of |DecreaseLease|, | ||
// unless an |ExtendLeaseTo| gets called. | ||
void MergeWithLease(size_t lease_term); | ||
|
||
void ExtendLeaseTo(size_t lease_term); | ||
|
||
// Returns |GpuThreadStatus::kUnmergedNow| if this call resulted in splitting | ||
// the GPU and platform threads. Reduces the lease term by 1. | ||
GpuThreadStatus DecrementLease(); | ||
|
||
bool IsMerged() const; | ||
|
||
GpuThreadMerger(fml::TaskQueueId platform_queue_id, | ||
fml::TaskQueueId gpu_queue_id); | ||
|
||
// Returns true if the the current thread owns rasterizing. | ||
// When the threads are merged, platform thread owns rasterizing. | ||
// When un-merged, gpu thread owns rasterizing. | ||
bool IsOnRasterizingThread(); | ||
|
||
private: | ||
static const int kLeaseNotSet; | ||
fml::TaskQueueId platform_queue_id_; | ||
fml::TaskQueueId gpu_queue_id_; | ||
fml::RefPtr<fml::MessageLoopTaskQueues> task_queues_; | ||
std::atomic_int lease_term_; | ||
bool is_merged_; | ||
|
||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(GpuThreadMerger); | ||
FML_FRIEND_MAKE_REF_COUNTED(GpuThreadMerger); | ||
FML_DISALLOW_COPY_AND_ASSIGN(GpuThreadMerger); | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif // FML_SHELL_COMMON_TASK_RUNNER_MERGER_H_ |
Oops, something went wrong.