Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@ ORIGIN: ../../../flutter/lib/ui/painting/image_filter.cc + ../../../flutter/LICE
ORIGIN: ../../../flutter/lib/ui/painting/image_filter.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator_apng.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator_apng.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator_registry.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_generator_registry.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/image_shader.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4273,6 +4275,8 @@ FILE: ../../../flutter/lib/ui/painting/image_filter.cc
FILE: ../../../flutter/lib/ui/painting/image_filter.h
FILE: ../../../flutter/lib/ui/painting/image_generator.cc
FILE: ../../../flutter/lib/ui/painting/image_generator.h
FILE: ../../../flutter/lib/ui/painting/image_generator_apng.cc
FILE: ../../../flutter/lib/ui/painting/image_generator_apng.h
FILE: ../../../flutter/lib/ui/painting/image_generator_registry.cc
FILE: ../../../flutter/lib/ui/painting/image_generator_registry.h
FILE: ../../../flutter/lib/ui/painting/image_shader.cc
Expand Down
14 changes: 11 additions & 3 deletions fml/endianness.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@

namespace fml {

template <typename T>
struct IsByteSwappable
: public std::
integral_constant<bool, std::is_integral_v<T> || std::is_enum_v<T>> {
};
template <typename T>
constexpr bool IsByteSwappableV = IsByteSwappable<T>::value;

/// @brief Flips the endianness of the given value.
/// The given value must be an integral type of size 1, 2, 4, or 8.
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
constexpr T ByteSwap(T n) {
if constexpr (sizeof(T) == 1) {
return n;
Expand All @@ -47,7 +55,7 @@ constexpr T ByteSwap(T n) {
/// current architecture. This is effectively a cross platform
/// ntohl/ntohs (as network byte order is always Big Endian).
/// The given value must be an integral type of size 1, 2, 4, or 8.
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
constexpr T BigEndianToArch(T n) {
#if FML_ARCH_CPU_LITTLE_ENDIAN
return ByteSwap<T>(n);
Expand All @@ -59,7 +67,7 @@ constexpr T BigEndianToArch(T n) {
/// @brief Convert a known little endian value to match the endianness of the
/// current architecture.
/// The given value must be an integral type of size 1, 2, 4, or 8.
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
template <typename T, class = std::enable_if_t<IsByteSwappableV<T>>>
constexpr T LittleEndianToArch(T n) {
#if !FML_ARCH_CPU_LITTLE_ENDIAN
return ByteSwap<T>(n);
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ source_set("ui") {
"painting/image_filter.h",
"painting/image_generator.cc",
"painting/image_generator.h",
"painting/image_generator_apng.cc",
"painting/image_generator_apng.h",
"painting/image_generator_registry.cc",
"painting/image_generator_registry.h",
"painting/image_shader.cc",
Expand Down Expand Up @@ -161,6 +163,7 @@ source_set("ui") {
"//third_party/dart/runtime/bin:dart_io_api",
"//third_party/rapidjson",
"//third_party/skia",
"//third_party/zlib:zlib",
]

if (impeller_supports_rendering) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/image_decoder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class UnknownImageGenerator : public ImageGenerator {

unsigned int GetPlayCount() const { return 1; }

const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index) const {
const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index) {
return {std::nullopt, 0, SkCodecAnimation::DisposalMethod::kKeep};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ui/painting/image_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ unsigned int BuiltinSkiaImageGenerator::GetPlayCount() const {
}

const ImageGenerator::FrameInfo BuiltinSkiaImageGenerator::GetFrameInfo(
unsigned int frame_index) const {
unsigned int frame_index) {
return {.required_frame = std::nullopt,
.duration = 0,
.disposal_method = SkCodecAnimation::DisposalMethod::kKeep};
Expand Down Expand Up @@ -105,7 +105,7 @@ unsigned int BuiltinSkiaCodecImageGenerator::GetPlayCount() const {
}

const ImageGenerator::FrameInfo BuiltinSkiaCodecImageGenerator::GetFrameInfo(
unsigned int frame_index) const {
unsigned int frame_index) {
SkCodec::FrameInfo info = {};
codec_generator_->getFrameInfo(frame_index, &info);
return {
Expand Down
12 changes: 8 additions & 4 deletions lib/ui/painting/image_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ class ImageGenerator {
/// blended with.
std::optional<unsigned int> required_frame;

/// Number of milliseconds to show this frame.
/// Number of milliseconds to show this frame. 0 means only show it for one
/// frame.
unsigned int duration;

/// How this frame should be modified before decoding the next one.
SkCodecAnimation::DisposalMethod disposal_method;

/// How this frame should be blended with the previous frame.
SkCodecAnimation::Blend blend_mode;
};

virtual ~ImageGenerator();
Expand Down Expand Up @@ -80,7 +84,7 @@ class ImageGenerator {
/// @return Information about the given frame. If the image is
/// single-frame, a default result is returned.
/// @see `GetFrameCount`
virtual const FrameInfo GetFrameInfo(unsigned int frame_index) const = 0;
virtual const FrameInfo GetFrameInfo(unsigned int frame_index) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the |const| modifier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetFrameInfo requires decoding the image header as per the registry protocol, which is expected to have substantial side effects per the protocol.


/// @brief Given a scale value, find the closest image size that can be
/// used for efficiently decoding the image. If subpixel image
Expand Down Expand Up @@ -152,7 +156,7 @@ class BuiltinSkiaImageGenerator : public ImageGenerator {

// |ImageGenerator|
const ImageGenerator::FrameInfo GetFrameInfo(
unsigned int frame_index) const override;
unsigned int frame_index) override;

// |ImageGenerator|
SkISize GetScaledDimensions(float desired_scale) override;
Expand Down Expand Up @@ -192,7 +196,7 @@ class BuiltinSkiaCodecImageGenerator : public ImageGenerator {

// |ImageGenerator|
const ImageGenerator::FrameInfo GetFrameInfo(
unsigned int frame_index) const override;
unsigned int frame_index) override;

// |ImageGenerator|
SkISize GetScaledDimensions(float desired_scale) override;
Expand Down
Loading