Commit bd28b6f5 authored by v.paturi's avatar v.paturi Committed by Commit Bot

Skip classification of images with css filters in dark mode.

CSS filters such as invert, greyscale etc. are not available
in DarkModeImageClassifier where the extraction of features
happens.

So we end up extracting the features on the original image
which is not what is seen on the user's screen.

Until we have a way to take the css filters into consideration
while extracting the features, it's safer to just skip the
feature extraction altogether when such filters do exist.

Bug: 1007925
Change-Id: I1b082a628709178e64aed488bb4656dd7044386a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824051Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarAran Gilman <gilmanmh@google.com>
Reviewed-by: default avatarPrashant Nevase <prashant.n@samsung.com>
Commit-Queue: Varun Chowdhary Paturi <v.paturi@samsung.com>
Cr-Commit-Position: refs/heads/master@{#702739}
parent ea7a5d2d
......@@ -739,6 +739,7 @@ void HTMLCanvasElement::PaintInternal(GraphicsContext& context,
context_->PaintRenderingResultsToCanvas(kFrontBuffer);
if (HasResourceProvider()) {
if (!context.ContextDisabled()) {
const ComputedStyle* style = GetComputedStyle();
// For 2D Canvas, there are two ways of render Canvas for printing:
// display list or image snapshot. Display list allows better PDF printing
// and we prefer this method.
......@@ -752,7 +753,6 @@ void HTMLCanvasElement::PaintInternal(GraphicsContext& context,
if (IsPrinting() && !Is3d() && canvas2d_bridge_) {
canvas2d_bridge_->FlushRecording();
if (canvas2d_bridge_->getLastRecord()) {
const ComputedStyle* style = GetComputedStyle();
if (style && style->ImageRendering() != EImageRendering::kPixelated) {
context.Canvas()->save();
context.Canvas()->translate(r.X(), r.Y());
......@@ -782,6 +782,7 @@ void HTMLCanvasElement::PaintInternal(GraphicsContext& context,
DCHECK(!snapshot->IsTextureBacked());
context.DrawImage(snapshot.get(), Image::kSyncDecode,
FloatRect(PixelSnappedIntRect(r)), &src_rect,
style && style->HasFilterInducingProperty(),
composite_operator);
}
}
......
......@@ -6,6 +6,7 @@
#include "base/optional.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/inspector_trace_events.h"
#include "third_party/blink/renderer/core/paint/background_image_geometry.h"
......@@ -383,7 +384,8 @@ void DrawTiledBackground(GraphicsContext& context,
const FloatPoint& phase,
const FloatSize& tile_size,
SkBlendMode op,
const FloatSize& repeat_spacing) {
const FloatSize& repeat_spacing,
bool has_filter_property) {
DCHECK(!tile_size.IsEmpty());
// Use the intrinsic size of the image if it has one, otherwise force the
......@@ -418,7 +420,8 @@ void DrawTiledBackground(GraphicsContext& context,
// calculations up the stack.
visible_src_rect = FloatRect(RoundedIntRect(visible_src_rect));
context.DrawImage(image, Image::kSyncDecode, snapped_paint_rect,
&visible_src_rect, op, kDoNotRespectImageOrientation);
&visible_src_rect, has_filter_property, op,
kDoNotRespectImageOrientation);
return;
}
......@@ -555,8 +558,10 @@ inline bool PaintFastBottomLayer(Node* node,
// Since there is no way for the developer to specify decode behavior, use
// kSync by default.
context.DrawImageRRect(image, Image::kSyncDecode, image_border, src_rect,
composite_op);
context.DrawImageRRect(
image, Image::kSyncDecode, image_border, src_rect,
node && node->ComputedStyleRef().HasFilterInducingProperty(),
composite_op);
if (RuntimeEnabledFeatures::FirstContentfulPaintPlusPlusEnabled()) {
if (info.image && info.image->IsImageResource()) {
......@@ -686,11 +691,13 @@ void PaintFillLayerBackground(GraphicsContext& context,
inspector_paint_image_event::Data(
node, *info.image, FloatRect(image->Rect()),
FloatRect(scrolled_paint_rect)));
DrawTiledBackground(context, image,
FloatSize(geometry.UnsnappedDestRect().size),
FloatRect(geometry.SnappedDestRect()), geometry.Phase(),
FloatSize(geometry.TileSize()), composite_op,
FloatSize(geometry.SpaceSize()));
DrawTiledBackground(
context, image, FloatSize(geometry.UnsnappedDestRect().size),
FloatRect(geometry.SnappedDestRect()), geometry.Phase(),
FloatSize(geometry.TileSize()), composite_op,
FloatSize(geometry.SpaceSize()),
node && node->ComputedStyleRef().HasFilterInducingProperty());
if (RuntimeEnabledFeatures::FirstContentfulPaintPlusPlusEnabled()) {
if (info.image && info.image->IsImageResource()) {
PaintTimingDetector::NotifyBackgroundImagePaint(
......
......@@ -246,6 +246,7 @@ void ImagePainter::PaintIntoRect(GraphicsContext& context,
context.DrawImage(
image.get(), decode_mode, FloatRect(pixel_snapped_dest_rect), &src_rect,
layout_image_.StyleRef().HasFilterInducingProperty(),
SkBlendMode::kSrcOver,
LayoutObject::ShouldRespectImageOrientation(&layout_image_));
if (RuntimeEnabledFeatures::ElementTimingEnabled(
......
......@@ -99,14 +99,14 @@ void PaintPieces(GraphicsContext& context,
// Since there is no way for the developer to specify decode behavior,
// use kSync by default.
context.DrawImage(image, Image::kSyncDecode, draw_info.destination,
&draw_info.source);
&draw_info.source, style.HasFilterInducingProperty());
} else if (draw_info.tile_rule.horizontal == kStretchImageRule &&
draw_info.tile_rule.vertical == kStretchImageRule) {
// Just do a scale.
// Since there is no way for the developer to specify decode behavior,
// use kSync by default.
context.DrawImage(image, Image::kSyncDecode, draw_info.destination,
&draw_info.source);
&draw_info.source, style.HasFilterInducingProperty());
} else {
// TODO(cavalcantii): see crbug.com/662513.
base::Optional<TileParameters> h_tile = ComputeTileParameters(
......
......@@ -78,7 +78,10 @@ void SVGImagePainter::PaintForeground(const PaintInfo& paint_info) {
layout_svg_image_.StyleRef().GetInterpolationQuality());
Image::ImageDecodingMode decode_mode =
image_element->GetDecodingModeForPainting(image->paint_image_id());
paint_info.context.DrawImage(image.get(), decode_mode, dest_rect, &src_rect);
paint_info.context.DrawImage(
image.get(), decode_mode, dest_rect, &src_rect,
layout_svg_image_.StyleRef().HasFilterInducingProperty());
if (RuntimeEnabledFeatures::ElementTimingEnabled(
&layout_svg_image_.GetDocument()) &&
!paint_info.context.ContextDisabled() && image_resource->CachedImage() &&
......
......@@ -916,6 +916,7 @@ void GraphicsContext::DrawImage(
Image::ImageDecodingMode decode_mode,
const FloatRect& dest,
const FloatRect* src_ptr,
bool has_filter_property,
SkBlendMode op,
RespectImageOrientationEnum should_respect_image_orientation) {
if (ContextDisabled() || !image)
......@@ -928,7 +929,9 @@ void GraphicsContext::DrawImage(
image_flags.setColor(SK_ColorBLACK);
image_flags.setFilterQuality(ComputeFilterQuality(image, dest, src));
dark_mode_filter_.ApplyToImageFlagsIfNeeded(src, dest, image, &image_flags);
// Do not classify the image if the element has any CSS filters.
if (!has_filter_property)
dark_mode_filter_.ApplyToImageFlagsIfNeeded(src, dest, image, &image_flags);
image->Draw(canvas_, image_flags, dest, src, should_respect_image_orientation,
Image::kClampImageToSourceRect, decode_mode);
......@@ -940,14 +943,15 @@ void GraphicsContext::DrawImageRRect(
Image::ImageDecodingMode decode_mode,
const FloatRoundedRect& dest,
const FloatRect& src_rect,
bool has_filter_property,
SkBlendMode op,
RespectImageOrientationEnum respect_orientation) {
if (ContextDisabled() || !image)
return;
if (!dest.IsRounded()) {
DrawImage(image, decode_mode, dest.Rect(), &src_rect, op,
respect_orientation);
DrawImage(image, decode_mode, dest.Rect(), &src_rect, has_filter_property,
op, respect_orientation);
return;
}
......
......@@ -222,6 +222,7 @@ class PLATFORM_EXPORT GraphicsContext {
Image::ImageDecodingMode,
const FloatRect& dest_rect,
const FloatRect* src_rect = nullptr,
bool has_filter_property = false,
SkBlendMode = SkBlendMode::kSrcOver,
RespectImageOrientationEnum = kDoNotRespectImageOrientation);
void DrawImageRRect(
......@@ -229,6 +230,7 @@ class PLATFORM_EXPORT GraphicsContext {
Image::ImageDecodingMode,
const FloatRoundedRect& dest,
const FloatRect& src_rect,
bool has_filter_property = false,
SkBlendMode = SkBlendMode::kSrcOver,
RespectImageOrientationEnum = kDoNotRespectImageOrientation);
void DrawImageTiled(Image* image,
......
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