GraphicsContextCG.cpp [plain text]
#define _USE_MATH_DEFINES 1
#include "config.h"
#include "GraphicsContextCG.h"
#include "AffineTransform.h"
#include "FloatConversion.h"
#include "GraphicsContextPlatformPrivateCG.h"
#include "ImageBuffer.h"
#include "KURL.h"
#include "Path.h"
#include "Pattern.h"
#include "ShadowBlur.h"
#include <CoreGraphics/CoreGraphics.h>
#include <wtf/MathExtras.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/UnusedParam.h>
#if ENABLE(RESPECT_EXIF_ORIENTATION)
#include "BitmapImage.h"
#include "ImageSourceCG.h"
#endif
#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
#include "WebCoreSystemInterface.h"
#endif
#if PLATFORM(WIN)
#include <WebKitSystemInterface/WebKitSystemInterface.h>
#endif
#include <CoreGraphics/CGContextGState.h>
#include <wtf/HashMap.h>
#include <wtf/UnusedParam.h>
#define HAVE_CG_INTERPOLATION_MEDIUM 1
#define WTF_USE_CG_INTERPOLATION_MEDIUM 1
using namespace std;
namespace WebCore {
static void setCGFillColor(CGContextRef context, const Color& color, ColorSpace colorSpace)
{
CGContextSetFillColorWithColor(context, cachedCGColor(color, colorSpace));
}
static void setCGStrokeColor(CGContextRef context, const Color& color, ColorSpace colorSpace)
{
CGContextSetStrokeColorWithColor(context, cachedCGColor(color, colorSpace));
}
CGColorSpaceRef deviceRGBColorSpaceRef()
{
static CGColorSpaceRef deviceSpace = CGColorSpaceCreateDeviceRGB();
return deviceSpace;
}
CGColorSpaceRef sRGBColorSpaceRef()
{
return deviceRGBColorSpaceRef();
}
void setStrokeAndFillColor(CGContextRef context, CGColorRef color)
{
CGContextSetStrokeColorWithColor(context, color);
CGContextSetFillColorWithColor(context, color);
}
CGColorSpaceRef linearRGBColorSpaceRef()
{
return deviceRGBColorSpaceRef();
}
void GraphicsContext::platformInit(CGContextRef cgContext, bool setContextColors)
{
m_data = new GraphicsContextPlatformPrivate(cgContext);
setPaintingDisabled(!cgContext);
m_state.shouldUseContextColors = setContextColors;
if (cgContext && setContextColors) {
setPlatformFillColor(fillColor(), fillColorSpace());
setPlatformStrokeColor(strokeColor(), strokeColorSpace());
}
}
void GraphicsContext::platformDestroy()
{
delete m_data;
}
CGContextRef GraphicsContext::platformContext() const
{
ASSERT(!paintingDisabled());
ASSERT(m_data->m_cgContext);
return m_data->m_cgContext.get();
}
void GraphicsContext::savePlatformState()
{
CGContextSaveGState(platformContext());
m_data->save();
}
void GraphicsContext::restorePlatformState()
{
CGContextRestoreGState(platformContext());
m_data->restore();
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::drawNativeImage(NativeImagePtr imagePtr, const FloatSize& imageSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect,
#if ENABLE(RESPECT_EXIF_ORIENTATION)
int orientation,
#endif
float scale,
CompositeOperator op)
{
RetainPtr<CGImageRef> image(imagePtr);
float currHeight = CGImageGetHeight(image.get());
#if ENABLE(RESPECT_EXIF_ORIENTATION)
if (orientationRequiresWidthAndHeightSwapped(orientation))
currHeight = CGImageGetWidth(image.get());
#endif
currHeight /= scale;
if (currHeight <= srcRect.y())
return;
CGContextRef context = platformContext();
CGContextSaveGState(context);
CGContextSetShouldAntialias(context, false);
bool shouldUseSubimage = false;
FloatRect adjustedDestRect = destRect;
if (srcRect.size() != imageSize) {
CGInterpolationQuality interpolationQuality = CGContextGetInterpolationQuality(context);
shouldUseSubimage = (interpolationQuality != kCGInterpolationNone) && (srcRect.size() != destRect.size() || !getCTM().isIdentityOrTranslationOrFlipped());
float xScale = srcRect.width() / destRect.width();
float yScale = srcRect.height() / destRect.height();
if (shouldUseSubimage) {
FloatRect subimageRect = srcRect;
float leftPadding = srcRect.x() - floorf(srcRect.x());
float topPadding = srcRect.y() - floorf(srcRect.y());
subimageRect.move(-leftPadding, -topPadding);
adjustedDestRect.move(-leftPadding / xScale, -topPadding / yScale);
subimageRect.setWidth(ceilf(subimageRect.width() + leftPadding));
adjustedDestRect.setWidth(subimageRect.width() / xScale);
subimageRect.setHeight(ceilf(subimageRect.height() + topPadding));
adjustedDestRect.setHeight(subimageRect.height() / yScale);
subimageRect.scale(scale, scale);
image.adoptCF(CGImageCreateWithImageInRect(image.get(), subimageRect));
if (currHeight < srcRect.maxY()) {
ASSERT(CGImageGetHeight(image.get()) == currHeight - CGRectIntegral(srcRect).origin.y);
adjustedDestRect.setHeight(CGImageGetHeight(image.get()) / yScale);
}
} else {
adjustedDestRect.setLocation(FloatPoint(destRect.x() - srcRect.x() / xScale, destRect.y() - srcRect.y() / yScale));
adjustedDestRect.setSize(FloatSize(imageSize.width() / xScale, imageSize.height() / yScale));
}
if (!destRect.contains(adjustedDestRect))
CGContextClipToRect(context, destRect);
}
if (!shouldUseSubimage && currHeight < imageSize.height())
adjustedDestRect.setHeight(adjustedDestRect.height() * currHeight / imageSize.height());
adjustedDestRect = roundToDevicePixels(adjustedDestRect);
#if ENABLE(RESPECT_EXIF_ORIENTATION)
float w = adjustedDestRect.width();
float h = adjustedDestRect.height();
CGAffineTransform transform;
switch (orientation) {
case BitmapImage::ImageEXIFOrientationBottomRight:
transform = CGAffineTransformMake(-1, 0, 0, -1, w, h);
break;
case BitmapImage::ImageEXIFOrientationLeftBottom:
transform = CGAffineTransformMake( 0, 1, -1, 0, w, 0);
break;
case BitmapImage::ImageEXIFOrientationRightTop:
transform = CGAffineTransformMake( 0, -1, 1, 0, 0, h);
break;
case BitmapImage::ImageEXIFOrientationTopRight:
transform = CGAffineTransformMake(-1, 0, 0, 1, w, 0);
break;
case BitmapImage::ImageEXIFOrientationBottomLeft:
transform = CGAffineTransformMake( 1, 0, 0, -1, 0, h);
break;
case BitmapImage::ImageEXIFOrientationLeftTop:
transform = CGAffineTransformMake( 0, -1, -1, 0, w, h);
break;
case BitmapImage::ImageEXIFOrientationRightBottom:
transform = CGAffineTransformMake( 0, 1, 1, 0, 0, 0);
break;
default:
transform = CGAffineTransformIdentity;
break;
}
CGContextTranslateCTM(context, adjustedDestRect.x(), adjustedDestRect.maxY());
#endif
setPlatformCompositeOperation(op);
CGContextScaleCTM(context, 1, -1);
#if ENABLE(RESPECT_EXIF_ORIENTATION)
CGContextConcatCTM(context, transform);
if (orientationRequiresWidthAndHeightSwapped(orientation)) {
adjustedDestRect = FloatRect(adjustedDestRect.x(), adjustedDestRect.y(), adjustedDestRect.height(), adjustedDestRect.width());
}
adjustedDestRect.setLocation(FloatPoint());
#else
adjustedDestRect.setY(-adjustedDestRect.maxY());
#endif
image = Image::imageWithColorSpace(image.get(), styleColorSpace);
CGContextDrawImage(context, adjustedDestRect, image.get());
CGContextRestoreGState(context);
}
void GraphicsContext::drawRect(const IntRect& rect)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
CGContextFillRect(context, rect);
if (strokeStyle() != NoStroke) {
Color oldFillColor = fillColor();
if (oldFillColor != strokeColor())
setCGFillColor(context, strokeColor(), strokeColorSpace());
CGRect rects[4] = {
FloatRect(rect.x(), rect.y(), rect.width(), 1),
FloatRect(rect.x(), rect.maxY() - 1, rect.width(), 1),
FloatRect(rect.x(), rect.y() + 1, 1, rect.height() - 2),
FloatRect(rect.maxX() - 1, rect.y() + 1, 1, rect.height() - 2)
};
CGContextFillRects(context, rects, 4);
if (oldFillColor != strokeColor())
setCGFillColor(context, oldFillColor, fillColorSpace());
}
}
void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2, bool antialias)
{
if (paintingDisabled())
return;
if (strokeStyle() == NoStroke)
return;
float width = strokeThickness();
FloatPoint p1 = point1;
FloatPoint p2 = point2;
bool isVerticalLine = (p1.x() == p2.x());
if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) {
if (isVerticalLine) {
p1.move(0, width);
p2.move(0, -width);
} else {
p1.move(width, 0);
p2.move(-width, 0);
}
}
if (((int)width) % 2) {
if (isVerticalLine) {
p1.move(0.5f, 0.0f);
p2.move(0.5f, 0.0f);
} else {
p1.move(0.0f, 0.5f);
p2.move(0.0f, 0.5f);
}
}
int patWidth = 0;
switch (strokeStyle()) {
case NoStroke:
case SolidStroke:
break;
case DottedStroke:
patWidth = (int)width;
break;
case DashedStroke:
patWidth = 3 * (int)width;
break;
}
CGContextRef context = platformContext();
if (shouldAntialias()) {
CGContextSetShouldAntialias(context, patWidth ? true : antialias);
}
if (patWidth) {
CGContextSaveGState(context);
setCGFillColor(context, strokeColor(), strokeColorSpace()); if (isVerticalLine) {
CGContextFillRect(context, FloatRect(p1.x() - width / 2, p1.y() - width, width, width));
CGContextFillRect(context, FloatRect(p2.x() - width / 2, p2.y(), width, width));
} else {
CGContextFillRect(context, FloatRect(p1.x() - width, p1.y() - width / 2, width, width));
CGContextFillRect(context, FloatRect(p2.x(), p2.y() - width / 2, width, width));
}
int distance = (isVerticalLine ? (point2.y() - point1.y()) : (point2.x() - point1.x())) - 2*(int)width;
int remainder = distance % patWidth;
int coverage = distance - remainder;
int numSegments = coverage / patWidth;
float patternOffset = 0.0f;
if (patWidth == 1)
patternOffset = 1.0f;
else {
bool evenNumberOfSegments = !(numSegments % 2);
if (remainder)
evenNumberOfSegments = !evenNumberOfSegments;
if (evenNumberOfSegments) {
if (remainder) {
patternOffset += patWidth - remainder;
patternOffset += remainder / 2;
} else
patternOffset = patWidth / 2;
} else {
if (remainder)
patternOffset = (patWidth - remainder)/2;
}
}
const CGFloat dottedLine[2] = { patWidth, patWidth };
CGContextSetLineDash(context, patternOffset, dottedLine, 2);
}
CGContextBeginPath(context);
CGContextMoveToPoint(context, p1.x(), p1.y());
CGContextAddLineToPoint(context, p2.x(), p2.y());
CGContextStrokePath(context);
if (patWidth)
CGContextRestoreGState(context);
if (shouldAntialias())
CGContextSetShouldAntialias(context, true);
}
void GraphicsContext::drawJoinedLines(CGPoint points [], unsigned count, bool antialias, CGLineCap lineCap)
{
if (paintingDisabled() || !count)
return;
CGContextRef context = platformContext();
float width = CGContextGetLineWidth(context);
CGContextSaveGState(context);
CGContextSetShouldAntialias(context, antialias);
CGContextSetLineWidth(context, width < 1 ? 1 : width);
CGContextBeginPath(context);
CGContextSetLineCap(context, lineCap);
CGContextMoveToPoint(context, points[0].x, points[0].y);
for (unsigned i = 1; i < count; ++i)
CGContextAddLineToPoint(context, points[i].x, points[i].y);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
void GraphicsContext::drawEllipse(const IntRect& rect)
{
if (paintingDisabled())
return;
Path path;
path.addEllipse(rect);
drawPath(path);
}
void GraphicsContext::drawEllipse(const FloatRect& rect)
{
if (paintingDisabled())
return;
CGContextRef context(platformContext());
CGContextSaveGState(context);
setCGFillColor(context, fillColor(), fillColorSpace());
setCGStrokeColor(context, strokeColor(), strokeColorSpace());
CGContextSetLineWidth(context, strokeThickness());
CGContextBeginPath(context);
CGContextAddEllipseInRect(context, rect);
CGContextFillPath(context);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan)
{
if (paintingDisabled() || strokeStyle() == NoStroke || strokeThickness() <= 0.0f)
return;
CGContextRef context = platformContext();
CGContextSaveGState(context);
CGContextBeginPath(context);
CGContextSetShouldAntialias(context, false);
int x = rect.x();
int y = rect.y();
float w = (float)rect.width();
float h = (float)rect.height();
float scaleFactor = h / w;
float reverseScaleFactor = w / h;
if (w != h)
scale(FloatSize(1, scaleFactor));
float hRadius = w / 2;
float vRadius = h / 2;
float fa = startAngle;
float falen = fa + angleSpan;
float start = -fa * piFloat / 180.0f;
float end = -falen * piFloat / 180.0f;
CGContextAddArc(context, x + hRadius, (y + vRadius) * reverseScaleFactor, hRadius, start, end, true);
if (w != h)
scale(FloatSize(1, reverseScaleFactor));
float width = strokeThickness();
int patWidth = 0;
switch (strokeStyle()) {
case DottedStroke:
patWidth = (int)(width / 2);
break;
case DashedStroke:
patWidth = 3 * (int)(width / 2);
break;
default:
break;
}
if (patWidth) {
int distance;
if (hRadius == vRadius)
distance = static_cast<int>((piFloat * hRadius) / 2.0f);
else distance = static_cast<int>((piFloat * sqrtf((hRadius * hRadius + vRadius * vRadius) / 2.0f)) / 2.0f);
int remainder = distance % patWidth;
int coverage = distance - remainder;
int numSegments = coverage / patWidth;
float patternOffset = 0.0f;
if (patWidth == 1)
patternOffset = 1.0f;
else {
bool evenNumberOfSegments = !(numSegments % 2);
if (remainder)
evenNumberOfSegments = !evenNumberOfSegments;
if (evenNumberOfSegments) {
if (remainder) {
patternOffset += patWidth - remainder;
patternOffset += remainder / 2.0f;
} else
patternOffset = patWidth / 2.0f;
} else {
if (remainder)
patternOffset = (patWidth - remainder) / 2.0f;
}
}
const CGFloat dottedLine[2] = { patWidth, patWidth };
CGContextSetLineDash(context, patternOffset, dottedLine, 2);
}
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
static void addConvexPolygonToPath(Path& path, size_t numberOfPoints, const FloatPoint* points)
{
ASSERT(numberOfPoints > 0);
path.moveTo(points[0]);
for (size_t i = 1; i < numberOfPoints; ++i)
path.addLineTo(points[i]);
path.closeSubpath();
}
void GraphicsContext::drawConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
{
if (paintingDisabled())
return;
if (numberOfPoints <= 1)
return;
CGContextRef context = platformContext();
if (antialiased != shouldAntialias())
CGContextSetShouldAntialias(context, antialiased);
Path path;
addConvexPolygonToPath(path, numberOfPoints, points);
drawPath(path);
if (antialiased != shouldAntialias())
CGContextSetShouldAntialias(context, shouldAntialias());
}
void GraphicsContext::clipConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialias)
{
if (paintingDisabled())
return;
if (numberOfPoints <= 1)
return;
CGContextRef context = platformContext();
if (antialias != shouldAntialias())
CGContextSetShouldAntialias(context, antialias);
Path path;
addConvexPolygonToPath(path, numberOfPoints, points);
clipPath(path, RULE_NONZERO);
if (antialias != shouldAntialias())
CGContextSetShouldAntialias(context, shouldAntialias());
}
void GraphicsContext::applyStrokePattern()
{
CGContextRef cgContext = platformContext();
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.strokePattern->createPlatformPattern(getCTM()));
if (!platformPattern)
return;
RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
CGContextSetStrokeColorSpace(cgContext, patternSpace.get());
const CGFloat patternAlpha = 1;
CGContextSetStrokePattern(cgContext, platformPattern.get(), &patternAlpha);
}
void GraphicsContext::applyFillPattern()
{
CGContextRef cgContext = platformContext();
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.fillPattern->createPlatformPattern(getCTM()));
if (!platformPattern)
return;
RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
CGContextSetFillColorSpace(cgContext, patternSpace.get());
const CGFloat patternAlpha = 1;
CGContextSetFillPattern(cgContext, platformPattern.get(), &patternAlpha);
}
static inline bool calculateDrawingMode(const GraphicsContextState& state, CGPathDrawingMode& mode)
{
bool shouldFill = state.fillPattern || state.fillColor.alpha();
bool shouldStroke = state.strokePattern || (state.strokeStyle != NoStroke && state.strokeColor.alpha());
bool useEOFill = state.fillRule == RULE_EVENODD;
if (shouldFill) {
if (shouldStroke) {
if (useEOFill)
mode = kCGPathEOFillStroke;
else
mode = kCGPathFillStroke;
} else { if (useEOFill)
mode = kCGPathEOFill;
else
mode = kCGPathFill;
}
} else {
mode = kCGPathStroke;
}
return shouldFill || shouldStroke;
}
void GraphicsContext::drawPath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
const GraphicsContextState& state = m_state;
if (state.fillGradient || state.strokeGradient) {
fillPath(path);
strokePath(path);
return;
}
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
if (state.fillPattern)
applyFillPattern();
if (state.strokePattern)
applyStrokePattern();
CGPathDrawingMode drawingMode;
if (calculateDrawingMode(state, drawingMode))
CGContextDrawPath(context, drawingMode);
}
static inline void fillPathWithFillRule(CGContextRef context, WindRule fillRule)
{
if (fillRule == RULE_EVENODD)
CGContextEOFillPath(context);
else
CGContextFillPath(context);
}
void GraphicsContext::fillPath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
if (m_state.fillGradient) {
if (hasShadow()) {
FloatRect rect = path.boundingRect();
CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextTranslateCTM(layerContext, -rect.x(), -rect.y());
CGContextBeginPath(layerContext);
CGContextAddPath(layerContext, path.platformPath());
CGContextConcatCTM(layerContext, m_state.fillGradient->gradientSpaceTransform());
if (fillRule() == RULE_EVENODD)
CGContextEOClip(layerContext);
else
CGContextClip(layerContext);
m_state.fillGradient->paint(layerContext);
CGContextDrawLayerAtPoint(context, CGPointMake(rect.x(), rect.y()), layer);
CGLayerRelease(layer);
} else {
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
CGContextSaveGState(context);
CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
if (fillRule() == RULE_EVENODD)
CGContextEOClip(context);
else
CGContextClip(context);
m_state.fillGradient->paint(this);
CGContextRestoreGState(context);
}
return;
}
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
if (m_state.fillPattern)
applyFillPattern();
fillPathWithFillRule(context, fillRule());
}
void GraphicsContext::strokePath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
if (m_state.strokeGradient) {
if (hasShadow()) {
FloatRect rect = path.boundingRect();
float lineWidth = strokeThickness();
float doubleLineWidth = lineWidth * 2;
float layerWidth = ceilf(rect.width() + doubleLineWidth);
float layerHeight = ceilf(rect.height() + doubleLineWidth);
CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(layerWidth, layerHeight), 0);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextSetLineWidth(layerContext, lineWidth);
float translationX = lineWidth - rect.x();
float translationY = lineWidth - rect.y();
CGContextTranslateCTM(layerContext, translationX, translationY);
CGContextAddPath(layerContext, path.platformPath());
CGContextReplacePathWithStrokedPath(layerContext);
CGContextClip(layerContext);
CGContextConcatCTM(layerContext, m_state.strokeGradient->gradientSpaceTransform());
m_state.strokeGradient->paint(layerContext);
float destinationX = roundf(rect.x() - lineWidth);
float destinationY = roundf(rect.y() - lineWidth);
CGContextDrawLayerAtPoint(context, CGPointMake(destinationX, destinationY), layer);
CGLayerRelease(layer);
} else {
CGContextSaveGState(context);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
m_state.strokeGradient->paint(this);
CGContextRestoreGState(context);
}
return;
}
if (m_state.strokePattern)
applyStrokePattern();
CGContextStrokePath(context);
}
static float radiusToLegacyRadius(float radius)
{
return radius > 8 ? 8 + 4 * sqrt((radius - 8) / 2) : radius;
}
static bool hasBlurredShadow(const GraphicsContextState& state)
{
return state.shadowColor.isValid() && state.shadowColor.alpha() && state.shadowBlur;
}
void GraphicsContext::fillRect(const FloatRect& rect)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
if (m_state.fillGradient) {
CGContextSaveGState(context);
if (hasShadow()) {
CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextTranslateCTM(layerContext, -rect.x(), -rect.y());
CGContextAddRect(layerContext, rect);
CGContextClip(layerContext);
CGContextConcatCTM(layerContext, m_state.fillGradient->gradientSpaceTransform());
m_state.fillGradient->paint(layerContext);
CGContextDrawLayerAtPoint(context, CGPointMake(rect.x(), rect.y()), layer);
CGLayerRelease(layer);
} else {
CGContextClipToRect(context, rect);
CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
m_state.fillGradient->paint(this);
}
CGContextRestoreGState(context);
return;
}
if (m_state.fillPattern)
applyFillPattern();
bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; if (drawOwnShadow) {
float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur;
CGContextSaveGState(context);
CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
ShadowBlur contextShadow(FloatSize(shadowBlur, shadowBlur), m_state.shadowOffset, m_state.shadowColor, m_state.shadowColorSpace);
contextShadow.drawRectShadow(this, rect, RoundedIntRect::Radii());
}
CGContextFillRect(context, rect);
if (drawOwnShadow)
CGContextRestoreGState(context);
}
void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
Color oldFillColor = fillColor();
ColorSpace oldColorSpace = fillColorSpace();
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, color, colorSpace);
bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; if (drawOwnShadow) {
float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur;
CGContextSaveGState(context);
CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
ShadowBlur contextShadow(FloatSize(shadowBlur, shadowBlur), m_state.shadowOffset, m_state.shadowColor, m_state.shadowColorSpace);
contextShadow.drawRectShadow(this, rect, RoundedIntRect::Radii());
}
CGContextFillRect(context, rect);
if (drawOwnShadow)
CGContextRestoreGState(context);
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, oldFillColor, oldColorSpace);
}
void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
Color oldFillColor = fillColor();
ColorSpace oldColorSpace = fillColorSpace();
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, color, colorSpace);
bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; if (drawOwnShadow) {
float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur;
CGContextSaveGState(context);
CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
ShadowBlur contextShadow(FloatSize(shadowBlur, shadowBlur), m_state.shadowOffset, m_state.shadowColor, m_state.shadowColorSpace);
contextShadow.drawRectShadow(this, rect, RoundedIntRect::Radii(topLeft, topRight, bottomLeft, bottomRight));
}
bool equalWidths = (topLeft.width() == topRight.width() && topRight.width() == bottomLeft.width() && bottomLeft.width() == bottomRight.width());
bool equalHeights = (topLeft.height() == bottomLeft.height() && bottomLeft.height() == topRight.height() && topRight.height() == bottomRight.height());
if (equalWidths && equalHeights && topLeft.width() * 2 == rect.width() && topLeft.height() * 2 == rect.height())
CGContextFillEllipseInRect(context, rect);
else {
Path path;
path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
fillPath(path);
}
if (drawOwnShadow)
CGContextRestoreGState(context);
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, oldFillColor, oldColorSpace);
}
void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const RoundedIntRect& roundedHoleRect, const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
Path path;
path.addRect(rect);
if (!roundedHoleRect.radii().isZero())
path.addRoundedRect(roundedHoleRect);
else
path.addRect(roundedHoleRect.rect());
WindRule oldFillRule = fillRule();
Color oldFillColor = fillColor();
ColorSpace oldFillColorSpace = fillColorSpace();
setFillRule(RULE_EVENODD);
setFillColor(color, colorSpace);
bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms;
if (drawOwnShadow) {
float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur;
CGContextSaveGState(context);
CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
ShadowBlur contextShadow(FloatSize(shadowBlur, shadowBlur), m_state.shadowOffset, m_state.shadowColor, m_state.shadowColorSpace);
contextShadow.drawInsetShadow(this, rect, roundedHoleRect.rect(), roundedHoleRect.radii());
}
fillPath(path);
if (drawOwnShadow)
CGContextRestoreGState(context);
setFillRule(oldFillRule);
setFillColor(oldFillColor, oldFillColorSpace);
}
void GraphicsContext::clip(const FloatRect& rect)
{
if (paintingDisabled())
return;
CGContextClipToRect(platformContext(), rect);
m_data->clip(rect);
}
void GraphicsContext::clipOut(const IntRect& rect)
{
if (paintingDisabled())
return;
CGRect rects[2] = { CGContextGetClipBoundingBox(platformContext()), rect };
CGContextBeginPath(platformContext());
CGContextAddRects(platformContext(), rects, 2);
CGContextEOClip(platformContext());
}
void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
{
if (paintingDisabled())
return;
if (path.isEmpty())
return;
CGContextRef context = platformContext();
CGContextBeginPath(platformContext());
CGContextAddPath(platformContext(), path.platformPath());
if (clipRule == RULE_EVENODD)
CGContextEOClip(context);
else
CGContextClip(context);
}
IntRect GraphicsContext::clipBounds() const
{
return enclosingIntRect(CGContextGetClipBoundingBox(platformContext()));
}
void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
{
if (paintingDisabled())
return;
clip(rect);
CGContextRef context = platformContext();
CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
CGContextAddEllipseInRect(context, CGRectMake(rect.x() + thickness, rect.y() + thickness,
rect.width() - (thickness * 2), rect.height() - (thickness * 2)));
CGContextEOClip(context);
}
void GraphicsContext::beginTransparencyLayer(float opacity)
{
if (paintingDisabled())
return;
save();
CGContextRef context = platformContext();
CGContextSetAlpha(context, opacity);
CGContextBeginTransparencyLayer(context, 0);
m_data->beginTransparencyLayer();
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::endTransparencyLayer()
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
CGContextEndTransparencyLayer(context);
m_data->endTransparencyLayer();
restore();
}
void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
CGFloat xOffset = offset.width();
CGFloat yOffset = offset.height();
CGFloat blurRadius = blur;
CGContextRef context = platformContext();
if (!m_state.shadowsIgnoreTransforms) {
CGAffineTransform userToBaseCTM = wkGetUserToBaseCTM(context);
CGFloat A = userToBaseCTM.a * userToBaseCTM.a + userToBaseCTM.b * userToBaseCTM.b;
CGFloat B = userToBaseCTM.a * userToBaseCTM.c + userToBaseCTM.b * userToBaseCTM.d;
CGFloat C = B;
CGFloat D = userToBaseCTM.c * userToBaseCTM.c + userToBaseCTM.d * userToBaseCTM.d;
CGFloat smallEigenvalue = narrowPrecisionToCGFloat(sqrt(0.5 * ((A + D) - sqrt(4 * B * C + (A - D) * (A - D)))));
blurRadius = blur * smallEigenvalue;
CGSize offsetInBaseSpace = CGSizeApplyAffineTransform(offset, userToBaseCTM);
xOffset = offsetInBaseSpace.width;
yOffset = offsetInBaseSpace.height;
}
blurRadius = min(blurRadius, narrowPrecisionToCGFloat(1000.0));
static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128);
if (xOffset > 0)
xOffset += extraShadowOffset;
else if (xOffset < 0)
xOffset -= extraShadowOffset;
if (yOffset > 0)
yOffset += extraShadowOffset;
else if (yOffset < 0)
yOffset -= extraShadowOffset;
if (!color.isValid())
CGContextSetShadow(context, CGSizeMake(xOffset, yOffset), blurRadius);
else
CGContextSetShadowWithColor(context, CGSizeMake(xOffset, yOffset), blurRadius, cachedCGColor(color, colorSpace));
}
void GraphicsContext::clearPlatformShadow()
{
if (paintingDisabled())
return;
CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
}
void GraphicsContext::setMiterLimit(float limit)
{
if (paintingDisabled())
return;
CGContextSetMiterLimit(platformContext(), limit);
}
void GraphicsContext::setAlpha(float alpha)
{
if (paintingDisabled())
return;
CGContextSetAlpha(platformContext(), alpha);
}
void GraphicsContext::clearRect(const FloatRect& r)
{
if (paintingDisabled())
return;
CGContextClearRect(platformContext(), r);
}
void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
if (m_state.strokeGradient) {
if (hasShadow()) {
const float doubleLineWidth = lineWidth * 2;
const float layerWidth = ceilf(rect.width() + doubleLineWidth);
const float layerHeight = ceilf(rect.height() + doubleLineWidth);
CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(layerWidth, layerHeight), 0);
CGContextRef layerContext = CGLayerGetContext(layer);
m_state.strokeThickness = lineWidth;
CGContextSetLineWidth(layerContext, lineWidth);
const float translationX = lineWidth - rect.x();
const float translationY = lineWidth - rect.y();
CGContextTranslateCTM(layerContext, translationX, translationY);
CGContextAddRect(layerContext, rect);
CGContextReplacePathWithStrokedPath(layerContext);
CGContextClip(layerContext);
CGContextConcatCTM(layerContext, m_state.strokeGradient->gradientSpaceTransform());
m_state.strokeGradient->paint(layerContext);
const float destinationX = roundf(rect.x() - lineWidth);
const float destinationY = roundf(rect.y() - lineWidth);
CGContextDrawLayerAtPoint(context, CGPointMake(destinationX, destinationY), layer);
CGLayerRelease(layer);
} else {
CGContextSaveGState(context);
setStrokeThickness(lineWidth);
CGContextAddRect(context, rect);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
m_state.strokeGradient->paint(this);
CGContextRestoreGState(context);
}
return;
}
if (m_state.strokePattern)
applyStrokePattern();
CGContextStrokeRectWithWidth(context, rect, lineWidth);
}
void GraphicsContext::setLineCap(LineCap cap)
{
if (paintingDisabled())
return;
switch (cap) {
case ButtCap:
CGContextSetLineCap(platformContext(), kCGLineCapButt);
break;
case RoundCap:
CGContextSetLineCap(platformContext(), kCGLineCapRound);
break;
case SquareCap:
CGContextSetLineCap(platformContext(), kCGLineCapSquare);
break;
}
}
void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
{
CGContextSetLineDash(platformContext(), dashOffset, dashes.data(), dashes.size());
}
void GraphicsContext::setLineJoin(LineJoin join)
{
if (paintingDisabled())
return;
switch (join) {
case MiterJoin:
CGContextSetLineJoin(platformContext(), kCGLineJoinMiter);
break;
case RoundJoin:
CGContextSetLineJoin(platformContext(), kCGLineJoinRound);
break;
case BevelJoin:
CGContextSetLineJoin(platformContext(), kCGLineJoinBevel);
break;
}
}
void GraphicsContext::clip(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
if (path.isEmpty())
CGContextClipToRect(context, CGRectZero);
else {
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
CGContextClip(context);
}
m_data->clip(path);
}
void GraphicsContext::canvasClip(const Path& path)
{
clip(path);
}
void GraphicsContext::clipOut(const Path& path)
{
if (paintingDisabled())
return;
CGContextBeginPath(platformContext());
CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
CGContextAddPath(platformContext(), path.platformPath());
CGContextEOClip(platformContext());
}
void GraphicsContext::scale(const FloatSize& size)
{
if (paintingDisabled())
return;
CGContextScaleCTM(platformContext(), size.width(), size.height());
m_data->scale(size);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::rotate(float angle)
{
if (paintingDisabled())
return;
CGContextRotateCTM(platformContext(), angle);
m_data->rotate(angle);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::translate(float x, float y)
{
if (paintingDisabled())
return;
CGContextTranslateCTM(platformContext(), x, y);
m_data->translate(x, y);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::concatCTM(const AffineTransform& transform)
{
if (paintingDisabled())
return;
CGContextConcatCTM(platformContext(), transform);
m_data->concatCTM(transform);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
void GraphicsContext::setCTM(const AffineTransform& transform)
{
if (paintingDisabled())
return;
CGContextSetCTM(platformContext(), transform);
m_data->setCTM(transform);
m_data->m_userToDeviceTransformKnownToBeIdentity = false;
}
AffineTransform GraphicsContext::getCTM() const
{
CGAffineTransform t = CGContextGetCTM(platformContext());
return AffineTransform(t.a, t.b, t.c, t.d, t.tx, t.ty);
}
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect, RoundingMode roundingMode)
{
#if PLATFORM(CHROMIUM)
return rect;
#else
if (m_data->m_userToDeviceTransformKnownToBeIdentity)
return rect;
CGAffineTransform deviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(platformContext());
if (CGAffineTransformIsIdentity(deviceMatrix)) {
m_data->m_userToDeviceTransformKnownToBeIdentity = true;
return rect;
}
float deviceScaleX = sqrtf(deviceMatrix.a * deviceMatrix.a + deviceMatrix.b * deviceMatrix.b);
float deviceScaleY = sqrtf(deviceMatrix.c * deviceMatrix.c + deviceMatrix.d * deviceMatrix.d);
CGPoint deviceOrigin = CGPointMake(rect.x() * deviceScaleX, rect.y() * deviceScaleY);
CGPoint deviceLowerRight = CGPointMake((rect.x() + rect.width()) * deviceScaleX,
(rect.y() + rect.height()) * deviceScaleY);
deviceOrigin.x = roundf(deviceOrigin.x);
deviceOrigin.y = roundf(deviceOrigin.y);
if (roundingMode == RoundAllSides) {
deviceLowerRight.x = roundf(deviceLowerRight.x);
deviceLowerRight.y = roundf(deviceLowerRight.y);
} else {
deviceLowerRight.x = deviceOrigin.x + roundf(rect.width() * deviceScaleX);
deviceLowerRight.y = deviceOrigin.y + roundf(rect.height() * deviceScaleY);
}
if (deviceOrigin.y == deviceLowerRight.y && rect.height())
deviceLowerRight.y += 1;
if (deviceOrigin.x == deviceLowerRight.x && rect.width())
deviceLowerRight.x += 1;
FloatPoint roundedOrigin = FloatPoint(deviceOrigin.x / deviceScaleX, deviceOrigin.y / deviceScaleY);
FloatPoint roundedLowerRight = FloatPoint(deviceLowerRight.x / deviceScaleX, deviceLowerRight.y / deviceScaleY);
return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);
#endif
}
void GraphicsContext::drawLineForText(const FloatPoint& point, float width, bool printing)
{
if (paintingDisabled())
return;
if (width <= 0)
return;
CGContextRef context = platformContext();
CGContextSaveGState(context);
Color color(strokeColor());
CGPoint origin;
CGFloat thickness;
if (printing) {
origin = CGPointMake(point.x(), point.y() + 1);
thickness = max(strokeThickness(), 0.5f);
} else {
CGContextSetShouldAntialias(context, false);
CGAffineTransform t = CGContextGetUserSpaceToDeviceSpaceTransform(context);
CGFloat scale = t.b ? sqrtf(t.a * t.a + t.b * t.b) : t.a;
if (scale < 1.0) {
static const float MinUnderlineAlpha = 0.4f;
float shade = scale > MinUnderlineAlpha ? scale : MinUnderlineAlpha;
int alpha = color.alpha() * shade;
color = Color(color.red(), color.green(), color.blue(), alpha);
}
static const CGFloat OffsetUnderlineScale = 0.4f;
CGFloat dy = scale < OffsetUnderlineScale ? 0 : 1;
CGPoint devicePoint = CGPointApplyAffineTransform(point, t);
CGPoint deviceOrigin = CGPointMake(roundf(devicePoint.x), ceilf(devicePoint.y) + dy);
origin = CGPointApplyAffineTransform(deviceOrigin, CGAffineTransformInvert(t));
thickness = MAX(1, roundf(scale)) / scale;
}
if (m_state.shouldUseContextColors)
setCGFillColor(context, color, strokeColorSpace());
CGRect rect = CGRectMake(origin.x, origin.y, width, thickness);
CGContextFillRect(context, rect);
CGContextRestoreGState(context);
}
void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
{
UNUSED_PARAM(link);
UNUSED_PARAM(destRect);
}
void GraphicsContext::setImageInterpolationQuality(InterpolationQuality mode)
{
if (paintingDisabled())
return;
CGInterpolationQuality quality = kCGInterpolationDefault;
switch (mode) {
case InterpolationDefault:
quality = kCGInterpolationDefault;
break;
case InterpolationNone:
quality = kCGInterpolationNone;
break;
case InterpolationLow:
quality = kCGInterpolationLow;
break;
case InterpolationMedium:
#if USE(CG_INTERPOLATION_MEDIUM)
quality = kCGInterpolationMedium;
break;
#endif
case InterpolationHigh:
quality = kCGInterpolationHigh;
break;
}
CGContextSetInterpolationQuality(platformContext(), quality);
}
InterpolationQuality GraphicsContext::imageInterpolationQuality() const
{
if (paintingDisabled())
return InterpolationDefault;
CGInterpolationQuality quality = CGContextGetInterpolationQuality(platformContext());
switch (quality) {
case kCGInterpolationDefault:
return InterpolationDefault;
case kCGInterpolationNone:
return InterpolationNone;
case kCGInterpolationLow:
return InterpolationLow;
#if HAVE(CG_INTERPOLATION_MEDIUM)
case kCGInterpolationMedium:
#if USE(CG_INTERPOLATION_MEDIUM)
return InterpolationMedium;
#else
return InterpolationDefault;
#endif // USE(CG_INTERPOLATION_MEDIUM)
#endif // HAVE(CG_INTERPOLATION_MEDIUM)
case kCGInterpolationHigh:
return InterpolationHigh;
}
return InterpolationDefault;
}
void GraphicsContext::setAllowsFontSmoothing(bool allowsFontSmoothing)
{
UNUSED_PARAM(allowsFontSmoothing);
#if !defined(BUILDING_ON_LEOPARD)
CGContextRef context = platformContext();
CGContextSetAllowsFontSmoothing(context, allowsFontSmoothing);
#endif
}
void GraphicsContext::setIsCALayerContext(bool isLayerContext)
{
if (isLayerContext)
m_data->m_contextFlags |= IsLayerCGContext;
else
m_data->m_contextFlags &= ~IsLayerCGContext;
}
bool GraphicsContext::isCALayerContext() const
{
return m_data->m_contextFlags & IsLayerCGContext;
}
void GraphicsContext::setIsAcceleratedContext(bool isAccelerated)
{
if (isAccelerated)
m_data->m_contextFlags |= IsAcceleratedCGContext;
else
m_data->m_contextFlags &= ~IsAcceleratedCGContext;
}
bool GraphicsContext::isAcceleratedContext() const
{
return m_data->m_contextFlags & IsAcceleratedCGContext;
}
void GraphicsContext::setPlatformTextDrawingMode(TextDrawingModeFlags mode)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
switch (mode) {
case TextModeInvisible:
CGContextSetTextDrawingMode(context, kCGTextInvisible);
break;
case TextModeFill:
CGContextSetTextDrawingMode(context, kCGTextFill);
break;
case TextModeStroke:
CGContextSetTextDrawingMode(context, kCGTextStroke);
break;
case TextModeFill | TextModeStroke:
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
break;
case TextModeClip:
CGContextSetTextDrawingMode(context, kCGTextClip);
break;
case TextModeFill | TextModeClip:
CGContextSetTextDrawingMode(context, kCGTextFillClip);
break;
case TextModeStroke | TextModeClip:
CGContextSetTextDrawingMode(context, kCGTextStrokeClip);
break;
case TextModeFill | TextModeStroke | TextModeClip:
CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);
break;
default:
break;
}
}
void GraphicsContext::setPlatformStrokeColor(const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
setCGStrokeColor(platformContext(), color, colorSpace);
}
void GraphicsContext::setPlatformStrokeThickness(float thickness)
{
if (paintingDisabled())
return;
CGContextSetLineWidth(platformContext(), thickness);
}
void GraphicsContext::setPlatformFillColor(const Color& color, ColorSpace colorSpace)
{
if (paintingDisabled())
return;
setCGFillColor(platformContext(), color, colorSpace);
}
void GraphicsContext::setPlatformShouldAntialias(bool enable)
{
if (paintingDisabled())
return;
CGContextSetShouldAntialias(platformContext(), enable);
}
void GraphicsContext::setPlatformShouldSmoothFonts(bool enable)
{
if (paintingDisabled())
return;
CGContextSetShouldSmoothFonts(platformContext(), enable);
}
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator mode)
{
if (paintingDisabled())
return;
CGBlendMode target = kCGBlendModeNormal;
switch (mode) {
case CompositeClear:
target = kCGBlendModeClear;
break;
case CompositeCopy:
target = kCGBlendModeCopy;
break;
case CompositeSourceOver:
break;
case CompositeSourceIn:
target = kCGBlendModeSourceIn;
break;
case CompositeSourceOut:
target = kCGBlendModeSourceOut;
break;
case CompositeSourceAtop:
target = kCGBlendModeSourceAtop;
break;
case CompositeDestinationOver:
target = kCGBlendModeDestinationOver;
break;
case CompositeDestinationIn:
target = kCGBlendModeDestinationIn;
break;
case CompositeDestinationOut:
target = kCGBlendModeDestinationOut;
break;
case CompositeDestinationAtop:
target = kCGBlendModeDestinationAtop;
break;
case CompositeXOR:
target = kCGBlendModeXOR;
break;
case CompositePlusDarker:
target = kCGBlendModePlusDarker;
break;
case CompositeHighlight:
break;
case CompositePlusLighter:
target = kCGBlendModePlusLighter;
break;
}
CGContextSetBlendMode(platformContext(), target);
}
}