| Index: third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp b/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
|
| index 1db843e4db952283a979b46c9f8a9d3936842774..089091a3fb3eac7a66372d34fa3797cbd92aaa26 100644
|
| --- a/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
|
| +++ b/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp
|
| @@ -4,9 +4,14 @@
|
|
|
| #include "platform/graphics/ImagePattern.h"
|
|
|
| +#include "platform/graphics/BitmapImage.h"
|
| +#include "platform/graphics/ColorSpaceFilter.h"
|
| +#include "platform/graphics/ColorSpaceProfile.h"
|
| +#include "platform/graphics/GraphicsScreen.h"
|
| #include "platform/graphics/Image.h"
|
| #include "platform/graphics/skia/SkiaUtils.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkColorFilter.h"
|
| #include "third_party/skia/include/core/SkImage.h"
|
| #include "third_party/skia/include/core/SkShader.h"
|
| #include "third_party/skia/include/core/SkSurface.h"
|
| @@ -21,6 +26,7 @@ PassRefPtr<ImagePattern> ImagePattern::create(PassRefPtr<Image> image, RepeatMod
|
| ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode)
|
| : Pattern(repeatMode)
|
| , m_tileImage(image->imageForCurrentFrame())
|
| + , m_image(image)
|
| {
|
| if (m_tileImage) {
|
| // TODO(fmalita): mechanism to extract the actual SkImageInfo from an SkImage?
|
| @@ -30,14 +36,34 @@ ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode)
|
| }
|
| }
|
|
|
| +inline PassRefPtr<ColorSpaceProfile> sourceColorProfile(Image* image)
|
| +{
|
| + return image->isBitmapImage() ? toBitmapImage(image)->colorProfile() : nullptr;
|
| +}
|
| +
|
| PassRefPtr<SkShader> ImagePattern::createShader()
|
| {
|
| if (!m_tileImage)
|
| return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT));
|
|
|
| + // Patterns of tagged images (those that have a color profile) are drawn to sRGB
|
| + // on supported platforms. Note the only allowed caller is the <canvas> element.
|
| + RefPtr<SkColorFilter> colorTransform;
|
| + if (RefPtr<ColorSpaceProfile> source = sourceColorProfile(m_image.get())) {
|
| + RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenId());
|
| + colorTransform = createColorSpaceFilter(source.get(), screen.get());
|
| +
|
| + if (currentScreenId()) {
|
| + fprintf(stderr, "ImagePattern::createShader has a non-zero page %ld\n", (long int)currentScreenId());
|
| + fflush(stderr);
|
| + }
|
| +
|
| + RELEASE_ASSERT(!currentScreenId()); // Check caller is an HTML <canvas>.
|
| + }
|
| +
|
| SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformation);
|
|
|
| - if (isRepeatXY()) {
|
| + if (isRepeatXY() && !colorTransform.get()) {
|
| // Fast path: for repeatXY we just return a shader from the original image.
|
| return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode,
|
| SkShader::kRepeat_TileMode, &localMatrix));
|
| @@ -58,18 +84,22 @@ PassRefPtr<SkShader> ImagePattern::createShader()
|
| // Create a transparent image 1 pixel wider and/or taller than the
|
| // original, then copy the orignal into it.
|
| // FIXME: Is there a better way to pad (not scale) an image in skia?
|
| + // since the drawing is noticably pixelated compared to drawing the
|
| + // same tiled image with Image:drawTiled (which is used to draw CSS
|
| + // background-image repeat tiles).
|
| RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(
|
| m_tileImage->width() + expandW, m_tileImage->height() + expandH));
|
| if (!surface)
|
| return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT));
|
| -
|
| surface->getCanvas()->clear(SK_ColorTRANSPARENT);
|
| +
|
| SkPaint paint;
|
| + paint.setColorFilter(colorTransform.get());
|
| paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
| surface->getCanvas()->drawImage(m_tileImage.get(), 0, 0, &paint);
|
| - RefPtr<SkImage> expandedImage = adoptRef(surface->newImageSnapshot());
|
|
|
| - return adoptRef(expandedImage->newShader(tileModeX, tileModeY, &localMatrix));
|
| + RefPtr<SkImage> image = adoptRef(surface->newImageSnapshot());
|
| + return adoptRef(image->newShader(tileModeX, tileModeY, &localMatrix));
|
| }
|
|
|
| bool ImagePattern::isTextureBacked() const
|
|
|