Index: third_party/WebKit/Source/platform/graphics/Image.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/Image.cpp b/third_party/WebKit/Source/platform/graphics/Image.cpp |
index ed58bd10ca9fa0e793a0eccd991e95c36dc51f0f..9326a30b034c7f0a46fc495359bfaf3c19f132ef 100644 |
--- a/third_party/WebKit/Source/platform/graphics/Image.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/Image.cpp |
@@ -36,8 +36,11 @@ |
#include "platform/geometry/FloatRect.h" |
#include "platform/geometry/FloatSize.h" |
#include "platform/graphics/BitmapImage.h" |
+#include "platform/graphics/ColorSpaceFilter.h" |
+#include "platform/graphics/ColorSpaceProfile.h" |
#include "platform/graphics/DeferredImageDecoder.h" |
#include "platform/graphics/GraphicsContext.h" |
+#include "platform/graphics/GraphicsScreen.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebData.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
@@ -183,30 +186,26 @@ void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& dstRect, const Flo |
startAnimation(); |
} |
-namespace { |
- |
-PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shaderMatrix, |
- const SkPaint& paint, const FloatSize& spacing) |
+static PassRefPtr<SkShader> createPatternShader(const SkImage* image, SkPaint* paint, const SkMatrix& shaderMatrix, const FloatSize& spacing) |
{ |
if (spacing.isZero()) |
return adoptRef(image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix)); |
- // Arbitrary tiling is currently only supported for SkPictureShader - so we use it instead |
- // of a plain bitmap shader to implement spacing. |
- const SkRect tileRect = SkRect::MakeWH( |
- image->width() + spacing.width(), |
- image->height() + spacing.height()); |
+ // Arbitrary tiling is currently only supported for SkPictureShader so use it, instead |
+ // of a plain bitmap shader, to implement spacing (CSS background-repeat: space). |
+ SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), image->height() + spacing.height()); |
SkPictureRecorder recorder; |
SkCanvas* canvas = recorder.beginRecording(tileRect); |
- canvas->drawImage(image, 0, 0, &paint); |
+ canvas->drawImage(image, 0, 0, paint); |
RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture()); |
- return adoptRef(SkShader::CreatePictureShader( |
- picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, nullptr)); |
-} |
+ // Remove any color filter from callers paint: it is applied when drawing the SkPicture |
+ // shader: clearing it here prevents caller from applying the filter twice. |
+ paint->setColorFilter(nullptr); |
-} // anonymous namespace |
+ return adoptRef(SkShader::CreatePictureShader(picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, nullptr)); |
+} |
void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, const FloatSize& scale, |
const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& destRect, const FloatSize& repeatSpacing) |
@@ -218,7 +217,6 @@ void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, |
return; |
FloatRect normSrcRect = floatSrcRect; |
- |
normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); |
if (destRect.isEmpty() || normSrcRect.isEmpty()) |
return; // nothing to draw |
@@ -236,24 +234,28 @@ void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, |
// set to the pattern's transform, which just includes scale. |
localMatrix.preScale(scale.width(), scale.height()); |
- // Fetch this now as subsetting may swap the image. |
+ // Fetch the image ID now since subsetting and/or the application of color |
+ // transforms may swap out the image. |
auto imageID = image->uniqueID(); |
+ if (imageColorProfilesEnabled() && this->isBitmapImage()) |
+ image = toBitmapImage(this)->pictureForCurrentFrame(); |
+ |
image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); |
if (!image) |
return; |
- { |
- SkPaint paint = context.fillPaint(); |
- paint.setColor(SK_ColorBLACK); |
- paint.setXfermodeMode(compositeOp); |
- paint.setFilterQuality(context.computeFilterQuality(this, destRect, normSrcRect)); |
- paint.setAntiAlias(context.shouldAntialias()); |
- RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix, paint, |
- FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.height() / scale.height())); |
- paint.setShader(shader.get()); |
- context.drawRect(destRect, paint); |
- } |
+ SkPaint paint = context.fillPaint(); |
+ paint.setColor(SK_ColorBLACK); // FIXME: not color correct. |
+ paint.setXfermodeMode(compositeOp); |
+ paint.setFilterQuality(context.computeFilterQuality(this, destRect, normSrcRect)); |
+ paint.setAntiAlias(context.shouldAntialias()); |
+ |
+ FloatSize spacing = FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.height() / scale.height()); |
+ RefPtr<SkShader> shader = createPatternShader(image.get(), &paint, localMatrix, spacing); |
+ paint.setShader(shader.get()); |
+ |
+ context.drawRect(destRect, paint); |
if (currentFrameIsLazyDecoded()) |
PlatformInstrumentation::didDrawLazyPixelRef(imageID); |