Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
2d3e1c58
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2d3e1c58
编写于
8月 27, 2020
作者:
C
Chris Yang
提交者:
GitHub
8月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
|MessageLoopImpl::FlushTasks| runs one task at a time (#20771)
上级
fc4da62b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
233 addition
and
60 deletion
+233
-60
fml/message_loop_impl.cc
fml/message_loop_impl.cc
+11
-5
fml/message_loop_task_queues.cc
fml/message_loop_task_queues.cc
+12
-20
fml/message_loop_task_queues.h
fml/message_loop_task_queues.h
+2
-4
fml/message_loop_task_queues_benchmark.cc
fml/message_loop_task_queues_benchmark.cc
+11
-4
fml/message_loop_task_queues_merge_unmerge_unittests.cc
fml/message_loop_task_queues_merge_unmerge_unittests.cc
+60
-9
fml/message_loop_task_queues_unittests.cc
fml/message_loop_task_queues_unittests.cc
+12
-5
fml/raster_thread_merger_unittests.cc
fml/raster_thread_merger_unittests.cc
+119
-0
shell/common/rasterizer.cc
shell/common/rasterizer.cc
+5
-7
shell/common/rasterizer.h
shell/common/rasterizer.h
+1
-6
未找到文件。
fml/message_loop_impl.cc
浏览文件 @
2d3e1c58
...
@@ -119,18 +119,24 @@ void MessageLoopImpl::DoTerminate() {
...
@@ -119,18 +119,24 @@ void MessageLoopImpl::DoTerminate() {
void
MessageLoopImpl
::
FlushTasks
(
FlushType
type
)
{
void
MessageLoopImpl
::
FlushTasks
(
FlushType
type
)
{
TRACE_EVENT0
(
"fml"
,
"MessageLoop::FlushTasks"
);
TRACE_EVENT0
(
"fml"
,
"MessageLoop::FlushTasks"
);
std
::
vector
<
fml
::
closure
>
invocations
;
task_queue_
->
GetTasksToRunNow
(
queue_id_
,
type
,
invocations
);
const
auto
now
=
fml
::
TimePoint
::
Now
();
fml
::
closure
invocation
;
for
(
const
auto
&
invocation
:
invocations
)
{
do
{
invocation
=
task_queue_
->
GetNextTaskToRun
(
queue_id_
,
now
);
if
(
!
invocation
)
{
break
;
}
invocation
();
invocation
();
std
::
vector
<
fml
::
closure
>
observers
=
std
::
vector
<
fml
::
closure
>
observers
=
task_queue_
->
GetObserversToNotify
(
queue_id_
);
task_queue_
->
GetObserversToNotify
(
queue_id_
);
for
(
const
auto
&
observer
:
observers
)
{
for
(
const
auto
&
observer
:
observers
)
{
observer
();
observer
();
}
}
}
if
(
type
==
FlushType
::
kSingle
)
{
break
;
}
}
while
(
invocation
);
}
}
void
MessageLoopImpl
::
RunExpiredTasksNow
()
{
void
MessageLoopImpl
::
RunExpiredTasksNow
()
{
...
...
fml/message_loop_task_queues.cc
浏览文件 @
2d3e1c58
...
@@ -87,35 +87,27 @@ bool MessageLoopTaskQueues::HasPendingTasks(TaskQueueId queue_id) const {
...
@@ -87,35 +87,27 @@ bool MessageLoopTaskQueues::HasPendingTasks(TaskQueueId queue_id) const {
return
HasPendingTasksUnlocked
(
queue_id
);
return
HasPendingTasksUnlocked
(
queue_id
);
}
}
void
MessageLoopTaskQueues
::
GetTasksToRunNow
(
fml
::
closure
MessageLoopTaskQueues
::
GetNextTaskToRun
(
TaskQueueId
queue_id
,
TaskQueueId
queue_id
,
fml
::
TimePoint
from_time
)
{
FlushType
type
,
std
::
vector
<
fml
::
closure
>&
invocations
)
{
std
::
lock_guard
guard
(
queue_mutex_
);
std
::
lock_guard
guard
(
queue_mutex_
);
if
(
!
HasPendingTasksUnlocked
(
queue_id
))
{
if
(
!
HasPendingTasksUnlocked
(
queue_id
))
{
return
;
return
nullptr
;
}
const
auto
now
=
fml
::
TimePoint
::
Now
();
while
(
HasPendingTasksUnlocked
(
queue_id
))
{
TaskQueueId
top_queue
=
_kUnmerged
;
const
auto
&
top
=
PeekNextTaskUnlocked
(
queue_id
,
top_queue
);
if
(
top
.
GetTargetTime
()
>
now
)
{
break
;
}
invocations
.
emplace_back
(
top
.
GetTask
());
queue_entries_
.
at
(
top_queue
)
->
delayed_tasks
.
pop
();
if
(
type
==
FlushType
::
kSingle
)
{
break
;
}
}
}
TaskQueueId
top_queue
=
_kUnmerged
;
const
auto
&
top
=
PeekNextTaskUnlocked
(
queue_id
,
top_queue
);
if
(
!
HasPendingTasksUnlocked
(
queue_id
))
{
if
(
!
HasPendingTasksUnlocked
(
queue_id
))
{
WakeUpUnlocked
(
queue_id
,
fml
::
TimePoint
::
Max
());
WakeUpUnlocked
(
queue_id
,
fml
::
TimePoint
::
Max
());
}
else
{
}
else
{
WakeUpUnlocked
(
queue_id
,
GetNextWakeTimeUnlocked
(
queue_id
));
WakeUpUnlocked
(
queue_id
,
GetNextWakeTimeUnlocked
(
queue_id
));
}
}
if
(
top
.
GetTargetTime
()
>
from_time
)
{
return
nullptr
;
}
fml
::
closure
invocation
=
top
.
GetTask
();
queue_entries_
.
at
(
top_queue
)
->
delayed_tasks
.
pop
();
return
invocation
;
}
}
void
MessageLoopTaskQueues
::
WakeUpUnlocked
(
TaskQueueId
queue_id
,
void
MessageLoopTaskQueues
::
WakeUpUnlocked
(
TaskQueueId
queue_id
,
...
...
fml/message_loop_task_queues.h
浏览文件 @
2d3e1c58
...
@@ -83,9 +83,7 @@ class MessageLoopTaskQueues
...
@@ -83,9 +83,7 @@ class MessageLoopTaskQueues
bool
HasPendingTasks
(
TaskQueueId
queue_id
)
const
;
bool
HasPendingTasks
(
TaskQueueId
queue_id
)
const
;
void
GetTasksToRunNow
(
TaskQueueId
queue_id
,
fml
::
closure
GetNextTaskToRun
(
TaskQueueId
queue_id
,
fml
::
TimePoint
from_time
);
FlushType
type
,
std
::
vector
<
fml
::
closure
>&
invocations
);
size_t
GetNumPendingTasks
(
TaskQueueId
queue_id
)
const
;
size_t
GetNumPendingTasks
(
TaskQueueId
queue_id
)
const
;
...
@@ -112,7 +110,7 @@ class MessageLoopTaskQueues
...
@@ -112,7 +110,7 @@ class MessageLoopTaskQueues
// 3. Each task queue can only be merged and subsumed once.
// 3. Each task queue can only be merged and subsumed once.
//
//
// Methods currently aware of the merged state of the queues:
// Methods currently aware of the merged state of the queues:
// HasPendingTasks, Get
TasksToRunNow
, GetNumPendingTasks
// HasPendingTasks, Get
NextTaskToRun
, GetNumPendingTasks
// This method returns false if either the owner or subsumed has already been
// This method returns false if either the owner or subsumed has already been
// merged with something else.
// merged with something else.
...
...
fml/message_loop_task_queues_benchmark.cc
浏览文件 @
2d3e1c58
...
@@ -39,10 +39,17 @@ static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT
...
@@ -39,10 +39,17 @@ static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT
}
}
tasks_registered
.
CountDown
();
tasks_registered
.
CountDown
();
tasks_registered
.
Wait
();
tasks_registered
.
Wait
();
std
::
vector
<
fml
::
closure
>
invocations
;
const
auto
now
=
fml
::
TimePoint
::
Now
();
task_queue
->
GetTasksToRunNow
(
TaskQueueId
(
task_runner_id
),
int
num_invocations
=
0
;
fml
::
FlushType
::
kAll
,
invocations
);
for
(;;)
{
assert
(
invocations
.
size
()
==
num_tasks_per_queue
);
fml
::
closure
invocation
=
task_queue
->
GetNextTaskToRun
(
TaskQueueId
(
task_runner_id
),
now
);
if
(
!
invocation
)
{
break
;
}
num_invocations
++
;
}
assert
(
num_invocations
==
num_tasks_per_queue
);
tasks_done
.
CountDown
();
tasks_done
.
CountDown
();
});
});
}
}
...
...
fml/message_loop_task_queues_merge_unmerge_unittests.cc
浏览文件 @
2d3e1c58
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
fml
{
namespace
testing
{
class
TestWakeable
:
public
fml
::
Wakeable
{
class
TestWakeable
:
public
fml
::
Wakeable
{
public:
public:
using
WakeUpCall
=
std
::
function
<
void
(
const
fml
::
TimePoint
)
>
;
using
WakeUpCall
=
std
::
function
<
void
(
const
fml
::
TimePoint
)
>
;
...
@@ -23,6 +26,25 @@ class TestWakeable : public fml::Wakeable {
...
@@ -23,6 +26,25 @@ class TestWakeable : public fml::Wakeable {
WakeUpCall
wake_up_call_
;
WakeUpCall
wake_up_call_
;
};
};
static
int
CountRemainingTasks
(
fml
::
RefPtr
<
MessageLoopTaskQueues
>
task_queue
,
const
TaskQueueId
&
queue_id
,
bool
run_invocation
=
false
)
{
const
auto
now
=
fml
::
TimePoint
::
Now
();
int
count
=
0
;
fml
::
closure
invocation
;
do
{
invocation
=
task_queue
->
GetNextTaskToRun
(
queue_id
,
now
);
if
(
!
invocation
)
{
break
;
}
count
++
;
if
(
run_invocation
)
{
invocation
();
}
}
while
(
invocation
);
return
count
;
}
TEST
(
MessageLoopTaskQueueMergeUnmerge
,
TEST
(
MessageLoopTaskQueueMergeUnmerge
,
AfterMergePrimaryTasksServicedOnPrimary
)
{
AfterMergePrimaryTasksServicedOnPrimary
)
{
auto
task_queue
=
fml
::
MessageLoopTaskQueues
::
GetInstance
();
auto
task_queue
=
fml
::
MessageLoopTaskQueues
::
GetInstance
();
...
@@ -127,8 +149,7 @@ TEST(MessageLoopTaskQueueMergeUnmerge, MergeInvokesBothWakeables) {
...
@@ -127,8 +149,7 @@ TEST(MessageLoopTaskQueueMergeUnmerge, MergeInvokesBothWakeables) {
task_queue
->
Merge
(
queue_id_1
,
queue_id_2
);
task_queue
->
Merge
(
queue_id_1
,
queue_id_2
);
std
::
vector
<
fml
::
closure
>
invocations
;
CountRemainingTasks
(
task_queue
,
queue_id_1
);
task_queue
->
GetTasksToRunNow
(
queue_id_1
,
fml
::
FlushType
::
kAll
,
invocations
);
latch
.
Wait
();
latch
.
Wait
();
}
}
...
@@ -157,12 +178,12 @@ TEST(MessageLoopTaskQueueMergeUnmerge,
...
@@ -157,12 +178,12 @@ TEST(MessageLoopTaskQueueMergeUnmerge,
task_queue
->
Merge
(
queue_id_1
,
queue_id_2
);
task_queue
->
Merge
(
queue_id_1
,
queue_id_2
);
task_queue
->
Unmerge
(
queue_id_1
);
task_queue
->
Unmerge
(
queue_id_1
);
std
::
vector
<
fml
::
closure
>
invocations
;
CountRemainingTasks
(
task_queue
,
queue_id_1
)
;
task_queue
->
GetTasksToRunNow
(
queue_id_1
,
fml
::
FlushType
::
kAll
,
invocations
);
latch_1
.
Wait
();
latch_1
.
Wait
();
task_queue
->
GetTasksToRunNow
(
queue_id_2
,
fml
::
FlushType
::
kAll
,
invocations
);
CountRemainingTasks
(
task_queue
,
queue_id_2
);
latch_2
.
Wait
();
latch_2
.
Wait
();
}
}
...
@@ -183,10 +204,8 @@ TEST(MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge) {
...
@@ -183,10 +204,8 @@ TEST(MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge) {
wake_up_end
.
Wait
();
wake_up_end
.
Wait
();
}));
}));
std
::
thread
tasks_to_run_now_thread
([
&
]()
{
std
::
thread
tasks_to_run_now_thread
(
std
::
vector
<
fml
::
closure
>
invocations
;
[
&
]()
{
CountRemainingTasks
(
task_queue
,
queue_id_1
);
});
task_queue
->
GetTasksToRunNow
(
queue_id_1
,
fml
::
FlushType
::
kAll
,
invocations
);
});
wake_up_start
.
Wait
();
wake_up_start
.
Wait
();
bool
merge_done
=
false
;
bool
merge_done
=
false
;
...
@@ -208,3 +227,35 @@ TEST(MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge) {
...
@@ -208,3 +227,35 @@ TEST(MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge) {
tasks_to_run_now_thread
.
join
();
tasks_to_run_now_thread
.
join
();
merge_thread
.
join
();
merge_thread
.
join
();
}
}
TEST
(
MessageLoopTaskQueueMergeUnmerge
,
FollowingTasksSwitchQueueIfFirstTaskMergesThreads
)
{
auto
task_queue
=
fml
::
MessageLoopTaskQueues
::
GetInstance
();
auto
queue_id_1
=
task_queue
->
CreateTaskQueue
();
auto
queue_id_2
=
task_queue
->
CreateTaskQueue
();
fml
::
CountDownLatch
latch
(
2
);
task_queue
->
SetWakeable
(
queue_id_1
,
new
TestWakeable
([
&
](
fml
::
TimePoint
wake_time
)
{
latch
.
CountDown
();
}));
task_queue
->
SetWakeable
(
queue_id_2
,
new
TestWakeable
([
&
](
fml
::
TimePoint
wake_time
)
{
latch
.
CountDown
();
}));
task_queue
->
RegisterTask
(
queue_id_2
,
[
&
]()
{
task_queue
->
Merge
(
queue_id_1
,
queue_id_2
);
},
fml
::
TimePoint
::
Now
());
task_queue
->
RegisterTask
(
queue_id_2
,
[]()
{},
fml
::
TimePoint
::
Now
());
ASSERT_EQ
(
CountRemainingTasks
(
task_queue
,
queue_id_2
,
true
),
1
);
ASSERT_EQ
(
CountRemainingTasks
(
task_queue
,
queue_id_1
,
true
),
1
);
latch
.
Wait
();
}
}
// namespace testing
}
// namespace fml
fml/message_loop_task_queues_unittests.cc
浏览文件 @
2d3e1c58
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
fml
{
namespace
testing
{
class
TestWakeable
:
public
fml
::
Wakeable
{
class
TestWakeable
:
public
fml
::
Wakeable
{
public:
public:
using
WakeUpCall
=
std
::
function
<
void
(
const
fml
::
TimePoint
)
>
;
using
WakeUpCall
=
std
::
function
<
void
(
const
fml
::
TimePoint
)
>
;
...
@@ -69,12 +72,13 @@ TEST(MessageLoopTaskQueue, PreserveTaskOrdering) {
...
@@ -69,12 +72,13 @@ TEST(MessageLoopTaskQueue, PreserveTaskOrdering) {
task_queue
->
RegisterTask
(
task_queue
->
RegisterTask
(
queue_id
,
[
&
test_val
]()
{
test_val
=
2
;
},
fml
::
TimePoint
::
Now
());
queue_id
,
[
&
test_val
]()
{
test_val
=
2
;
},
fml
::
TimePoint
::
Now
());
std
::
vector
<
fml
::
closure
>
invocations
;
const
auto
now
=
fml
::
TimePoint
::
Now
();
task_queue
->
GetTasksToRunNow
(
queue_id
,
fml
::
FlushType
::
kAll
,
invocations
);
int
expected_value
=
1
;
int
expected_value
=
1
;
for
(;;)
{
for
(
auto
&
invocation
:
invocations
)
{
fml
::
closure
invocation
=
task_queue
->
GetNextTaskToRun
(
queue_id
,
now
);
if
(
!
invocation
)
{
break
;
}
invocation
();
invocation
();
ASSERT_TRUE
(
test_val
==
expected_value
);
ASSERT_TRUE
(
test_val
==
expected_value
);
expected_value
++
;
expected_value
++
;
...
@@ -277,3 +281,6 @@ TEST(MessageLoopTaskQueue, RegisterTaskWakesUpOwnerQueue) {
...
@@ -277,3 +281,6 @@ TEST(MessageLoopTaskQueue, RegisterTaskWakesUpOwnerQueue) {
ASSERT_EQ
(
time1
,
wakes
[
1
]);
ASSERT_EQ
(
time1
,
wakes
[
1
]);
ASSERT_EQ
(
time1
,
wakes
[
2
]);
ASSERT_EQ
(
time1
,
wakes
[
2
]);
}
}
}
// namespace testing
}
// namespace fml
fml/raster_thread_merger_unittests.cc
浏览文件 @
2d3e1c58
...
@@ -14,6 +14,9 @@
...
@@ -14,6 +14,9 @@
#include "flutter/fml/task_runner.h"
#include "flutter/fml/task_runner.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
fml
{
namespace
testing
{
TEST
(
RasterThreadMerger
,
RemainMergedTillLeaseExpires
)
{
TEST
(
RasterThreadMerger
,
RemainMergedTillLeaseExpires
)
{
fml
::
MessageLoop
*
loop1
=
nullptr
;
fml
::
MessageLoop
*
loop1
=
nullptr
;
fml
::
AutoResetWaitableEvent
latch1
;
fml
::
AutoResetWaitableEvent
latch1
;
...
@@ -301,3 +304,119 @@ TEST(RasterThreadMerger, HandleTaskQueuesAreTheSame) {
...
@@ -301,3 +304,119 @@ TEST(RasterThreadMerger, HandleTaskQueuesAreTheSame) {
term1
.
Signal
();
term1
.
Signal
();
thread1
.
join
();
thread1
.
join
();
}
}
TEST
(
RasterThreadMerger
,
RunExpiredTasksWhileFirstTaskMergesThreads
)
{
fml
::
MessageLoop
*
loop_platform
=
nullptr
;
fml
::
AutoResetWaitableEvent
latch1
;
std
::
thread
thread_platform
([
&
loop_platform
,
&
latch1
]()
{
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
loop_platform
=
&
fml
::
MessageLoop
::
GetCurrent
();
loop_platform
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
latch1
.
Signal
();
});
loop_platform
->
Run
();
});
fml
::
MessageLoop
*
loop_raster
=
nullptr
;
fml
::
AutoResetWaitableEvent
latch2
;
std
::
thread
thread_raster
([
&
loop_raster
,
&
loop_platform
,
&
latch1
,
&
latch2
]()
{
latch1
.
Wait
();
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
loop_raster
=
&
fml
::
MessageLoop
::
GetCurrent
();
fml
::
TaskQueueId
qid_platform
=
loop_platform
->
GetTaskRunner
()
->
GetTaskQueueId
();
fml
::
TaskQueueId
qid_raster
=
loop_raster
->
GetTaskRunner
()
->
GetTaskQueueId
();
fml
::
CountDownLatch
post_merge
(
2
);
const
auto
raster_thread_merger_
=
fml
::
MakeRefCounted
<
fml
::
RasterThreadMerger
>
(
qid_platform
,
qid_raster
);
loop_raster
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnRasterizingThread
());
ASSERT_FALSE
(
raster_thread_merger_
->
IsOnPlatformThread
());
ASSERT_EQ
(
fml
::
MessageLoop
::
GetCurrentTaskQueueId
(),
qid_raster
);
raster_thread_merger_
->
MergeWithLease
(
1
);
post_merge
.
CountDown
();
});
loop_raster
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnRasterizingThread
());
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnPlatformThread
());
ASSERT_EQ
(
fml
::
MessageLoop
::
GetCurrentTaskQueueId
(),
qid_platform
);
raster_thread_merger_
->
DecrementLease
();
post_merge
.
CountDown
();
});
loop_raster
->
RunExpiredTasksNow
();
post_merge
.
Wait
();
latch2
.
Signal
();
});
latch2
.
Wait
();
loop_platform
->
GetTaskRunner
()
->
PostTask
(
[
&
]()
{
loop_platform
->
Terminate
();
});
thread_platform
.
join
();
thread_raster
.
join
();
}
TEST
(
RasterThreadMerger
,
RunExpiredTasksWhileFirstTaskUnMergesThreads
)
{
fml
::
MessageLoop
*
loop_platform
=
nullptr
;
fml
::
AutoResetWaitableEvent
latch1
;
std
::
thread
thread_platform
([
&
loop_platform
,
&
latch1
]()
{
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
loop_platform
=
&
fml
::
MessageLoop
::
GetCurrent
();
loop_platform
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
latch1
.
Signal
();
});
loop_platform
->
Run
();
});
fml
::
MessageLoop
*
loop_raster
=
nullptr
;
fml
::
AutoResetWaitableEvent
latch2
;
std
::
thread
thread_raster
([
&
loop_raster
,
&
loop_platform
,
&
latch1
,
&
latch2
]()
{
latch1
.
Wait
();
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
loop_raster
=
&
fml
::
MessageLoop
::
GetCurrent
();
fml
::
TaskQueueId
qid_platform
=
loop_platform
->
GetTaskRunner
()
->
GetTaskQueueId
();
fml
::
TaskQueueId
qid_raster
=
loop_raster
->
GetTaskRunner
()
->
GetTaskQueueId
();
fml
::
CountDownLatch
post_merge
(
2
);
const
auto
raster_thread_merger_
=
fml
::
MakeRefCounted
<
fml
::
RasterThreadMerger
>
(
qid_platform
,
qid_raster
);
loop_raster
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
raster_thread_merger_
->
MergeWithLease
(
1
);
post_merge
.
CountDown
();
});
loop_raster
->
RunExpiredTasksNow
();
loop_raster
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnRasterizingThread
());
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnPlatformThread
());
ASSERT_EQ
(
fml
::
MessageLoop
::
GetCurrentTaskQueueId
(),
qid_platform
);
raster_thread_merger_
->
DecrementLease
();
post_merge
.
CountDown
();
});
loop_raster
->
GetTaskRunner
()
->
PostTask
([
&
]()
{
ASSERT_TRUE
(
raster_thread_merger_
->
IsOnRasterizingThread
());
ASSERT_FALSE
(
raster_thread_merger_
->
IsOnPlatformThread
());
ASSERT_EQ
(
fml
::
MessageLoop
::
GetCurrentTaskQueueId
(),
qid_platform
);
post_merge
.
CountDown
();
});
loop_raster
->
RunExpiredTasksNow
();
post_merge
.
Wait
();
latch2
.
Signal
();
});
latch2
.
Wait
();
loop_platform
->
GetTaskRunner
()
->
PostTask
(
[
&
]()
{
loop_platform
->
Terminate
();
});
thread_platform
.
join
();
thread_raster
.
join
();
}
}
// namespace testing
}
// namespace fml
shell/common/rasterizer.cc
浏览文件 @
2d3e1c58
...
@@ -96,6 +96,7 @@ void Rasterizer::Teardown() {
...
@@ -96,6 +96,7 @@ void Rasterizer::Teardown() {
compositor_context_
->
OnGrContextDestroyed
();
compositor_context_
->
OnGrContextDestroyed
();
surface_
.
reset
();
surface_
.
reset
();
last_layer_tree_
.
reset
();
last_layer_tree_
.
reset
();
if
(
raster_thread_merger_
.
get
()
!=
nullptr
&&
if
(
raster_thread_merger_
.
get
()
!=
nullptr
&&
raster_thread_merger_
.
get
()
->
IsMerged
())
{
raster_thread_merger_
.
get
()
->
IsMerged
())
{
raster_thread_merger_
->
UnMergeNow
();
raster_thread_merger_
->
UnMergeNow
();
...
@@ -667,22 +668,19 @@ std::optional<size_t> Rasterizer::GetResourceCacheMaxBytes() const {
...
@@ -667,22 +668,19 @@ std::optional<size_t> Rasterizer::GetResourceCacheMaxBytes() const {
return
std
::
nullopt
;
return
std
::
nullopt
;
}
}
bool
Rasterizer
::
EnsureThreadsAreMerged
()
{
void
Rasterizer
::
EnsureThreadsAreMerged
()
{
if
(
surface_
==
nullptr
||
raster_thread_merger_
.
get
()
==
nullptr
)
{
if
(
surface_
==
nullptr
||
raster_thread_merger_
.
get
()
==
nullptr
)
{
return
false
;
return
;
}
}
const
size_t
ThreadMergeLeaseTermDefault
=
10
;
fml
::
TaskRunner
::
RunNowOrPostTask
(
fml
::
TaskRunner
::
RunNowOrPostTask
(
delegate_
.
GetTaskRunners
().
GetRasterTaskRunner
(),
delegate_
.
GetTaskRunners
().
GetRasterTaskRunner
(),
[
weak_this
=
weak_factory_
.
GetWeakPtr
(),
[
weak_this
=
weak_factory_
.
GetWeakPtr
(),
thread_merger
=
raster_thread_merger_
]()
{
thread_merger
=
raster_thread_merger_
]()
{
if
(
weak_this
->
surface_
==
nullptr
)
{
thread_merger
->
MergeWithLease
(
ThreadMergeLeaseTermDefault
);
return
;
}
thread_merger
->
MergeWithLease
(
10
);
});
});
raster_thread_merger_
->
WaitUntilMerged
();
raster_thread_merger_
->
WaitUntilMerged
();
FML_DCHECK
(
raster_thread_merger_
->
IsMerged
());
FML_DCHECK
(
raster_thread_merger_
->
IsMerged
());
return
true
;
}
}
Rasterizer
::
Screenshot
::
Screenshot
()
{}
Rasterizer
::
Screenshot
::
Screenshot
()
{}
...
...
shell/common/rasterizer.h
浏览文件 @
2d3e1c58
...
@@ -400,12 +400,7 @@ class Rasterizer final : public SnapshotDelegate {
...
@@ -400,12 +400,7 @@ class Rasterizer final : public SnapshotDelegate {
/// blocking the current thread until the 2 task runners are
/// blocking the current thread until the 2 task runners are
/// merged.
/// merged.
///
///
/// @return `true` if raster and platform task runners are the same.
void
EnsureThreadsAreMerged
();
/// `true` if/when raster and platform task runners are merged.
/// `false` if the surface or the |RasterThreadMerger| has not
/// been initialized.
///
bool
EnsureThreadsAreMerged
();
private:
private:
Delegate
&
delegate_
;
Delegate
&
delegate_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录