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

Test Framework for SKP based shader warmup #19260

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ FILE: ../../../flutter/shell/common/rasterizer.cc
FILE: ../../../flutter/shell/common/rasterizer.h
FILE: ../../../flutter/shell/common/run_configuration.cc
FILE: ../../../flutter/shell/common/run_configuration.h
FILE: ../../../flutter/shell/common/serialization_callbacks.cc
FILE: ../../../flutter/shell/common/serialization_callbacks.h
FILE: ../../../flutter/shell/common/shell.cc
FILE: ../../../flutter/shell/common/shell.h
FILE: ../../../flutter/shell/common/shell_benchmarks.cc
Expand All @@ -629,6 +631,7 @@ FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.h
FILE: ../../../flutter/shell/common/shell_unittests.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h
FILE: ../../../flutter/shell/common/skp_shader_warmup_unittests.cc
FILE: ../../../flutter/shell/common/switches.cc
FILE: ../../../flutter/shell/common/switches.h
FILE: ../../../flutter/shell/common/thread_host.cc
Expand Down
3 changes: 3 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ source_set_maybe_fuchsia_legacy("common") {
"rasterizer.h",
"run_configuration.cc",
"run_configuration.h",
"serialization_callbacks.cc",
"serialization_callbacks.h",
"shell.cc",
"shell.h",
"shell_io_manager.cc",
Expand Down Expand Up @@ -264,6 +266,7 @@ if (enable_unittests) {
"persistent_cache_unittests.cc",
"pipeline_unittests.cc",
"shell_unittests.cc",
"skp_shader_warmup_unittests.cc",
]

deps = [
Expand Down
21 changes: 16 additions & 5 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/time/time_point.h"
#include "flutter/shell/common/persistent_cache.h"
#include "flutter/shell/common/serialization_callbacks.h"
#include "third_party/skia/include/core/SkEncodedImageFormat.h"
#include "third_party/skia/include/core/SkImageEncoder.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
Expand Down Expand Up @@ -447,10 +448,6 @@ RasterStatus Rasterizer::DrawToSurface(flutter::LayerTree& layer_tree) {
return RasterStatus::kFailed;
}

static sk_sp<SkData> SerializeTypeface(SkTypeface* typeface, void* ctx) {
return typeface->serialize(SkTypeface::SerializeBehavior::kDoIncludeData);
}

static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
flutter::LayerTree* tree,
flutter::CompositorContext& compositor_context) {
Expand All @@ -462,16 +459,30 @@ static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
SkMatrix root_surface_transformation;
root_surface_transformation.reset();

#if defined(LEGACY_FUCHSIA_EMBEDDER)
// TODO(arbreng: fxb/55805) Our ScopedFrame implementation doesnt do the
// right thing here so initialize the base class directly. This wont be
// needed after we move to using the embedder API on Fuchsia.
auto frame = std::make_unique<flutter::CompositorContext::ScopedFrame>(
compositor_context, nullptr, recorder.getRecordingCanvas(), nullptr,
root_surface_transformation, false, true, nullptr);
#else
// TODO(amirh): figure out how to take a screenshot with embedded UIView.
// https://github.com/flutter/flutter/issues/23435
auto frame = compositor_context.AcquireFrame(
nullptr, recorder.getRecordingCanvas(), nullptr,
root_surface_transformation, false, true, nullptr);
#endif // defined(LEGACY_FUCHSIA_EMBEDDER)

frame->Raster(*tree, true);

#if defined(OS_FUCHSIA)
SkSerialProcs procs = {0};
procs.fTypefaceProc = SerializeTypeface;
procs.fImageProc = SerializeImageWithoutData;
#else
SkSerialProcs procs = {0};
procs.fTypefaceProc = SerializeTypefaceWithData;
#endif

return recorder.finishRecordingAsPicture()->serialize(&procs);
}
Expand Down
74 changes: 74 additions & 0 deletions shell/common/serialization_callbacks.cc
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.

#include "flutter/fml/logging.h"
#include "include/core/SkImage.h"
#include "include/core/SkPicture.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"

namespace flutter {

sk_sp<SkData> SerializeTypefaceWithoutData(SkTypeface* typeface, void* ctx) {
return typeface->serialize(SkTypeface::SerializeBehavior::kDoIncludeData);
}

sk_sp<SkData> SerializeTypefaceWithData(SkTypeface* typeface, void* ctx) {
return typeface->serialize(SkTypeface::SerializeBehavior::kDontIncludeData);
}

struct ImageMetaData {
int32_t width;
int32_t height;
uint32_t color_type;
uint32_t alpha_type;
bool has_color_space;
} __attribute__((packed));

sk_sp<SkData> SerializeImageWithoutData(SkImage* image, void* ctx) {
auto info = image->imageInfo();
SkDynamicMemoryWStream stream;

ImageMetaData metadata = {info.width(), info.height(),
static_cast<uint32_t>(info.colorType()),
static_cast<uint32_t>(info.alphaType()),
static_cast<bool>(info.colorSpace())};
stream.write(&metadata, sizeof(ImageMetaData));

if (info.colorSpace()) {
auto color_space_data = info.colorSpace()->serialize();
FML_CHECK(color_space_data);
SkMemoryStream color_space_stream(color_space_data);
stream.writeStream(&color_space_stream, color_space_data->size());
}

return stream.detachAsData();
};

sk_sp<SkImage> DeserializeImageWithoutData(const void* data,
size_t length,
void* ctx) {
FML_CHECK(length >= sizeof(ImageMetaData));
auto metadata = static_cast<const ImageMetaData*>(data);
sk_sp<SkColorSpace> color_space = nullptr;
if (metadata->has_color_space) {
color_space = SkColorSpace::Deserialize(
static_cast<const uint8_t*>(data) + sizeof(ImageMetaData),
length - sizeof(ImageMetaData));
}

auto image_size = SkISize::Make(metadata->width, metadata->height);
auto info = SkImageInfo::Make(
image_size, static_cast<SkColorType>(metadata->color_type),
static_cast<SkAlphaType>(metadata->alpha_type), color_space);
sk_sp<SkData> image_data =
SkData::MakeUninitialized(image_size.width() * image_size.height() * 4);
memset(image_data->writable_data(), 0x0f, image_data->size());
sk_sp<SkImage> image =
SkImage::MakeRasterData(info, image_data, image_size.width() * 4);

return image;
};

} // namespace flutter
27 changes: 27 additions & 0 deletions shell/common/serialization_callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_SHELL_COMMON_SERIALIZATION_CALLBACKS_H_
#define FLUTTER_SHELL_COMMON_SERIALIZATION_CALLBACKS_H_

#include "flutter/fml/logging.h"
#include "include/core/SkImage.h"
#include "include/core/SkPicture.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"

namespace flutter {

sk_sp<SkData> SerializeTypefaceWithoutData(SkTypeface* typeface, void* ctx);
sk_sp<SkData> SerializeTypefaceWithData(SkTypeface* typeface, void* ctx);

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

} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_SERIALIZATION_CALLBACKS_H_
Loading