Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 85523b5

Browse files
author
Kaushik Iska
committed
add tests
1 parent 8041778 commit 85523b5

File tree

5 files changed

+103
-2
lines changed

5 files changed

+103
-2
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ FILE: ../../../flutter/shell/common/isolate_configuration.cc
579579
FILE: ../../../flutter/shell/common/isolate_configuration.h
580580
FILE: ../../../flutter/shell/common/layer_tree_holder.cc
581581
FILE: ../../../flutter/shell/common/layer_tree_holder.h
582+
FILE: ../../../flutter/shell/common/layer_tree_holder_unittests.cc
582583
FILE: ../../../flutter/shell/common/persistent_cache.cc
583584
FILE: ../../../flutter/shell/common/persistent_cache.h
584585
FILE: ../../../flutter/shell/common/persistent_cache_unittests.cc

flow/compositor_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ enum class RasterStatus {
2727
// Frame needs to be resubmitted for rasterization. This is
2828
// currently only called when thread configuration change occurs.
2929
kResubmit,
30+
// Frame has been successfully rasterized, but "there are additional items in
31+
// the pipeline waiting to be consumed. This is currently
32+
// only called when thread configuration change occurs.
33+
kEnqueuePipeline,
3034
// Failed to rasterize the frame.
3135
kFailed
3236
};

shell/common/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ if (enable_unittests) {
190190
"animator_unittests.cc",
191191
"canvas_spy_unittests.cc",
192192
"input_events_unittests.cc",
193+
"layer_tree_holder_unittests.cc",
193194
"persistent_cache_unittests.cc",
194195
"renderer_context_manager_unittests.cc",
195196
"renderer_context_test.cc",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#define FML_USED_ON_EMBEDDER
6+
7+
#include <functional>
8+
#include <future>
9+
#include <memory>
10+
11+
#include "flutter/shell/common/layer_tree_holder.h"
12+
#include "gtest/gtest.h"
13+
14+
namespace flutter {
15+
namespace testing {
16+
17+
TEST(LayerTreeHolder, EmptyOnInit) {
18+
const LayerTreeHolder layer_tree_holder;
19+
ASSERT_TRUE(layer_tree_holder.IsEmpty());
20+
}
21+
22+
TEST(LayerTreeHolder, PutOneAndGet) {
23+
LayerTreeHolder layer_tree_holder;
24+
const auto frame_size = SkISize::Make(64, 64);
25+
auto layer_tree = std::make_unique<LayerTree>(frame_size, 100.0f, 1.0f);
26+
layer_tree_holder.ReplaceIfNewer(std::move(layer_tree));
27+
ASSERT_FALSE(layer_tree_holder.IsEmpty());
28+
const auto stored = layer_tree_holder.Get();
29+
ASSERT_EQ(stored->frame_size(), frame_size);
30+
}
31+
32+
TEST(LayerTreeHolder, PutMultiGetsLatest) {
33+
const auto build_begin = fml::TimePoint::Now();
34+
const auto target_time_1 = build_begin + fml::TimeDelta::FromSeconds(2);
35+
const auto target_time_2 = build_begin + fml::TimeDelta::FromSeconds(5);
36+
37+
LayerTreeHolder layer_tree_holder;
38+
const auto frame_size_1 = SkISize::Make(64, 64);
39+
auto layer_tree_1 = std::make_unique<LayerTree>(frame_size_1, 100.0f, 1.0f);
40+
layer_tree_1->RecordBuildTime(build_begin, target_time_1);
41+
layer_tree_holder.ReplaceIfNewer(std::move(layer_tree_1));
42+
43+
const auto frame_size_2 = SkISize::Make(128, 128);
44+
auto layer_tree_2 = std::make_unique<LayerTree>(frame_size_2, 100.0f, 1.0f);
45+
layer_tree_2->RecordBuildTime(build_begin, target_time_2);
46+
layer_tree_holder.ReplaceIfNewer(std::move(layer_tree_2));
47+
48+
const auto stored = layer_tree_holder.Get();
49+
ASSERT_EQ(stored->frame_size(), frame_size_2);
50+
}
51+
52+
TEST(LayerTreeHolder, RetainsOlderIfNewerFrameHasEarlierTargetTime) {
53+
const auto build_begin = fml::TimePoint::Now();
54+
const auto target_time_1 = build_begin + fml::TimeDelta::FromSeconds(5);
55+
const auto target_time_2 = build_begin + fml::TimeDelta::FromSeconds(2);
56+
57+
LayerTreeHolder layer_tree_holder;
58+
const auto frame_size_1 = SkISize::Make(64, 64);
59+
auto layer_tree_1 = std::make_unique<LayerTree>(frame_size_1, 100.0f, 1.0f);
60+
layer_tree_1->RecordBuildTime(build_begin, target_time_1);
61+
layer_tree_holder.ReplaceIfNewer(std::move(layer_tree_1));
62+
63+
const auto frame_size_2 = SkISize::Make(128, 128);
64+
auto layer_tree_2 = std::make_unique<LayerTree>(frame_size_2, 100.0f, 1.0f);
65+
layer_tree_2->RecordBuildTime(build_begin, target_time_2);
66+
layer_tree_holder.ReplaceIfNewer(std::move(layer_tree_2));
67+
68+
const auto stored = layer_tree_holder.Get();
69+
ASSERT_EQ(stored->frame_size(), frame_size_1);
70+
}
71+
72+
} // namespace testing
73+
} // namespace flutter

shell/common/rasterizer.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
#include "flutter/shell/common/rasterizer.h"
66

7-
#include "flutter/shell/common/persistent_cache.h"
8-
97
#include <utility>
108

119
#include "flutter/fml/time/time_delta.h"
1210
#include "flutter/fml/time/time_point.h"
11+
#include "flutter/shell/common/persistent_cache.h"
1312
#include "third_party/skia/include/core/SkEncodedImageFormat.h"
1413
#include "third_party/skia/include/core/SkImageEncoder.h"
1514
#include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -294,6 +293,29 @@ RasterStatus Rasterizer::DoDraw(
294293
);
295294
}
296295

296+
// Pipeline pressure is applied from a couple of places:
297+
// rasterizer: When there are more items as of the time of Consume.
298+
// animator (via shell): Frame gets produces every vsync.
299+
// Enqueing here is to account for the following scenario:
300+
// T = 1
301+
// - one item (A) in the pipeline
302+
// - rasterizer starts (and merges the threads)
303+
// - pipeline consume result says no items to process
304+
// T = 2
305+
// - animator produces (B) to the pipeline
306+
// - applies pipeline pressure via platform thread.
307+
// T = 3
308+
// - rasterizes finished (and un-merges the threads)
309+
// - |Draw| for B yields as its on the wrong thread.
310+
// This enqueue ensures that we attempt to consume from the right
311+
// thread one more time after un-merge.
312+
if (raster_thread_merger_) {
313+
if (raster_thread_merger_->DecrementLease() ==
314+
fml::RasterThreadStatus::kUnmergedNow) {
315+
return RasterStatus::kEnqueuePipeline;
316+
}
317+
}
318+
297319
return raster_status;
298320
}
299321

0 commit comments

Comments
 (0)