[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:43:11 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 02796a4979621aa76e7d2a2f3d4b0992700d0e36
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jun 2 02:12:10 2004 +0000

    WebCore:
    		Added support for composite attribute to <CANVAS>
    		Added support for drawImage and drawImageFromRect to <CANVAS>, i.e.:
    
    			<html>
    			<head>
    			<script>
    
    			var img = new Image(600,600);
    
    			function drawImage()
    			{
    				var aCanvas = document.getElementById ("canvas1");
    				var context = aCanvas.getContext("context-2d");
    				context.drawImage (img, 0, 0, 600, 600, "copy");
    			}
    
    			img.onload = drawImage;
    			img.src = "http://www.google.com/images/logo.gif";
    
    			</script>
    			</head>
    			<body>
    			<canvas id="canvas1" width=600 height=600>
    			</body>
    			<html>
    
            Reviewed by Trey.
    
            * khtml/ecma/kjs_html.cpp:
            (KJS::Context2DFunction::tryCall):
            (Context2D::Context2D):
            * khtml/ecma/kjs_html.h:
            * khtml/rendering/render_canvasimage.cpp:
            (RenderCanvasImage::paint):
            * kwq/KWQPainter.h:
            * kwq/KWQPainter.mm:
            (QPainter::getCompositeOperation):
            (QPainter::setCompositeOperation):
            (QPainter::drawPixmap):
            (QPainter::drawTiledPixmap):
            * kwq/KWQPixmap.h:
            * kwq/KWQPixmap.mm:
            (QPixmap::flushRasterCache):
            * kwq/WebCoreImageRenderer.h:
            * kwq/WebCoreImageRendererFactory.h:
    
    WebKit:
    		Added support for drawImage and drawImageFromRect to <CANVAS>
    		Added support for composite attribute to <CANVAS>
    
            Reviewed by Trey.
    
            * WebCoreSupport.subproj/WebImageRenderer.h:
            * WebCoreSupport.subproj/WebImageRenderer.m:
            (-[WebImageContext initWithBounds:context:]):
            (-[WebImageContext dealloc]):
            (-[WebImageContext saveGraphicsState]):
            (-[WebImageContext restoreGraphicsState]):
            (-[WebImageContext isDrawingToScreen]):
            (-[WebImageContext focusStack]):
            (-[WebImageContext setFocusStack:]):
            (-[WebImageContext bounds]):
            (-[WebImageContext isFlipped]):
            (-[WebImageRenderer incrementalLoadWithBytes:length:complete:]):
            (-[WebImageRenderer dealloc]):
            (-[WebImageRenderer _beginRedirectContext:]):
            (-[WebImageRenderer _endRedirectContext:]):
            (-[WebImageRenderer _needsRasterFlush]):
            (-[WebImageRenderer drawClippedToValidInRect:fromRect:]):
            (-[WebImageRenderer drawImageInRect:fromRect:]):
            (-[WebImageRenderer flushRasterCache]):
            (-[WebImageRenderer drawImageInRect:fromRect:compositeOperator:context:]):
            (-[WebImageRenderer tileInRect:fromPoint:context:]):
            * WebCoreSupport.subproj/WebImageRendererFactory.m:
            (-[WebImageRendererFactory imageRendererWithMIMEType:]):
            (-[WebImageRendererFactory imageRendererWithName:]):
            (-[WebImageRendererFactory CGCompositeOperationInContext:]):
            (-[WebImageRendererFactory setCGCompositeOperation:inContext:]):
            (-[WebImageRendererFactory setCGCompositeOperationFromString:inContext:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6741 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 52e4336..013d052 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,51 @@
+2004-06-01  Richard Williamson   <rjw at apple.com>
+
+		Added support for composite attribute to <CANVAS>
+		Added support for drawImage and drawImageFromRect to <CANVAS>, i.e.:
+
+			<html>
+			<head>
+			<script>
+			
+			var img = new Image(600,600);
+			
+			function drawImage()
+			{
+				var aCanvas = document.getElementById ("canvas1");
+				var context = aCanvas.getContext("context-2d");
+				context.drawImage (img, 0, 0, 600, 600, "copy");
+			}
+			
+			img.onload = drawImage;
+			img.src = "http://www.google.com/images/logo.gif";
+			
+			</script>
+			</head>
+			<body>
+			<canvas id="canvas1" width=600 height=600>
+			</body>
+			<html>
+
+        Reviewed by Trey.
+
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::Context2DFunction::tryCall):
+        (Context2D::Context2D):
+        * khtml/ecma/kjs_html.h:
+        * khtml/rendering/render_canvasimage.cpp:
+        (RenderCanvasImage::paint):
+        * kwq/KWQPainter.h:
+        * kwq/KWQPainter.mm:
+        (QPainter::getCompositeOperation):
+        (QPainter::setCompositeOperation):
+        (QPainter::drawPixmap):
+        (QPainter::drawTiledPixmap):
+        * kwq/KWQPixmap.h:
+        * kwq/KWQPixmap.mm:
+        (QPixmap::flushRasterCache):
+        * kwq/WebCoreImageRenderer.h:
+        * kwq/WebCoreImageRendererFactory.h:
+
 2004-06-01  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Darin
diff --git a/WebCore/khtml/ecma/kjs_html.cpp b/WebCore/khtml/ecma/kjs_html.cpp
index f4c2944..c277558 100644
--- a/WebCore/khtml/ecma/kjs_html.cpp
+++ b/WebCore/khtml/ecma/kjs_html.cpp
@@ -3586,6 +3586,7 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
             float sx = (float)args[0].toNumber(exec);
             float sy = (float)args[1].toNumber(exec);
             CGContextScaleCTM (drawingContext, sx, sy);
+            contextObject->_needsFlushRasterCache = true;
             break;
         }
         case Context2D::Rotate: {
@@ -3596,6 +3597,7 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
             }
             float angle = (float)args[0].toNumber(exec);
             CGContextRotateCTM (drawingContext, angle);
+            contextObject->_needsFlushRasterCache = true;
             break;
         }
         case Context2D::Translate: {
@@ -3776,7 +3778,9 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
             offset.height = (float)args[1].toNumber(exec);
             float blur = (float)args[2].toNumber(exec);
             
-            if (numArgs == 3) {
+            QColor color = QColor(args[3].toString(exec).ascii());
+
+             if (numArgs == 3) {
                 CGContextSetShadow (drawingContext, offset, blur);
             } else {
                 CGColorSpaceRef colorSpace;
@@ -3874,23 +3878,50 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
                 return err;
             }
             Image *i = static_cast<Image*>(o);
-            float x = (float)args[1].toNumber(exec);
-            float y = (float)args[2].toNumber(exec);
-            float w = (float)args[3].toNumber(exec);
-            float h = (float)args[4].toNumber(exec);
+            int x = args[1].toInt32(exec);
+            int y = args[2].toInt32(exec);
+            int w = args[3].toInt32(exec);
+            int h = args[4].toInt32(exec);
             QString compositeOperator = args[5].toString(exec).qstring().lower();
             QPixmap pixmap = i->image()->pixmap();
-            printf ("%s:%d  %p %f,%f,%f,%f %s\n", __FILE__, __LINE__, pixmap.image(), x, y, w, h, compositeOperator.ascii());
+            QPainter p;
+            p.drawPixmap (x, y, pixmap, 0, 0, w, h, 1, drawingContext);
+            
+            if (contextObject->_needsFlushRasterCache)
+                pixmap.flushRasterCache();
+
             renderer->setNeedsImageUpdate();
             break;
         }
         case Context2D::DrawImageFromRect: {
-            if (args.size() != 10) {
+            if (args.size() != 6) {
                 Object err = Error::create(exec,SyntaxError);
                 exec->setException(err);
                 return err;
             }
-            // FIXME:  Implement
+            ObjectImp *o = static_cast<ObjectImp*>(args[0].imp());
+            if (!o->inherits(&Image::info)) {
+                Object err = Error::create(exec,TypeError);
+                exec->setException(err);
+                return err;
+            }
+            Image *i = static_cast<Image*>(o);
+            int sx = args[1].toInt32(exec);
+            int sy = args[2].toInt32(exec);
+            int sw = args[3].toInt32(exec);
+            int sh = args[4].toInt32(exec);
+            int dx = args[5].toInt32(exec);
+            int dy = args[6].toInt32(exec);
+            int dw = args[7].toInt32(exec);
+            int dh = args[8].toInt32(exec);
+            QString compositeOperator = args[9].toString(exec).qstring().lower();
+            QPixmap pixmap = i->image()->pixmap();
+            QPainter p;
+            p.drawPixmap (dx, dy, dw, dh, pixmap, sx, sy, sw, sh, 1, drawingContext);
+            
+            if (contextObject->_needsFlushRasterCache)
+                pixmap.flushRasterCache();
+
             renderer->setNeedsImageUpdate();
             break;
         }
@@ -3975,7 +4006,7 @@ void Context2D::putValue(ExecState *exec, int token, const Value& value, int /*a
 }
 
 Context2D::Context2D(const DOM::HTMLElement &e)
-  : _element(static_cast<DOM::HTMLElementImpl*>(e.handle()))
+  : _element(static_cast<DOM::HTMLElementImpl*>(e.handle())), _needsFlushRasterCache(0)
 {
 }
 
diff --git a/WebCore/khtml/ecma/kjs_html.h b/WebCore/khtml/ecma/kjs_html.h
index 99fd3d8..3974dda 100644
--- a/WebCore/khtml/ecma/kjs_html.h
+++ b/WebCore/khtml/ecma/kjs_html.h
@@ -240,6 +240,7 @@ namespace KJS {
   ////////////////////// Context2D Object ////////////////////////
 
   class Context2D : public DOMObject {
+  friend class Context2DFunction;
   public:
     Context2D(const DOM::HTMLElement &e);
     ~Context2D();
@@ -264,6 +265,7 @@ namespace KJS {
         SetAlpha};
 
     DOM::HTMLElementImpl *_element;
+    unsigned int _needsFlushRasterCache;
   };
 
   Value getHTMLCollection(ExecState *exec, const DOM::HTMLCollection &c);
diff --git a/WebCore/khtml/rendering/render_canvasimage.cpp b/WebCore/khtml/rendering/render_canvasimage.cpp
index 0440676..45822b4 100644
--- a/WebCore/khtml/rendering/render_canvasimage.cpp
+++ b/WebCore/khtml/rendering/render_canvasimage.cpp
@@ -39,12 +39,21 @@
 #include "misc/htmlattrs.h"
 #include "misc/htmltags.h"
 #include "html/html_formimpl.h"
-#include "html/html_imageimpl.h"
+#include "html/html_canvasimpl.h"
 #include "html/dtd.h"
 #include "xml/dom2_eventsimpl.h"
 #include "html/html_documentimpl.h"
 #include <math.h>
 
+
+
+// To be public in Tiger.  Test on tiger and add conditional.
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
+CG_EXTERN_C_BEGIN
+CG_EXTERN CGImageRef CGBitmapContextCreateImage(CGContextRef c);
+CG_EXTERN_C_END
+#endif
+
 using namespace DOM;
 using namespace khtml;
 
@@ -108,10 +117,6 @@ CGContextRef RenderCanvasImage::drawingContext()
     return _drawingContext;
 }
 
-CG_EXTERN_C_BEGIN
-CG_EXTERN CGImageRef CGBitmapContextCreateImage(CGContextRef c);
-CG_EXTERN_C_END
-
 void RenderCanvasImage::setNeedsImageUpdate()
 {
     _needsImageUpdate = true;
@@ -174,8 +179,18 @@ void RenderCanvasImage::paint(PaintInfo& i, int _tx, int _ty)
         _needsImageUpdate = false;
     }
     
-    if (drawnImage())
+    if (drawnImage()) {
+         HTMLCanvasElementImpl* i = (element() && element()->id() == ID_IMG) ? static_cast<HTMLCanvasElementImpl*>(element()) : 0;
+         int oldOperation;
+         if (i && !i->compositeOperator().isNull()){
+            oldOperation = QPainter::getCompositeOperation(p->currentContext());
+            QPainter::setCompositeOperation (p->currentContext(),i->compositeOperator());
+        }
         CGContextDrawImage (p->currentContext(), CGRectMake (x, y, cWidth, cHeight), drawnImage());
+        if (i && !i->compositeOperator().isNull()) {
+            QPainter::setCompositeOperation (p->currentContext(),oldOperation);
+        }
+    }
 
     if (drawSelectionTint) {
         QSize tintSize(cWidth, cHeight);
diff --git a/WebCore/kwq/KWQPainter.h b/WebCore/kwq/KWQPainter.h
index 6366f17..094b592 100644
--- a/WebCore/kwq/KWQPainter.h
+++ b/WebCore/kwq/KWQPainter.h
@@ -89,7 +89,9 @@ public:
     void drawPixmap(const QPoint &, const QPixmap &, const QRect &, const QString &);
     void drawPixmap( int x, int y, const QPixmap &,
 			    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context=0);
-    void drawTiledPixmap(int, int, int, int, const QPixmap &, int sx=0, int sy=0);
+    void drawPixmap( int x, int y, int w, int h, const QPixmap &,
+			    int sx=0, int sy=0, int sw=-1, int sh=-1, int compositeOperator=-1, CGContextRef context=0);
+    void drawTiledPixmap(int, int, int, int, const QPixmap &, int sx=0, int sy=0, CGContextRef context=0);
 
     void addClip(const QRect &);
 
@@ -127,6 +129,10 @@ public:
     
     CGContextRef currentContext();
     
+    static int getCompositeOperation(CGContextRef context);
+    static void setCompositeOperation (CGContextRef context, QString operation);
+    static void setCompositeOperation (CGContextRef context, int operation);
+
 private:
     // no copying or assignment
     QPainter(const QPainter &);
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index 0611386..5acf4a1 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -37,6 +37,7 @@
 #import "KWQWidget.h"
 #import "WebCoreGraphicsBridge.h"
 #import "WebCoreImageRenderer.h"
+#import "WebCoreImageRendererFactory.h"
 #import "WebCoreTextRenderer.h"
 #import "WebCoreTextRendererFactory.h"
 
@@ -461,6 +462,21 @@ struct CompositeOperator compositeOperators[NUM_COMPOSITE_OPERATORS] = {
     { "lighter", NSCompositePlusLighter }
 };
 
+int QPainter::getCompositeOperation(CGContextRef context)
+{
+    return (int)[[WebCoreImageRendererFactory sharedFactory] CGCompositeOperationInContext:context];
+}
+
+void QPainter::setCompositeOperation (CGContextRef context, QString op)
+{
+    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperationFromString:op.getNSString() inContext:context];
+}
+
+void QPainter::setCompositeOperation (CGContextRef context, int op)
+{
+    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperation:op inContext:context];
+}
+
 static NSCompositingOperation compositeOperatorFromString (QString aString)
 {
     if (aString.length()) {
@@ -484,45 +500,42 @@ void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix, const QRect &r, c
 void QPainter::drawPixmap( int x, int y, const QPixmap &pixmap,
                            int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
 {
+    drawPixmap (x, y, sw, sh, pixmap, sx, sy, sw, sh, compositeOperator, context);
+}
+
+void QPainter::drawPixmap( int x, int y, int w, int h, const QPixmap &pixmap,
+                           int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
+{
     if (data->state.paintingDisabled)
         return;
         
-#if 0
-    NSGraphicsContext *oldContext = 0;
-    if (context) {
-        oldContext = [NSGraphicsContext currentContext];
-        // Somehow set up a NSGraphicsContext using the context parameter.
-    }
-#endif
-    
     if (sw == -1)
         sw = pixmap.width();
     if (sh == -1)
         sh = pixmap.height();
 
-    NSRect inRect = NSMakeRect(x, y, sw, sh);
+    if (w == -1)
+        w = pixmap.width();
+    if (h == -1)
+        h = pixmap.height();
+
+    NSRect inRect = NSMakeRect(x, y, w, h);
     NSRect fromRect = NSMakeRect(sx, sy, sw, sh);
     
     KWQ_BLOCK_EXCEPTIONS;
     [pixmap.imageRenderer drawImageInRect:inRect
-                                      fromRect:fromRect compositeOperator:(NSCompositingOperation)compositeOperator];
+                                      fromRect:fromRect compositeOperator:(NSCompositingOperation)compositeOperator context:context];
     KWQ_UNBLOCK_EXCEPTIONS;
-
-#if 0
-    if (context) {
-        [NSGraphicsContext setCurrentContext:oldContext];
-    }
-#endif
 }
 
 void QPainter::drawTiledPixmap( int x, int y, int w, int h,
-				const QPixmap &pixmap, int sx, int sy )
+				const QPixmap &pixmap, int sx, int sy, CGContextRef context)
 {
     if (data->state.paintingDisabled)
         return;
     
     KWQ_BLOCK_EXCEPTIONS;
-    [pixmap.imageRenderer tileInRect:NSMakeRect(x, y, w, h) fromPoint:NSMakePoint(sx, sy)];
+    [pixmap.imageRenderer tileInRect:NSMakeRect(x, y, w, h) fromPoint:NSMakePoint(sx, sy) context:context];
     KWQ_UNBLOCK_EXCEPTIONS;
 }
 
diff --git a/WebCore/kwq/KWQPixmap.h b/WebCore/kwq/KWQPixmap.h
index 13cdc93..8ad49df 100644
--- a/WebCore/kwq/KWQPixmap.h
+++ b/WebCore/kwq/KWQPixmap.h
@@ -86,6 +86,8 @@ public:
     void increaseUseCount() const;
     void decreaseUseCount() const;
     
+    void flushRasterCache();
+    
 private:
 
     WebCoreImageRendererPtr imageRenderer;
diff --git a/WebCore/kwq/KWQPixmap.mm b/WebCore/kwq/KWQPixmap.mm
index e0fd2e4..9d59b98 100644
--- a/WebCore/kwq/KWQPixmap.mm
+++ b/WebCore/kwq/KWQPixmap.mm
@@ -209,3 +209,8 @@ void QPixmap::stopAnimations()
 {
     [imageRenderer stopAnimation];
 }
+
+void QPixmap::flushRasterCache()
+{
+    [imageRenderer flushRasterCache];
+}
diff --git a/WebCore/kwq/WebCoreImageRenderer.h b/WebCore/kwq/WebCoreImageRenderer.h
index db4b41a..f60ed1e 100644
--- a/WebCore/kwq/WebCoreImageRenderer.h
+++ b/WebCore/kwq/WebCoreImageRenderer.h
@@ -32,11 +32,12 @@
 - (NSSize)size;
 - (void)resize:(NSSize)s;
 - (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr;
-- (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr compositeOperator:(NSCompositingOperation)compsiteOperator;
+- (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr compositeOperator:(NSCompositingOperation)compsiteOperator context:(CGContextRef)context;
 - (void)stopAnimation;
-- (void)tileInRect:(NSRect)r fromPoint:(NSPoint)p;
+- (void)tileInRect:(NSRect)r fromPoint:(NSPoint)p context:(CGContextRef)context;
 - (BOOL)isNull;
 - (id <WebCoreImageRenderer>)retainOrCopyIfNeeded;
 - (void)increaseUseCount;
 - (void)decreaseUseCount;
+- (void)flushRasterCache;
 @end
diff --git a/WebCore/kwq/WebCoreImageRendererFactory.h b/WebCore/kwq/WebCoreImageRendererFactory.h
index 796b21c..72134c0 100644
--- a/WebCore/kwq/WebCoreImageRendererFactory.h
+++ b/WebCore/kwq/WebCoreImageRendererFactory.h
@@ -36,6 +36,9 @@
 - (id <WebCoreImageRenderer>)imageRendererWithSize:(NSSize)size;
 - (id <WebCoreImageRenderer>)imageRendererWithName:(NSString *)name;
 - (NSArray *)supportedMIMETypes;
+- (int)CGCompositeOperationInContext:(CGContextRef)context;
+- (void)setCGCompositeOperation:(int)op inContext:(CGContextRef)context;
+- (void)setCGCompositeOperationFromString:(NSString *)op inContext:(CGContextRef)context;
 
 @end
 
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index fb64a67..7e1f7d6 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,38 @@
+2004-06-01  Richard Williamson   <rjw at apple.com>
+
+		Added support for drawImage and drawImageFromRect to <CANVAS>
+		Added support for composite attribute to <CANVAS>
+
+        Reviewed by Trey.
+
+        * WebCoreSupport.subproj/WebImageRenderer.h:
+        * WebCoreSupport.subproj/WebImageRenderer.m:
+        (-[WebImageContext initWithBounds:context:]):
+        (-[WebImageContext dealloc]):
+        (-[WebImageContext saveGraphicsState]):
+        (-[WebImageContext restoreGraphicsState]):
+        (-[WebImageContext isDrawingToScreen]):
+        (-[WebImageContext focusStack]):
+        (-[WebImageContext setFocusStack:]):
+        (-[WebImageContext bounds]):
+        (-[WebImageContext isFlipped]):
+        (-[WebImageRenderer incrementalLoadWithBytes:length:complete:]):
+        (-[WebImageRenderer dealloc]):
+        (-[WebImageRenderer _beginRedirectContext:]):
+        (-[WebImageRenderer _endRedirectContext:]):
+        (-[WebImageRenderer _needsRasterFlush]):
+        (-[WebImageRenderer drawClippedToValidInRect:fromRect:]):
+        (-[WebImageRenderer drawImageInRect:fromRect:]):
+        (-[WebImageRenderer flushRasterCache]):
+        (-[WebImageRenderer drawImageInRect:fromRect:compositeOperator:context:]):
+        (-[WebImageRenderer tileInRect:fromPoint:context:]):
+        * WebCoreSupport.subproj/WebImageRendererFactory.m:
+        (-[WebImageRendererFactory imageRendererWithMIMEType:]):
+        (-[WebImageRendererFactory imageRendererWithName:]):
+        (-[WebImageRendererFactory CGCompositeOperationInContext:]):
+        (-[WebImageRendererFactory setCGCompositeOperation:inContext:]):
+        (-[WebImageRendererFactory setCGCompositeOperationFromString:inContext:]):
+
 2004-06-01  John Sullivan  <sullivan at apple.com>
 
         Reviewed by Trey.
diff --git a/WebKit/WebCoreSupport.subproj/WebImageRenderer.h b/WebKit/WebCoreSupport.subproj/WebImageRenderer.h
index da26b96..413dfca 100644
--- a/WebKit/WebCoreSupport.subproj/WebImageRenderer.h
+++ b/WebKit/WebCoreSupport.subproj/WebImageRenderer.h
@@ -25,6 +25,11 @@
     BOOL animatedTile;
 
     int compositeOperator;
+    id redirectContext;
+    CGContextRef context;
+    BOOL needFlushRasterCache;
+    BOOL rasterFlushing;
+    NSImageCacheMode rasterFlushingOldMode;
     
     NSString *MIMEType;
     BOOL isNull;
diff --git a/WebKit/WebCoreSupport.subproj/WebImageRenderer.m b/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
index 9880cc6..2e3611b 100644
--- a/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebImageRenderer.m
@@ -12,11 +12,104 @@
 
 extern NSString *NSImageLoopCount;
 
+/*
+    We need to get the AppKit to redirect drawing to our
+    CGContext.  There is currently (on Panther) no public
+    way to make this happen.  So we create a NSCGSContext
+    subclass and twiddle it's _cgsContext ivar directly.
+    Very fragile, but the only way...
+*/
+ at interface NSCGSContext : NSGraphicsContext {
+    CGContextRef _cgsContext;
+}
+ at end
+
+ at interface NSFocusStack : NSObject
+ at end
+
+ at interface WebImageContext : NSCGSContext {
+  @private
+    NSFocusStack* _focusStack;
+    NSRect        _bounds;
+    BOOL          _isFlipped;
+}
+- (id)initWithBounds:(NSRect)b context:(CGContextRef)context;
+- (NSRect)bounds;
+ at end
+
+ at implementation WebImageContext
+
+- (id)initWithBounds:(NSRect)b context:(CGContextRef)context {
+    
+    self = [super init];
+    if (self != nil) {
+	_bounds     = b;
+	_isFlipped  = YES;
+        if (context)
+            _cgsContext = (CGContextRef)CFRetain(context);
+    }
+    
+    return self;
+}
+
+- (void)dealloc {
+    
+    // done with focus stack
+    //
+    [_focusStack release]; _focusStack = nil;
+    
+    // done with context we own
+    //
+    CGContextRelease(_cgsContext); _cgsContext = NULL;
+    
+    [super dealloc];
+}
+
+- (void)saveGraphicsState {
+    if (_cgsContext) {
+        CGContextSaveGState(_cgsContext);
+    }
+}
+
+- (void)restoreGraphicsState {
+    if (_cgsContext) {
+        CGContextRestoreGState(_cgsContext);
+    }
+}
+
+- (BOOL)isDrawingToScreen {
+    return NO;
+}
+
+- (void *)focusStack {
+    if (!_focusStack) _focusStack = [[NSFocusStack allocWithZone:NULL] init];
+    return _focusStack;
+}
+
+- (void)setFocusStack:(void *)stack {
+    id oldstack = _focusStack;
+    _focusStack = [(id)stack retain];
+    [oldstack release];
+}
+
+- (NSRect)bounds {
+    return _bounds;
+}
+
+- (BOOL)isFlipped {
+    return _isFlipped;
+}
+
+ at end
+
 #define MINIMUM_DURATION (1.0/30.0)
 
 // Forward declarations
 @interface WebImageRenderer (WebInternal)
 - (void)startAnimationIfNecessary;
+- (NSGraphicsContext *)_beginRedirectContext:(CGContextRef)aContext;
+- (void)_endRedirectContext:(NSGraphicsContext *)aContext;
+- (void)_needsRasterFlush;
 @end
 
 @implementation WebImageRenderer
@@ -179,51 +272,68 @@ static NSMutableSet *activeImageRenderers;
 
 - (BOOL)incrementalLoadWithBytes:(const void *)bytes length:(unsigned)length complete:(BOOL)isComplete
 {
-    NSBitmapImageRep *imageRep = [[self representations] objectAtIndex:0];
-    NSData *data = [[NSData alloc] initWithBytes:bytes length:length];
-
-    NS_DURING
-        loadStatus = [imageRep incrementalLoadFromData:data complete:isComplete];
-    NS_HANDLER
-        loadStatus = NSImageRepLoadStatusInvalidData; // Arbitrary choice; any error will do.
-    NS_ENDHANDLER
-
-    // Hold onto the original data in case we need to copy this image.  (Workaround for appkit NSImage
-    // copy flaw).
-    if (isComplete && [self frameCount] > 1)
-        originalData = data;
-    else
-        [data release];
-
-    switch (loadStatus) {
-    case NSImageRepLoadStatusUnknownType:       // not enough data to determine image format. please feed me more data
-        //printf ("NSImageRepLoadStatusUnknownType size %d, isComplete %d\n", length, isComplete);
-        return NO;
-    case NSImageRepLoadStatusReadingHeader:     // image format known, reading header. not yet valid. more data needed
-        //printf ("NSImageRepLoadStatusReadingHeader size %d, isComplete %d\n", length, isComplete);
-        return NO;
-    case NSImageRepLoadStatusWillNeedAllData:   // can't read incrementally. will wait for complete data to become avail.
-        //printf ("NSImageRepLoadStatusWillNeedAllData size %d, isComplete %d\n", length, isComplete);
-        return NO;
-    case NSImageRepLoadStatusInvalidData:       // image decompression encountered error.
-        //printf ("NSImageRepLoadStatusInvalidData size %d, isComplete %d\n", length, isComplete);
-        return NO;
-    case NSImageRepLoadStatusUnexpectedEOF:     // ran out of data before full image was decompressed.
-        //printf ("NSImageRepLoadStatusUnexpectedEOF size %d, isComplete %d\n", length, isComplete);
-        return NO;
-    case NSImageRepLoadStatusCompleted:         // all is well, the full pixelsHigh image is valid.
-        //printf ("NSImageRepLoadStatusCompleted size %d, isComplete %d\n", length, isComplete);
-        [self _adjustSizeToPixelDimensions];        
-        isNull = NO;
-        return YES;
-    default:
-        [self _adjustSizeToPixelDimensions];
-        //printf ("incrementalLoadWithBytes: size %d, isComplete %d\n", length, isComplete);
-        // We have some valid data.  Return YES so we can attempt to draw what we've got.
-        isNull = NO;
-        return YES;
-    }
+    NSArray *reps = [self representations];
+    NSBitmapImageRep *imageRep = [reps count] > 0 ? [[self representations] objectAtIndex:0] : nil;
     
+    if (imageRep && [imageRep isKindOfClass: [NSBitmapImageRep class]]) {
+        NSData *data = [[NSData alloc] initWithBytes:bytes length:length];
+
+        NS_DURING
+            loadStatus = [imageRep incrementalLoadFromData:data complete:isComplete];
+        NS_HANDLER
+            loadStatus = NSImageRepLoadStatusInvalidData; // Arbitrary choice; any error will do.
+        NS_ENDHANDLER
+
+        // Hold onto the original data in case we need to copy this image.  (Workaround for appkit NSImage
+        // copy flaw).
+        if (isComplete && [self frameCount] > 1)
+            originalData = data;
+        else
+            [data release];
+
+        switch (loadStatus) {
+        case NSImageRepLoadStatusUnknownType:       // not enough data to determine image format. please feed me more data
+            //printf ("NSImageRepLoadStatusUnknownType size %d, isComplete %d\n", length, isComplete);
+            return NO;
+        case NSImageRepLoadStatusReadingHeader:     // image format known, reading header. not yet valid. more data needed
+            //printf ("NSImageRepLoadStatusReadingHeader size %d, isComplete %d\n", length, isComplete);
+            return NO;
+        case NSImageRepLoadStatusWillNeedAllData:   // can't read incrementally. will wait for complete data to become avail.
+            //printf ("NSImageRepLoadStatusWillNeedAllData size %d, isComplete %d\n", length, isComplete);
+            return NO;
+        case NSImageRepLoadStatusInvalidData:       // image decompression encountered error.
+            //printf ("NSImageRepLoadStatusInvalidData size %d, isComplete %d\n", length, isComplete);
+            return NO;
+        case NSImageRepLoadStatusUnexpectedEOF:     // ran out of data before full image was decompressed.
+            //printf ("NSImageRepLoadStatusUnexpectedEOF size %d, isComplete %d\n", length, isComplete);
+            return NO;
+        case NSImageRepLoadStatusCompleted:         // all is well, the full pixelsHigh image is valid.
+            //printf ("NSImageRepLoadStatusCompleted size %d, isComplete %d\n", length, isComplete);
+            [self _adjustSizeToPixelDimensions];        
+            isNull = NO;
+            return YES;
+        default:
+            [self _adjustSizeToPixelDimensions];
+            //printf ("incrementalLoadWithBytes: size %d, isComplete %d\n", length, isComplete);
+            // We have some valid data.  Return YES so we can attempt to draw what we've got.
+            isNull = NO;
+            return YES;
+        }
+    }
+    else {
+        if (isComplete) {
+            originalData = [[NSData alloc] initWithBytes:bytes length:length];
+            if ([MIMEType isEqual:@"application/pdf"]) {
+                Class repClass = [NSImageRep imageRepClassForData:originalData];
+                if (repClass) {
+                    NSImageRep *rep = [[repClass alloc] initWithData:originalData];
+                    [self addRepresentation:rep];
+                }
+            }
+            isNull = NO;
+            return YES;
+        }
+    }
     return NO;
 }
 
@@ -234,6 +344,12 @@ static NSMutableSet *activeImageRenderers;
     [patternColor release];
     [MIMEType release];
     [originalData release];
+    
+    if (context) {
+        CFRelease (context);
+        context = 0;
+    }
+    
     [super dealloc];
 }
 
@@ -307,6 +423,48 @@ static NSMutableSet *activeImageRenderers;
                                                    repeats:NO] retain];
 }
 
