Commit 5521e0bd authored by Madeleine Barowsky's avatar Madeleine Barowsky Committed by Commit Bot

Add GetImageType for PaintImage to query file type of underlying image

Change-Id: If8ea00756ba3a22b078a6cf19a39b1f923d5ca9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1740130Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: Madeleine Barowsky <mbarowsky@chromium.org>
Auto-Submit: Madeleine Barowsky <mbarowsky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685307}
parent 544e42ce
...@@ -279,6 +279,12 @@ SkColorType PaintImage::GetColorType() const { ...@@ -279,6 +279,12 @@ SkColorType PaintImage::GetColorType() const {
return kUnknown_SkColorType; return kUnknown_SkColorType;
} }
PaintImage::ImageType PaintImage::GetImageType() const {
if (paint_image_generator_)
return paint_image_generator_->GetImageType();
return PaintImage::ImageType::kInvalid;
}
bool PaintImage::IsYuv(SkYUVASizeInfo* yuva_size_info, bool PaintImage::IsYuv(SkYUVASizeInfo* yuva_size_info,
SkYUVAIndex* plane_indices) const { SkYUVAIndex* plane_indices) const {
SkYUVASizeInfo temp_yuva_size_info; SkYUVASizeInfo temp_yuva_size_info;
......
...@@ -117,6 +117,7 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -117,6 +117,7 @@ class CC_PAINT_EXPORT PaintImage {
// CheckerImageTracker for all heuristics used. // CheckerImageTracker for all heuristics used.
kAsync kAsync
}; };
enum class ImageType { kPNG, kJPEG, kWEBP, kGIF, kICO, kBMP, kInvalid };
// Returns the more conservative mode out of the two given ones. // Returns the more conservative mode out of the two given ones.
static DecodingMode GetConservative(DecodingMode one, DecodingMode two); static DecodingMode GetConservative(DecodingMode one, DecodingMode two);
...@@ -244,6 +245,9 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -244,6 +245,9 @@ class CC_PAINT_EXPORT PaintImage {
// Returns the color type of this image. // Returns the color type of this image.
SkColorType GetColorType() const; SkColorType GetColorType() const;
// Returns the image type (e.g. PNG, WEBP) of this image.
ImageType GetImageType() const;
// Returns a unique id for the pixel data for the frame at |frame_index|. // Returns a unique id for the pixel data for the frame at |frame_index|.
FrameKey GetKeyForFrame(size_t frame_index) const; FrameKey GetKeyForFrame(size_t frame_index) const;
......
...@@ -33,4 +33,8 @@ SkISize PaintImageGenerator::GetSupportedDecodeSize( ...@@ -33,4 +33,8 @@ SkISize PaintImageGenerator::GetSupportedDecodeSize(
return info_.dimensions(); return info_.dimensions();
} }
PaintImage::ImageType PaintImageGenerator::GetImageType() const {
return PaintImage::ImageType::kInvalid;
}
} // namespace cc } // namespace cc
...@@ -88,6 +88,8 @@ class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt { ...@@ -88,6 +88,8 @@ class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt {
const SkImageInfo& GetSkImageInfo() const { return info_; } const SkImageInfo& GetSkImageInfo() const { return info_; }
const std::vector<FrameMetadata>& GetFrameMetadata() const { return frames_; } const std::vector<FrameMetadata>& GetFrameMetadata() const { return frames_; }
virtual PaintImage::ImageType GetImageType() const;
protected: protected:
// |info| is the info for this paint image generator. // |info| is the info for this paint image generator.
PaintImageGenerator(const SkImageInfo& info, PaintImageGenerator(const SkImageInfo& info,
......
...@@ -38,6 +38,27 @@ ...@@ -38,6 +38,27 @@
namespace blink { namespace blink {
namespace {
// These filename extension strings come from ImageDecoder::FilenameExtension.
PaintImage::ImageType FileExtensionToImageType(String image_extension) {
if (image_extension == "png")
return PaintImage::ImageType::kPNG;
if (image_extension == "jpg")
return PaintImage::ImageType::kJPEG;
if (image_extension == "webp")
return PaintImage::ImageType::kWEBP;
if (image_extension == "gif")
return PaintImage::ImageType::kGIF;
if (image_extension == "ico")
return PaintImage::ImageType::kICO;
if (image_extension == "bmp")
return PaintImage::ImageType::kBMP;
return PaintImage::ImageType::kInvalid;
}
} // namespace
// static // static
std::unique_ptr<SkImageGenerator> std::unique_ptr<SkImageGenerator>
DecodingImageGenerator::CreateAsSkImageGenerator(sk_sp<SkData> data) { DecodingImageGenerator::CreateAsSkImageGenerator(sk_sp<SkData> data) {
...@@ -70,7 +91,7 @@ DecodingImageGenerator::CreateAsSkImageGenerator(sk_sp<SkData> data) { ...@@ -70,7 +91,7 @@ DecodingImageGenerator::CreateAsSkImageGenerator(sk_sp<SkData> data) {
std::move(frame), info, std::move(segment_reader), std::move(frames), std::move(frame), info, std::move(segment_reader), std::move(frames),
PaintImage::GetNextContentId(), true /* all_data_received */, PaintImage::GetNextContentId(), true /* all_data_received */,
true /* is_eligible_for_accelerated_decoding */, true /* is_eligible_for_accelerated_decoding */,
false /* can_yuv_decode */); false /* can_yuv_decode */, decoder->FilenameExtension());
return std::make_unique<SkiaPaintImageGenerator>( return std::make_unique<SkiaPaintImageGenerator>(
std::move(generator), PaintImage::kDefaultFrameIndex, std::move(generator), PaintImage::kDefaultFrameIndex,
PaintImage::kDefaultGeneratorClientId); PaintImage::kDefaultGeneratorClientId);
...@@ -85,11 +106,13 @@ sk_sp<DecodingImageGenerator> DecodingImageGenerator::Create( ...@@ -85,11 +106,13 @@ sk_sp<DecodingImageGenerator> DecodingImageGenerator::Create(
PaintImage::ContentId content_id, PaintImage::ContentId content_id,
bool all_data_received, bool all_data_received,
bool is_eligible_for_accelerated_decoding, bool is_eligible_for_accelerated_decoding,
bool can_yuv_decode) { bool can_yuv_decode,
String image_type) {
PaintImage::ImageType paint_image_type = FileExtensionToImageType(image_type);
return sk_sp<DecodingImageGenerator>(new DecodingImageGenerator( return sk_sp<DecodingImageGenerator>(new DecodingImageGenerator(
std::move(frame_generator), info, std::move(data), std::move(frames), std::move(frame_generator), info, std::move(data), std::move(frames),
content_id, all_data_received, is_eligible_for_accelerated_decoding, content_id, all_data_received, is_eligible_for_accelerated_decoding,
can_yuv_decode)); can_yuv_decode, paint_image_type));
} }
DecodingImageGenerator::DecodingImageGenerator( DecodingImageGenerator::DecodingImageGenerator(
...@@ -100,7 +123,8 @@ DecodingImageGenerator::DecodingImageGenerator( ...@@ -100,7 +123,8 @@ DecodingImageGenerator::DecodingImageGenerator(
PaintImage::ContentId complete_frame_content_id, PaintImage::ContentId complete_frame_content_id,
bool all_data_received, bool all_data_received,
bool is_eligible_for_accelerated_decoding, bool is_eligible_for_accelerated_decoding,
bool can_yuv_decode) bool can_yuv_decode,
PaintImage::ImageType image_type)
: PaintImageGenerator(info, frames.ReleaseVector()), : PaintImageGenerator(info, frames.ReleaseVector()),
frame_generator_(std::move(frame_generator)), frame_generator_(std::move(frame_generator)),
data_(std::move(data)), data_(std::move(data)),
...@@ -108,7 +132,8 @@ DecodingImageGenerator::DecodingImageGenerator( ...@@ -108,7 +132,8 @@ DecodingImageGenerator::DecodingImageGenerator(
is_eligible_for_accelerated_decoding_( is_eligible_for_accelerated_decoding_(
is_eligible_for_accelerated_decoding), is_eligible_for_accelerated_decoding),
can_yuv_decode_(can_yuv_decode), can_yuv_decode_(can_yuv_decode),
complete_frame_content_id_(complete_frame_content_id) {} complete_frame_content_id_(complete_frame_content_id),
image_type_(image_type) {}
DecodingImageGenerator::~DecodingImageGenerator() = default; DecodingImageGenerator::~DecodingImageGenerator() = default;
......
...@@ -64,7 +64,8 @@ class PLATFORM_EXPORT DecodingImageGenerator final ...@@ -64,7 +64,8 @@ class PLATFORM_EXPORT DecodingImageGenerator final
PaintImage::ContentId, PaintImage::ContentId,
bool all_data_received, bool all_data_received,
bool is_eligible_for_accelerated_decoding, bool is_eligible_for_accelerated_decoding,
bool can_yuv_decode); bool can_yuv_decode,
String image_type);
~DecodingImageGenerator() override; ~DecodingImageGenerator() override;
...@@ -87,6 +88,7 @@ class PLATFORM_EXPORT DecodingImageGenerator final ...@@ -87,6 +88,7 @@ class PLATFORM_EXPORT DecodingImageGenerator final
uint32_t lazy_pixel_ref) override; uint32_t lazy_pixel_ref) override;
SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override; SkISize GetSupportedDecodeSize(const SkISize& requested_size) const override;
PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const override; PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const override;
PaintImage::ImageType GetImageType() const override { return image_type_; }
private: private:
DecodingImageGenerator(scoped_refptr<ImageFrameGenerator>, DecodingImageGenerator(scoped_refptr<ImageFrameGenerator>,
...@@ -96,7 +98,8 @@ class PLATFORM_EXPORT DecodingImageGenerator final ...@@ -96,7 +98,8 @@ class PLATFORM_EXPORT DecodingImageGenerator final
PaintImage::ContentId, PaintImage::ContentId,
bool all_data_received, bool all_data_received,
bool is_eligible_for_accelerated_decoding, bool is_eligible_for_accelerated_decoding,
bool can_yuv_decode); bool can_yuv_decode,
PaintImage::ImageType image_type);
scoped_refptr<ImageFrameGenerator> frame_generator_; scoped_refptr<ImageFrameGenerator> frame_generator_;
const scoped_refptr<SegmentReader> data_; // Data source. const scoped_refptr<SegmentReader> data_; // Data source.
...@@ -104,6 +107,9 @@ class PLATFORM_EXPORT DecodingImageGenerator final ...@@ -104,6 +107,9 @@ class PLATFORM_EXPORT DecodingImageGenerator final
const bool is_eligible_for_accelerated_decoding_; const bool is_eligible_for_accelerated_decoding_;
const bool can_yuv_decode_; const bool can_yuv_decode_;
const PaintImage::ContentId complete_frame_content_id_; const PaintImage::ContentId complete_frame_content_id_;
// The image file kind as returned by the underlying decoder and
// translated into PaintImage::ImageType.
const PaintImage::ImageType image_type_;
DISALLOW_COPY_AND_ASSIGN(DecodingImageGenerator); DISALLOW_COPY_AND_ASSIGN(DecodingImageGenerator);
}; };
......
...@@ -238,7 +238,7 @@ sk_sp<PaintImageGenerator> DeferredImageDecoder::CreateGenerator(size_t index) { ...@@ -238,7 +238,7 @@ sk_sp<PaintImageGenerator> DeferredImageDecoder::CreateGenerator(size_t index) {
frame_generator_, info, std::move(segment_reader), std::move(frames), frame_generator_, info, std::move(segment_reader), std::move(frames),
complete_frame_content_id_, all_data_received_, complete_frame_content_id_, all_data_received_,
!incremental_decode_needed_.value() /* able to do accelerated decoding */, !incremental_decode_needed_.value() /* able to do accelerated decoding */,
can_yuv_decode_); can_yuv_decode_, image_type);
first_decoding_generator_created_ = true; first_decoding_generator_created_ = true;
size_t image_byte_size = ByteSize(); size_t image_byte_size = ByteSize();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment