Index: third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp |
index b7b79c3656410450041b3ac09c617307c4f5606a..4a0eda73ca5b9b88cdc2ca8c528b9dc000d520a7 100644 |
--- a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp |
@@ -35,9 +35,12 @@ |
#include "platform/geometry/FloatRect.h" |
#include "platform/geometry/LayoutRect.h" |
#include "platform/graphics/BitmapImage.h" |
+#include "platform/graphics/ColorSpaceFilter.h" |
+#include "platform/graphics/ColorSpaceProfile.h" |
#include "platform/graphics/FirstPaintInvalidationTracking.h" |
#include "platform/graphics/GraphicsContext.h" |
#include "platform/graphics/GraphicsLayerFactory.h" |
+#include "platform/graphics/GraphicsScreen.h" |
#include "platform/graphics/Image.h" |
#include "platform/graphics/LinkHighlight.h" |
#include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
@@ -54,6 +57,7 @@ |
#include "public/platform/WebLayer.h" |
#include "public/platform/WebPoint.h" |
#include "public/platform/WebSize.h" |
+#include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
#include "wtf/CurrentTime.h" |
#include "wtf/HashMap.h" |
#include "wtf/HashSet.h" |
@@ -1082,8 +1086,23 @@ void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum |
{ |
RefPtr<SkImage> skImage = image ? image->imageForCurrentFrame() : nullptr; |
- if (image && skImage && image->isBitmapImage()) { |
- if (respectImageOrientation == RespectImageOrientation) { |
+ RefPtr<SkColorFilter> colorTransform; |
+ |
+ if (skImage && image->isBitmapImage()) { |
+ RELEASE_ASSERT(currentScreenId()); // There should be an active graphics screen. |
+ |
+ if (imageColorProfilesEnabled() && toBitmapImage(image)->hasColorProfile()) { |
+ // FIXME: In an experiment, I passed a SkColorCubeFilter to the GPU and that works. But note |
+ // that a SkColorCurveFilter does not - it gets dropped on floor somewhere after CC sends it |
+ // to the GPU process (maybe because SkColorCurveFilter has float-16 (HALF_FLOAT) textures, |
+ // whereas SkColorCubeFilter does not?). |
+ if (RefPtr<ColorSpaceProfile> source = toBitmapImage(image)->colorProfile()) { |
+ RefPtr<ColorSpaceProfile> target = screenColorProfile(currentScreenId()); |
+ colorTransform = createColorSpaceFilter(source.get(), target.get()); |
+ } |
+ } |
+ |
+ if (skImage && respectImageOrientation == RespectImageOrientation) { |
ImageOrientation imageOrientation = toBitmapImage(image)->currentFrameOrientation(); |
skImage = DragImage::resizeAndOrientImage(skImage.release(), imageOrientation); |
} |
@@ -1105,6 +1124,14 @@ void GraphicsLayer::setContentsToImage(Image* image, RespectImageOrientationEnum |
} |
setContentsTo(m_imageLayer ? m_imageLayer->layer() : 0); |
+ |
+ if (!imageColorProfilesEnabled()) |
+ return; |
+ |
+ if (colorTransform) |
+ setContentsLayerColorTransform(colorSpaceFlattenableFilter(colorTransform.get())); |
+ else |
+ setContentsLayerColorTransform(nullptr); |
} |
bool GraphicsLayer::addAnimation(PassOwnPtr<WebCompositorAnimation> popAnimation) |
@@ -1138,6 +1165,21 @@ WebLayer* GraphicsLayer::platformLayer() const |
return m_layer->layer(); |
} |
+void GraphicsLayer::setContentsLayerColorTransform(PassRefPtr<SkColorFilter> filter) |
+{ |
+ if (!m_contentsLayer) |
+ return; |
+ |
+ RefPtr<SkImageFilter> colorTransform; |
+ if (RefPtr<SkColorFilter> colorFilter = filter) |
+ colorTransform = adoptRef(SkColorFilterImageFilter::Create(colorFilter.get())); |
+ |
+ OwnPtr<WebFilterOperations> webFilters = adoptPtr(Platform::current()->compositorSupport()->createFilterOperations()); |
+ if (colorTransform) |
+ webFilters->appendReferenceFilter(colorTransform.get()); |
+ m_contentsLayer->setFilters(*webFilters); |
+} |
+ |
void GraphicsLayer::setFilters(const FilterOperations& filters) |
{ |
SkiaImageFilterBuilder builder; |