+- (NSGraphicsContext *)_beginRedirectContext:(CGContextRef)aContext
+{
+    NSGraphicsContext *oldContext = 0;
+    if (aContext) {
+        oldContext = [NSGraphicsContext currentContext];
+        // Assumes that we are redirecting to a CGBitmapContext.
+        size_t w = CGBitmapContextGetWidth (aContext);
+        size_t h = CGBitmapContextGetHeight (aContext);
+        redirectContext = [[WebImageContext alloc] initWithBounds:NSMakeRect(0, 0, (float)w, (float)h) context:aContext];
+        [NSGraphicsContext setCurrentContext:redirectContext];
+    }
+    return oldContext; 
+}
+
+- (void)_endRedirectContext:(NSGraphicsContext *)aContext
+{
+    if (aContext) {
+        [NSGraphicsContext setCurrentContext:aContext];
+        [redirectContext autorelease];
+        redirectContext = 0;
+    }
+}
+
+- (void)_needsRasterFlush
+{
+#if 0
+    // This doesn't work.  The PDF is always rasterized and cached!  Leaving
+    // this code in place, but excluded, pending response from AP.
+    NSImageRep *imageRep = [[self representations] objectAtIndex:0];
+    rasterFlushing = NO;
+    if (needFlushRasterCache && [imageRep isKindOfClass:[NSCachedImageRep class]] && [MIMEType isEqual: @"application/pdf"]) {
+        [self removeRepresentation:imageRep];
+        Class repClass = [NSImageRep imageRepClassForData:originalData];
+        if (repClass) {
+            NSImageRep *rep = [[repClass alloc] initWithData:originalData];
+            [self addRepresentation:rep];
+        }
+    }
+#endif
+}
+
+
 - (void)drawClippedToValidInRect:(NSRect)ir fromRect:(NSRect)fr
 {
     if (loadStatus >= 0) {
@@ -340,8 +498,13 @@ static NSMutableSet *activeImageRenderers;
         }
     }
     
