NPAPI:CoreGraphicsDrawing: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 92: Line 92:
In 64-bit, the QuickDraw drawing model does not exist, so CoreGraphics is the default drawing model.
In 64-bit, the QuickDraw drawing model does not exist, so CoreGraphics is the default drawing model.


The CoreGraphics drawing model
== The CoreGraphics 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:
Line 136: Line 136:
  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);   
    // 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);
    // 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.
    RgnHandle clipRegion = NewRgn();
    RgnHandle clipRegion = NewRgn();
    GetPortClipRegion(npPort->port, clipRegion);
    GetPortClipRegion(npPort->port, clipRegion);
    Rect portBounds;
    Rect portBounds;
    GetPortBounds(npPort->port, &portBounds);
    GetPortBounds(npPort->port, &portBounds);
    ClipCGContextToRegion(cgContext, &portBounds, clipRegion);
    ClipCGContextToRegion(cgContext, &portBounds, clipRegion);
    DisposeRgn(clipRegion);
    DisposeRgn(clipRegion);
    // 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);
    return cgContext;
    return cgContext;
  }<br>
  }<br>
  static void endQDPluginUpdate(NPWindow *window, CGContextRef cgContext)
  static void endQDPluginUpdate(NPWindow *window, CGContextRef cgContext)
  {
  {
    // Restore state (it was saved in beginQDPluginUpdate())
    // Restore state (it was saved in beginQDPluginUpdate())
    CGContextRestoreGState(cgContext);
    CGContextRestoreGState(cgContext);
    // 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.
    CGContextFlush(cgContext);
    CGContextFlush(cgContext);
    QDEndCGContext(((NP_Port *)window->window)->port, &cgContext);
    QDEndCGContext(((NP_Port *)window->window)->port, &cgContext);
  }
  }


Confirmed users, Bureaucrats and Sysops emeriti
1,680

edits

Navigation menu