diff options
author | cabanier@adobe.com <cabanier@adobe.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-05-09 04:50:40 +0000 |
---|---|---|
committer | cabanier@adobe.com <cabanier@adobe.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-05-09 04:50:40 +0000 |
commit | aef1dc37b5293ef76ad4e7c99ccacd5f1e8651a5 (patch) | |
tree | 3f34603407a67bc043dc1a671dee6073ef194b39 | |
parent | ef6e000b7b2a189efe5ae79a881f91ea9cd27223 (diff) | |
download | chromium_src-aef1dc37b5293ef76ad4e7c99ccacd5f1e8651a5.zip chromium_src-aef1dc37b5293ef76ad4e7c99ccacd5f1e8651a5.tar.gz chromium_src-aef1dc37b5293ef76ad4e7c99ccacd5f1e8651a5.tar.bz2 |
Add canvas blending modes behind a runtime flag
Refresh of https://codereview.chromium.org/13637006/
BUG=229111
TEST=fast/canvas/canvas-blend-*
I duplicated issue https://codereview.chromium.org/13637006/ because Ion has no committer right and can't run his patch on the try bots
Review URL: https://chromiumcodereview.appspot.com/14679003
git-svn-id: svn://svn.chromium.org/blink/trunk@150004 bbb929c8-8fbe-4397-9dbb-9b2b20218538
11 files changed, 50 insertions, 19 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-image-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-image-expected.txt index 65eaefe..8a2726d 100644 --- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-image-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-image-expected.txt @@ -538,7 +538,7 @@ PASS pixelDataAtPoint(1)[1] is within 5 of 128 PASS pixelDataAtPoint(1)[2] is within 5 of 127 PASS pixelDataAtPoint(1)[3] is within 5 of 255 PASS pixelDataAtPoint(2)[0] is within 5 of 0 -PASS pixelDataAtPoint(2)[1] is within 5 of 0 +PASS pixelDataAtPoint(2)[1] is within 5 of 64 PASS pixelDataAtPoint(2)[2] is within 5 of 127 PASS pixelDataAtPoint(2)[3] is within 5 of 255 PASS pixelDataAtPoint(3)[0] is within 5 of 0 @@ -555,7 +555,7 @@ PASS pixelDataAtPoint(1)[1] is within 5 of 85 PASS pixelDataAtPoint(1)[2] is within 5 of 170 PASS pixelDataAtPoint(1)[3] is within 5 of 191 PASS pixelDataAtPoint(2)[0] is within 5 of 0 -PASS pixelDataAtPoint(2)[1] is within 5 of 0 +PASS pixelDataAtPoint(2)[1] is within 5 of 42 PASS pixelDataAtPoint(2)[2] is within 5 of 170 PASS pixelDataAtPoint(2)[3] is within 5 of 191 PASS pixelDataAtPoint(3)[0] is within 5 of 0 diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-solid-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-solid-expected.txt index 65eaefe..8a2726d 100644 --- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-solid-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-blend-solid-expected.txt @@ -538,7 +538,7 @@ PASS pixelDataAtPoint(1)[1] is within 5 of 128 PASS pixelDataAtPoint(1)[2] is within 5 of 127 PASS pixelDataAtPoint(1)[3] is within 5 of 255 PASS pixelDataAtPoint(2)[0] is within 5 of 0 -PASS pixelDataAtPoint(2)[1] is within 5 of 0 +PASS pixelDataAtPoint(2)[1] is within 5 of 64 PASS pixelDataAtPoint(2)[2] is within 5 of 127 PASS pixelDataAtPoint(2)[3] is within 5 of 255 PASS pixelDataAtPoint(3)[0] is within 5 of 0 @@ -555,7 +555,7 @@ PASS pixelDataAtPoint(1)[1] is within 5 of 85 PASS pixelDataAtPoint(1)[2] is within 5 of 170 PASS pixelDataAtPoint(1)[3] is within 5 of 191 PASS pixelDataAtPoint(2)[0] is within 5 of 0 -PASS pixelDataAtPoint(2)[1] is within 5 of 0 +PASS pixelDataAtPoint(2)[1] is within 5 of 42 PASS pixelDataAtPoint(2)[2] is within 5 of 170 PASS pixelDataAtPoint(2)[3] is within 5 of 191 PASS pixelDataAtPoint(3)[0] is within 5 of 0 diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-image.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-image.js index 5cd0478..e0698ce 100644 --- a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-image.js +++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-image.js @@ -66,11 +66,10 @@ var blendModes = [[85, 0, 170, 191],[85, 85, 170, 191],[0, 43, 170, 191],[0, 0, 255, 191]] ], ['color-burn', - [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], - [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], - [[128, 0, 127, 255],[128, 128, 127, 255],[0, 0, 127, 255],[0, 0, 255, 255]], - [[85, 0, 170, 191],[85, 85, 170, 191],[0, 0, 170, 191],[0, 0, 255, 191]] - + [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], + [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], + [[128, 0, 127, 255],[128, 128, 127, 255],[0, 64, 127, 255],[0, 0, 255, 255]], + [[85, 0, 170, 191],[85, 85, 170, 191],[0, 42, 170, 191],[0, 0, 255, 191]] ], ['hard-light', [[255, 0, 0, 255],[255, 255, 0, 255],[0, 1, 0, 255],[0, 0, 255, 255]], @@ -173,4 +172,4 @@ function prepareTestScenario(sigma) { } // Run test and allow variation of results. -prepareTestScenario(5);
\ No newline at end of file +prepareTestScenario(5); diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-solid.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-solid.js index 4e3ca91..a05c67a 100644 --- a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-solid.js +++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-blend-solid.js @@ -69,8 +69,8 @@ var blendModes = ['color-burn', [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], [[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255],[0, 0, 255, 255]], - [[128, 0, 127, 255],[128, 128, 127, 255],[0, 0, 127, 255],[0, 0, 255, 255]], - [[85, 0, 170, 191],[85, 85, 170, 191],[0, 0, 170, 191],[0, 0, 255, 191]] + [[128, 0, 127, 255],[128, 128, 127, 255],[0, 64, 127, 255],[0, 0, 255, 255]], + [[85, 0, 170, 191],[85, 85, 170, 191],[0, 42, 170, 191],[0, 0, 255, 191]] ], ['hard-light', diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp index 3864544..0ecca0d 100644 --- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp +++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext2D.cpp @@ -35,6 +35,7 @@ #include "CSSPropertyNames.h" #include "HTMLNames.h" +#include "RuntimeEnabledFeatures.h" #include "core/css/CSSFontSelector.h" #include "core/css/CSSParser.h" #include "core/css/StylePropertySet.h" @@ -611,6 +612,8 @@ void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operati BlendMode blendMode = BlendModeNormal; if (!parseCompositeAndBlendOperator(operation, op, blendMode)) return; + if (!RuntimeEnabledFeatures::cssCompositingEnabled() && blendMode != BlendModeNormal) + blendMode = BlendModeNormal; if ((state().m_globalComposite == op) && (state().m_globalBlend == blendMode)) return; realizeSaves(); diff --git a/third_party/WebKit/Source/core/platform/graphics/GraphicsContext.cpp b/third_party/WebKit/Source/core/platform/graphics/GraphicsContext.cpp index 4ba40f3..b0d0653 100644 --- a/third_party/WebKit/Source/core/platform/graphics/GraphicsContext.cpp +++ b/third_party/WebKit/Source/core/platform/graphics/GraphicsContext.cpp @@ -1817,7 +1817,7 @@ void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation if (paintingDisabled()) return; - m_skiaState->m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation); + m_skiaState->m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode); } CompositeOperator GraphicsContext::compositeOperation() const diff --git a/third_party/WebKit/Source/core/platform/graphics/GraphicsTypes.h b/third_party/WebKit/Source/core/platform/graphics/GraphicsTypes.h index 586f7ec..5460118 100644 --- a/third_party/WebKit/Source/core/platform/graphics/GraphicsTypes.h +++ b/third_party/WebKit/Source/core/platform/graphics/GraphicsTypes.h @@ -47,6 +47,7 @@ namespace WebCore { CompositeDifference }; + // keep it in sync with gMapBlendOpsToXfermodeModes array in SkiaUtils.h enum BlendMode { BlendModeNormal, BlendModeMultiply, diff --git a/third_party/WebKit/Source/core/platform/graphics/skia/ImageBufferSkia.cpp b/third_party/WebKit/Source/core/platform/graphics/skia/ImageBufferSkia.cpp index 0917120..69464c7 100644 --- a/third_party/WebKit/Source/core/platform/graphics/skia/ImageBufferSkia.cpp +++ b/third_party/WebKit/Source/core/platform/graphics/skia/ImageBufferSkia.cpp @@ -259,11 +259,11 @@ static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) } void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, - CompositeOperator op, BlendMode, bool useLowQualityScale) + CompositeOperator op, BlendMode blendMode, bool useLowQualityScale) { const SkBitmap& bitmap = *m_context->bitmap(); RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsCopy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); - context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, DoNotRespectImageOrientation, useLowQualityScale); + context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, blendMode, DoNotRespectImageOrientation, useLowQualityScale); } void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform, diff --git a/third_party/WebKit/Source/core/platform/graphics/skia/ImageSkia.cpp b/third_party/WebKit/Source/core/platform/graphics/skia/ImageSkia.cpp index 92a0fb7f..88b804b 100644 --- a/third_party/WebKit/Source/core/platform/graphics/skia/ImageSkia.cpp +++ b/third_party/WebKit/Source/core/platform/graphics/skia/ImageSkia.cpp @@ -609,7 +609,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl draw(ctxt, dstRect, srcRect, colorSpace, compositeOp, blendMode, DoNotRespectImageOrientation); } -void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace colorSpace, CompositeOperator compositeOp, BlendMode, RespectImageOrientationEnum shouldRespectImageOrientation) +void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace colorSpace, CompositeOperator compositeOp, BlendMode blendMode, RespectImageOrientationEnum shouldRespectImageOrientation) { // Spin the animation to the correct frame before we try to draw it, so we // don't draw an old frame and then immediately need to draw a newer one, @@ -648,7 +648,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl } } - paintSkBitmap(ctxt, *bm, normSrcRect, normDstRect, WebCoreCompositeToSkiaComposite(compositeOp)); + paintSkBitmap(ctxt, *bm, normSrcRect, normDstRect, WebCoreCompositeToSkiaComposite(compositeOp, blendMode)); if (ImageObserver* observer = imageObserver()) observer->didDraw(this); diff --git a/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.cpp b/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.cpp index 9b343ff..d4330e4 100644 --- a/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.cpp +++ b/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.cpp @@ -61,8 +61,36 @@ static const struct CompositOpToXfermodeMode { { CompositePlusLighter, SkXfermode::kPlus_Mode } }; -SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op) +// keep this array in sync with BlendMode enum in GraphicsTypes.h +static const uint8_t gMapBlendOpsToXfermodeModes[] = { + SkXfermode::kClear_Mode, // BlendModeNormal + SkXfermode::kMultiply_Mode, // BlendModeMultiply + SkXfermode::kScreen_Mode, // BlendModeScreen + SkXfermode::kOverlay_Mode, // BlendModeOverlay + SkXfermode::kDarken_Mode, // BlendModeDarken + SkXfermode::kLighten_Mode, // BlendModeLighten + SkXfermode::kColorDodge_Mode, // BlendModeColorDodge + SkXfermode::kColorBurn_Mode, // BlendModeColorBurn + SkXfermode::kHardLight_Mode, // BlendModeHardLight + SkXfermode::kSoftLight_Mode, // BlendModeSoftLight + SkXfermode::kDifference_Mode, // BlendModeDifference + SkXfermode::kExclusion_Mode, // BlendModeExclusion + SkXfermode::kHue_Mode, // BlendModeHue + SkXfermode::kSaturation_Mode, // BlendModeSaturation + SkXfermode::kColor_Mode, // BlendModeColor + SkXfermode::kLuminosity_Mode // BlendModeLuminosity +}; + +SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op, BlendMode blendMode) { + if (blendMode != BlendModeNormal) { + if ((uint8_t)blendMode >= SK_ARRAY_COUNT(gMapBlendOpsToXfermodeModes)) { + SkDEBUGF(("GraphicsContext::setPlatformCompositeOperation unknown BlendMode %d\n", blendMode)); + return SkXfermode::kSrcOver_Mode; + } + return (SkXfermode::Mode)gMapBlendOpsToXfermodeModes[(uint8_t)blendMode]; + } + const CompositOpToXfermodeMode* table = gMapCompositOpsToXfermodeModes; for (unsigned i = 0; i < SK_ARRAY_COUNT(gMapCompositOpsToXfermodeModes); i++) { diff --git a/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.h b/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.h index 661b60a..6e04a5a 100644 --- a/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.h +++ b/third_party/WebKit/Source/core/platform/graphics/skia/SkiaUtils.h @@ -43,7 +43,7 @@ class SkRegion; namespace WebCore { -SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator); +SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator, BlendMode = BlendModeNormal); // move this guy into SkColor.h SkColor SkPMColorToColor(SkPMColor); |