diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebCore/platform/graphics/cg | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebCore/platform/graphics/cg')
5 files changed, 83 insertions, 133 deletions
diff --git a/Source/WebCore/platform/graphics/cg/FontPlatformData.h b/Source/WebCore/platform/graphics/cg/FontPlatformData.h deleted file mode 100644 index e21b444..0000000 --- a/Source/WebCore/platform/graphics/cg/FontPlatformData.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This file is part of the internal font implementation. It should not be included by anyone other than - * FontMac.cpp, FontWin.cpp and Font.cpp. - * - * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef FontPlatformData_h -#define FontPlatformData_h - -#include "FontOrientation.h" -#include "RefCountedGDIHandle.h" -#include "StringImpl.h" -#include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefCounted.h> -#include <wtf/RetainPtr.h> - -typedef struct HFONT__* HFONT; -typedef struct CGFont* CGFontRef; - -namespace WebCore { - -class FontDescription; - -class FontPlatformData { -public: - FontPlatformData() - : m_size(0) - , m_syntheticBold(false) - , m_syntheticOblique(false) - , m_useGDI(false) - { - } - - FontPlatformData(HFONT, float size, bool bold, bool oblique, bool useGDI); - FontPlatformData(float size, bool bold, bool oblique); - - FontPlatformData(HFONT, CGFontRef, float size, bool bold, bool oblique, bool useGDI); - ~FontPlatformData(); - - FontPlatformData(WTF::HashTableDeletedValueType) : m_font(WTF::HashTableDeletedValue) { } - bool isHashTableDeletedValue() const { return m_font.isHashTableDeletedValue(); } - - HFONT hfont() const { return m_font->handle(); } - CGFontRef cgFont() const { return m_cgFont.get(); } - - float size() const { return m_size; } - void setSize(float size) { m_size = size; } - bool syntheticBold() const { return m_syntheticBold; } - bool syntheticOblique() const { return m_syntheticOblique; } - bool useGDI() const { return m_useGDI; } - - FontOrientation orientation() const { return Horizontal; } // FIXME: Implement. - - unsigned hash() const - { - return m_font->hash(); - } - - bool operator==(const FontPlatformData& other) const - { - return m_font == other.m_font - && m_cgFont == other.m_cgFont - && m_size == other.m_size - && m_syntheticBold == other.m_syntheticBold - && m_syntheticOblique == other.m_syntheticOblique - && m_useGDI == other.m_useGDI; - } - -#ifndef NDEBUG - String description() const; -#endif - -private: - void platformDataInit(HFONT, float size, HDC, WCHAR* faceName); - - RefPtr<RefCountedGDIHandle<HFONT> > m_font; - RetainPtr<CGFontRef> m_cgFont; - - float m_size; - bool m_syntheticBold; - bool m_syntheticOblique; - bool m_useGDI; -}; - -} // namespace WebCore - -#endif diff --git a/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp index dbcab45..7799137 100644 --- a/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp +++ b/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp @@ -695,7 +695,7 @@ void GraphicsContext::fillRect(const FloatRect& rect) if (m_state.fillPattern) applyFillPattern(); - bool drawOwnShadow = hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. + bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. if (drawOwnShadow) { float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur; // Turn off CG shadows. @@ -724,7 +724,7 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS if (oldFillColor != color || oldColorSpace != colorSpace) setCGFillColor(context, color, colorSpace); - bool drawOwnShadow = hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. + bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. if (drawOwnShadow) { float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur; // Turn off CG shadows. @@ -759,7 +759,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef Path path; path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight); - bool drawOwnShadow = hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. + bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. if (drawOwnShadow) { float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur; @@ -803,7 +803,7 @@ void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const Rounded setFillColor(color, colorSpace); // fillRectWithRoundedHole() assumes that the edges of rect are clipped out, so we only care about shadows cast around inside the hole. - bool drawOwnShadow = hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; + bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow(m_state) && !m_state.shadowsIgnoreTransforms; if (drawOwnShadow) { float shadowBlur = m_state.shadowsUseLegacyRadius ? radiusToLegacyRadius(m_state.shadowBlur) : m_state.shadowBlur; @@ -929,8 +929,7 @@ void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, con 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)); + blurRadius = blur * smallEigenvalue; CGSize offsetInBaseSpace = CGSizeApplyAffineTransform(offset, userToBaseCTM); @@ -938,6 +937,9 @@ void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, con yOffset = offsetInBaseSpace.height; } + // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp + blurRadius = min(blurRadius, narrowPrecisionToCGFloat(1000.0)); + // 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); @@ -1343,14 +1345,30 @@ void GraphicsContext::setAllowsFontSmoothing(bool allowsFontSmoothing) #endif } -void GraphicsContext::setIsCALayerContext(bool) +void GraphicsContext::setIsCALayerContext(bool isLayerContext) { - m_data->m_isCALayerContext = true; + if (isLayerContext) + m_data->m_contextFlags |= IsLayerCGContext; + else + m_data->m_contextFlags &= ~IsLayerCGContext; } bool GraphicsContext::isCALayerContext() const { - return m_data->m_isCALayerContext; + 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) diff --git a/Source/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h b/Source/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h index f9255df..722f5a0 100644 --- a/Source/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h +++ b/Source/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h @@ -31,9 +31,16 @@ namespace WebCore { +enum GraphicsContextCGFlag { + IsLayerCGContext = 1 << 0, + IsAcceleratedCGContext = 1 << 1 +}; + +typedef unsigned GraphicsContextCGFlags; + class GraphicsContextPlatformPrivate { public: - GraphicsContextPlatformPrivate(CGContextRef cgContext, bool isLayerContext = false) + GraphicsContextPlatformPrivate(CGContextRef cgContext, GraphicsContextCGFlags flags = 0) : m_cgContext(cgContext) #if PLATFORM(WIN) , m_hdc(0) @@ -41,7 +48,7 @@ public: , m_shouldIncludeChildWindows(false) #endif , m_userToDeviceTransformKnownToBeIdentity(false) - , m_isCALayerContext(isLayerContext) + , m_contextFlags(flags) { } @@ -87,7 +94,7 @@ public: RetainPtr<CGContextRef> m_cgContext; bool m_userToDeviceTransformKnownToBeIdentity; - bool m_isCALayerContext; + GraphicsContextCGFlags m_contextFlags; }; } diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp index 7c8e313..3c8f959 100644 --- a/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp +++ b/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp @@ -32,6 +32,7 @@ #include "BitmapImage.h" #include "GraphicsContext.h" #include "GraphicsContextCG.h" +#include "ImageData.h" #include "MIMETypeRegistry.h" #include <ApplicationServices/ApplicationServices.h> #include <wtf/Assertions.h> @@ -498,21 +499,8 @@ static RetainPtr<CFStringRef> utiFromMIMEType(const String& mimeType) #endif } -String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const +static String CGImageToDataURL(CGImageRef image, const String& mimeType, const double* quality) { - ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); - - RetainPtr<CGImageRef> image; - if (!m_accelerateRendering) - image.adoptCF(CGBitmapContextCreateImage(context()->platformContext())); -#if USE(IOSURFACE_CANVAS_BACKING_STORE) - else - image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext())); -#endif - - if (!image) - return "data:,"; - RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); if (!data) return "data:,"; @@ -533,7 +521,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con imageProperties.adoptCF(CFDictionaryCreate(0, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); } - CGImageDestinationAddImage(destination.get(), image.get(), imageProperties.get()); + CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); CGImageDestinationFinalize(destination.get()); Vector<char> out; @@ -541,4 +529,46 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con return makeString("data:", mimeType, ";base64,", out); } + +String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const +{ + ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); + + RetainPtr<CGImageRef> image; + if (!m_accelerateRendering) + image.adoptCF(CGBitmapContextCreateImage(context()->platformContext())); +#if USE(IOSURFACE_CANVAS_BACKING_STORE) + else + image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext())); +#endif + + if (!image) + return "data:,"; + + return CGImageToDataURL(image.get(), mimeType, quality); +} + +String ImageDataToDataURL(const ImageData& source, const String& mimeType, const double* quality) +{ + ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); + + RetainPtr<CGImageRef> image; + RetainPtr<CGDataProviderRef> dataProvider; + + dataProvider.adoptCF(CGDataProviderCreateWithData(0, source.data()->data()->data(), + 4 * source.width() * source.height(), 0)); + + if (!dataProvider) + return "data:,"; + + image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(), + CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault | kCGImageAlphaLast, + dataProvider.get(), 0, false, kCGRenderingIntentDefault)); + + + if (!image) + return "data:,"; + + return CGImageToDataURL(image.get(), mimeType, quality); +} } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/cg/PathCG.cpp b/Source/WebCore/platform/graphics/cg/PathCG.cpp index d6a1e6e..b8fc7d4 100644 --- a/Source/WebCore/platform/graphics/cg/PathCG.cpp +++ b/Source/WebCore/platform/graphics/cg/PathCG.cpp @@ -166,7 +166,7 @@ FloatRect Path::boundingRect() const return CGPathGetBoundingBox(m_path); } -FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) +FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { CGContextRef context = scratchContext(); |