+    NSGraphicsContext *oldContext = [self _beginRedirectContext:context];
+    [self _needsRasterFlush];
+
     // This is the operation that handles transparent portions of the source image correctly.
     [self drawInRect:ir fromRect:fr operation:compositeOperator fraction: 1.0];
+
+    [self _endRedirectContext:oldContext];
 }
 
 - (void)nextFrame:(id)context
@@ -378,7 +541,7 @@ static NSMutableSet *activeImageRenderers;
 - (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr
 {
     if (animatedTile){
-        [self tileInRect:ir fromPoint:tilePoint];
+        [self tileInRect:ir fromPoint:tilePoint context:context];
     }
     else {
         [self drawClippedToValidInRect:ir fromRect:fr];
@@ -388,9 +551,23 @@ static NSMutableSet *activeImageRenderers;
     }
 }
 
-- (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr compositeOperator:(NSCompositingOperation)operator
+- (void)flushRasterCache
+{
+    needFlushRasterCache = YES;
+}
+
+- (void)drawImageInRect:(NSRect)ir fromRect:(NSRect)fr compositeOperator:(NSCompositingOperation)operator context:(CGContextRef)aContext
 {
     compositeOperator = operator;
+    
+    if (context != aContext) {
+        if (context)
+            CFRelease (context);
+        if (aContext)
+            CFRetain (aContext);
+        context = aContext;
+    }
+        
     [self drawImageInRect:ir fromRect:fr];
 }
 
@@ -422,7 +599,7 @@ static NSMutableSet *activeImageRenderers;
     [activeImageRenderers removeObject:self];
 }
 
-- (void)tileInRect:(NSRect)rect fromPoint:(NSPoint)point
+- (void)tileInRect:(NSRect)rect fromPoint:(NSPoint)point context:(CGContextRef)aContext
 {
     // These calculations are only correct for the flipped case.
     ASSERT([self isFlipped]);
@@ -470,6 +647,9 @@ static NSMutableSet *activeImageRenderers;
         patternColorLoadStatus = loadStatus;
     }
         
+    NSGraphicsContext *oldContext = [self _beginRedirectContext:context];
+    [self _needsRasterFlush];
+    
     [NSGraphicsContext saveGraphicsState];
     
     CGContextSetPatternPhase((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort], phase);    
@@ -478,6 +658,8 @@ static NSMutableSet *activeImageRenderers;
     
     [NSGraphicsContext restoreGraphicsState];
 
+    [self _endRedirectContext:oldContext];
+
     animatedTile = YES;
     tilePoint = point;
     targetRect = rect;
diff --git a/WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m b/WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m
index 880d876..fcdb188 100644
--- a/WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m
+++ b/WebKit/WebCoreSupport.subproj/WebImageRendererFactory.m
@@ -29,6 +29,8 @@
 #import <WebKit/WebAssertions.h>
 #import <Foundation/NSURLFileTypeMappings.h>
 
+#import <CoreGraphics/CGContextPrivate.h>
+
 @implementation WebImageRendererFactory
 
 + (void)createSharedFactory
@@ -48,9 +50,12 @@
 {
     NSImage *imageRenderer = [[WebImageRenderer alloc] initWithMIMEType:MIMEType];
 
-    NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initForIncrementalLoad];
-    [imageRenderer addRepresentation:rep];
-    [rep autorelease];
+    if (![MIMEType isEqual:@"application/pdf"]) {
+        NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initForIncrementalLoad];
+        [imageRenderer addRepresentation:rep];
+        [rep autorelease];
+    }
+
     [imageRenderer setFlipped:YES];
     
     // Turn the default caching mode back on when the image has completed load.
