Index: third_party/WebKit/Source/core/html/HTMLVideoElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp b/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp |
index ab6deeb1a452b50dac4f0d1c44d344b7e6da9446..cad1b5f29451c890e4b1bcb9d4c360689b4284e6 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLVideoElement.cpp |
@@ -41,7 +41,10 @@ |
#include "core/layout/LayoutVideo.h" |
#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/UserGestureIndicator.h" |
+#include "platform/graphics/ColorSpaceFilter.h" |
+#include "platform/graphics/ColorSpaceProfile.h" |
#include "platform/graphics/GraphicsContext.h" |
+#include "platform/graphics/GraphicsScreen.h" |
#include "platform/graphics/ImageBuffer.h" |
#include "platform/graphics/gpu/Extensions3DUtil.h" |
#include "public/platform/WebCanvas.h" |
@@ -194,7 +197,7 @@ void HTMLVideoElement::updateDisplayState() |
setDisplayMode(Poster); |
} |
-void HTMLVideoElement::paintCurrentFrame(SkCanvas* canvas, const IntRect& destRect, const SkPaint* paint) const |
+void HTMLVideoElement::paintCurrentFrame(SkCanvas* canvas, const IntRect& destRect, const SkPaint* paint, ColorSpaceProfile* target) const |
{ |
if (!webMediaPlayer()) |
return; |
@@ -203,8 +206,31 @@ void HTMLVideoElement::paintCurrentFrame(SkCanvas* canvas, const IntRect& destRe |
if (!paint || !SkXfermode::AsMode(paint->getXfermode(), &mode)) |
mode = SkXfermode::kSrcOver_Mode; |
+ // FIXME: read the video color space from the video frame and use it as the source color profile |
+ // rather than assuming an sRGB source as is done here. |
+ RefPtr<SkColorFilter> colorTransform; |
+ if (RefPtr<ColorSpaceProfile> targetProfile = target) { |
+ RefPtr<ColorSpaceProfile> sourceProfile = screenColorProfile(ScreenDevice::sRGB); |
+ colorTransform = createColorSpaceFilter(sourceProfile.get(), targetProfile.get()); |
+ } |
+ |
+ SkPictureRecorder recorder; |
+ IntRect sourceRect = IntRect(0, 0, videoWidth(), videoHeight()); |
+ SkCanvas* recordingCanvas = recorder.beginRecording(sourceRect); |
// TODO(junov, philipj): crbug.com/456529 Pass the whole SkPaint instead of only alpha and xfermode |
- webMediaPlayer()->paint(canvas, destRect, paint ? paint->getAlpha() : 0xFF, mode); |
+ // and maybe correctly handle the video source color profile as well. |
+ webMediaPlayer()->paint(recordingCanvas, sourceRect, 0xFF, SkXfermode::kSrc_Mode); |
+ RefPtr<SkPicture> recorded = adoptRef(recorder.endRecording()); |
+ |
+ SkPaint transformPaint; |
+ transformPaint.setColorFilter(colorTransform.get()); |
+ transformPaint.setAlpha(paint ? paint->getAlpha() : 0xFF); |
+ transformPaint.setXfermodeMode(mode); |
+ transformPaint.setFilterQuality(kLow_SkFilterQuality); |
+ |
+ SkISize size = SkISize::Make(videoWidth(), videoHeight()); |
+ RefPtr<SkImage> image = adoptRef(SkImage::NewFromPicture(recorded.get(), size, nullptr, nullptr)); |
+ canvas->drawImageRect(image.get(), SkIRect::MakeSize(size), destRect, &transformPaint); |
} |
bool HTMLVideoElement::copyVideoTextureToPlatformTexture(WebGraphicsContext3D* context, Platform3DObject texture, GLenum internalFormat, GLenum type, bool premultiplyAlpha, bool flipY) |
@@ -300,7 +326,7 @@ PassRefPtr<Image> HTMLVideoElement::getSourceImageForCanvas(SourceImageStatus* s |
return nullptr; |
} |
- paintCurrentFrame(imageBuffer->canvas(), IntRect(IntPoint(0, 0), intrinsicSize), nullptr); |
+ paintCurrentFrame(imageBuffer->canvas(), IntRect(IntPoint(0, 0), intrinsicSize), nullptr, nullptr); |
RefPtr<Image> snapshot = imageBuffer->newImageSnapshot(); |
if (!snapshot) { |
*status = InvalidSourceImageStatus; |