<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[20042] trunk/WebKit</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/20042">20042</a></dd>
<dt>Author</dt> <dd>bdash</dd>
<dt>Date</dt> <dd>2007-03-07 17:34:23 -0800 (Wed, 07 Mar 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre>2007-03-07 Bruce Q Hammond <bruceq@apple.om>
Reviewed by Darin.
This fixes a problem with Netscape-style Plug-ins which draw through the Quickdraw APIs
being unable to render into offscreen bitmap contexts.
This patches both saveAndSetNewPortStateForUpdate: and restorePortState:
These methods now check the current context and see if appropriate setup/cleanup needs to be done
for offscreen rendering.
* Plugins/WebBaseNetscapePluginView.mm:
(QDPixelFormatFromCGBitmapInfo):
(-[WebBaseNetscapePluginView saveAndSetNewPortStateForUpdate:]):
(-[WebBaseNetscapePluginView restorePortState:]):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitChangeLog">trunk/WebKit/ChangeLog</a></li>
<li><a href="#trunkWebKitPluginsWebBaseNetscapePluginViewmm">trunk/WebKit/Plugins/WebBaseNetscapePluginView.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/ChangeLog (20041 => 20042)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/ChangeLog        2007-03-08 01:29:17 UTC (rev 20041)
+++ trunk/WebKit/ChangeLog        2007-03-08 01:34:23 UTC (rev 20042)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2007-03-07 Bruce Q Hammond <bruceq@apple.om>
+
+ Reviewed by Darin.
+
+ This fixes a problem with Netscape-style Plug-ins which draw through the Quickdraw APIs
+ being unable to render into offscreen bitmap contexts.
+
+ This patches both saveAndSetNewPortStateForUpdate: and restorePortState:
+ These methods now check the current context and see if appropriate setup/cleanup needs to be done
+ for offscreen rendering.
+
+ * Plugins/WebBaseNetscapePluginView.mm:
+ (QDPixelFormatFromCGBitmapInfo):
+ (-[WebBaseNetscapePluginView saveAndSetNewPortStateForUpdate:]):
+ (-[WebBaseNetscapePluginView restorePortState:]):
+
</ins><span class="cx"> 2007-03-07 Anders Carlsson <acarlsson@apple.com>
</span><span class="cx">
</span><span class="cx"> Reviewed by Darin.
</span></span></pre></div>
<a id="trunkWebKitPluginsWebBaseNetscapePluginViewmm"></a>
<div class="modfile"><h4>Modified: trunk/WebKit/Plugins/WebBaseNetscapePluginView.mm (20041 => 20042)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKit/Plugins/WebBaseNetscapePluginView.mm        2007-03-08 01:29:17 UTC (rev 20041)
+++ trunk/WebKit/Plugins/WebBaseNetscapePluginView.mm        2007-03-08 01:34:23 UTC (rev 20042)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #import "WebGraphicsExtras.h"
</span><span class="cx"> #import "WebKitLogging.h"
</span><span class="cx"> #import "WebKitNSStringExtras.h"
</span><ins>+#import "WebKitSystemInterface.h"
</ins><span class="cx"> #import "WebNSDataExtras.h"
</span><span class="cx"> #import "WebNSDictionaryExtras.h"
</span><span class="cx"> #import "WebNSObjectExtras.h"
</span><span class="lines">@@ -56,10 +57,8 @@
</span><span class="cx"> #import <WebCore/FrameLoader.h>
</span><span class="cx"> #import <WebCore/FrameTree.h>
</span><span class="cx"> #import <WebCore/Page.h>
</span><del>-#import <WebCore/WebCoreObjCExtras.h>
</del><span class="cx"> #import <WebKit/DOMPrivate.h>
</span><span class="cx"> #import <WebKit/WebUIDelegate.h>
</span><del>-#import <WebKitSystemInterface.h>
</del><span class="cx"> #import <objc/objc-runtime.h>
</span><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span><span class="lines">@@ -262,6 +261,28 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#ifndef NP_NO_QUICKDRAW
+static UInt32 QDPixelFormatFromCGBitmapInfo(CGBitmapInfo bitmapInfo)
+{
+ UInt32 cgByteOrder = bitmapInfo & kCGBitmapByteOrderMask;
+ switch (cgByteOrder) {
+ case kCGBitmapByteOrderDefault:
+ return 0;
+ case kCGBitmapByteOrder16Little:
+ return k16LE555PixelFormat;
+ case kCGBitmapByteOrder32Little:
+ return k32BGRAPixelFormat;
+ case kCGBitmapByteOrder16Big:
+ return k16BE555PixelFormat;
+ case kCGBitmapByteOrder32Big:
+ return k32ARGBPixelFormat;
+ default:
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+}
+#endif
+
</ins><span class="cx"> - (PortState)saveAndSetNewPortStateForUpdate:(BOOL)forUpdate
</span><span class="cx"> {
</span><span class="cx"> ASSERT([self currentWindow] != nil);
</span><span class="lines">@@ -372,13 +393,58 @@
</span><span class="cx">
</span><span class="cx"> RgnHandle clipRegion = NewRgn();
</span><span class="cx"> qdPortState->clipRegion = clipRegion;
</span><del>-
</del><ins>+
+ CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+ // If the current context is an offscreen bitmap, then we create a GWorld for it
+ bool offScreenContext = WKCGContextIsBitmapContext(currentContext);
+ if (offScreenContext) {
+ CGBitmapInfo contextBitmapInfo = CGBitmapContextGetBitmapInfo(currentContext);
+ GWorldPtr pOffScreenGWorld;
+ Rect offscreenBounds;
+ int rowBytes = CGBitmapContextGetBytesPerRow(currentContext);
+ offscreenBounds.top = 0;
+ offscreenBounds.left = 0;
+ offscreenBounds.right = CGBitmapContextGetWidth(currentContext);
+ offscreenBounds.bottom = CGBitmapContextGetHeight(currentContext);
+ UInt32 pixelFormat = QDPixelFormatFromCGBitmapInfo(contextBitmapInfo);
+ if (pixelFormat == 0) {
+ // Not a valid pixel format - don't render at all.
+ offscreenBounds.top = 0;
+ offscreenBounds.left = 0;
+ offscreenBounds.right = 0;
+ offscreenBounds.bottom = 0;
+ rowBytes = 0;
+ pixelFormat = k32BGRAPixelFormat;
+ }
+ void* bits = CGBitmapContextGetData(currentContext);
+ QDErr err = NewGWorldFromPtr(&pOffScreenGWorld, pixelFormat, &offscreenBounds, 0, 0, 0, static_cast<char*>(bits), rowBytes);
+ ASSERT(pOffScreenGWorld && !err);
+ if (!err) {
+ SetGWorld(pOffScreenGWorld, NULL);
+ nPort.qdPort.port = pOffScreenGWorld;
+ NSRect boundsInWindow = [self bounds];
+ nPort.qdPort.portx = ((int32)-boundsInWindow.origin.x);
+ nPort.qdPort.porty = ((int32)-boundsInWindow.origin.y);
+ window.x = 0;
+ window.y = 0;
+ window.window = &nPort;
+
+ // Get the clip bounds for the existing context and use that for the plug-in's window.clipRect.
+ // The plug-in will intersect this clip rect with the port's dirty region clip constructed below.
+ CGRect contextClip = CGContextGetClipBoundingBox(currentContext);
+ window.clipRect.top = contextClip.origin.y;
+ window.clipRect.left = contextClip.origin.x;
+ window.clipRect.right = window.clipRect.left + contextClip.size.width;
+ window.clipRect.bottom = window.clipRect.top + contextClip.size.height;
+ }
+ }
</ins><span class="cx"> MacSetRectRgn(clipRegion,
</span><span class="cx"> window.clipRect.left + nPort.qdPort.portx, window.clipRect.top + nPort.qdPort.porty,
</span><span class="cx"> window.clipRect.right + nPort.qdPort.portx, window.clipRect.bottom + nPort.qdPort.porty);
</span><span class="cx">
</span><span class="cx"> // Clip to dirty region so plug-in does not draw over already-drawn regions of the window that are
</span><span class="cx"> // not going to be redrawn this update. This forces plug-ins to play nice with z-index ordering.
</span><ins>+ Rect clipBounds;
</ins><span class="cx"> if (forUpdate) {
</span><span class="cx"> RgnHandle viewClipRegion = NewRgn();
</span><span class="cx">
</span><span class="lines">@@ -406,19 +472,19 @@
</span><span class="cx"> // Intersect the dirty region with the clip region, so that we only draw over dirty parts
</span><span class="cx"> SectRgn(clipRegion, viewClipRegion, clipRegion);
</span><span class="cx"> DisposeRgn(viewClipRegion);
</span><ins>+ if (offScreenContext) {
+ GetRegionBounds(clipRegion, &clipBounds);
+ OffsetRgn(clipRegion, -clipBounds.left, -clipBounds.top);
+ port = nPort.qdPort.port;
+ }
</ins><span class="cx"> }
</span><del>-
- qdPortState->forUpdate = forUpdate;
-
</del><ins>+
</ins><span class="cx"> // Switch to the port and set it up.
</span><span class="cx"> SetPort(port);
</span><del>-
</del><span class="cx"> PenNormal();
</span><span class="cx"> ForeColor(blackColor);
</span><span class="cx"> BackColor(whiteColor);
</span><del>-
</del><span class="cx"> SetOrigin(nPort.qdPort.portx, nPort.qdPort.porty);
</span><del>-
</del><span class="cx"> SetPortClipRegion(nPort.qdPort.port, clipRegion);
</span><span class="cx">
</span><span class="cx"> if (forUpdate) {
</span><span class="lines">@@ -429,8 +495,13 @@
</span><span class="cx">
</span><span class="cx"> // Some plugins do their own BeginUpdate/EndUpdate.
</span><span class="cx"> // For those, we must make sure that the update region contains the area we want to draw.
</span><ins>+ if (offScreenContext)
+ OffsetRgn(clipRegion, clipBounds.left, clipBounds.top);
</ins><span class="cx"> InvalWindowRgn(windowRef, clipRegion);
</span><span class="cx"> }
</span><ins>+
+ qdPortState->forUpdate = forUpdate;
+
</ins><span class="cx"> }
</span><span class="cx"> break;
</span><span class="cx"> #endif /* NP_NO_QUICKDRAW */
</span><span class="lines">@@ -526,6 +597,19 @@
</span><span class="cx"> #ifndef NP_NO_QUICKDRAW
</span><span class="cx"> case NPDrawingModelQuickDraw:
</span><span class="cx"> {
</span><ins>+ CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+
+ // If the current context is an offscreen bitmap, then we need to
+ // dispose its GWorld and restore the Window's GWorld
+ if (WKCGContextIsBitmapContext(currentContext)) {
+ GWorldPtr curGWorld;
+ GetGWorld(&curGWorld, NULL);
+ DisposeGWorld(curGWorld);
+ WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
+ CGrafPtr port = GetWindowPort(windowRef);
+ SetGWorld(port, NULL);
+ }
+
</ins><span class="cx"> PortState_QD *qdPortState = (PortState_QD *)portState;
</span><span class="cx"> WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
</span><span class="cx"> CGrafPtr port = GetWindowPort(windowRef);
</span><span class="lines">@@ -542,7 +626,7 @@
</span><span class="cx"> DisposeRgn(qdPortState->oldVisibleRegion);
</span><span class="cx"> DisposeRgn(qdPortState->clipRegion);
</span><span class="cx">
</span><del>- SetPort(qdPortState->oldPort);
</del><ins>+ SetGWorld(qdPortState->oldPort, NULL);
</ins><span class="cx"> }
</span><span class="cx"> break;
</span><span class="cx"> #endif /* NP_NO_QUICKDRAW */
</span></span></pre>
</div>
</div>
</body>
</html>