diff options
author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/platform/graphics/cg | |
parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/platform/graphics/cg')
-rw-r--r-- | WebCore/platform/graphics/cg/ColorCG.cpp | 4 | ||||
-rw-r--r-- | WebCore/platform/graphics/cg/GradientCG.cpp | 49 | ||||
-rw-r--r-- | WebCore/platform/graphics/cg/GraphicsContextCG.cpp | 61 | ||||
-rw-r--r-- | WebCore/platform/graphics/cg/PatternCG.cpp | 2 |
4 files changed, 86 insertions, 30 deletions
diff --git a/WebCore/platform/graphics/cg/ColorCG.cpp b/WebCore/platform/graphics/cg/ColorCG.cpp index 40aacc5..e514fa3 100644 --- a/WebCore/platform/graphics/cg/ColorCG.cpp +++ b/WebCore/platform/graphics/cg/ColorCG.cpp @@ -68,7 +68,7 @@ Color::Color(CGColorRef color) m_color = makeRGBA(r * 255, g * 255, b * 255, a * 255); } -#if PLATFORM(WIN_OS) +#if OS(WINDOWS) CGColorRef createCGColor(const Color& c) { @@ -89,7 +89,7 @@ CGColorRef createCGColor(const Color& c) return color; } -#endif // PLATFORM(WIN_OS) +#endif // OS(WINDOWS) } diff --git a/WebCore/platform/graphics/cg/GradientCG.cpp b/WebCore/platform/graphics/cg/GradientCG.cpp index 05a0aad..e9b5de7 100644 --- a/WebCore/platform/graphics/cg/GradientCG.cpp +++ b/WebCore/platform/graphics/cg/GradientCG.cpp @@ -36,10 +36,15 @@ namespace WebCore { void Gradient::platformDestroy() { +#ifdef BUILDING_ON_TIGER CGShadingRelease(m_gradient); +#else + CGGradientRelease(m_gradient); +#endif m_gradient = 0; } +#ifdef BUILDING_ON_TIGER static void gradientCallback(void* info, const CGFloat* in, CGFloat* out) { float r, g, b, a; @@ -69,11 +74,55 @@ CGShadingRef Gradient::platformGradient() return m_gradient; } +#else +CGGradientRef Gradient::platformGradient() +{ + if (m_gradient) + return m_gradient; + + static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + sortStopsIfNecessary(); + + const int cReservedStops = 3; + Vector<CGFloat, 4 * cReservedStops> colorComponents; + colorComponents.reserveCapacity(m_stops.size() * 4); // RGBA components per stop + + Vector<CGFloat, cReservedStops> locations; + locations.reserveCapacity(m_stops.size()); + + for (size_t i = 0; i < m_stops.size(); ++i) { + colorComponents.uncheckedAppend(m_stops[i].red); + colorComponents.uncheckedAppend(m_stops[i].green); + colorComponents.uncheckedAppend(m_stops[i].blue); + colorComponents.uncheckedAppend(m_stops[i].alpha); + + locations.uncheckedAppend(m_stops[i].stop); + } + + m_gradient = CGGradientCreateWithColorComponents(colorSpace, colorComponents.data(), locations.data(), m_stops.size()); + + return m_gradient; +} +#endif void Gradient::fill(GraphicsContext* context, const FloatRect& rect) { context->clip(rect); + paint(context); +} + +void Gradient::paint(GraphicsContext* context) +{ +#ifdef BUILDING_ON_TIGER CGContextDrawShading(context->platformContext(), platformGradient()); +#else + CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; + if (m_radial) + CGContextDrawRadialGradient(context->platformContext(), platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions); + else + CGContextDrawLinearGradient(context->platformContext(), platformGradient(), m_p0, m_p1, extendOptions); +#endif } } //namespace diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp index 39f06a6..b11ba66 100644 --- a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp +++ b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp @@ -43,7 +43,15 @@ #include <wtf/OwnArrayPtr.h> #include <wtf/RetainPtr.h> -#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) +#if PLATFORM(MAC) || PLATFORM(CHROMIUM) +#include "WebCoreSystemInterface.h" +#endif + +#if PLATFORM(WIN) +#include <WebKitSystemInterface/WebKitSystemInterface.h> +#endif + +#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)) #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) // Building on 10.6 or later: kCGInterpolationMedium is defined in the CGInterpolationQuality enum. @@ -490,7 +498,7 @@ static inline bool calculateDrawingMode(const GraphicsContextState& state, CGPat } } else { // Setting mode to kCGPathStroke even if shouldStroke is false. In that case, we return false and mode will not be used, - // but the compiler will not compain about an uninitialized variable. + // but the compiler will not complain about an uninitialized variable. mode = kCGPathStroke; } @@ -547,7 +555,7 @@ void GraphicsContext::fillPath() else CGContextClip(context); CGContextConcatCTM(context, m_common->state.fillGradient->gradientSpaceTransform()); - CGContextDrawShading(context, m_common->state.fillGradient->platformGradient()); + m_common->state.fillGradient->paint(this); CGContextRestoreGState(context); return; } @@ -572,7 +580,7 @@ void GraphicsContext::strokePath() CGContextReplacePathWithStrokedPath(context); CGContextClip(context); CGContextConcatCTM(context, m_common->state.strokeGradient->gradientSpaceTransform()); - CGContextDrawShading(context, m_common->state.strokeGradient->platformGradient()); + m_common->state.strokeGradient->paint(this); CGContextRestoreGState(context); return; } @@ -596,7 +604,7 @@ void GraphicsContext::fillRect(const FloatRect& rect) CGContextSaveGState(context); CGContextClipToRect(context, rect); CGContextConcatCTM(context, m_common->state.fillGradient->gradientSpaceTransform()); - CGContextDrawShading(context, m_common->state.fillGradient->platformGradient()); + m_common->state.fillGradient->paint(this); CGContextRestoreGState(context); return; } @@ -739,56 +747,55 @@ void GraphicsContext::endTransparencyLayer() m_data->m_userToDeviceTransformKnownToBeIdentity = false; } -void GraphicsContext::setPlatformShadow(const IntSize& size, int blur, const Color& color, ColorSpace colorSpace) +void GraphicsContext::setPlatformShadow(const IntSize& offset, int blur, const Color& color, ColorSpace colorSpace) { if (paintingDisabled()) return; - CGFloat width = size.width(); - CGFloat height = size.height(); + CGFloat xOffset = offset.width(); + CGFloat yOffset = offset.height(); CGFloat blurRadius = blur; CGContextRef context = platformContext(); if (!m_common->state.shadowsIgnoreTransforms) { - CGAffineTransform transform = CGContextGetCTM(context); + CGAffineTransform userToBaseCTM = wkGetUserToBaseCTM(context); - CGFloat A = transform.a * transform.a + transform.b * transform.b; - CGFloat B = transform.a * transform.c + transform.b * transform.d; + 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 = transform.c * transform.c + transform.d * transform.d; + 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))))); // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp blurRadius = min(blur * smallEigenvalue, narrowPrecisionToCGFloat(1000.0)); - CGSize sizeInDeviceSpace = CGSizeApplyAffineTransform(size, transform); - - width = sizeInDeviceSpace.width; - height = sizeInDeviceSpace.height; + CGSize offsetInBaseSpace = CGSizeApplyAffineTransform(offset, userToBaseCTM); + xOffset = offsetInBaseSpace.width; + yOffset = offsetInBaseSpace.height; } // Work around <rdar://problem/5539388> by ensuring that the offsets will get truncated // to the desired integer. static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128); - if (width > 0) - width += extraShadowOffset; - else if (width < 0) - width -= extraShadowOffset; + if (xOffset > 0) + xOffset += extraShadowOffset; + else if (xOffset < 0) + xOffset -= extraShadowOffset; - if (height > 0) - height += extraShadowOffset; - else if (height < 0) - height -= extraShadowOffset; + if (yOffset > 0) + yOffset += extraShadowOffset; + else if (yOffset < 0) + yOffset -= extraShadowOffset; // Check for an invalid color, as this means that the color was not set for the shadow // and we should therefore just use the default shadow color. if (!color.isValid()) - CGContextSetShadow(context, CGSizeMake(width, height), blurRadius); + CGContextSetShadow(context, CGSizeMake(xOffset, yOffset), blurRadius); else { RetainPtr<CGColorRef> colorCG(AdoptCF, createCGColorWithColorSpace(color, colorSpace)); CGContextSetShadowWithColor(context, - CGSizeMake(width, height), + CGSizeMake(xOffset, yOffset), blurRadius, colorCG.get()); } @@ -838,7 +845,7 @@ void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth) CGContextAddRect(context, r); CGContextReplacePathWithStrokedPath(context); CGContextClip(context); - CGContextDrawShading(context, m_common->state.strokeGradient->platformGradient()); + m_common->state.strokeGradient->paint(this); CGContextRestoreGState(context); return; } diff --git a/WebCore/platform/graphics/cg/PatternCG.cpp b/WebCore/platform/graphics/cg/PatternCG.cpp index 63628f4..26f402b 100644 --- a/WebCore/platform/graphics/cg/PatternCG.cpp +++ b/WebCore/platform/graphics/cg/PatternCG.cpp @@ -61,7 +61,7 @@ CGPatternRef Pattern::createPlatformPattern(const TransformationMatrix& userSpac // If FLT_MAX should also be used for xStep or yStep, nothing is rendered. Using fractions of FLT_MAX also // result in nothing being rendered. - // INT_MAX is almost correct, but there seems to be some number wrapping occuring making the fill + // INT_MAX is almost correct, but there seems to be some number wrapping occurring making the fill // pattern is not filled correctly. // To make error of floating point less than 0.5, we use the half of the number of mantissa of float (1 << 22). CGFloat xStep = m_repeatX ? tileRect.width() : (1 << 22); |