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

Commit b046a42

Browse files
committed
[fuchsia][skp warmup] dont serialize font data
1 parent 68fc128 commit b046a42

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed

shell/common/BUILD.gn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,15 @@ if (enable_unittests) {
255255
"//flutter/shell/version",
256256
"//third_party/googletest:gmock",
257257
]
258+
259+
if (is_fuchsia) {
260+
if (using_fuchsia_gn_sdk) {
261+
deps += [ "$fuchsia_sdk_root/pkg/sys_cpp" ]
262+
} else if (using_fuchsia_sdk) {
263+
deps += [ "$fuchsia_sdk_root/pkg:sys_cpp" ]
264+
} else {
265+
deps += [ "//sdk/lib/sys/cpp" ]
266+
}
267+
}
258268
}
259269
}

shell/common/rasterizer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
510510
#if defined(OS_FUCHSIA)
511511
SkSerialProcs procs = {0};
512512
procs.fImageProc = SerializeImageWithoutData;
513+
procs.fTypefaceProc = SerializeTypefaceWithoutData;
513514
#else
514515
SkSerialProcs procs = {0};
515516
procs.fTypefaceProc = SerializeTypefaceWithData;

shell/common/serialization_callbacks.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55
#include "flutter/fml/logging.h"
66
#include "include/core/SkImage.h"
77
#include "include/core/SkPicture.h"
8+
#include "include/core/SkSerialProcs.h"
89
#include "include/core/SkStream.h"
910
#include "include/core/SkTypeface.h"
1011

1112
namespace flutter {
1213

1314
sk_sp<SkData> SerializeTypefaceWithoutData(SkTypeface* typeface, void* ctx) {
14-
return typeface->serialize(SkTypeface::SerializeBehavior::kDontIncludeData);
15+
return SkData::MakeEmpty();
1516
}
1617

1718
sk_sp<SkData> SerializeTypefaceWithData(SkTypeface* typeface, void* ctx) {
1819
return typeface->serialize(SkTypeface::SerializeBehavior::kDoIncludeData);
1920
}
2021

22+
sk_sp<SkTypeface> DeserializeTypefaceWithoutData(const void* data,
23+
size_t length,
24+
void* ctx) {
25+
return SkTypeface::MakeDefault();
26+
}
27+
2128
struct ImageMetaData {
2229
int32_t width;
2330
int32_t height;

shell/common/serialization_callbacks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace flutter {
1515

1616
sk_sp<SkData> SerializeTypefaceWithoutData(SkTypeface* typeface, void* ctx);
1717
sk_sp<SkData> SerializeTypefaceWithData(SkTypeface* typeface, void* ctx);
18+
sk_sp<SkTypeface> DeserializeTypefaceWithoutData(const void* data,
19+
size_t length,
20+
void* ctx);
1821

1922
// Serializes only the metadata of the image and not the underlying pixel data.
2023
sk_sp<SkData> SerializeImageWithoutData(SkImage* image, void* ctx);

shell/common/skp_shader_warmup_unittests.cc

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
#include "flutter/shell/common/switches.h"
2020
#include "flutter/shell/version/version.h"
2121
#include "flutter/testing/testing.h"
22+
#include "include/core/SkFont.h"
2223
#include "include/core/SkPicture.h"
2324
#include "include/core/SkPictureRecorder.h"
2425
#include "include/core/SkSerialProcs.h"
26+
#include "include/core/SkTextBlob.h"
27+
28+
#if defined(OS_FUCHSIA)
29+
#include "lib/sys/cpp/component_context.h"
30+
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
2531

2632
namespace flutter {
2733
namespace testing {
2834

29-
#if defined(OS_FUCHSIA)
30-
3135
static void WaitForIO(Shell* shell) {
3236
std::promise<bool> io_task_finished;
3337
shell->GetTaskRunners().GetIOTaskRunner()->PostTask(
@@ -103,8 +107,13 @@ class SkpWarmupTest : public ShellTest {
103107

104108
SkDeserialProcs procs = {0};
105109
procs.fImageProc = DeserializeImageWithoutData;
110+
procs.fTypefaceProc = DeserializeTypefaceWithoutData;
106111
sk_sp<SkPicture> picture =
107112
SkPicture::MakeFromStream(stream.get(), &procs);
113+
if (!picture) {
114+
FML_LOG(ERROR) << "Failed to deserialize " << filename;
115+
return true;
116+
}
108117
pictures.push_back(std::move(picture));
109118
fd.reset();
110119
}
@@ -242,7 +251,51 @@ TEST_F(SkpWarmupTest, Image) {
242251
TestWarmup(draw_size, builder);
243252
}
244253

245-
#endif
254+
// Re-enable once https://bugs.chromium.org/p/skia/issues/detail?id=10404
255+
// is fixed and integrated, or a workaround is found.
256+
TEST_F(SkpWarmupTest, DISABLED_Text) {
257+
auto context = sys::ComponentContext::Create();
258+
fuchsia::fonts::ProviderSyncPtr sync_font_provider;
259+
context->svc()->Connect(sync_font_provider.NewRequest());
260+
auto font_mgr = SkFontMgr_New_Fuchsia(std::move(sync_font_provider));
261+
auto raw_typeface =
262+
font_mgr->matchFamilyStyle(nullptr, SkFontStyle::Normal());
263+
auto typeface = sk_sp<SkTypeface>(raw_typeface);
264+
265+
SkFont font(typeface, 12);
266+
auto text_blob =
267+
SkTextBlob::MakeFromString("test", font, SkTextEncoding::kUTF8);
268+
269+
SkISize draw_size =
270+
SkISize::Make(text_blob->bounds().width(), text_blob->bounds().height());
271+
// We reuse this builder to draw the same content sever times in this test
272+
LayerTreeBuilder builder = [&draw_size, &text_blob,
273+
this](std::shared_ptr<ContainerLayer> root) {
274+
SkPictureRecorder recorder;
275+
276+
auto canvas =
277+
recorder.beginRecording(draw_size.width(), draw_size.height());
278+
279+
auto color_space = SkColorSpace::MakeSRGB();
280+
auto paint = SkPaint(SkColors::kWhite, color_space.get());
281+
canvas->drawTextBlob(text_blob, draw_size.width() / 2,
282+
draw_size.height() / 2, paint);
283+
284+
auto picture = recorder.finishRecordingAsPicture();
285+
286+
fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
287+
this->GetCurrentTaskRunner(), fml::TimeDelta::FromSeconds(0));
288+
auto picture_layer = std::make_shared<PictureLayer>(
289+
SkPoint::Make(0, 0), SkiaGPUObject<SkPicture>(picture, queue),
290+
/* is_complex */ false,
291+
/* will_change */ false);
292+
root->Add(picture_layer);
293+
};
294+
295+
TestWarmup(draw_size, builder);
296+
}
246297

247298
} // namespace testing
248299
} // namespace flutter
300+
301+
#endif

testing/fuchsia/meta/fuchsia_test.cmx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"fuchsia.vulkan.loader.Loader",
1919
"fuchsia.logger.LogSink",
2020
"fuchsia.tracing.provider.Registry",
21-
"fuchsia.intl.PropertyProvider"
21+
"fuchsia.intl.PropertyProvider",
22+
"fuchsia.fonts.Provider"
2223
]
2324
}
2425
}

0 commit comments

Comments
 (0)