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..df304018b8f9666a0155c9f21a28de0aac50901e 100644 |
--- a/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/ImagePattern.cpp |
@@ -4,6 +4,8 @@ |
#include "platform/graphics/ImagePattern.h" |
+#include "platform/graphics/BitmapImage.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" |
@@ -22,6 +24,18 @@ ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode) |
: Pattern(repeatMode) |
, m_tileImage(image->imageForCurrentFrame()) |
{ |
+ if (!m_tileImage) |
+ return; |
+ |
+ // Patterns of tagged images (those that have a color profile) are drawn to sRGB |
+ // on supported platforms. The only allowed caller is the <canvas> element. Grab |
+ // the image assuming <canvas>: createShader() checks for it again on draw. |
+ |
+ if (image->isBitmapImage()) { |
+ WillPaintForDevice device(ScreenDevice::sRGBCanvas); |
+ m_tileImage = toBitmapImage(image.get())->pictureForCurrentFrame(); |
+ } |
+ |
if (m_tileImage) { |
// TODO(fmalita): mechanism to extract the actual SkImageInfo from an SkImage? |
const SkImageInfo info = |
@@ -32,6 +46,8 @@ ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode) |
PassRefPtr<SkShader> ImagePattern::createShader() |
{ |
+ RELEASE_ASSERT(currentScreenId() == ScreenDevice::sRGBCanvas); |
+ |
if (!m_tileImage) |
return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); |
@@ -58,18 +74,21 @@ 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.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 |