LayoutTests:
authoraboule@apple.com <aboule@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Dec 2007 21:57:01 +0000 (21:57 +0000)
committeraboule@apple.com <aboule@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Dec 2007 21:57:01 +0000 (21:57 +0000)
        Reviewed by Dan Bernstein.

        Adding tests for canvas compositing modes to make sure the results don't change after:
        <rdar://problem/5640059> GraphicsContext::setCompositeOperation should use CGContextSetBlendMode

        The following compositing modes don't pass however that is covered by another bug:
        source-in
        source-out
        destination-in
        destination-atop
        copy
        <rdar://problem/5651783> Some canvas tag compositing modes don't render correctly

        * fast/canvas/canvas-composite.html: Added.
        * platform/mac/fast/canvas/canvas-composite-expected.checksum: Added.
        * platform/mac/fast/canvas/canvas-composite-expected.png: Added.
        * platform/mac/fast/canvas/canvas-composite-expected.txt: Added.

WebCore:

        Reviewed by Dan Bernstein.

        Test: fast/canvas/canvas-composite.html

        Fix for:
        <rdar://problem/5640059> GraphicsContext::setCompositeOperation should use CGContextSetBlendMode

        This fix makes setCompositeOperation consistent across all platforms that use CG.

        The following compositing modes don't pass however that is covered by another bug:
        source-in
        source-out
        destination-in
        destination-atop
        copy
        <rdar://problem/5651783> Some canvas tag compositing modes don't render correctly

        * platform/graphics/GraphicsTypes.h:
        * platform/graphics/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::setCompositeOperation):
        * platform/graphics/mac/GraphicsContextMac.mm:
        * platform/win/GraphicsContextWin.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28874 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-composite.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/platform/graphics/GraphicsTypes.h
WebCore/platform/graphics/cg/GraphicsContextCG.cpp
WebCore/platform/graphics/mac/GraphicsContextMac.mm
WebCore/platform/win/GraphicsContextWin.cpp

index b9ef32e0a34fd4f28697ff2fb92534d39a4b976e..ee724e4b64f75877c72b3cf717feca25c9c8cb64 100644 (file)
@@ -1,3 +1,23 @@
+2007-12-19  Andre Boule  <aboule@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Adding tests for canvas compositing modes to make sure the results don't change after:
+        <rdar://problem/5640059> GraphicsContext::setCompositeOperation should use CGContextSetBlendMode
+
+        The following compositing modes don't pass however that is covered by another bug:
+        source-in
+        source-out
+        destination-in
+        destination-atop
+        copy
+        <rdar://problem/5651783> Some canvas tag compositing modes don't render correctly
+
+        * fast/canvas/canvas-composite.html: Added.
+        * platform/mac/fast/canvas/canvas-composite-expected.checksum: Added.
+        * platform/mac/fast/canvas/canvas-composite-expected.png: Added.
+        * platform/mac/fast/canvas/canvas-composite-expected.txt: Added.
+
 2007-12-19  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/LayoutTests/fast/canvas/canvas-composite.html b/LayoutTests/fast/canvas/canvas-composite.html
