void Gradient::platformDestroy()
{
#ifdef BUILDING_ON_TIGER
    CGShadingRelease(m_gradient);
#else
    CGGradientRelease(m_gradient);
#endif
    m_gradient = 0;
}
// -----------------------------------------------------------------------------
//	ShadeRectColor
// -----------------------------------------------------------------------------
//
OSStatus ShadeRectColor(
	const CGRGB*		inStartColor,
	const CGRGB*		inEndColor,
	const HIRect*		inRect,
	CGContextRef		inContext )
{
	OSStatus			err = noErr;
	CGColorSpaceRef		colorSpace;
	CGFunctionCallbacks	callbacks = { 0, ColorGradientEvaluate, NULL };
	CGFunctionRef		function;
	CGShadingRef		shading;
	ColorShadeData		data;
	
	// Warning: this stuff is sitting on the stack.  Be careful if you move
	// the shading code around.
	data.start = *inStartColor;
	data.range.red = inEndColor->red - inStartColor->red;
	data.range.green = inEndColor->green - inStartColor->green;
	data.range.blue = inEndColor->blue - inStartColor->blue;
	
	CGContextSaveGState( inContext );
	CGContextClipToRect( inContext, *inRect );

	colorSpace = CGColorSpaceCreateDeviceRGB();
	require_action( colorSpace != NULL, CantCreateColorSpace, err = memFullErr );

	function = CGFunctionCreate(
			&data,			// info
			1,				// domainDimension
			NULL,			// input domain NULL == no range clipping
			4,				// rangeDimension,
			NULL,			// output domain NULL == no range clipping
			&callbacks );	// CGFunctionCallbacks
	require_action( function != NULL, CantCreateFunction, err = memFullErr );

	shading = CGShadingCreateAxial(
			colorSpace,
			inRect->origin,	// start
			CGPointMake( CGRectGetMinX( *inRect ), CGRectGetMaxY( *inRect ) ),	// end
			function,
			false,			// extendStart
			false );		// extendEnd
	require_action( colorSpace != NULL, CantCreateShading, err = memFullErr );

	CGContextDrawShading( inContext, shading);

CantCreateFunction:
	CGShadingRelease( shading );

CantCreateShading:
	CGColorSpaceRelease( colorSpace );

CantCreateColorSpace:
	CGContextRestoreGState( inContext );
	
	return err;
}
void SVGPaintServerGradient::invalidate()
{
    // Invalidate caches
    delete m_stopsCache;
    CGShadingRelease(m_shadingCache);

    m_stopsCache = 0;
    m_shadingCache = 0;
}
Exemple #4
0
void Gradient::platformDestroy()
{
#if USE_CG_SHADING
    CGShadingRelease(m_gradient);
#else
    CGGradientRelease(m_gradient);
#endif
    m_gradient = 0;
}
void SVGPaintServerGradient::updateQuartzGradientCache(const SVGPaintServerGradient* server)
{
    // cache our own copy of the stops for faster access.
    // this is legacy code, probably could be reworked.
    if (!m_stopsCache)
        updateQuartzGradientStopsCache(gradientStops());

    CGShadingRelease(m_shadingCache);

    if (type() == RadialGradientPaintServer) {
        const SVGPaintServerRadialGradient* radial = static_cast<const SVGPaintServerRadialGradient*>(server);
        m_shadingCache = CGShadingRefForRadialGradient(radial);
    } else if (type() == LinearGradientPaintServer) {
        const SVGPaintServerLinearGradient* linear = static_cast<const SVGPaintServerLinearGradient*>(server);
        m_shadingCache = CGShadingRefForLinearGradient(linear);
    }
}
void TIPGradientRadialFillRect( CGContextRef theContext, TIPGradientRef theGradient, CGRect theRect, CGPoint center, float radius)
{
    CGPoint startPoint = center;
    CGPoint endPoint = center;
    float startRadius = 1.0f;
    float endRadius = radius;

    // CoreGraphics Calls
    CGContextSaveGState(theContext);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    CGShadingRef myCGShading = CGShadingCreateRadial(colorSpace,startPoint,startRadius,endPoint,endRadius,theGradient->gradientFunction,FALSE,FALSE);

    CGContextClipToRect(theContext,theRect);
    CGContextDrawShading(theContext,myCGShading);

    CGShadingRelease(myCGShading);
    CGColorSpaceRelease(colorSpace);
    CGContextRestoreGState(theContext);
}
void TIPGradientAxialFillRect( CGContextRef theContext, TIPGradientRef theGradient, CGRect theRect, float angle)
{
    CGPoint startPoint;
    CGPoint endPoint;

    TIPGradientFindEndpointsForRotation(theRect,angle,&startPoint,&endPoint);

    // CoreGraphics Calls
    CGContextSaveGState(theContext);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    CGShadingRef myCGShading = CGShadingCreateAxial(colorSpace,startPoint,endPoint,theGradient->gradientFunction,FALSE,FALSE);

    CGContextClipToRect(theContext,theRect);
    CGContextDrawShading(theContext,myCGShading);

    CGShadingRelease(myCGShading);
    CGColorSpaceRelease(colorSpace);
    CGContextRestoreGState(theContext);
}
SVGPaintServerGradient::~SVGPaintServerGradient()
{
#if PLATFORM(CG)
    CGShadingRelease(m_shadingCache);
#endif
}