Commit 62f57782 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for blink::BitmapImage

This CL has two goals,
  1. Use To<BitmapImage> and DynamicTo<BitmapImage> as new
   downcast helper
  2. Use IsA<BitmapImage>(element) in place of
   IsBitmapImage(element)

Bug: 891908
Change-Id: I1534b601cfae0f99adb15355f7f1042d1c889552
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019644Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#744303}
parent 2e435943
......@@ -123,7 +123,7 @@ TEST(ImageResourceTest, DimensionsDecodableFromPartialTestImage) {
image->SetData(SharedBuffer::Create(
kJpegImage, kJpegImageSubrangeWithDimensionsLength),
true));
EXPECT_TRUE(image->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image.get()));
EXPECT_EQ(1, image->width());
EXPECT_EQ(1, image->height());
}
......@@ -310,7 +310,7 @@ void TestThatIsPlaceholderRequestAndServeResponse(
// A placeholder image.
EXPECT_TRUE(image_resource->ShouldShowPlaceholder());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_FALSE(IsA<SVGImage>(image_resource->GetContent()->GetImage()));
}
......@@ -352,7 +352,7 @@ void TestThatIsNotPlaceholderRequestAndServeResponse(
// A non-placeholder bitmap image.
EXPECT_FALSE(image_resource->ShouldShowPlaceholder());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_FALSE(IsA<SVGImage>(image_resource->GetContent()->GetImage()));
}
......@@ -481,7 +481,7 @@ TEST(ImageResourceTest, BitmapMultipartImage) {
image_resource->AppendData(kBoundary, strlen(kBoundary));
image_resource->Loader()->DidFinishLoading(base::TimeTicks(), 0, 0, 0, false);
EXPECT_TRUE(image_resource->GetContent()->HasImage());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_TRUE(image_resource->GetContent()
->GetImage()
->PaintImageForCurrentFrame()
......@@ -636,7 +636,7 @@ TEST(ImageResourceTest, UpdateBitmapImages) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
}
TEST(ImageResourceReloadTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
......@@ -677,7 +677,7 @@ TEST(ImageResourceTest, SVGImage) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(1, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
}
TEST(ImageResourceTest, SVGImageWithSubresource) {
......@@ -692,7 +692,7 @@ TEST(ImageResourceTest, SVGImageWithSubresource) {
EXPECT_FALSE(image_resource->ErrorOccurred());
ASSERT_TRUE(image_resource->GetContent()->HasImage());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
// At this point, image is (mostly) available but the loading is not yet
// finished because of SVG's subresources, and thus ImageChanged() or
......@@ -740,7 +740,7 @@ TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
......@@ -756,7 +756,7 @@ TEST(ImageResourceTest, SuccessfulRevalidationJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
......@@ -776,7 +776,7 @@ TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(1, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->height());
......@@ -790,7 +790,7 @@ TEST(ImageResourceTest, SuccessfulRevalidationSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(1, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->height());
}
......@@ -810,7 +810,7 @@ TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
......@@ -825,7 +825,7 @@ TEST(ImageResourceTest, FailedRevalidationJpegToJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(4, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height());
}
......@@ -845,7 +845,7 @@ TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
......@@ -859,7 +859,7 @@ TEST(ImageResourceTest, FailedRevalidationJpegToSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(3, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->height());
}
......@@ -878,7 +878,7 @@ TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(1, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->height());
......@@ -892,7 +892,7 @@ TEST(ImageResourceTest, FailedRevalidationSvgToJpeg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(3, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(kJpegImageWidth, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
......@@ -912,7 +912,7 @@ TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(1, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(200, image_resource->GetContent()->GetImage()->height());
......@@ -925,7 +925,7 @@ TEST(ImageResourceTest, FailedRevalidationSvgToSvg) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(2, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_FALSE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(300, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(300, image_resource->GetContent()->GetImage()->height());
}
......@@ -1294,7 +1294,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
// |imageResource2| is still a non-placeholder image.
EXPECT_FALSE(image_resource2->ShouldShowPlaceholder());
EXPECT_TRUE(image_resource2->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource2->GetContent()->GetImage()));
}
TEST(ImageResourceTest,
......@@ -1389,7 +1389,7 @@ TEST(ImageResourceTest, FetchAllowPlaceholderFullResponseDecodeSuccess) {
image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(kJpegImageHeight,
image_resource->GetContent()->GetImage()->height());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
}
}
......@@ -1584,7 +1584,7 @@ TEST(ImageResourceTest, PeriodicFlushTest) {
EXPECT_FALSE(image_resource->GetContent()->GetImage()->IsNull());
EXPECT_EQ(5, observer->ImageChangedCount());
EXPECT_TRUE(observer->ImageNotifyFinishedCalled());
EXPECT_TRUE(image_resource->GetContent()->GetImage()->IsBitmapImage());
EXPECT_TRUE(IsA<BitmapImage>(image_resource->GetContent()->GetImage()));
EXPECT_EQ(50, image_resource->GetContent()->GetImage()->width());
EXPECT_EQ(50, image_resource->GetContent()->GetImage()->height());
}
......
......@@ -109,9 +109,10 @@ std::unique_ptr<DragImage> DragImage::Create(
return nullptr;
ImageOrientation orientation;
auto* bitmap_image = DynamicTo<BitmapImage>(image);
if (should_respect_image_orientation == kRespectImageOrientation &&
image->IsBitmapImage())
orientation = ToBitmapImage(image)->CurrentFrameOrientation();
bitmap_image)
orientation = bitmap_image->CurrentFrameOrientation();
SkBitmap bm;
paint_image = Image::ResizeAndOrientImage(
......
......@@ -1578,8 +1578,7 @@ bool CompositedLayerMapping::IsDirectlyCompositedImage() const {
if (!cached_image->HasImage())
return false;
Image* image = cached_image->GetImage();
if (!image->IsBitmapImage())
if (!IsA<BitmapImage>(cached_image->GetImage()))
return false;
UseCounter::Count(GetLayoutObject().GetDocument(),
......
......@@ -25,6 +25,7 @@
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/graphics/bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/graphics/paint/float_clip_rect.h"
#include "third_party/blink/renderer/platform/graphics/paint/geometry_mapper.h"
......@@ -52,7 +53,7 @@ bool IsBackgroundImageContentful(const LayoutObject& object,
}
// Generated images are excluded here, as they are likely to serve for
// background purpose.
if (!image.IsBitmapImage() && !image.IsStaticBitmapImage() &&
if (!IsA<BitmapImage>(image) && !image.IsStaticBitmapImage() &&
!IsA<SVGImage>(image) && !image.IsPlaceholderImage())
return false;
return true;
......
......@@ -38,6 +38,7 @@
#include "third_party/blink/renderer/platform/graphics/image_animation_policy.h"
#include "third_party/blink/renderer/platform/image-decoders/image_animation.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/skia/include/core/SkRefCnt.h"
......@@ -184,7 +185,10 @@ class PLATFORM_EXPORT BitmapImage final : public Image {
PaintImage::AnimationSequenceId reset_animation_sequence_id_ = 0;
};
DEFINE_IMAGE_TYPE_CASTS(BitmapImage);
template <>
struct DowncastTraits<BitmapImage> {
static bool AllowFrom(const Image& image) { return image.IsBitmapImage(); }
};
} // namespace blink
......
......@@ -648,9 +648,10 @@ void GraphicsLayer::SetContentsToImage(
ImageOrientation image_orientation = kOriginTopLeft;
SkMatrix matrix;
if (paint_image && image->IsBitmapImage() &&
auto* bitmap_image = DynamicTo<BitmapImage>(image);
if (paint_image && bitmap_image &&
respect_image_orientation == kRespectImageOrientation) {
image_orientation = ToBitmapImage(image)->CurrentFrameOrientation();
image_orientation = bitmap_image->CurrentFrameOrientation();
image_size_ = IntSize(paint_image.width(), paint_image.height());
if (image_orientation.UsesWidthAsHeight())
image_size_ = image_size_.TransposedSize();
......
......@@ -338,10 +338,9 @@ SkBitmap Image::AsSkBitmapForCurrentFrame(
if (!paint_image)
return {};
if (respect_image_orientation == kRespectImageOrientation &&
IsBitmapImage()) {
ImageOrientation orientation =
ToBitmapImage(this)->CurrentFrameOrientation();
auto* bitmap_image = DynamicTo<BitmapImage>(this);
if (respect_image_orientation == kRespectImageOrientation && bitmap_image) {
ImageOrientation orientation = bitmap_image->CurrentFrameOrientation();
paint_image = ResizeAndOrientImage(paint_image, orientation);
if (!paint_image)
return {};
......
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