new file mode 100644 (file)
index 0000000..c49fc44
--- /dev/null
@@ -0,0 +1,65 @@
+<html>
+  <head>
+    <title>A canvas globalCompositeOperation example</title>
+    <meta name="DC.creator" content="Kamiel Martinet, http://www.martinet.nl/">
+    <meta name="DC.publisher" content="Mozilla Developer Center, http://developer.mozilla.org">
+    <script type="application/x-javascript">
+      var compositeTypes = [
+        'source-over','source-in','source-out','source-atop',
+        'destination-over','destination-in','destination-out','destination-atop',
+        'lighter','darker','copy','xor'
+      ];
+      function draw(){
+        for (i=0;i<compositeTypes.length;i++){
+          var label = document.createTextNode(compositeTypes[i]);
+          document.getElementById('lab'+i).appendChild(label);
+          var ctx = document.getElementById('tut'+i).getContext('2d');
+
+          // draw rectangle
+          ctx.fillStyle = "#09f";
+          ctx.fillRect(15,15,70,70);
+
+          // set composite property
+          ctx.globalCompositeOperation = compositeTypes[i];
+          
+          // draw circle
+          ctx.fillStyle = "#f30";
+          ctx.beginPath();
+          ctx.arc(75,75,35,0,Math.PI*2,true);
+          ctx.fill();
+        }
+      }
+    </script>
+    <style type="text/css">
+      body { margin: 20px; font-family: arial,verdana,helvetica; background: #fff;}
+      h1 { font-size: 140%; font-weight:normal; color: #036; border-bottom: 1px solid #ccc; }
+      canvas { border: 2px solid #000; margin-bottom: 5px; }
+      td { padding: 7px; }
+      pre { float:left; display:block; background: rgb(238,238,238); border: 1px dashed #666; padding: 15px 20px; margin: 0 0 10px 0; }
+    </style>
+  </head>
+  <body onload="draw();">
+    <div>
+      <table>
+        <tr>
+          <td><canvas id="tut0" width="125" height="125"></canvas><br/><label id="lab0"></label></td>
+          <td><canvas id="tut1" width="125" height="125"></canvas><br/><label id="lab1"></label></td>
+          <td><canvas id="tut2" width="125" height="125"></canvas><br/><label id="lab2"></label></td>
+          <td><canvas id="tut3" width="125" height="125"></canvas><br/><label id="lab3"></label></td>
+        </tr>
+        <tr>
+          <td><canvas id="tut4" width="125" height="125"></canvas><br/><label id="lab4"></label></td>
+          <td><canvas id="tut5" width="125" height="125"></canvas><br/><label id="lab5"></label></td>
+          <td><canvas id="tut6" width="125" height="125"></canvas><br/><label id="lab6"></label></td>
+          <td><canvas id="tut7" width="125" height="125"></canvas><br/><label id="lab7"></label></td>
+        </tr>
+        <tr>
+          <td><canvas id="tut8" width="125" height="125"></canvas><br/><label id="lab8"></label></td>
+          <td><canvas id="tut9" width="125" height="125"></canvas><br/><label id="lab9"></label></td>
+          <td><canvas id="tut10" width="125" height="125"></canvas><br/><label id="lab10"></label></td>
+          <td><canvas id="tut11" width="125" height="125"></canvas><br/><label id="lab11"></label></td>
+        </tr>
+      </table>
+    </div>
+  </body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.checksum b/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.checksum
new file mode 100644 (file)
index 0000000..a33e2d1
--- /dev/null
@@ -0,0 +1 @@
+463794be94d038d765064ed4432e81ac
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.png b/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.png
new file mode 100644 (file)
index 0000000..39966ac
Binary files /dev/null and b/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.txt b/LayoutTests/platform/mac/fast/canvas/canvas-composite-expected.txt
new file mode 100644 (file)
index 0000000..0a203d5
--- /dev/null
@@ -0,0 +1,83 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (20,20) size 760x560 [bgcolor=#FFFFFF]
+      RenderBlock {DIV} at (0,0) size 760x506
+        RenderTable {TABLE} at (0,0) size 582x506
+          RenderTableSection {TBODY} at (0,0) size 582x506
+            RenderTableRow {TR} at (0,2) size 582x166
+              RenderTableCell {TD} at (2,2) size 143x166 [r=0 c=0 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 84x17
+                  RenderText {#text} at (7,141) size 84x17
+                    text run at (7,141) width 84: "source-over"
+              RenderTableCell {TD} at (147,2) size 143x166 [r=0 c=1 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 66x17
+                  RenderText {#text} at (7,141) size 66x17
+                    text run at (7,141) width 66: "source-in"
+              RenderTableCell {TD} at (292,2) size 143x166 [r=0 c=2 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 75x17
+                  RenderText {#text} at (7,141) size 75x17
+                    text run at (7,141) width 75: "source-out"
+              RenderTableCell {TD} at (437,2) size 143x166 [r=0 c=3 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 84x17
+                  RenderText {#text} at (7,141) size 84x17
+                    text run at (7,141) width 84: "source-atop"
+            RenderTableRow {TR} at (0,170) size 582x166
+              RenderTableCell {TD} at (2,170) size 143x166 [r=1 c=0 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 114x17
+                  RenderText {#text} at (7,141) size 114x17
+                    text run at (7,141) width 114: "destination-over"
+              RenderTableCell {TD} at (147,170) size 143x166 [r=1 c=1 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 96x17
+                  RenderText {#text} at (7,141) size 96x17
+                    text run at (7,141) width 96: "destination-in"
+              RenderTableCell {TD} at (292,170) size 143x166 [r=1 c=2 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 105x17
+                  RenderText {#text} at (7,141) size 105x17
+                    text run at (7,141) width 105: "destination-out"
+              RenderTableCell {TD} at (437,170) size 143x166 [r=1 c=3 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 114x17
+                  RenderText {#text} at (7,141) size 114x17
+                    text run at (7,141) width 114: "destination-atop"
+            RenderTableRow {TR} at (0,338) size 582x166
+              RenderTableCell {TD} at (2,338) size 143x166 [r=2 c=0 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 44x17
+                  RenderText {#text} at (7,141) size 44x17
+                    text run at (7,141) width 44: "lighter"
+              RenderTableCell {TD} at (147,338) size 143x166 [r=2 c=1 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 45x17
+                  RenderText {#text} at (7,141) size 45x17
+                    text run at (7,141) width 45: "darker"
+              RenderTableCell {TD} at (292,338) size 143x166 [r=2 c=2 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 34x17
+                  RenderText {#text} at (7,141) size 34x17
+                    text run at (7,141) width 34: "copy"
+              RenderTableCell {TD} at (437,338) size 143x166 [r=2 c=3 rs=1 cs=1]
+                RenderHTMLCanvas {CANVAS} at (7,7) size 129x129 [border: (2px solid #000000)]
+                RenderBR {BR} at (136,141) size 0x0
+                RenderInline {LABEL} at (0,0) size 22x17
+                  RenderText {#text} at (7,141) size 22x17
+                    text run at (7,141) width 22: "xor"
index 8fd0dc31f6518dac95875b3b64959a316e1d3b9c..8f5988911731799865b3e62c2552cb7a37d104b7 100644 (file)
@@ -1,3 +1,28 @@
+2007-12-19  Andre Boule  <aboule@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Test: fast/canvas/canvas-composite.html
+
+        Fix for:
+        <rdar://problem/5640059> GraphicsContext::setCompositeOperation should use CGContextSetBlendMode
+
+        This fix makes setCompositeOperation consistent across all platforms that use CG.
+
+        The following compositing modes don't pass however that is covered by another bug:
+        source-in
+        source-out
+        destination-in
+        destination-atop
+        copy
+        <rdar://problem/5651783> Some canvas tag compositing modes don't render correctly
+
+        * platform/graphics/GraphicsTypes.h:
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::setCompositeOperation):
+        * platform/graphics/mac/GraphicsContextMac.mm:
+        * platform/win/GraphicsContextWin.cpp:
+
 2007-12-19  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
index 10bbc64c34bf525f6c1567ce713d4acc76af5ee5..a7b66f50fbf26d34dc5158a13315fee2663f303f 100644 (file)
@@ -30,9 +30,6 @@ namespace WebCore {
 
     class String;
 
-    // Note: These constants exactly match the NSCompositeOperator constants of
-    // AppKit on Mac OS X. If that's ever changed, we'll need to change the Mac
-    // platform code to map one to the other.
     enum CompositeOperator {
         CompositeClear,
         CompositeCopy,
index fc9d58687fae0834bca8b7ab4a4665245ca0d44f..077ec0240c49fdcfbd85e4b719a6319e79c4965c 100644 (file)
@@ -868,6 +868,59 @@ void GraphicsContext::setUseAntialiasing(bool enable)
     CGContextSetShouldAntialias(platformContext(), enable);
 }
 
+void GraphicsContext::setCompositeOperation(CompositeOperator mode)
+{   
+    if (paintingDisabled())
+        return;
+
+    CGBlendMode target = kCGBlendModeNormal;   
+    switch (mode) {
+        case CompositeClear:
+            target = kCGBlendModeClear;
+            break;
+        case CompositeCopy:
+            target = kCGBlendModeCopy;
+            break;
+        case CompositeSourceOver:
+            //kCGBlendModeNormal
+            break;
+        case CompositeSourceIn:
+            target = kCGBlendModeSourceIn;
+            break;
+        case CompositeSourceOut:
+            target = kCGBlendModeSourceOut;
+            break;
+        case CompositeSourceAtop:
+            target = kCGBlendModeSourceAtop; 
+            break;
+        case CompositeDestinationOver:
+            target = kCGBlendModeDestinationOver;
+            break;
+        case CompositeDestinationIn:
+            target = kCGBlendModeDestinationIn;
+            break;
+        case CompositeDestinationOut:
+            target = kCGBlendModeDestinationOut;
+            break;
+        case CompositeDestinationAtop:
+            target = kCGBlendModeDestinationAtop;
+            break;
+        case CompositeXOR:
+            target = kCGBlendModeXOR;
+            break;
+        case CompositePlusDarker:
+            target = kCGBlendModePlusDarker;
+            break;
+        case CompositeHighlight:
+            // currently unsupported
+            break;
+        case CompositePlusLighter:
+            target = kCGBlendModePlusLighter;
+            break;
+    }
+    CGContextSetBlendMode(platformContext(), target);
+}
+    
 }
 
 #endif // PLATFORM(CG)
index 3b1d3fe4dd5939c4c4566f44bdb7052912c359c9..eca6451a8b8f786f8b80dd3d5befbadab93882fa 100644 (file)
@@ -69,16 +69,6 @@ void GraphicsContext::drawFocusRing(const Color& color)
     CGPathRelease(focusRingPath);
 }
 
-void GraphicsContext::setCompositeOperation(CompositeOperator op)
-{
-    if (paintingDisabled())
-        return;
-    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-    [[NSGraphicsContext graphicsContextWithGraphicsPort:platformContext() flipped:YES]
-        setCompositingOperation:(NSCompositingOperation)op];
-    [pool drain];
-}
-
 void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint& point, int width, bool grammar)
 {
     if (paintingDisabled())
index d77928d2a8764f0092946eaf1b5c0fe2b7656eb3..57eb7ea969980a14adba0e5ae26b9db70cf4fb01 100644 (file)
@@ -255,59 +255,6 @@ void GraphicsContextPlatformPrivate::concatCTM(const AffineTransform& transform)
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
-void GraphicsContext::setCompositeOperation(CompositeOperator mode) 
-{ 
-    if (paintingDisabled())
-        return;
-
-    CGBlendMode target = kCGBlendModeNormal;   
-    switch (mode) {
-        case CompositeClear:
-            target = kCGBlendModeClear;
-            break;
-        case CompositeCopy:
-            target = kCGBlendModeCopy;
-            break;
-        case CompositeSourceOver:
-            //kCGBlendModeNormal
-            break;
-        case CompositeSourceIn:
-            target = kCGBlendModeSourceIn;
-            break;
-        case CompositeSourceOut:
-            target = kCGBlendModeSourceOut;
-            break;
-        case CompositeSourceAtop:
-            target = kCGBlendModeSourceAtop;
-            break;
-        case CompositeDestinationOver:
-            target = kCGBlendModeDestinationOver;
-            break;
-        case CompositeDestinationIn:
-            target = kCGBlendModeDestinationIn;
-            break;
-        case CompositeDestinationOut:
-            target = kCGBlendModeDestinationOut;
-            break;
-        case CompositeDestinationAtop:
-            target = kCGBlendModeDestinationAtop;
-            break;
-        case CompositeXOR:
-            target = kCGBlendModeXOR;
-            break;
-        case CompositePlusDarker:
-            target = kCGBlendModePlusDarker;
-            break;
-        case CompositeHighlight:
-            // currently unsupported
-            break;
-        case CompositePlusLighter:
-            target = kCGBlendModePlusLighter;
-            break;
-    }
-    CGContextSetBlendMode(platformContext(), target);
-}
-
 void GraphicsContext::drawFocusRing(const Color& color)
 {
     if (paintingDisabled())