@@ -121,6 +126,59 @@
     return imageRenderer;
 }
 
+struct CompositeOperator
+{
+    NSString *name;
+    CGCompositeOperation value;
+};
+
+#define NUM_COMPOSITE_OPERATORS 14
+struct CompositeOperator CGCompositeOperations[NUM_COMPOSITE_OPERATORS] = {
+    { @"clear", kCGCompositeClear },
+    { @"copy", kCGCompositeCopy },
+    { @"source-over", kCGCompositeSover },
+    { @"source-in", kCGCompositeSin },
+    { @"source-out", kCGCompositeSout },
+    { @"source-atop", kCGCompositeSatop },
+    { @"destination-over", kCGCompositeDover },
+    { @"destination-in", kCGCompositeDin },
+    { @"destination-out", kCGCompositeDout },
+    { @"destination-atop", kCGCompositeDatop },
+    { @"xor", kCGCompositeXor },
+    { @"darker", kCGCompositePlusd },
+    { @"highlight", kCGCompositePlusl },
+    { @"lighter", kCGCompositePlusl }    // Per AppKit
+};
+
+- (int)CGCompositeOperationInContext:(CGContextRef)context
+{
+    CGCompositeOperation op = CGContextGetCompositeOperation (context);
+    return (int)op;
+}
+
+- (void)setCGCompositeOperation:(int)op inContext:(CGContextRef)context
+{
+    CGContextSetCompositeOperation(context, (CGCompositeOperation)op);
+}
+
+- (void)setCGCompositeOperationFromString:(NSString *)operatorString inContext:(CGContextRef)context
+{
+    CGCompositeOperation op = kCGCompositeSover;
+    
+    if (operatorString) {
+        int i;
+        
+        for (i = 0; i < NUM_COMPOSITE_OPERATORS; i++) {
+            if ([operatorString caseInsensitiveCompare:CGCompositeOperations[i].name] == NSOrderedSame) {
+                op = CGCompositeOperations[i].value;
+                break;
+            }
+        }
+    }
+    
+    CGContextSetCompositeOperation(context, op);
+}
+
 
 - (NSArray *)supportedMIMETypes
 {

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list