70
edits
No edit summary |
Stuartmorgan (talk | contribs) (Clarify that this spec assumes the Carbon model, and explain the precedence, since it's a common point of confusion) |
||
| (19 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
= | = Status = | ||
Accepted, ready for implementation. | |||
== Contributors == | |||
* Last modified: April 22, 2010 | |||
* Authors: Tim Omernick (Apple) | |||
* Contributors: Josh Aas (Mozilla Corporation) | |||
== Overview == | == Overview == | ||
The Core Graphics drawing model is an alternative drawing model for 32-bit Mac OS X plugins and the default drawing model for 64-bit Mac OS X plugins. | |||
<i>Note: This specification pre-dates the Cocoa specification, so it assumes the Carbon event model. Discussions of "changes" refer to differences from the QuickDraw drawing model. When using CoreGraphics with the [[NPAPI:CocoaEventModel|Cocoa event model]], changes in the Cocoa model may supersede information given here.</i> | |||
== Negotiating Core Graphics Drawing == | |||
For documentation on negotiating drawing models, see [[NPAPI:Models]]. The drawing model variables for Core Graphics are: | |||
* NPDrawingModelCoreGraphics (NPDrawingModel = 1) | |||
* NPNVsupportsCoreGraphicsBool (NPNVariable = 2001) | |||
== Excluding QuickDraw == | |||
QuickDraw is default drawing model for 32-bit Mac OS X plugins. The QuickDraw drawing model does not exist for 64-bit Mac OS X. The drawing model variables for Quickdraw are: | |||
== | * NPDrawingModelQuickDraw (NPDrawingModel = 0) | ||
* NPNVsupportsQuickDrawBool (NPNVariable = 2000) | |||
Plugins and browsers that are compiled 64-bit must entirely exclude QuickDraw support, since there will be no 64-bit QuickDraw. | Plugins and browsers that are compiled 64-bit must entirely exclude QuickDraw support, since there will be no 64-bit QuickDraw. | ||
| Line 29: | Line 37: | ||
#endif | #endif | ||
== The Core Graphics Drawing Model == | |||
== The Drawing Model | |||
If a plugin sets the drawing model to NPDrawingModelCoreGraphics, then the meanings of some of the NPAPI data structures change: | If a plugin sets the drawing model to NPDrawingModelCoreGraphics, then the meanings of some of the NPAPI data structures change: | ||
- NPWindow's 'window' field becomes a NP_CGContext: | - NPWindow's 'window' field (under the Carbon event model) becomes a NP_CGContext: | ||
/* NP_CGContext is the type of the NPWindow's 'window' when the | /* NP_CGContext is the type of the NPWindow's 'window' when the | ||
| Line 106: | Line 51: | ||
WindowRef window; | WindowRef window; | ||
} NP_CGContext; | } NP_CGContext; | ||
'''Note:''' the CG context here is always flipped for historical reasons. | |||
- NPRegion becomes a CGPathRef instead of a RgnHandle: | - NPRegion becomes a CGPathRef instead of a RgnHandle: | ||
| Line 130: | Line 77: | ||
== Bridging QuickDraw and CoreGraphics == | == Bridging QuickDraw and CoreGraphics == | ||
There is a way for plugins to draw using CoreGraphics, yet remain compatible with QuickDraw-only browsers. The idea is to use QDBeginCGContext() and QDEndCGContext() to obtain a CGContextRef for the CGrafPtr provided by the browser. | |||
static CGContextRef beginQDPluginUpdate(NPWindow *window) | static CGContextRef beginQDPluginUpdate(NPWindow *window) | ||
{ | { | ||
// window->window is an NPPort* since the browser is using QuickDraw | // window->window is an NPPort* since the browser is using QuickDraw | ||
NP_Port *npPort = ((NP_Port *)window->window); | NP_Port *npPort = ((NP_Port *)window->window);<br> | ||
// Get the CGContext for the port | // Get the CGContext for the port | ||
CGContextRef cgContext; | CGContextRef cgContext; | ||
QDBeginCGContext(npPort->port, &cgContext); | QDBeginCGContext(npPort->port, &cgContext); | ||
CGContextSaveGState(cgContext); | CGContextSaveGState(cgContext);<br> | ||
// Set the CG clip path to the port's clip region -- QDBeginCGContext() | // Set the CG clip path to the port's clip region -- QDBeginCGContext() | ||
// does not automatically respect the QuickDraw port's clip region. | // does not automatically respect the QuickDraw port's clip region. | ||
| Line 149: | Line 94: | ||
GetPortBounds(npPort->port, &portBounds); | GetPortBounds(npPort->port, &portBounds); | ||
ClipCGContextToRegion(cgContext, &portBounds, clipRegion); | ClipCGContextToRegion(cgContext, &portBounds, clipRegion); | ||
DisposeRgn(clipRegion); | DisposeRgn(clipRegion);<br> | ||
// Flip the CG context vertically -- its origin is at the lower left, | // Flip the CG context vertically -- its origin is at the lower left, | ||
// but QuickDraw's origin is at the upper left. | // but QuickDraw's origin is at the upper left. | ||
CGContextTranslateCTM(cgContext, 0.0, portBounds.bottom - portBounds.top); | CGContextTranslateCTM(cgContext, 0.0, portBounds.bottom - portBounds.top); | ||
CGContextScaleCTM(cgContext, 1.0, -1.0); | CGContextScaleCTM(cgContext, 1.0, -1.0);<br> | ||
return cgContext; | return cgContext; | ||
}<br> | }<br> | ||
| Line 159: | Line 104: | ||
{ | { | ||
// Restore state (it was saved in beginQDPluginUpdate()) | // Restore state (it was saved in beginQDPluginUpdate()) | ||
CGContextRestoreGState(cgContext); | CGContextRestoreGState(cgContext);<br> | ||
// If we had to prepare the CGContext for use in a QuickDraw-only browser, | // If we had to prepare the CGContext for use in a QuickDraw-only browser, | ||
// restore its state and notify QD that the CG drawing sequence is over. | // restore its state and notify QD that the CG drawing sequence is over. | ||
| Line 167: | Line 112: | ||
This trick will not work once QuickDraw is removed from Mac OS X. It is intended for plugin developers that want to draw using CoreGraphics, yet remain compatible with QuickDraw-only browsers that haven't adopted these proposed NPAPI extensions. | This trick will not work once QuickDraw is removed from Mac OS X. It is intended for plugin developers that want to draw using CoreGraphics, yet remain compatible with QuickDraw-only browsers that haven't adopted these proposed NPAPI extensions. | ||
edits