diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/platform/graphics')
68 files changed, 2521 insertions, 1123 deletions
diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/BitmapImage.h b/src/3rdparty/webkit/WebCore/platform/graphics/BitmapImage.h index 8b770a173..7e8f2b075 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/BitmapImage.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/BitmapImage.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2008-2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +45,10 @@ class NSImage; typedef struct HBITMAP__ *HBITMAP; #endif +#if PLATFORM(HAIKU) +class BBitmap; +#endif + namespace WebCore { struct FrameData; } @@ -135,6 +140,9 @@ public: virtual CGImageRef getCGImageRef(); #endif +#if PLATFORM(WIN) || (PLATFORM(QT) && PLATFORM(WIN_OS)) + static PassRefPtr<BitmapImage> create(HBITMAP); +#endif #if PLATFORM(WIN) virtual bool getHBITMAP(HBITMAP); virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE); @@ -160,10 +168,16 @@ protected: virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator); #endif virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator); -#if PLATFORM(WX) + +#if PLATFORM(WX) || (PLATFORM(WINCE) && !PLATFORM(QT)) virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator, const FloatRect& destRect); -#endif +#endif + +#if PLATFORM(HAIKU) + virtual BBitmap* getBBitmap() const; +#endif + size_t currentFrame() const { return m_currentFrame; } size_t frameCount(); NativeImagePtr frameAtIndex(size_t); @@ -220,7 +234,11 @@ protected: { if (!m_checkedForSolidColor && frameCount() > 0) { checkForSolidColor(); + // WINCE PORT: checkForSolidColor() doesn't set m_checkedForSolidColor until + // it gets enough information to make final decision. +#if !PLATFORM(WINCE) ASSERT(m_checkedForSolidColor); +#endif } return m_isSolidColor && m_currentFrame == 0; } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/Color.h b/src/3rdparty/webkit/WebCore/platform/graphics/Color.h index 7ac432f40..4fa151380 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/Color.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/Color.h @@ -47,6 +47,10 @@ typedef struct _GdkColor GdkColor; class wxColour; #endif +#if PLATFORM(HAIKU) +struct rgb_color; +#endif + namespace WebCore { class String; @@ -121,6 +125,11 @@ public: Color(CGColorRef); #endif +#if PLATFORM(HAIKU) + Color(const rgb_color&); + operator rgb_color() const; +#endif + static bool parseHexColor(const String& name, RGBA32& rgb); static const RGBA32 black = 0xFF000000; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint.h b/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint.h index 157c1e7cb..45a1e832d 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint.h @@ -36,7 +36,7 @@ typedef struct CGPoint CGPoint; #endif -#if PLATFORM(MAC) +#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES typedef struct CGPoint NSPoint; #else @@ -51,6 +51,10 @@ class QPointF; QT_END_NAMESPACE #endif +#if PLATFORM(HAIKU) +class BPoint; +#endif + #if PLATFORM(SKIA) struct SkPoint; #endif @@ -80,7 +84,8 @@ public: operator CGPoint() const; #endif -#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) +#if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \ + || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) FloatPoint(const NSPoint&); operator NSPoint() const; #endif @@ -90,6 +95,11 @@ public: operator QPointF() const; #endif +#if PLATFORM(HAIKU) + FloatPoint(const BPoint&); + operator BPoint() const; +#endif + #if PLATFORM(SKIA) operator SkPoint() const; FloatPoint(const SkPoint&); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint3D.h b/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint3D.h index 2e71ddd73..73c3a37c9 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint3D.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FloatPoint3D.h @@ -49,6 +49,16 @@ private: float m_z; }; +inline bool operator==(const FloatPoint3D& a, const FloatPoint3D& b) +{ + return a.x() == b.x() && a.y() == b.y() && a.z() == b.z(); +} + +inline bool operator!=(const FloatPoint3D& a, const FloatPoint3D& b) +{ + return a.x() != b.x() || a.y() != b.y() || a.z() != b.z(); +} + } // namespace WebCore #endif // FloatPoint3D_h diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FloatRect.h b/src/3rdparty/webkit/WebCore/platform/graphics/FloatRect.h index 0723eb783..073f13569 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FloatRect.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FloatRect.h @@ -33,7 +33,7 @@ typedef struct CGRect CGRect; #endif -#if PLATFORM(MAC) +#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES typedef struct CGRect NSRect; #else @@ -51,6 +51,10 @@ QT_END_NAMESPACE class wxRect2DDouble; #endif +#if PLATFORM(HAIKU) +class BRect; +#endif + #if PLATFORM(SKIA) struct SkRect; #endif @@ -123,7 +127,8 @@ public: operator CGRect() const; #endif -#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) +#if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \ + || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) FloatRect(const NSRect&); operator NSRect() const; #endif @@ -138,6 +143,11 @@ public: operator wxRect2DDouble() const; #endif +#if PLATFORM(HAIKU) + FloatRect(const BRect&); + operator BRect() const; +#endif + #if PLATFORM(SKIA) FloatRect(const SkRect&); operator SkRect() const; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FloatSize.h b/src/3rdparty/webkit/WebCore/platform/graphics/FloatSize.h index 6e792b69f..5a84fd1a1 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FloatSize.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FloatSize.h @@ -34,7 +34,7 @@ typedef struct CGSize CGSize; #endif -#if PLATFORM(MAC) +#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES typedef struct CGSize NSSize; #else @@ -79,7 +79,8 @@ public: operator CGSize() const; #endif -#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) +#if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \ + || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) explicit FloatSize(const NSSize &); // don't do this implicitly since it's lossy operator NSSize() const; #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FontCache.h b/src/3rdparty/webkit/WebCore/platform/graphics/FontCache.h index 3c0f2d916..b88305f8d 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FontCache.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FontCache.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2006, 2008 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2007-2008 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -63,7 +64,15 @@ public: // Also implemented by the platform. void platformInit(); -#if PLATFORM(WIN) +#if PLATFORM(WINCE) && !PLATFORM(QT) +#if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2) + IMLangFontLink2* getFontLinkInterface(); +#else + IMLangFontLink* getFontLinkInterface(); +#endif + static void comInitialize(); + static void comUninitialize(); +#elif PLATFORM(WIN) IMLangFontLink2* getFontLinkInterface(); #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FontDescription.h b/src/3rdparty/webkit/WebCore/platform/graphics/FontDescription.h index c893b8a11..fc63db9e7 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FontDescription.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FontDescription.h @@ -27,7 +27,9 @@ #include "FontFamily.h" #include "FontRenderingMode.h" +#include "FontSmoothingMode.h" #include "FontTraitsMask.h" +#include "TextRenderingMode.h" namespace WebCore { @@ -61,6 +63,8 @@ public: , m_usePrinterFont(false) , m_renderingMode(NormalRenderingMode) , m_keywordSize(0) + , m_fontSmoothing(AutoSmoothing) + , m_textRendering(AutoTextRendering) { } @@ -80,8 +84,12 @@ public: FontWeight bolderWeight() const; GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); } bool usePrinterFont() const { return m_usePrinterFont; } + // only use fixed default size when there is only one font family, and that family is "monospace" + bool useFixedDefaultSize() const { return genericFamily() == MonospaceFamily && !family().next() && family().family() == "-webkit-monospace"; } FontRenderingMode renderingMode() const { return static_cast<FontRenderingMode>(m_renderingMode); } unsigned keywordSize() const { return m_keywordSize; } + FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); } + TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); } FontTraitsMask traitsMask() const; @@ -96,6 +104,8 @@ public: void setUsePrinterFont(bool p) { m_usePrinterFont = p; } void setRenderingMode(FontRenderingMode mode) { m_renderingMode = mode; } void setKeywordSize(unsigned s) { m_keywordSize = s; } + void setFontSmoothing(FontSmoothingMode smoothing) { m_fontSmoothing = smoothing; } + void setTextRenderingMode(TextRenderingMode rendering) { m_textRendering = rendering; } private: FontFamily m_familyList; // The list of font families to be used. @@ -117,6 +127,9 @@ private: unsigned m_keywordSize : 4; // We cache whether or not a font is currently represented by a CSS keyword (e.g., medium). If so, // then we can accurately translate across different generic families to adjust for different preference settings // (e.g., 13px monospace vs. 16px everything else). Sizes are 1-8 (like the HTML size values for <font>). + + unsigned m_fontSmoothing : 2; // FontSmoothingMode + unsigned m_textRendering : 2; // TextRenderingMode }; inline bool FontDescription::operator==(const FontDescription& other) const @@ -131,7 +144,9 @@ inline bool FontDescription::operator==(const FontDescription& other) const && m_genericFamily == other.m_genericFamily && m_usePrinterFont == other.m_usePrinterFont && m_renderingMode == other.m_renderingMode - && m_keywordSize == other.m_keywordSize; + && m_keywordSize == other.m_keywordSize + && m_fontSmoothing == other.m_fontSmoothing + && m_textRendering == other.m_textRendering; } } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FontFastPath.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/FontFastPath.cpp index 74b7ec18b..5246593c7 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/FontFastPath.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FontFastPath.cpp @@ -1,6 +1,7 @@ /** * Copyright (C) 2003, 2006 Apple Computer, Inc. * Copyright (C) 2008 Holger Hans Peter Freyther + * Copyright (C) 2009 Torch Mobile, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -155,16 +156,33 @@ GlyphData Font::glyphDataForCharacter(UChar32 c, bool mirror, bool forceSmallCap GlyphPage* fallbackPage = GlyphPageTreeNode::getRootChild(characterFontData, pageNumber)->page(); GlyphData data = fallbackPage && fallbackPage->fontDataForCharacter(c) ? fallbackPage->glyphDataForCharacter(c) : characterFontData->missingGlyphData(); // Cache it so we don't have to do system fallback again next time. - if (!useSmallCapsFont) + if (!useSmallCapsFont) { +#if PLATFORM(WINCE) + // missingGlyphData returns a null character, which is not suitable for GDI to display. + // Also, sometimes we cannot map a font for the character on WINCE, but GDI can still + // display the character, probably because the font package is not installed correctly. + // So we just always set the glyph to be same as the character, and let GDI solve it. + page->setGlyphDataForCharacter(c, c, characterFontData); + return page->glyphDataForCharacter(c); +#else page->setGlyphDataForCharacter(c, data.glyph, data.fontData); +#endif + } return data; } // Even system fallback can fail; use the missing glyph in that case. // FIXME: It would be nicer to use the missing glyph from the last resort font instead. GlyphData data = primaryFont()->missingGlyphData(); - if (!useSmallCapsFont) + if (!useSmallCapsFont) { +#if PLATFORM(WINCE) + // See comment about WINCE GDI handling near setGlyphDataForCharacter above. + page->setGlyphDataForCharacter(c, c, data.fontData); + return page->glyphDataForCharacter(c); +#else page->setGlyphDataForCharacter(c, data.glyph, data.fontData); +#endif + } return data; } @@ -233,6 +251,10 @@ bool Font::canUseGlyphCache(const TextRun& run) const return false; } + TextRenderingMode textMode = m_fontDescription.textRenderingMode(); + if (textMode == OptimizeLegibility || textMode == GeometricPrecision) + return false; + return true; } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/FontSmoothingMode.h b/src/3rdparty/webkit/WebCore/platform/graphics/FontSmoothingMode.h new file mode 100644 index 000000000..7c23394f1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/FontSmoothingMode.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef FontSmoothingMode_h +#define FontSmoothingMode_h + +namespace WebCore { + + enum FontSmoothingMode { AutoSmoothing, NoSmoothing, Antialiased, SubpixelAntialiased }; + +} // namespace WebCore + +#endif // FontSmoothingMode_h diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GeneratedImage.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/GeneratedImage.cpp index c40a40ae1..bac9da018 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GeneratedImage.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GeneratedImage.cpp @@ -51,7 +51,7 @@ void GeneratedImage::drawPattern(GraphicsContext* context, const FloatRect& srcR const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& destRect) { // Create a BitmapImage and call drawPattern on it. - OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size, false); + OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size); ASSERT(imageBuffer.get()); // Fill with the gradient. diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GlyphBuffer.h b/src/3rdparty/webkit/WebCore/platform/graphics/GlyphBuffer.h index dcda419bd..04491a7ce 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GlyphBuffer.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GlyphBuffer.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007-2008 Torch Mobile Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -49,6 +50,8 @@ class SimpleFontData; #if PLATFORM(CAIRO) // FIXME: Why does Cairo use such a huge struct instead of just an offset into an array? typedef cairo_glyph_t GlyphBufferGlyph; +#elif PLATFORM(WINCE) +typedef wchar_t GlyphBufferGlyph; #else typedef Glyph GlyphBufferGlyph; #endif @@ -57,6 +60,10 @@ typedef Glyph GlyphBufferGlyph; // can be passed directly to CGContextShowGlyphsWithAdvances in FontMac.mm #if PLATFORM(CG) typedef CGSize GlyphBufferAdvance; +#elif PLATFORM(WINCE) +// There is no cross-platform code that uses the height of GlyphBufferAdvance, +// so we can save memory space on embedded devices by storing only the width +typedef float GlyphBufferAdvance; #else typedef FloatSize GlyphBufferAdvance; #endif @@ -117,6 +124,8 @@ public: { #if PLATFORM(CG) return m_advances[index].width; +#elif PLATFORM(WINCE) + return m_advances[index]; #else return m_advances[index].width(); #endif @@ -147,6 +156,8 @@ public: #if PLATFORM(CG) CGSize advance = { width, 0 }; m_advances.append(advance); +#elif PLATFORM(WINCE) + m_advances.append(width); #else m_advances.append(FloatSize(width, 0)); #endif @@ -161,6 +172,7 @@ public: #endif } +#if !PLATFORM(WINCE) void add(Glyph glyph, const SimpleFontData* font, GlyphBufferAdvance advance) { m_fontData.append(font); @@ -174,6 +186,7 @@ public: m_advances.append(advance); } +#endif private: Vector<const SimpleFontData*, 2048> m_fontData; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GlyphPageTreeNode.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/GlyphPageTreeNode.cpp index 6419e0c4e..9f53f0b57 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GlyphPageTreeNode.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GlyphPageTreeNode.cpp @@ -202,8 +202,10 @@ void GlyphPageTreeNode::initializePage(const FontData* fontData, unsigned pageNu GlyphPage* pageToFill = m_page.get(); for (unsigned i = 0; i < numRanges; i++) { const FontDataRange& range = segmentedFontData->rangeAt(i); - int from = max(0, range.from() - static_cast<int>(start)); - int to = 1 + min(range.to() - static_cast<int>(start), static_cast<int>(GlyphPage::size) - 1); + // all this casting is to ensure all the parameters to min and max have the same type, + // to avoid ambiguous template parameter errors on Windows + int from = max(0, static_cast<int>(range.from()) - static_cast<int>(start)); + int to = 1 + min(static_cast<int>(range.to()) - static_cast<int>(start), static_cast<int>(GlyphPage::size) - 1); if (from < static_cast<int>(GlyphPage::size) && to > 0) { if (haveGlyphs && !scratchPage) { scratchPage = GlyphPage::create(this); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/Gradient.h b/src/3rdparty/webkit/WebCore/platform/graphics/Gradient.h index a74b1ef56..0e39e7330 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/Gradient.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/Gradient.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * Copyright (C) 2008 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,8 +74,17 @@ namespace WebCore { void getColor(float value, float* r, float* g, float* b, float* a) const; +#if PLATFORM(WINCE) && !PLATFORM(QT) + const FloatPoint& p0() const { return m_p0; } + const FloatPoint& p1() const { return m_p1; } + float r0() const { return m_r0; } + float r1() const { return m_r1; } + bool isRadial() const { return m_radial; } + struct ColorStop; + const Vector<ColorStop>& getStops() const; +#else PlatformGradient platformGradient(); - +#endif struct ColorStop { float stop; float red; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.cpp index 3e36f7316..ccdce089b 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.cpp @@ -27,9 +27,9 @@ #include "GraphicsContext.h" #include "BidiResolver.h" +#include "Font.h" #include "Generator.h" #include "GraphicsContextPrivate.h" -#include "Font.h" using namespace std; @@ -89,7 +89,7 @@ void GraphicsContext::save() return; m_common->stack.append(m_common->state); - + savePlatformState(); } @@ -104,7 +104,7 @@ void GraphicsContext::restore() } m_common->state = m_common->stack.last(); m_common->stack.removeLast(); - + restorePlatformState(); } @@ -305,7 +305,7 @@ bool GraphicsContext::paintingDisabled() const } void GraphicsContext::drawImage(Image* image, const IntPoint& p, CompositeOperator op) -{ +{ drawImage(image, p, IntRect(0, 0, -1, -1), op); } @@ -324,13 +324,15 @@ void GraphicsContext::drawImage(Image* image, const IntRect& dest, const IntRect drawImage(image, FloatRect(dest), srcRect, op, useLowQualityScale); } +#if !PLATFORM(WINCE) || PLATFORM(QT) void GraphicsContext::drawText(const Font& font, const TextRun& run, const IntPoint& point, int from, int to) { if (paintingDisabled()) return; - + font.drawText(this, run, point, from, to); } +#endif void GraphicsContext::drawBidiText(const Font& font, const TextRun& run, const FloatPoint& point) { @@ -381,7 +383,7 @@ void GraphicsContext::initFocusRing(int width, int offset) if (paintingDisabled()) return; clearFocusRing(); - + m_common->m_focusRingWidth = width; m_common->m_focusRingOffset = offset; } @@ -394,12 +396,12 @@ void GraphicsContext::clearFocusRing() IntRect GraphicsContext::focusRingBoundingRect() { IntRect result = IntRect(0, 0, 0, 0); - + const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); for (unsigned i = 0; i < rectCount; i++) result.unite(rects[i]); - + return result; } @@ -434,7 +436,7 @@ void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float float tsh = src.height(); float tw = dest.width(); float th = dest.height(); - + if (tsw == -1) tsw = image->width(); if (tsh == -1) @@ -538,10 +540,39 @@ void GraphicsContext::setPlatformTextDrawingMode(int mode) } #endif -#if !PLATFORM(QT) && !PLATFORM(CAIRO) && !PLATFORM(SKIA) +#if !PLATFORM(QT) && !PLATFORM(CAIRO) && !PLATFORM(SKIA) && !PLATFORM(HAIKU) void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle&) { } #endif +void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle& penStyle) +{ + // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic + // works out. For example, with a border width of 3, WebKit will pass us (y1+y2)/2, e.g., + // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave + // us a perfect position, but an odd width gave us a position that is off by exactly 0.5. + if (penStyle == DottedStroke || penStyle == DashedStroke) { + if (p1.x() == p2.x()) { + p1.setY(p1.y() + strokeWidth); + p2.setY(p2.y() - strokeWidth); + } else { + p1.setX(p1.x() + strokeWidth); + p2.setX(p2.x() - strokeWidth); + } + } + + if (static_cast<int>(strokeWidth) % 2) { //odd + if (p1.x() == p2.x()) { + // We're a vertical line. Adjust our x. + p1.setX(p1.x() + 0.5f); + p2.setX(p2.x() + 0.5f); + } else { + // We're a horizontal line. Adjust our y. + p1.setY(p1.y() + 0.5f); + p2.setY(p2.y() + 0.5f); + } + } +} + } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.h b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.h index 0237abf78..c6bb20c00 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008-2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,8 +49,8 @@ typedef QPainter PlatformGraphicsContext; class wxGCDC; class wxWindowDC; -// wxGraphicsContext allows us to support Path, etc. -// but on some platforms, e.g. Linux, it requires fairly +// wxGraphicsContext allows us to support Path, etc. +// but on some platforms, e.g. Linux, it requires fairly // new software. #if USE(WXGC) // On OS X, wxGCDC is just a typedef for wxDC, so use wxDC explicitly to make @@ -65,6 +66,12 @@ class wxWindowDC; #endif #elif PLATFORM(SKIA) typedef class PlatformContextSkia PlatformGraphicsContext; +#elif PLATFORM(HAIKU) +class BView; +typedef BView PlatformGraphicsContext; +struct pattern; +#elif PLATFORM(WINCE) +typedef struct HDC__ PlatformGraphicsContext; #else typedef void PlatformGraphicsContext; #endif @@ -88,6 +95,12 @@ typedef unsigned char UInt8; namespace WebCore { +#if PLATFORM(WINCE) && !PLATFORM(QT) + class SharedBitmap; + class SimpleFontData; + class GlyphBuffer; +#endif + const int cMisspellingLineThickness = 3; const int cMisspellingLinePatternWidth = 4; const int cMisspellingLinePatternGapWidth = 1; @@ -109,7 +122,7 @@ namespace WebCore { const int cTextFill = 1; const int cTextStroke = 2; const int cTextClip = 4; - + enum StrokeStyle { NoStroke, SolidStroke, @@ -117,12 +130,12 @@ namespace WebCore { DashedStroke }; -// FIXME: This is a place-holder until we decide to add -// real color space support to WebCore. At that time, ColorSpace will be a -// class and instances will be held off of Colors. There will be -// special singleton Gradient and Pattern color spaces to mark when -// a fill or stroke is using a gradient or pattern instead of a solid color. -// https://bugs.webkit.org/show_bug.cgi?id=20558 + // FIXME: This is a place-holder until we decide to add + // real color space support to WebCore. At that time, ColorSpace will be a + // class and instances will be held off of Colors. There will be + // special singleton Gradient and Pattern color spaces to mark when + // a fill or stroke is using a gradient or pattern instead of a solid color. + // https://bugs.webkit.org/show_bug.cgi?id=20558 enum ColorSpace { SolidColorSpace, PatternColorSpace, @@ -141,9 +154,11 @@ namespace WebCore { public: GraphicsContext(PlatformGraphicsContext*); ~GraphicsContext(); - + +#if !PLATFORM(WINCE) || PLATFORM(QT) PlatformGraphicsContext* platformContext() const; - +#endif + float strokeThickness() const; void setStrokeThickness(float); StrokeStyle strokeStyle() const; @@ -219,7 +234,7 @@ namespace WebCore { CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false); void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, CompositeOperator = CompositeSourceOver); - void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, + void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile, CompositeOperator = CompositeSourceOver); @@ -243,13 +258,13 @@ namespace WebCore { void drawHighlightForText(const Font&, const TextRun&, const IntPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1); FloatRect roundToDevicePixels(const FloatRect&); - + void drawLineForText(const IntPoint&, int width, bool printing); void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar); - + bool paintingDisabled() const; void setPaintingDisabled(bool); - + bool updatingControlTints() const; void setUpdatingControlTints(bool); @@ -282,19 +297,40 @@ namespace WebCore { void addPath(const Path&); void clip(const Path&); + + // This clip function is used only by <canvas> code. It allows + // implementations to handle clipping on the canvas differently since + // the disipline is different. + void canvasClip(const Path&); void clipOut(const Path&); void scale(const FloatSize&); void rotate(float angleInRadians); void translate(float x, float y); IntPoint origin(); - + void setURLForRect(const KURL&, const IntRect&); void concatCTM(const TransformationMatrix&); TransformationMatrix getCTM() const; -#if PLATFORM(WIN) +#if PLATFORM(WINCE) && !PLATFORM(QT) + void setBitmap(PassRefPtr<SharedBitmap>); + const TransformationMatrix& affineTransform() const; + TransformationMatrix& affineTransform(); + void resetAffineTransform(); + void fillRect(const FloatRect&, const Gradient*); + void drawText(const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point); + void drawFrameControl(const IntRect& rect, unsigned type, unsigned state); + void drawFocusRect(const IntRect& rect); + void paintTextField(const IntRect& rect, unsigned state); + void drawBitmap(SharedBitmap*, const IntRect& dstRect, const IntRect& srcRect, CompositeOperator compositeOp); + void drawBitmapPattern(SharedBitmap*, const FloatRect& tileRectIn, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize); + void drawIcon(HICON icon, const IntRect& dstRect, UINT flags); + HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = false, bool mayCreateBitmap = true); // The passed in rect is used to create a bitmap for compositing inside transparency layers. + void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = false, bool mayCreateBitmap = true); // The passed in HDC should be the one handed back by getWindowsContext. + void drawRoundCorner(bool newClip, RECT clipRect, RECT rectWin, HDC dc, int width, int height); +#elif PLATFORM(WIN) GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed. bool inTransparencyLayer() const; HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); // The passed in rect is used to create a bitmap for compositing inside transparency layers. @@ -354,6 +390,10 @@ namespace WebCore { GdkEventExpose* gdkExposeEvent() const; #endif +#if PLATFORM(HAIKU) + pattern getHaikuStrokeStyle(); +#endif + private: void savePlatformState(); void restorePlatformState(); @@ -376,6 +416,8 @@ namespace WebCore { void setPlatformShadow(const IntSize&, int blur, const Color&); void clearPlatformShadow(); + static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&); + int focusRingWidth() const; int focusRingOffset() const; const Vector<IntRect>& focusRingRects() const; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext3D.h b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext3D.h new file mode 100644 index 000000000..07ec04d5c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsContext3D.h @@ -0,0 +1,346 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GraphicsContext3D_h +#define GraphicsContext3D_h + +#include "PlatformString.h" + +#include <wtf/Noncopyable.h> +#include <wtf/PassOwnPtr.h> + +#if PLATFORM(MAC) +#include <OpenGL/OpenGL.h> + +typedef void* PlatformGraphicsContext3D; +const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0; +typedef GLuint Platform3DObject; +const Platform3DObject NullPlatform3DObject = 0; +#else +typedef void* PlatformGraphicsContext3D; +const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0; +typedef int Platform3DObject; +const Platform3DObject NullPlatform3DObject = 0; +#endif + +namespace WebCore { + class CanvasActiveInfo; + class CanvasArray; + class CanvasBuffer; + class CanvasUnsignedByteArray; + class CanvasFloatArray; + class CanvasFramebuffer; + class CanvasIntArray; + class CanvasProgram; + class CanvasRenderbuffer; + class CanvasRenderingContext3D; + class CanvasShader; + class CanvasTexture; + class HTMLCanvasElement; + class HTMLImageElement; + class HTMLVideoElement; + class ImageData; + class WebKitCSSMatrix; + + struct ActiveInfo { + String name; + unsigned type; + int size; + }; + + // FIXME: ideally this would be used on all platforms. +#if PLATFORM(CHROMIUM) + class GraphicsContext3DInternal; +#endif + + class GraphicsContext3D : public Noncopyable { + public: + enum ShaderType { FRAGMENT_SHADER, VERTEX_SHADER }; + + static PassOwnPtr<GraphicsContext3D> create(); + virtual ~GraphicsContext3D(); + +#if PLATFORM(MAC) + PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; } + Platform3DObject platformTexture() const { return m_texture; } +#elif PLATFORM(CHROMIUM) + PlatformGraphicsContext3D platformGraphicsContext3D() const; + Platform3DObject platformTexture() const; +#else + PlatformGraphicsContext3D platformGraphicsContext3D() const { return NullPlatformGraphicsContext3D; } + Platform3DObject platformTexture() const { return NullPlatform3DObject; } +#endif + void checkError() const; + void makeContextCurrent(); + + // Helper to return the size in bytes of OpenGL data types + // like GL_FLOAT, GL_INT, etc. + int sizeInBytes(int type); + + void activeTexture(unsigned long texture); + void attachShader(CanvasProgram* program, CanvasShader* shader); + void bindAttribLocation(CanvasProgram*, unsigned long index, const String& name); + void bindBuffer(unsigned long target, CanvasBuffer*); + void bindFramebuffer(unsigned long target, CanvasFramebuffer*); + void bindRenderbuffer(unsigned long target, CanvasRenderbuffer*); + void bindTexture(unsigned long target, CanvasTexture* texture); + void blendColor(double red, double green, double blue, double alpha); + void blendEquation(unsigned long mode); + void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha); + void blendFunc(unsigned long sfactor, unsigned long dfactor); + void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha); + + void bufferData(unsigned long target, int size, unsigned long usage); + void bufferData(unsigned long target, CanvasArray* data, unsigned long usage); + void bufferSubData(unsigned long target, long offset, CanvasArray* data); + + unsigned long checkFramebufferStatus(unsigned long target); + void clear(unsigned long mask); + void clearColor(double red, double green, double blue, double alpha); + void clearDepth(double depth); + void clearStencil(long s); + void colorMask(bool red, bool green, bool blue, bool alpha); + void compileShader(CanvasShader*); + + //void compressedTexImage2D(unsigned long target, long level, unsigned long internalformat, unsigned long width, unsigned long height, long border, unsigned long imageSize, const void* data); + //void compressedTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, unsigned long width, unsigned long height, unsigned long format, unsigned long imageSize, const void* data); + + void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border); + void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height); + void cullFace(unsigned long mode); + void depthFunc(unsigned long func); + void depthMask(bool flag); + void depthRange(double zNear, double zFar); + void detachShader(CanvasProgram*, CanvasShader*); + void disable(unsigned long cap); + void disableVertexAttribArray(unsigned long index); + void drawArrays(unsigned long mode, long first, long count); + void drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset); + + void enable(unsigned long cap); + void enableVertexAttribArray(unsigned long index); + void finish(); + void flush(); + void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, CanvasRenderbuffer*); + void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, CanvasTexture*, long level); + void frontFace(unsigned long mode); + void generateMipmap(unsigned long target); + + bool getActiveAttrib(CanvasProgram* program, unsigned long index, ActiveInfo&); + bool getActiveUniform(CanvasProgram* program, unsigned long index, ActiveInfo&); + + int getAttribLocation(CanvasProgram*, const String& name); + + bool getBoolean(unsigned long pname); + PassRefPtr<CanvasUnsignedByteArray> getBooleanv(unsigned long pname); + int getBufferParameteri(unsigned long target, unsigned long pname); + PassRefPtr<CanvasIntArray> getBufferParameteriv(unsigned long target, unsigned long pname); + + unsigned long getError(); + + float getFloat(unsigned long pname); + PassRefPtr<CanvasFloatArray> getFloatv(unsigned long pname); + int getFramebufferAttachmentParameteri(unsigned long target, unsigned long attachment, unsigned long pname); + PassRefPtr<CanvasIntArray> getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname); + int getInteger(unsigned long pname); + PassRefPtr<CanvasIntArray> getIntegerv(unsigned long pname); + int getProgrami(CanvasProgram*, unsigned long pname); + PassRefPtr<CanvasIntArray> getProgramiv(CanvasProgram*, unsigned long pname); + String getProgramInfoLog(CanvasProgram*); + int getRenderbufferParameteri(unsigned long target, unsigned long pname); + PassRefPtr<CanvasIntArray> getRenderbufferParameteriv(unsigned long target, unsigned long pname); + int getShaderi(CanvasShader*, unsigned long pname); + PassRefPtr<CanvasIntArray> getShaderiv(CanvasShader*, unsigned long pname); + + String getShaderInfoLog(CanvasShader*); + + // TBD + // void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); + + String getShaderSource(CanvasShader*); + String getString(unsigned long name); + + float getTexParameterf(unsigned long target, unsigned long pname); + PassRefPtr<CanvasFloatArray> getTexParameterfv(unsigned long target, unsigned long pname); + int getTexParameteri(unsigned long target, unsigned long pname); + PassRefPtr<CanvasIntArray> getTexParameteriv(unsigned long target, unsigned long pname); + + float getUniformf(CanvasProgram* program, long location); + PassRefPtr<CanvasFloatArray> getUniformfv(CanvasProgram* program, long location); + int getUniformi(CanvasProgram* program, long location); + PassRefPtr<CanvasIntArray> getUniformiv(CanvasProgram* program, long location); + + long getUniformLocation(CanvasProgram*, const String& name); + + float getVertexAttribf(unsigned long index, unsigned long pname); + PassRefPtr<CanvasFloatArray> getVertexAttribfv(unsigned long index, unsigned long pname); + int getVertexAttribi(unsigned long index, unsigned long pname); + PassRefPtr<CanvasIntArray> getVertexAttribiv(unsigned long index, unsigned long pname); + + long getVertexAttribOffset(unsigned long index, unsigned long pname); + + void hint(unsigned long target, unsigned long mode); + bool isBuffer(CanvasBuffer*); + bool isEnabled(unsigned long cap); + bool isFramebuffer(CanvasFramebuffer*); + bool isProgram(CanvasProgram*); + bool isRenderbuffer(CanvasRenderbuffer*); + bool isShader(CanvasShader*); + bool isTexture(CanvasTexture*); + void lineWidth(double); + void linkProgram(CanvasProgram*); + void pixelStorei(unsigned long pname, long param); + void polygonOffset(double factor, double units); + + PassRefPtr<CanvasArray> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type); + + void releaseShaderCompiler(); + void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height); + void sampleCoverage(double value, bool invert); + void scissor(long x, long y, unsigned long width, unsigned long height); + void shaderSource(CanvasShader*, const String& string); + void stencilFunc(unsigned long func, long ref, unsigned long mask); + void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask); + void stencilMask(unsigned long mask); + void stencilMaskSeparate(unsigned long face, unsigned long mask); + void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass); + void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass); + + // These next several functions return an error code (0 if no errors) rather than using an ExceptionCode. + // Currently they return -1 on any error. + int texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, CanvasArray* pixels); + int texImage2D(unsigned target, unsigned level, unsigned internalformat, + unsigned width, unsigned height, unsigned border, + unsigned format, unsigned type, ImageData* pixels); + int texImage2D(unsigned target, unsigned level, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha); + int texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha); + int texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha); + + void texParameterf(unsigned target, unsigned pname, float param); + void texParameteri(unsigned target, unsigned pname, int param); + + int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, CanvasArray* pixels); + int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, + unsigned format, unsigned type, ImageData* pixels); + int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLImageElement* image, + bool flipY, bool premultiplyAlpha); + int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLCanvasElement* canvas, + bool flipY, bool premultiplyAlpha); + int texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, + unsigned width, unsigned height, HTMLVideoElement* video, + bool flipY, bool premultiplyAlpha); + + void uniform1f(long location, float x); + void uniform1fv(long location, float* v, int size); + void uniform1i(long location, int x); + void uniform1iv(long location, int* v, int size); + void uniform2f(long location, float x, float y); + void uniform2fv(long location, float* v, int size); + void uniform2i(long location, int x, int y); + void uniform2iv(long location, int* v, int size); + void uniform3f(long location, float x, float y, float z); + void uniform3fv(long location, float* v, int size); + void uniform3i(long location, int x, int y, int z); + void uniform3iv(long location, int* v, int size); + void uniform4f(long location, float x, float y, float z, float w); + void uniform4fv(long location, float* v, int size); + void uniform4i(long location, int x, int y, int z, int w); + void uniform4iv(long location, int* v, int size); + void uniformMatrix2fv(long location, bool transpose, float* value, int size); + void uniformMatrix3fv(long location, bool transpose, float* value, int size); + void uniformMatrix4fv(long location, bool transpose, float* value, int size); + + void useProgram(CanvasProgram*); + void validateProgram(CanvasProgram*); + + void vertexAttrib1f(unsigned long indx, float x); + void vertexAttrib1fv(unsigned long indx, float* values); + void vertexAttrib2f(unsigned long indx, float x, float y); + void vertexAttrib2fv(unsigned long indx, float* values); + void vertexAttrib3f(unsigned long indx, float x, float y, float z); + void vertexAttrib3fv(unsigned long indx, float* values); + void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w); + void vertexAttrib4fv(unsigned long indx, float* values); + void vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, + unsigned long stride, unsigned long offset); + + void viewport(long x, long y, unsigned long width, unsigned long height); + + void reshape(int width, int height); + + // Helpers for notification about paint events + void beginPaint(CanvasRenderingContext3D* context); + void endPaint(); + + // Support for buffer creation and deletion + unsigned createBuffer(); + unsigned createFramebuffer(); + unsigned createProgram(); + unsigned createRenderbuffer(); + unsigned createShader(ShaderType); + unsigned createTexture(); + + void deleteBuffer(unsigned); + void deleteFramebuffer(unsigned); + void deleteProgram(unsigned); + void deleteRenderbuffer(unsigned); + void deleteShader(unsigned); + void deleteTexture(unsigned); + + private: + GraphicsContext3D(); + + int m_currentWidth, m_currentHeight; + +#if PLATFORM(MAC) + Vector<Vector<float> > m_vertexArray; + + CGLContextObj m_contextObj; + GLuint m_texture; + GLuint m_fbo; + GLuint m_depthBuffer; +#endif + + // FIXME: ideally this would be used on all platforms. +#if PLATFORM(CHROMIUM) + friend class GraphicsContext3DInternal; + OwnPtr<GraphicsContext3DInternal> m_internal; +#endif + }; + +} // namespace WebCore + +#endif // GraphicsContext3D_h + diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.cpp index b1825481e..c8582bb82 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.cpp @@ -35,156 +35,31 @@ namespace WebCore { -void GraphicsLayer::FloatValue::set(float key, float value, const TimingFunction* timingFunction) -{ - m_key = key; - m_value = value; - if (timingFunction != m_timingFunction) { - if (timingFunction) - m_timingFunction.set(new TimingFunction(*timingFunction)); - else - m_timingFunction.clear(); - } -} - -void GraphicsLayer::TransformValue::set(float key, const TransformOperations* value, const TimingFunction* timingFunction) -{ - m_key = key; - if (value != m_value) { - if (value) - m_value.set(new TransformOperations(*value)); - else - m_value.clear(); - } - if (timingFunction != m_timingFunction) { - if (timingFunction) - m_timingFunction.set(new TimingFunction(*timingFunction)); - else - m_timingFunction.clear(); - } -} - -void GraphicsLayer::FloatValueList::insert(float key, float value, const TimingFunction* timingFunction) +void KeyframeValueList::insert(const AnimationValue* value) { for (size_t i = 0; i < m_values.size(); ++i) { - FloatValue& curFloatValue = m_values[i]; - if (curFloatValue.key() == key) { - curFloatValue.set(key, value, timingFunction); - return; - } - if (curFloatValue.key() > key) { - // insert before - m_values.insert(i, FloatValue(key, value, timingFunction)); - return; - } - } - - // append - m_values.append(FloatValue(key, value, timingFunction)); -} - -void GraphicsLayer::TransformValueList::insert(float key, const TransformOperations* value, const TimingFunction* timingFunction) -{ - for (size_t i = 0; i < m_values.size(); ++i) { - TransformValue& curTransValue = m_values[i]; - if (curTransValue.key() == key) { - curTransValue.set(key, value, timingFunction); + const AnimationValue* curValue = m_values[i]; + if (curValue->keyTime() == value->keyTime()) { + ASSERT_NOT_REACHED(); + // insert after + m_values.insert(i + 1, value); return; } - if (curTransValue.key() > key) { + if (curValue->keyTime() > value->keyTime()) { // insert before - m_values.insert(i, TransformValue(key, value, timingFunction)); - return; - } - } - - // append - m_values.append(TransformValue(key, value, timingFunction)); -} - -// An "invalid" list is one whose functions don't match, and therefore has to be animated as a Matrix -// The hasBigRotation flag will always return false if isValid is false. Otherwise hasBigRotation is -// true if the rotation between any two keyframes is >= 180 degrees. -void GraphicsLayer::TransformValueList::makeFunctionList(FunctionList& list, bool& isValid, bool& hasBigRotation) const -{ - list.clear(); - isValid = false; - hasBigRotation = false; - - if (m_values.size() < 2) - return; - - // empty transforms match anything, so find the first non-empty entry as the reference - size_t firstIndex = 0; - for ( ; firstIndex < m_values.size(); ++firstIndex) { - if (m_values[firstIndex].value()->operations().size() > 0) - break; - } - - if (firstIndex >= m_values.size()) - return; - - const TransformOperations* firstVal = m_values[firstIndex].value(); - - // see if the keyframes are valid - for (size_t i = firstIndex + 1; i < m_values.size(); ++i) { - const TransformOperations* val = m_values[i].value(); - - // a null transform matches anything - if (val->operations().isEmpty()) - continue; - - if (firstVal->operations().size() != val->operations().size()) + m_values.insert(i, value); return; - - for (size_t j = 0; j < firstVal->operations().size(); ++j) { - if (!firstVal->operations().at(j)->isSameType(*val->operations().at(j))) - return; } } - - // keyframes are valid, fill in the list - isValid = true; - double lastRotAngle = 0.0; - double maxRotAngle = -1.0; - - list.resize(firstVal->operations().size()); - for (size_t j = 0; j < firstVal->operations().size(); ++j) { - TransformOperation::OperationType type = firstVal->operations().at(j)->getOperationType(); - list[j] = type; - - // if this is a rotation entry, we need to see if any angle differences are >= 180 deg - if (type == TransformOperation::ROTATE_X || - type == TransformOperation::ROTATE_Y || - type == TransformOperation::ROTATE_Z || - type == TransformOperation::ROTATE_3D) { - lastRotAngle = static_cast<RotateTransformOperation*>(firstVal->operations().at(j).get())->angle(); - - if (maxRotAngle < 0) - maxRotAngle = fabs(lastRotAngle); - - for (size_t i = firstIndex + 1; i < m_values.size(); ++i) { - const TransformOperations* val = m_values[i].value(); - double rotAngle = val->operations().isEmpty() ? 0 : (static_cast<RotateTransformOperation*>(val->operations().at(j).get())->angle()); - double diffAngle = fabs(rotAngle - lastRotAngle); - if (diffAngle > maxRotAngle) - maxRotAngle = diffAngle; - lastRotAngle = rotAngle; - } - } - } - - hasBigRotation = maxRotAngle >= 180.0; + m_values.append(value); } GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) : m_client(client) , m_anchorPoint(0.5f, 0.5f, 0) , m_opacity(1) -#ifndef NDEBUG , m_zPosition(0) -#endif , m_backgroundColorSet(false) , m_contentsOpaque(false) , m_preserves3D(false) @@ -192,23 +67,31 @@ GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client) , m_usingTiledLayer(false) , m_masksToBounds(false) , m_drawsContent(false) - , m_paintingPhase(GraphicsLayerPaintAllMask) + , m_paintingPhase(GraphicsLayerPaintAll) + , m_geometryOrientation(CompositingCoordinatesTopDown) , m_contentsOrientation(CompositingCoordinatesTopDown) , m_parent(0) -#ifndef NDEBUG + , m_maskLayer(0) , m_repaintCount(0) -#endif { } GraphicsLayer::~GraphicsLayer() { - removeAllAnimations(); - removeAllChildren(); removeFromParent(); } +bool GraphicsLayer::hasAncestor(GraphicsLayer* ancestor) const +{ + for (GraphicsLayer* curr = parent(); curr; curr = curr->parent()) { + if (curr == ancestor) + return true; + } + + return false; +} + void GraphicsLayer::addChild(GraphicsLayer* childLayer) { ASSERT(childLayer != this); @@ -316,9 +199,9 @@ void GraphicsLayer::removeFromParent() } } -void GraphicsLayer::setBackgroundColor(const Color& inColor, const Animation*, double /*beginTime*/) +void GraphicsLayer::setBackgroundColor(const Color& color) { - m_backgroundColor = inColor; + m_backgroundColor = color; m_backgroundColorSet = true; } @@ -328,96 +211,13 @@ void GraphicsLayer::clearBackgroundColor() m_backgroundColorSet = false; } -bool GraphicsLayer::setOpacity(float opacity, const Animation*, double) -{ - m_opacity = opacity; - return false; // not animating -} - void GraphicsLayer::paintGraphicsLayerContents(GraphicsContext& context, const IntRect& clip) { - m_client->paintContents(this, context, m_paintingPhase, clip); -} - -String GraphicsLayer::propertyIdToString(AnimatedPropertyID property) -{ - switch (property) { - case AnimatedPropertyWebkitTransform: - return "transform"; - case AnimatedPropertyOpacity: - return "opacity"; - case AnimatedPropertyBackgroundColor: - return "backgroundColor"; - case AnimatedPropertyInvalid: - ASSERT_NOT_REACHED(); - } - ASSERT_NOT_REACHED(); - return ""; -} - -int GraphicsLayer::findAnimationEntry(AnimatedPropertyID property, short index) const -{ - for (size_t i = 0; i < m_animations.size(); ++i) { - if (m_animations[i].matches(property, index)) - return static_cast<int>(i); - } - return -1; -} - -void GraphicsLayer::addAnimationEntry(AnimatedPropertyID property, short index, bool isTransition, const Animation* transition) -{ - int i = findAnimationEntry(property, index); - - if (i >= 0) - m_animations[i].reset(transition, isTransition); - else - m_animations.append(AnimationEntry(transition, property, index, isTransition)); -} - -void GraphicsLayer::removeAllAnimations() -{ - size_t size = m_animations.size(); - for (size_t i = 0; i < size; ++i) - removeAnimation(0, true); -} - -void GraphicsLayer::removeAllAnimationsForProperty(AnimatedPropertyID property) -{ - for (short j = 0; ; ++j) { - int i = findAnimationEntry(property, j); - if (i < 0) - break; - removeAnimation(i, false); - } -} - -void GraphicsLayer::removeFinishedAnimations(const String& name, int /*index*/, bool reset) -{ - size_t size = m_animations.size(); - for (size_t i = 0; i < size; ) { - AnimationEntry& anim = m_animations[i]; - if (!anim.isTransition() && anim.animation()->name() == name) { - removeAnimation(i, reset); - --size; - } else - ++i; - } -} - -void GraphicsLayer::removeFinishedTransitions(AnimatedPropertyID property) -{ - size_t size = m_animations.size(); - for (size_t i = 0; i < size; ) { - AnimationEntry& anim = m_animations[i]; - if (anim.isTransition() && property == anim.property()) { - removeAnimation(i, false); - --size; - } else - ++i; - } + if (m_client) + m_client->paintContents(this, context, m_paintingPhase, clip); } -void GraphicsLayer::suspendAnimations() +void GraphicsLayer::suspendAnimations(double) { } @@ -425,7 +225,6 @@ void GraphicsLayer::resumeAnimations() { } -#ifndef NDEBUG void GraphicsLayer::updateDebugIndicators() { if (GraphicsLayer::showDebugBorders()) { @@ -447,7 +246,6 @@ void GraphicsLayer::setZPosition(float position) { m_zPosition = position; } -#endif float GraphicsLayer::accumulatedOpacity() const { @@ -474,6 +272,91 @@ void GraphicsLayer::distributeOpacity(float accumulatedOpacity) } } +// An "invalid" list is one whose functions don't match, and therefore has to be animated as a Matrix +// The hasBigRotation flag will always return false if isValid is false. Otherwise hasBigRotation is +// true if the rotation between any two keyframes is >= 180 degrees. + +static inline const TransformOperations* operationsAt(const KeyframeValueList& valueList, size_t index) +{ + return static_cast<const TransformAnimationValue*>(valueList.at(index))->value(); +} + +void GraphicsLayer::fetchTransformOperationList(const KeyframeValueList& valueList, TransformOperationList& list, bool& isValid, bool& hasBigRotation) +{ + ASSERT(valueList.property() == AnimatedPropertyWebkitTransform); + + list.clear(); + isValid = false; + hasBigRotation = false; + + if (valueList.size() < 2) + return; + + // Empty transforms match anything, so find the first non-empty entry as the reference. + size_t firstIndex = 0; + for ( ; firstIndex < valueList.size(); ++firstIndex) { + if (operationsAt(valueList, firstIndex)->operations().size() > 0) + break; + } + + if (firstIndex >= valueList.size()) + return; + + const TransformOperations* firstVal = operationsAt(valueList, firstIndex); + + // See if the keyframes are valid. + for (size_t i = firstIndex + 1; i < valueList.size(); ++i) { + const TransformOperations* val = operationsAt(valueList, i); + + // a null transform matches anything + if (val->operations().isEmpty()) + continue; + + if (firstVal->operations().size() != val->operations().size()) + return; + + for (size_t j = 0; j < firstVal->operations().size(); ++j) { + if (!firstVal->operations().at(j)->isSameType(*val->operations().at(j))) + return; + } + } + + // Keyframes are valid, fill in the list. + isValid = true; + + double lastRotAngle = 0.0; + double maxRotAngle = -1.0; + + list.resize(firstVal->operations().size()); + for (size_t j = 0; j < firstVal->operations().size(); ++j) { + TransformOperation::OperationType type = firstVal->operations().at(j)->getOperationType(); + list[j] = type; + + // if this is a rotation entry, we need to see if any angle differences are >= 180 deg + if (type == TransformOperation::ROTATE_X || + type == TransformOperation::ROTATE_Y || + type == TransformOperation::ROTATE_Z || + type == TransformOperation::ROTATE_3D) { + lastRotAngle = static_cast<RotateTransformOperation*>(firstVal->operations().at(j).get())->angle(); + + if (maxRotAngle < 0) + maxRotAngle = fabs(lastRotAngle); + + for (size_t i = firstIndex + 1; i < valueList.size(); ++i) { + const TransformOperations* val = operationsAt(valueList, i); + double rotAngle = val->operations().isEmpty() ? 0 : (static_cast<RotateTransformOperation*>(val->operations().at(j).get())->angle()); + double diffAngle = fabs(rotAngle - lastRotAngle); + if (diffAngle > maxRotAngle) + maxRotAngle = diffAngle; + lastRotAngle = rotAngle; + } + } + } + + hasBigRotation = maxRotAngle >= 180.0; +} + + static void writeIndent(TextStream& ts, int indent) { for (int i = 0; i != indent; ++i) diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.h b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.h index 3cc11286b..85eace092 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayer.h @@ -33,16 +33,21 @@ #include "FloatPoint.h" #include "FloatPoint3D.h" #include "FloatSize.h" +#if ENABLE(3D_CANVAS) +#include "GraphicsContext3D.h" +#endif #include "GraphicsLayerClient.h" +#include "IntRect.h" #include "TransformationMatrix.h" #include "TransformOperations.h" #include <wtf/OwnPtr.h> +#include <wtf/PassOwnPtr.h> #if PLATFORM(MAC) #ifdef __OBJC__ @class WebLayer; @class CALayer; -typedef WebLayer PlatformLayer; +typedef CALayer PlatformLayer; typedef CALayer* NativeLayer; #else typedef void* PlatformLayer; @@ -61,119 +66,97 @@ class Image; class TextStream; class TimingFunction; -// GraphicsLayer is an abstraction for a rendering surface with backing store, -// which may have associated transformation and animations. +// Base class for animation values (also used for transitions). Here to +// represent values for properties being animated via the GraphicsLayer, +// without pulling in style-related data from outside of the platform directory. +class AnimationValue : public Noncopyable { +public: + AnimationValue(float keyTime, const TimingFunction* timingFunction = 0) + : m_keyTime(keyTime) + , m_timingFunction(0) + { + if (timingFunction) + m_timingFunction.set(new TimingFunction(*timingFunction)); + } + + virtual ~AnimationValue() { } -class GraphicsLayer { + float keyTime() const { return m_keyTime; } + const TimingFunction* timingFunction() const { return m_timingFunction.get(); } + +private: + float m_keyTime; + OwnPtr<TimingFunction> m_timingFunction; +}; + +// Used to store one float value of an animation. +class FloatAnimationValue : public AnimationValue { +public: + FloatAnimationValue(float keyTime, float value, const TimingFunction* timingFunction = 0) + : AnimationValue(keyTime, timingFunction) + , m_value(value) + { + } + + float value() const { return m_value; } + +private: + float m_value; +}; + +// Used to store one transform value in a keyframe list. +class TransformAnimationValue : public AnimationValue { public: - // Used to store one float value of a keyframe animation. - class FloatValue { - public: - FloatValue(float key, float value, const TimingFunction* timingFunction = 0) - : m_key(key), m_value(value), m_timingFunction(0) - { - if (timingFunction) - m_timingFunction.set(new TimingFunction(*timingFunction)); - } - - FloatValue(const FloatValue& other) - : m_key(other.key()), m_value(other.value()), m_timingFunction(0) - { - if (other.timingFunction()) - m_timingFunction.set(new TimingFunction(*other.timingFunction())); - } - - const FloatValue& operator=(const FloatValue& other) - { - if (&other != this) - set(other.key(), other.value(), other.timingFunction()); - return *this; - } - - void set(float key, float value, const TimingFunction*); - - float key() const { return m_key; } - float value() const { return m_value; } - const TimingFunction* timingFunction() const { return m_timingFunction.get(); } - - private: - float m_key; - float m_value; - OwnPtr<TimingFunction> m_timingFunction; - }; + TransformAnimationValue(float keyTime, const TransformOperations* value = 0, const TimingFunction* timingFunction = 0) + : AnimationValue(keyTime, timingFunction) + { + if (value) + m_value.set(new TransformOperations(*value)); + } + + const TransformOperations* value() const { return m_value.get(); } + +private: + OwnPtr<TransformOperations> m_value; +}; + +// Used to store a series of values in a keyframe list. Values will all be of the same type, +// which can be inferred from the property. +class KeyframeValueList : public Noncopyable { +public: + + KeyframeValueList(AnimatedPropertyID property) + : m_property(property) + { + } + + ~KeyframeValueList() + { + deleteAllValues(m_values); + } + AnimatedPropertyID property() const { return m_property; } + + size_t size() const { return m_values.size(); } + const AnimationValue* at(size_t i) const { return m_values.at(i); } - class FloatValueList { - public: - void insert(float key, float value, const TimingFunction* timingFunction); - - size_t size() const { return m_values.size(); } - const FloatValue& at(size_t i) const { return m_values.at(i); } - const Vector<FloatValue>& values() const { return m_values; } - - private: - Vector<FloatValue> m_values; - }; - - // Used to store one transform in a keyframe list. - class TransformValue { - public: - TransformValue(float key = NAN, const TransformOperations* value = 0, const TimingFunction* timingFunction = 0) - : m_key(key) - { - if (value) - m_value.set(new TransformOperations(*value)); - if (timingFunction) - m_timingFunction.set(new TimingFunction(*timingFunction)); - } - - TransformValue(const TransformValue& other) - : m_key(other.key()) - { - if (other.value()) - m_value.set(new TransformOperations(*other.value())); - if (other.timingFunction()) - m_timingFunction.set(new TimingFunction(*other.timingFunction())); - } - - const TransformValue& operator=(const TransformValue& other) - { - if (&other != this) - set(other.key(), other.value(), other.timingFunction()); - return *this; - } - - void set(float key, const TransformOperations* value, const TimingFunction* timingFunction); - - float key() const { return m_key; } - const TransformOperations* value() const { return m_value.get(); } - const TimingFunction* timingFunction() const { return m_timingFunction.get(); } - - private: - float m_key; - OwnPtr<TransformOperations> m_value; - OwnPtr<TimingFunction> m_timingFunction; - }; + // Insert, sorted by keyTime. Takes ownership of the pointer. + void insert(const AnimationValue*); - // Used to store a series of transforms in a keyframe list. - class TransformValueList { - public: - typedef Vector<TransformOperation::OperationType> FunctionList; - - size_t size() const { return m_values.size(); } - const TransformValue& at(size_t i) const { return m_values.at(i); } - const Vector<TransformValue>& values() const { return m_values; } - - void insert(float key, const TransformOperations* value, const TimingFunction* timingFunction); - - // return a list of the required functions. List is empty if keyframes are not valid - // If return value is true, functions contain rotations of >= 180 degrees - void makeFunctionList(FunctionList& list, bool& isValid, bool& hasBigRotation) const; - private: - Vector<TransformValue> m_values; - }; - - static GraphicsLayer* createGraphicsLayer(GraphicsLayerClient*); +protected: + Vector<const AnimationValue*> m_values; + AnimatedPropertyID m_property; +}; + + + +// GraphicsLayer is an abstraction for a rendering surface with backing store, +// which may have associated transformation and animations. + +class GraphicsLayer { +public: + + static PassOwnPtr<GraphicsLayer> create(GraphicsLayerClient*); virtual ~GraphicsLayer(); @@ -189,6 +172,9 @@ public: GraphicsLayer* parent() const { return m_parent; }; void setParent(GraphicsLayer* layer) { m_parent = layer; } // Internal use only. + // Returns true if the layer has the given layer as an ancestor (excluding self). + bool hasAncestor(GraphicsLayer*) const; + const Vector<GraphicsLayer*>& children() const { return m_children; } // Add child layers. If the child is already parented, it will be removed from its old parent. @@ -201,6 +187,9 @@ public: void removeAllChildren(); virtual void removeFromParent(); + GraphicsLayer* maskLayer() const { return m_maskLayer; } + virtual void setMaskLayer(GraphicsLayer* layer) { m_maskLayer = layer; } + // Offset is origin of the renderer minus origin of the graphics layer (so either zero or negative). IntSize offsetFromRenderer() const { return m_offsetFromRenderer; } void setOffsetFromRenderer(const IntSize& offset) { m_offsetFromRenderer = offset; } @@ -235,7 +224,7 @@ public: // The color used to paint the layer backgrounds const Color& backgroundColor() const { return m_backgroundColor; } - virtual void setBackgroundColor(const Color&, const Animation* = 0, double beginTime = 0); + virtual void setBackgroundColor(const Color&); virtual void clearBackgroundColor(); bool backgroundColorSet() const { return m_backgroundColorSet; } @@ -247,35 +236,39 @@ public: virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; } float opacity() const { return m_opacity; } - // return true if we started an animation - virtual bool setOpacity(float o, const Animation* = 0, double beginTime = 0); + virtual void setOpacity(float opacity) { m_opacity = opacity; } // Some GraphicsLayers paint only the foreground or the background content - GraphicsLayerPaintingPhase drawingPhase() const { return m_paintingPhase; } - void setDrawingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; } + GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; } + void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; } virtual void setNeedsDisplay() = 0; // mark the given rect (in layer coords) as needing dispay. Never goes deep. virtual void setNeedsDisplayInRect(const FloatRect&) = 0; - virtual bool animateTransform(const TransformValueList&, const IntSize&, const Animation*, double beginTime, bool isTransition) = 0; - virtual bool animateFloat(AnimatedPropertyID, const FloatValueList&, const Animation*, double beginTime) = 0; + // Set that the position/size of the contents (image or video). + IntRect contentsRect() const { return m_contentsRect; } + virtual void setContentsRect(const IntRect& r) { m_contentsRect = r; } - void removeFinishedAnimations(const String& name, int index, bool reset); - void removeFinishedTransitions(AnimatedPropertyID); - void removeAllAnimations(); - - virtual void suspendAnimations(); + // Return true if the animation is handled by the compositing system. If this returns + // false, the animation will be run by AnimationController. + virtual bool addAnimation(const KeyframeValueList&, const IntSize& /*boxSize*/, const Animation*, const String& /*keyframesName*/, double /*beginTime*/) { return false; } + virtual void removeAnimationsForProperty(AnimatedPropertyID) { } + virtual void removeAnimationsForKeyframes(const String& /* keyframesName */) { } + virtual void pauseAnimation(const String& /* keyframesName */) { } + + virtual void suspendAnimations(double time); virtual void resumeAnimations(); // Layer contents virtual void setContentsToImage(Image*) { } virtual void setContentsToVideo(PlatformLayer*) { } virtual void setContentsBackgroundColor(const Color&) { } - virtual void clearContents() { } - virtual void updateContentsRect() { } - +#if ENABLE(3D_CANVAS) + virtual void setContentsToGraphicsContext3D(const GraphicsContext3D*) { } + virtual void setGraphicsContext3DNeedsDisplay() { } +#endif // Callback from the underlying graphics system to draw layer contents. void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip); @@ -283,10 +276,8 @@ public: void dumpLayer(TextStream&, int indent = 0) const; -#ifndef NDEBUG int repaintCount() const { return m_repaintCount; } int incrementRepaintCount() { return ++m_repaintCount; } -#endif // Report whether the underlying compositing system uses a top-down // or a bottom-up coordinate system. @@ -294,14 +285,13 @@ public: static CompositingCoordinatesOrientation compositingCoordinatesOrientation(); // Set the geometry orientation (top-down, or bottom-up) for this layer, which also controls sublayer geometry. - virtual void setGeometryOrientation(CompositingCoordinatesOrientation) { } - virtual CompositingCoordinatesOrientation geometryOrientation() const { return CompositingCoordinatesTopDown; } + virtual void setGeometryOrientation(CompositingCoordinatesOrientation orientation) { m_geometryOrientation = orientation; } + CompositingCoordinatesOrientation geometryOrientation() const { return m_geometryOrientation; } // Flippedness of the contents of this layer. Does not affect sublayer geometry. virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; } - virtual CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; } + CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; } -#ifndef NDEBUG static bool showDebugBorders(); static bool showRepaintCounter(); @@ -312,27 +302,27 @@ public: // z-position is the z-equivalent of position(). It's only used for debugging purposes. virtual float zPosition() const { return m_zPosition; } virtual void setZPosition(float); -#endif - static String propertyIdToString(AnimatedPropertyID); - virtual void distributeOpacity(float); virtual float accumulatedOpacity() const; + // Some compositing systems may do internal batching to synchronize compositing updates + // with updates drawn into the window. This is a signal to flush any internal batched state. + virtual void syncCompositingState() { } + protected: + + typedef Vector<TransformOperation::OperationType> TransformOperationList; + // Given a list of TransformAnimationValues, return an array of transform operations. + // On return, if hasBigRotation is true, functions contain rotations of >= 180 degrees + static void fetchTransformOperationList(const KeyframeValueList&, TransformOperationList&, bool& isValid, bool& hasBigRotation); + virtual void setOpacityInternal(float) { } GraphicsLayer(GraphicsLayerClient*); void dumpProperties(TextStream&, int indent) const; - // returns -1 if not found - int findAnimationEntry(AnimatedPropertyID, short index) const; - void addAnimationEntry(AnimatedPropertyID, short index, bool isTransition, const Animation*); - - virtual void removeAnimation(int /*index*/, bool /*reset*/) {} - void removeAllAnimationsForProperty(AnimatedPropertyID); - GraphicsLayerClient* m_client; String m_name; @@ -348,9 +338,7 @@ protected: Color m_backgroundColor; float m_opacity; -#ifndef NDEBUG float m_zPosition; -#endif bool m_backgroundColorSet : 1; bool m_contentsOpaque : 1; @@ -361,57 +349,17 @@ protected: bool m_drawsContent : 1; GraphicsLayerPaintingPhase m_paintingPhase; - CompositingCoordinatesOrientation m_contentsOrientation; + CompositingCoordinatesOrientation m_geometryOrientation; // affects geometry of layer positions + CompositingCoordinatesOrientation m_contentsOrientation; // affects orientation of layer contents Vector<GraphicsLayer*> m_children; GraphicsLayer* m_parent; - - // AnimationEntry represents an animation of a property on this layer. - // For transform only, there may be more than one, in which case 'index' - // is an index into the list of transforms. - class AnimationEntry { - public: - AnimationEntry(const Animation* animation, AnimatedPropertyID property, short index, bool isTransition) - : m_animation(const_cast<Animation*>(animation)) - , m_property(property) - , m_index(index) - , m_isCurrent(true) - , m_isTransition(isTransition) - { - } - - const Animation* animation() const { return m_animation.get(); } - AnimatedPropertyID property() const { return m_property; } - int index() const { return m_index; } - bool isCurrent() const { return m_isCurrent; } - void setIsCurrent(bool b = true) { m_isCurrent = b; } - bool isTransition() const { return m_isTransition; } - - bool matches(AnimatedPropertyID property, short index) const - { - return m_property == property && m_index == index; - } - - void reset(const Animation* animation, bool isTransition) - { - m_animation = const_cast<Animation*>(animation); - m_isTransition = isTransition; - m_isCurrent = true; - } - - private: - RefPtr<Animation> m_animation; - AnimatedPropertyID m_property : 14; - short m_index : 16; - bool m_isCurrent : 1; - bool m_isTransition : 1; - }; - - Vector<AnimationEntry> m_animations; // running animations/transitions - -#ifndef NDEBUG + + GraphicsLayer* m_maskLayer; // Reference to mask layer. We don't own this. + + IntRect m_contentsRect; + int m_repaintCount; -#endif }; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayerClient.h b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayerClient.h index 46382f2cf..5facc94c4 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayerClient.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/GraphicsLayerClient.h @@ -37,9 +37,10 @@ class IntRect; class FloatPoint; enum GraphicsLayerPaintingPhase { - GraphicsLayerPaintBackgroundMask = (1 << 0), - GraphicsLayerPaintForegroundMask = (1 << 1), - GraphicsLayerPaintAllMask = (GraphicsLayerPaintBackgroundMask | GraphicsLayerPaintForegroundMask) + GraphicsLayerPaintBackground = (1 << 0), + GraphicsLayerPaintForeground = (1 << 1), + GraphicsLayerPaintMask = (1 << 2), + GraphicsLayerPaintAll = (GraphicsLayerPaintBackground | GraphicsLayerPaintForeground | GraphicsLayerPaintMask) }; enum AnimatedPropertyID { @@ -53,13 +54,14 @@ class GraphicsLayerClient { public: virtual ~GraphicsLayerClient() {} - // Callbacks for when hardware-accelerated transitions and animation started + // Callback for when hardware-accelerated animation started. virtual void notifyAnimationStarted(const GraphicsLayer*, double time) = 0; + + // Notification that a layer property changed that requires a subsequent call to syncCompositingState() + // to appear on the screen. + virtual void notifySyncRequired(const GraphicsLayer*) = 0; virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& inClip) = 0; - - // Return a rect for the "contents" of the graphics layer, i.e. video or image content, in GraphicsLayer coordinates. - virtual IntRect contentsBox(const GraphicsLayer*) = 0; }; } // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.cpp new file mode 100644 index 000000000..55305d1b4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ImageBuffer.h" + +#if !PLATFORM(CG) + +#include <math.h> + +namespace WebCore { + +void ImageBuffer::transformColorSpace(ImageColorSpace srcColorSpace, ImageColorSpace dstColorSpace) +{ + if (srcColorSpace == dstColorSpace) + return; + + // only sRGB <-> linearRGB are supported at the moment + if ((srcColorSpace != LinearRGB && srcColorSpace != DeviceRGB) || + (dstColorSpace != LinearRGB && dstColorSpace != DeviceRGB)) + return; + + Vector<int> lookUpTable; + if (dstColorSpace == LinearRGB) { + if (m_linearRgbLUT.isEmpty()) { + for (unsigned i = 0; i < 256; i++) { + float color = i / 255.0f; + color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) / 1.055f, 2.4f)); + color = std::max(0.0f, color); + color = std::min(1.0f, color); + m_linearRgbLUT.append(static_cast<int>(color * 255)); + } + } + platformTransformColorSpace(m_linearRgbLUT); + } else if (dstColorSpace == DeviceRGB) { + if (m_deviceRgbLUT.isEmpty()) { + for (unsigned i = 0; i < 256; i++) { + float color = i / 255.0f; + color = pow(1.055f * color, 1.0f / 2.4f) - 0.055f; + color = std::max(0.0f, color); + color = std::min(1.0f, color); + m_deviceRgbLUT.append(static_cast<int>(color * 255)); + } + } + platformTransformColorSpace(m_deviceRgbLUT); + } +} + +} + +#endif // PLATFORM(CG) diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.h b/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.h index 841a8914d..94320584d 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/ImageBuffer.h @@ -43,13 +43,25 @@ namespace WebCore { class IntRect; class String; + enum ImageColorSpace { + Unknown, + DeviceRGB, // like sRGB + GrayScale, + LinearRGB + }; + + enum Multiply { + Premultiplied, + Unmultiplied + }; + class ImageBuffer : public Noncopyable { public: // Will return a null pointer on allocation failure. - static PassOwnPtr<ImageBuffer> create(const IntSize& size, bool grayScale) + static PassOwnPtr<ImageBuffer> create(const IntSize& size, ImageColorSpace colorSpace = DeviceRGB) { bool success = false; - OwnPtr<ImageBuffer> buf(new ImageBuffer(size, grayScale, success)); + OwnPtr<ImageBuffer> buf(new ImageBuffer(size, colorSpace, success)); if (success) return buf.release(); return 0; @@ -64,12 +76,17 @@ namespace WebCore { void clearImage() { m_image.clear(); } - PassRefPtr<ImageData> getImageData(const IntRect& rect) const; - void putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint); + PassRefPtr<ImageData> getUnmultipliedImageData(const IntRect&) const; + PassRefPtr<ImageData> getPremultipliedImageData(const IntRect&) const; + + void putUnmultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint); + void putPremultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint); String toDataURL(const String& mimeType) const; #if !PLATFORM(CG) TransformationMatrix baseTransform() const { return TransformationMatrix(); } + void transformColorSpace(ImageColorSpace srcColorSpace, ImageColorSpace dstColorSpace); + void platformTransformColorSpace(const Vector<int>&); #else TransformationMatrix baseTransform() const { return TransformationMatrix(1, 0, 0, -1, 0, m_size.height()); } #endif @@ -80,9 +97,14 @@ namespace WebCore { OwnPtr<GraphicsContext> m_context; mutable RefPtr<Image> m_image; +#if !PLATFORM(CG) + Vector<int> m_linearRgbLUT; + Vector<int> m_deviceRgbLUT; +#endif + // This constructor will place its success into the given out-variable // so that create() knows when it should return failure. - ImageBuffer(const IntSize&, bool grayScale, bool& success); + ImageBuffer(const IntSize&, ImageColorSpace colorSpace, bool& success); }; } // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageSourceQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.cpp index 1ffc1eb37..bf7ae21bb 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageSourceQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.cpp @@ -1,8 +1,8 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> + * Copyright (C) 2008, Google Inc. All rights reserved. + * Copyright (C) 2007-2009 Torch Mobile, Inc * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,12 +28,18 @@ #include "config.h" #include "ImageSource.h" + +#if PLATFORM(QT) #include "ImageDecoderQt.h" -#include "SharedBuffer.h" +#else +#include "ImageDecoder.h" +#endif -#include <QBuffer> -#include <QImage> -#include <QImageReader> +#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) +#ifndef IMAGE_DECODER_DOWN_SAMPLING_MAX_NUMBER_OF_PIXELS +#define IMAGE_DECODER_DOWN_SAMPLING_MAX_NUMBER_OF_PIXELS (1024 * 1024) +#endif +#endif namespace WebCore { @@ -47,6 +53,20 @@ ImageSource::~ImageSource() clear(true); } +void ImageSource::clear(bool destroyAll, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived) +{ + if (!destroyAll) { + if (m_decoder) + m_decoder->clearFrameBufferCache(clearBeforeFrame); + return; + } + + delete m_decoder; + m_decoder = 0; + if (data) + setData(data, allDataReceived); +} + bool ImageSource::initialized() const { return m_decoder; @@ -58,58 +78,46 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived) // This method will examine the data and instantiate an instance of the appropriate decoder plugin. // If insufficient bytes are available to determine the image type, no decoder plugin will be // made. - if (!m_decoder) - m_decoder = ImageDecoderQt::create(*data); - - if (!m_decoder) - return; + if (!m_decoder) { + m_decoder = static_cast<NativeImageSourcePtr>(ImageDecoder::create(*data)); +#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) + if (m_decoder) + m_decoder->setMaxNumPixels(IMAGE_DECODER_DOWN_SAMPLING_MAX_NUMBER_OF_PIXELS); +#endif + } - m_decoder->setData(data->buffer(), allDataReceived); + if (m_decoder) + m_decoder->setData(data, allDataReceived); } String ImageSource::filenameExtension() const { - if (!m_decoder) - return String(); - - return m_decoder->filenameExtension(); + return m_decoder ? m_decoder->filenameExtension() : String(); } bool ImageSource::isSizeAvailable() { - if (!m_decoder) - return false; - - return m_decoder->isSizeAvailable(); + return m_decoder && m_decoder->isSizeAvailable(); } IntSize ImageSource::size() const { - if (!m_decoder) - return IntSize(); - - return m_decoder->size(); + return m_decoder ? m_decoder->size() : IntSize(); } -IntSize ImageSource::frameSizeAtIndex(size_t) const +IntSize ImageSource::frameSizeAtIndex(size_t index) const { - return size(); + return m_decoder ? m_decoder->frameSizeAtIndex(index) : IntSize(); } int ImageSource::repetitionCount() { - if (!m_decoder) - return cAnimationNone; - - return m_decoder->repetitionCount(); + return m_decoder ? m_decoder->repetitionCount() : cAnimationNone; } size_t ImageSource::frameCount() const { - if (!m_decoder) - return 0; - - return m_decoder->frameCount(); + return m_decoder ? m_decoder->frameCount() : 0; } NativeImagePtr ImageSource::createFrameAtIndex(size_t index) @@ -117,7 +125,18 @@ NativeImagePtr ImageSource::createFrameAtIndex(size_t index) if (!m_decoder) return 0; - return m_decoder->imageAtIndex(index); + RGBA32Buffer* buffer = m_decoder->frameBufferAtIndex(index); + if (!buffer || buffer->status() == RGBA32Buffer::FrameEmpty) + return 0; + + // Zero-height images can cause problems for some ports. If we have an + // empty image dimension, just bail. + if (size().isEmpty()) + return 0; + + // Return the buffer contents as a native image. For some ports, the data + // is already in a native container, and this just increments its refcount. + return buffer->asNewNativeImage(); } float ImageSource::frameDurationAtIndex(size_t index) @@ -125,46 +144,38 @@ float ImageSource::frameDurationAtIndex(size_t index) if (!m_decoder) return 0; + RGBA32Buffer* buffer = m_decoder->frameBufferAtIndex(index); + if (!buffer || buffer->status() == RGBA32Buffer::FrameEmpty) + return 0; + // Many annoying ads specify a 0 duration to make an image flash as quickly // as possible. We follow WinIE's behavior and use a duration of 100 ms // for any frames that specify a duration of <= 50 ms. See // <http://bugs.webkit.org/show_bug.cgi?id=14413> or Radar 4051389 for // more. - const float duration = m_decoder->duration(index) / 1000.0f; + const float duration = buffer->duration() / 1000.0f; return (duration < 0.051f) ? 0.100f : duration; } bool ImageSource::frameHasAlphaAtIndex(size_t index) { - if (!m_decoder || !m_decoder->supportsAlpha()) - return false; - - const QPixmap* source = m_decoder->imageAtIndex(index); - if (!source) - return false; - - return source->hasAlphaChannel(); + // When a frame has not finished decoding, always mark it as having alpha. + // Ports that check the result of this function to determine their + // compositing op need this in order to not draw the undecoded portion as + // black. + // TODO: Perhaps we should ensure that each individual decoder returns true + // in this case. + return !frameIsCompleteAtIndex(index) + || m_decoder->frameBufferAtIndex(index)->hasAlpha(); } bool ImageSource::frameIsCompleteAtIndex(size_t index) { - return (m_decoder && m_decoder->imageAtIndex(index)); -} - -void ImageSource::clear(bool destroyAll, size_t clearBeforeFrame, SharedBuffer* data, bool allDataReceived) -{ - if (!destroyAll) { - if (m_decoder) - m_decoder->clearFrameBufferCache(clearBeforeFrame); - return; - } + if (!m_decoder) + return false; - delete m_decoder; - m_decoder = 0; - if (data) - setData(data, allDataReceived); + RGBA32Buffer* buffer = m_decoder->frameBufferAtIndex(index); + return buffer && buffer->status() == RGBA32Buffer::FrameComplete; } } - -// vim: ts=4 sw=4 et diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.h b/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.h index acb64de84..3559abe95 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/ImageSource.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2007-2008 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,6 +47,10 @@ struct _cairo_surface; typedef struct _cairo_surface cairo_surface_t; #elif PLATFORM(SKIA) class NativeImageSkia; +#elif PLATFORM(HAIKU) +class BBitmap; +#elif PLATFORM(WINCE) +#include "SharedBitmap.h" #endif namespace WebCore { @@ -54,30 +59,31 @@ class IntSize; class SharedBuffer; class String; -#if PLATFORM(WX) -class ImageDecoder; -typedef ImageDecoder* NativeImageSourcePtr; -typedef const Vector<char>* NativeBytePtr; -#if USE(WXGC) -typedef wxGraphicsBitmap* NativeImagePtr; -#else -typedef wxBitmap* NativeImagePtr; -#endif -#elif PLATFORM(CG) +#if PLATFORM(CG) typedef CGImageSourceRef NativeImageSourcePtr; typedef CGImageRef NativeImagePtr; #elif PLATFORM(QT) class ImageDecoderQt; typedef ImageDecoderQt* NativeImageSourcePtr; typedef QPixmap* NativeImagePtr; -#elif PLATFORM(CAIRO) +#else class ImageDecoder; typedef ImageDecoder* NativeImageSourcePtr; +#if PLATFORM(WX) +#if USE(WXGC) +typedef wxGraphicsBitmap* NativeImagePtr; +#else +typedef wxBitmap* NativeImagePtr; +#endif +#elif PLATFORM(CAIRO) typedef cairo_surface_t* NativeImagePtr; #elif PLATFORM(SKIA) -class ImageDecoder; -typedef ImageDecoder* NativeImageSourcePtr; typedef NativeImageSkia* NativeImagePtr; +#elif PLATFORM(HAIKU) +typedef BBitmap* NativeImagePtr; +#elif PLATFORM(WINCE) +typedef RefPtr<SharedBitmap> NativeImagePtr; +#endif #endif const int cAnimationLoopOnce = -1; @@ -135,9 +141,7 @@ public: bool frameHasAlphaAtIndex(size_t); // Whether or not the frame actually used any alpha. bool frameIsCompleteAtIndex(size_t); // Whether or not the frame is completely decoded. - // FIXME: This is protected only to allow ImageSourceSkia to set ICO decoder - // with a preferred size. See ImageSourceSkia.h for discussion. -protected: +private: NativeImageSourcePtr m_decoder; }; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/IntPoint.h b/src/3rdparty/webkit/WebCore/platform/graphics/IntPoint.h index 21af67b0a..ab5f3ec56 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/IntPoint.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/IntPoint.h @@ -55,6 +55,8 @@ class QPoint; QT_END_NAMESPACE #elif PLATFORM(GTK) typedef struct _GdkPoint GdkPoint; +#elif PLATFORM(HAIKU) +class BPoint; #endif #if PLATFORM(WX) @@ -121,6 +123,9 @@ public: #elif PLATFORM(GTK) IntPoint(const GdkPoint&); operator GdkPoint() const; +#elif PLATFORM(HAIKU) + explicit IntPoint(const BPoint&); + operator BPoint() const; #endif #if PLATFORM(WX) diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/IntRect.h b/src/3rdparty/webkit/WebCore/platform/graphics/IntRect.h index 6c02d213f..97b21bc80 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/IntRect.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/IntRect.h @@ -33,7 +33,7 @@ typedef struct CGRect CGRect; #endif -#if PLATFORM(MAC) +#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES typedef struct CGRect NSRect; #else @@ -49,6 +49,8 @@ class QRect; QT_END_NAMESPACE #elif PLATFORM(GTK) typedef struct _GdkRectangle GdkRectangle; +#elif PLATFORM(HAIKU) +class BRect; #endif #if PLATFORM(WX) @@ -144,6 +146,9 @@ public: #elif PLATFORM(GTK) IntRect(const GdkRectangle&); operator GdkRectangle() const; +#elif PLATFORM(HAIKU) + explicit IntRect(const BRect&); + operator BRect() const; #endif #if PLATFORM(CG) @@ -156,7 +161,8 @@ public: operator SkIRect() const; #endif -#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) +#if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \ + || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) operator NSRect() const; #endif @@ -193,7 +199,8 @@ inline bool operator!=(const IntRect& a, const IntRect& b) IntRect enclosingIntRect(const CGRect&); #endif -#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) +#if (PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)) \ + || (PLATFORM(CHROMIUM) && PLATFORM(DARWIN)) IntRect enclosingIntRect(const NSRect&); #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/IntSize.h b/src/3rdparty/webkit/WebCore/platform/graphics/IntSize.h index dc7a85dce..b242784f1 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/IntSize.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/IntSize.h @@ -47,6 +47,12 @@ typedef struct tagSIZE SIZE; QT_BEGIN_NAMESPACE class QSize; QT_END_NAMESPACE +#elif PLATFORM(HAIKU) +class BSize; +#endif + +#if PLATFORM(WX) +class wxSize; #endif namespace WebCore { @@ -113,6 +119,15 @@ public: operator QSize() const; #endif +#if PLATFORM(HAIKU) + explicit IntSize(const BSize&); + operator BSize() const; +#endif + +#if PLATFORM(WX) + IntSize(const wxSize&); + operator wxSize() const; +#endif private: int m_width, m_height; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.cpp index d4fab5235..3b32b654b 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.cpp @@ -35,9 +35,12 @@ #include "FrameView.h" #include "Frame.h" #include "Document.h" +#include "TimeRanges.h" #if PLATFORM(MAC) #include "MediaPlayerPrivateQTKit.h" +#elif PLATFORM(WINCE) && !PLATFORM(QT) +#include "MediaPlayerPrivateWince.h" #elif PLATFORM(WIN) #include "MediaPlayerPrivateQuickTimeWin.h" #elif PLATFORM(GTK) @@ -59,14 +62,16 @@ public: virtual void load(const String&) { } virtual void cancelLoad() { } + virtual void prepareToPlay() { } virtual void play() { } virtual void pause() { } - virtual bool supportsFullscreen() const { return false; } + virtual PlatformMedia platformMedia() const { return NoPlatformMedia; } virtual IntSize naturalSize() const { return IntSize(0, 0); } virtual bool hasVideo() const { return false; } + virtual bool hasAudio() const { return false; } virtual void setVisible(bool) { } @@ -88,7 +93,7 @@ public: virtual MediaPlayer::ReadyState readyState() const { return MediaPlayer::HaveNothing; } virtual float maxTimeSeekable() const { return 0; } - virtual float maxTimeBuffered() const { return 0; } + virtual PassRefPtr<TimeRanges> buffered() const { return TimeRanges::create(); } virtual int dataRate() const { return 0; } @@ -100,8 +105,10 @@ public: virtual void paint(GraphicsContext*, const IntRect&) { } + virtual bool canLoadPoster() const { return false; } + virtual void setPoster(const String&) { } + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) - virtual void setPoster(const String& /*url*/) { } virtual void deliverNotification(MediaPlayerProxyNotificationType) { } virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) { } #endif @@ -249,18 +256,26 @@ void MediaPlayer::load(const String& url, const ContentType& contentType) m_private.set(createNullMediaPlayer(this)); } -#if ENABLE(PLUGIN_PROXY_FOR_VIDEO) +bool MediaPlayer::canLoadPoster() const +{ + return m_private->canLoadPoster(); +} + void MediaPlayer::setPoster(const String& url) { m_private->setPoster(url); } -#endif void MediaPlayer::cancelLoad() { m_private->cancelLoad(); } +void MediaPlayer::prepareToPlay() +{ + m_private->prepareToPlay(); +} + void MediaPlayer::play() { m_private->play(); @@ -316,11 +331,16 @@ IntSize MediaPlayer::naturalSize() return m_private->naturalSize(); } -bool MediaPlayer::hasVideo() +bool MediaPlayer::hasVideo() const { return m_private->hasVideo(); } +bool MediaPlayer::hasAudio() const +{ + return m_private->hasAudio(); +} + bool MediaPlayer::inMediaDocument() { Frame* frame = m_frameView ? m_frameView->frame() : 0; @@ -329,6 +349,11 @@ bool MediaPlayer::inMediaDocument() return document && document->isMediaDocument(); } +PlatformMedia MediaPlayer::platformMedia() const +{ + return m_private->platformMedia(); +} + MediaPlayer::NetworkState MediaPlayer::networkState() { return m_private->networkState(); @@ -382,9 +407,9 @@ void MediaPlayer::setEndTime(float time) m_private->setEndTime(time); } -float MediaPlayer::maxTimeBuffered() +PassRefPtr<TimeRanges> MediaPlayer::buffered() { - return m_private->maxTimeBuffered(); + return m_private->buffered(); } float MediaPlayer::maxTimeSeekable() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.h b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.h index 7f5f2a04b..4cc6476db 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,8 +38,24 @@ #include <wtf/OwnPtr.h> #include <wtf/Noncopyable.h> +#ifdef __OBJC__ +@class QTMovie; +#else +class QTMovie; +#endif + namespace WebCore { +// Structure that will hold every native +// types supported by the current media player. +// We have to do that has multiple media players +// backend can live at runtime. +typedef struct PlatformMedia { + QTMovie* qtMovie; +} PlatformMedia; + +static const PlatformMedia NoPlatformMedia = { 0 }; + class ContentType; class FrameView; class GraphicsContext; @@ -48,6 +64,7 @@ class IntSize; class MediaPlayer; class MediaPlayerPrivateInterface; class String; +class TimeRanges; #if USE(ACCELERATED_COMPOSITING) class GraphicsLayer; @@ -109,8 +126,11 @@ public: bool supportsFullscreen() const; bool supportsSave() const; + PlatformMedia platformMedia() const; + IntSize naturalSize(); - bool hasVideo(); + bool hasVideo() const; + bool hasAudio() const; void setFrameView(FrameView* frameView) { m_frameView = frameView; } FrameView* frameView() { return m_frameView; } @@ -125,6 +145,7 @@ public: bool visible() const; void setVisible(bool); + void prepareToPlay(); void play(); void pause(); @@ -145,7 +166,7 @@ public: bool preservesPitch() const; void setPreservesPitch(bool); - float maxTimeBuffered(); + PassRefPtr<TimeRanges> buffered(); float maxTimeSeekable(); unsigned bytesLoaded(); @@ -184,8 +205,10 @@ public: MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; } + bool canLoadPoster() const; + void setPoster(const String&); + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) - void setPoster(const String& url); void deliverNotification(MediaPlayerProxyNotificationType notification); void setMediaPlayerProxy(WebMediaPlayerProxy* proxy); #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayerPrivate.h b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayerPrivate.h index 6d1359b35..f5687b311 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayerPrivate.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/MediaPlayerPrivate.h @@ -43,6 +43,9 @@ public: virtual void load(const String& url) = 0; virtual void cancelLoad() = 0; + virtual void prepareToPlay() { } + virtual PlatformMedia platformMedia() const { return NoPlatformMedia; } + virtual void play() = 0; virtual void pause() = 0; @@ -52,6 +55,7 @@ public: virtual IntSize naturalSize() const = 0; virtual bool hasVideo() const = 0; + virtual bool hasAudio() const = 0; virtual void setVisible(bool) = 0; @@ -76,7 +80,7 @@ public: virtual MediaPlayer::ReadyState readyState() const = 0; virtual float maxTimeSeekable() const = 0; - virtual float maxTimeBuffered() const = 0; + virtual PassRefPtr<TimeRanges> buffered() const = 0; virtual int dataRate() const = 0; @@ -92,8 +96,10 @@ public: virtual void setAutobuffer(bool) { }; + virtual bool canLoadPoster() const { return false; } + virtual void setPoster(const String&) { } + #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) - virtual void setPoster(const String& url) = 0; virtual void deliverNotification(MediaPlayerProxyNotificationType) = 0; virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) = 0; #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/Path.h b/src/3rdparty/webkit/WebCore/platform/graphics/Path.h index 04717246d..26927a1f0 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/Path.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/Path.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. * 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2007-2008 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,6 +49,13 @@ typedef WebCore::CairoPath PlatformPath; #elif PLATFORM(SKIA) class SkPath; typedef SkPath PlatformPath; +#elif PLATFORM(HAIKU) +class BRegion; +typedef BRegion PlatformPath; +#elif PLATFORM(WINCE) +namespace WebCore { + class PlatformPath; +} #else typedef void PlatformPath; #endif diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/Pattern.h b/src/3rdparty/webkit/WebCore/platform/graphics/Pattern.h index d4aa3b9ae..aa0a35702 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/Pattern.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/Pattern.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved. * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * Copyright (C) 2007-2008 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -52,6 +53,11 @@ typedef wxGraphicsBrush* PlatformPatternPtr; class wxBrush; typedef wxBrush* PlatformPatternPtr; #endif // USE(WXGC) +#elif PLATFORM(HAIKU) +#include <interface/GraphicsDefs.h> +typedef pattern* PlatformPatternPtr; +#elif PLATFORM(WINCE) +typedef void* PlatformPatternPtr; #endif namespace WebCore { diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.cpp index c879228a7..2ec8abb8e 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.cpp @@ -48,7 +48,9 @@ using namespace std; namespace WebCore { SimpleFontData::SimpleFontData(const FontPlatformData& f, bool customFont, bool loading, SVGFontData* svgFontData) - : m_unitsPerEm(defaultUnitsPerEm) + : m_maxCharWidth(-1) + , m_avgCharWidth(-1) + , m_unitsPerEm(defaultUnitsPerEm) , m_platformData(f) , m_treatAsFixedPitch(false) #if ENABLE(SVG_FONTS) diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.h b/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.h index cb472b073..387a5c77e 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/SimpleFontData.h @@ -2,6 +2,7 @@ * This file is part of the internal font implementation. * * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007-2008 Torch Mobile, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,13 +28,14 @@ #include "FontPlatformData.h" #include "GlyphPageTreeNode.h" #include "GlyphWidthMap.h" +#include "TextRenderingMode.h" #include <wtf/OwnPtr.h> #if USE(ATSUI) typedef struct OpaqueATSUStyle* ATSUStyle; #endif -#if PLATFORM(WIN) +#if PLATFORM(WIN) && !PLATFORM(WINCE) #include <usp10.h> #endif @@ -45,6 +47,10 @@ typedef struct OpaqueATSUStyle* ATSUStyle; #include <QFont> #endif +#if PLATFORM(HAIKU) +#include <Font.h> +#endif + namespace WebCore { class FontDescription; @@ -115,7 +121,7 @@ public: #if USE(CORE_TEXT) CTFontRef getCTFont() const; - CFDictionaryRef getCFStringAttributes() const; + CFDictionaryRef getCFStringAttributes(TextRenderingMode) const; #endif #if USE(ATSUI) @@ -134,17 +140,14 @@ public: #if PLATFORM(WIN) bool isSystemFont() const { return m_isSystemFont; } +#if !PLATFORM(WINCE) // disable unused members to save space SCRIPT_FONTPROPERTIES* scriptFontProperties() const; SCRIPT_CACHE* scriptCache() const { return &m_scriptCache; } - +#endif static void setShouldApplyMacAscentHack(bool); static bool shouldApplyMacAscentHack(); #endif -#if PLATFORM(CAIRO) - void setFont(cairo_t*) const; -#endif - #if PLATFORM(WX) wxFont* getWxFont() const { return m_platformData.font(); } #endif @@ -159,7 +162,7 @@ private: void commonInit(); -#if PLATFORM(WIN) +#if PLATFORM(WIN) && !PLATFORM(WINCE) void initGDIFont(); void platformCommonDestroy(); float widthForGDIGlyph(Glyph glyph) const; @@ -224,9 +227,11 @@ private: #if PLATFORM(WIN) bool m_isSystemFont; +#if !PLATFORM(WINCE) // disable unused members to save space mutable SCRIPT_CACHE m_scriptCache; mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties; #endif +#endif }; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/TextRenderingMode.h b/src/3rdparty/webkit/WebCore/platform/graphics/TextRenderingMode.h new file mode 100644 index 000000000..4f817a4a4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/TextRenderingMode.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TextRenderingMode_h +#define TextRenderingMode_h + +namespace WebCore { + + enum TextRenderingMode { AutoTextRendering, OptimizeSpeed, OptimizeLegibility, GeometricPrecision }; + +} // namespace WebCore + +#endif // TextRenderingMode_h diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.cpp index 86b702f4e..2364cc473 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.cpp @@ -2,6 +2,7 @@ Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2004, 2005 Rob Buis <buis@kde.org> 2005 Eric Seidel <eric@webkit.org> + 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,7 +25,13 @@ #if ENABLE(FILTERS) #include "FEBlend.h" +#include "CanvasPixelArray.h" #include "Filter.h" +#include "FloatPoint.h" +#include "GraphicsContext.h" +#include "ImageData.h" + +typedef unsigned char (*BlendType)(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB); namespace WebCore { @@ -61,8 +68,77 @@ void FEBlend::setBlendMode(BlendModeType mode) m_mode = mode; } -void FEBlend::apply(Filter*) +static unsigned char unknown(unsigned char, unsigned char, unsigned char, unsigned char) +{ + return 0; +} + +static unsigned char normal(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char) +{ + return (((255 - alphaA) * colorB + colorA * 255) / 255); +} + +static unsigned char multiply(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB) +{ + return (((255 - alphaA) * colorB + (255 - alphaB + colorB) * colorA) / 255); +} + +static unsigned char screen(unsigned char colorA, unsigned char colorB, unsigned char, unsigned char) +{ + return (((colorB + colorA) * 255 - colorA * colorB) / 255); +} + +static unsigned char darken(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB) +{ + return ((std::min((255 - alphaA) * colorB + colorA * 255, (255 - alphaB) * colorA + colorB * 255)) / 255); +} + +static unsigned char lighten(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB) { + return ((std::max((255 - alphaA) * colorB + colorA * 255, (255 - alphaB) * colorA + colorB * 255)) / 255); +} + +void FEBlend::apply(Filter* filter) +{ + m_in->apply(filter); + m_in2->apply(filter); + if (!m_in->resultImage() || !m_in2->resultImage()) + return; + + if (m_mode == FEBLEND_MODE_UNKNOWN) + return; + + if (!getEffectContext()) + return; + + IntRect effectADrawingRect = calculateDrawingIntRect(m_in->subRegion()); + RefPtr<CanvasPixelArray> srcPixelArrayA(m_in->resultImage()->getPremultipliedImageData(effectADrawingRect)->data()); + + IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->subRegion()); + RefPtr<CanvasPixelArray> srcPixelArrayB(m_in2->resultImage()->getPremultipliedImageData(effectBDrawingRect)->data()); + + IntRect imageRect(IntPoint(), resultImage()->size()); + RefPtr<ImageData> imageData = ImageData::create(imageRect.width(), imageRect.height()); + + // Keep synchronized with BlendModeType + static const BlendType callEffect[] = {unknown, normal, multiply, screen, darken, lighten}; + + ASSERT(srcPixelArrayA->length() == srcPixelArrayB->length()); + for (unsigned pixelOffset = 0; pixelOffset < srcPixelArrayA->length(); pixelOffset += 4) { + unsigned char alphaA = srcPixelArrayA->get(pixelOffset + 3); + unsigned char alphaB = srcPixelArrayB->get(pixelOffset + 3); + for (unsigned channel = 0; channel < 3; ++channel) { + unsigned char colorA = srcPixelArrayA->get(pixelOffset + channel); + unsigned char colorB = srcPixelArrayB->get(pixelOffset + channel); + + unsigned char result = (*callEffect[m_mode])(colorA, colorB, alphaA, alphaB); + imageData->data()->set(pixelOffset + channel, result); + } + unsigned char alphaR = 255 - ((255 - alphaA) * (255 - alphaB)) / 255; + imageData->data()->set(pixelOffset + 3, alphaR); + } + + resultImage()->putPremultipliedImageData(imageData.get(), imageRect, IntPoint()); } void FEBlend::dump() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.h b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.h index b09cd7227..31c625f31 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEBlend.h @@ -41,7 +41,7 @@ namespace WebCore { class FEBlend : public FilterEffect { public: static PassRefPtr<FEBlend> create(FilterEffect*, FilterEffect*, BlendModeType); - + FilterEffect* in2() const; void setIn2(FilterEffect*); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEColorMatrix.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEColorMatrix.cpp index 8704e645f..a2ed9bd08 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEColorMatrix.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEColorMatrix.cpp @@ -2,6 +2,7 @@ Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2004, 2005 Rob Buis <buis@kde.org> 2005 Eric Seidel <eric@webkit.org> + 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,7 +25,12 @@ #if ENABLE(FILTERS) #include "FEColorMatrix.h" +#include "CanvasPixelArray.h" #include "Filter.h" +#include "GraphicsContext.h" +#include "ImageData.h" +#include <math.h> +#include <wtf/MathExtras.h> namespace WebCore { @@ -61,8 +67,127 @@ void FEColorMatrix::setValues(const Vector<float> &values) m_values = values; } -void FEColorMatrix::apply(Filter*) +inline void matrix(double& red, double& green, double& blue, double& alpha, const Vector<float>& values) { + double r = values[0] * red + values[1] * green + values[2] * blue + values[3] * alpha; + double g = values[5] * red + values[6] * green + values[7] * blue + values[8] * alpha; + double b = values[10] * red + values[11] * green + values[12] * blue + values[13] * alpha; + double a = values[15] * red + values[16] * green + values[17] * blue + values[18] * alpha; + + red = r; + green = g; + blue = b; + alpha = a; +} + +inline void saturate(double& red, double& green, double& blue, const float& s) +{ + double r = (0.213 + 0.787 * s) * red + (0.715 - 0.715 * s) * green + (0.072 - 0.072 * s) * blue; + double g = (0.213 - 0.213 * s) * red + (0.715 + 0.285 * s) * green + (0.072 - 0.072 * s) * blue; + double b = (0.213 - 0.213 * s) * red + (0.715 - 0.715 * s) * green + (0.072 + 0.928 * s) * blue; + + red = r; + green = g; + blue = b; +} + +inline void huerotate(double& red, double& green, double& blue, const float& hue) +{ + double cosHue = cos(hue * piDouble / 180); + double sinHue = sin(hue * piDouble / 180); + double r = red * (0.213 + cosHue * 0.787 - sinHue * 0.213) + + green * (0.715 - cosHue * 0.715 - sinHue * 0.715) + + blue * (0.072 - cosHue * 0.072 + sinHue * 0.928); + double g = red * (0.213 - cosHue * 0.213 + sinHue * 0.143) + + green * (0.715 + cosHue * 0.285 + sinHue * 0.140) + + blue * (0.072 - cosHue * 0.072 - sinHue * 0.283); + double b = red * (0.213 - cosHue * 0.213 - sinHue * 0.787) + + green * (0.715 - cosHue * 0.715 + sinHue * 0.715) + + blue * (0.072 + cosHue * 0.928 + sinHue * 0.072); + + red = r; + green = g; + blue = b; +} + +inline void luminance(double& red, double& green, double& blue, double& alpha) +{ + alpha = 0.2125 * red + 0.7154 * green + 0.0721 * blue; + red = 0.; + green = 0.; + blue = 0.; +} + +template<ColorMatrixType filterType> +void effectType(const PassRefPtr<CanvasPixelArray>& srcPixelArray, PassRefPtr<ImageData>& imageData, const Vector<float>& values) +{ + for (unsigned pixelOffset = 0; pixelOffset < srcPixelArray->length(); pixelOffset++) { + unsigned pixelByteOffset = pixelOffset * 4; + + unsigned char r = 0, g = 0, b = 0, a = 0; + srcPixelArray->get(pixelByteOffset, r); + srcPixelArray->get(pixelByteOffset + 1, g); + srcPixelArray->get(pixelByteOffset + 2, b); + srcPixelArray->get(pixelByteOffset + 3, a); + + double red = r, green = g, blue = b, alpha = a; + + switch (filterType) { + case FECOLORMATRIX_TYPE_MATRIX: + matrix(red, green, blue, alpha, values); + break; + case FECOLORMATRIX_TYPE_SATURATE: + saturate(red, green, blue, values[0]); + break; + case FECOLORMATRIX_TYPE_HUEROTATE: + huerotate(red, green, blue, values[0]); + break; + case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: + luminance(red, green, blue, alpha); + break; + } + + imageData->data()->set(pixelByteOffset, red); + imageData->data()->set(pixelByteOffset + 1, green); + imageData->data()->set(pixelByteOffset + 2, blue); + imageData->data()->set(pixelByteOffset + 3, alpha); + } +} + +void FEColorMatrix::apply(Filter* filter) +{ + m_in->apply(filter); + if (!m_in->resultImage()) + return; + + GraphicsContext* filterContext = getEffectContext(); + if (!filterContext) + return; + + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion())); + + IntRect imageRect(IntPoint(), resultImage()->size()); + PassRefPtr<ImageData> imageData(resultImage()->getUnmultipliedImageData(imageRect)); + PassRefPtr<CanvasPixelArray> srcPixelArray(imageData->data()); + + switch (m_type) { + case FECOLORMATRIX_TYPE_UNKNOWN: + break; + case FECOLORMATRIX_TYPE_MATRIX: + effectType<FECOLORMATRIX_TYPE_MATRIX>(srcPixelArray, imageData, m_values); + break; + case FECOLORMATRIX_TYPE_SATURATE: + effectType<FECOLORMATRIX_TYPE_SATURATE>(srcPixelArray, imageData, m_values); + break; + case FECOLORMATRIX_TYPE_HUEROTATE: + effectType<FECOLORMATRIX_TYPE_HUEROTATE>(srcPixelArray, imageData, m_values); + break; + case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: + effectType<FECOLORMATRIX_TYPE_LUMINANCETOALPHA>(srcPixelArray, imageData, m_values); + break; + } + + resultImage()->putUnmultipliedImageData(imageData.get(), imageRect, IntPoint()); } void FEColorMatrix::dump() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComponentTransfer.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComponentTransfer.cpp index 54ac1232e..0d76d8d6a 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComponentTransfer.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComponentTransfer.cpp @@ -2,6 +2,7 @@ Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2004, 2005 Rob Buis <buis@kde.org> 2005 Eric Seidel <eric@webkit.org> + 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,10 +25,16 @@ #if ENABLE(FILTERS) #include "FEComponentTransfer.h" +#include "CanvasPixelArray.h" #include "Filter.h" +#include "GraphicsContext.h" +#include "ImageData.h" +#include <math.h> namespace WebCore { +typedef void (*TransferType)(unsigned char*, const ComponentTransferFunction&); + FEComponentTransfer::FEComponentTransfer(FilterEffect* in, const ComponentTransferFunction& redFunc, const ComponentTransferFunction& greenFunc, const ComponentTransferFunction& blueFunc, const ComponentTransferFunction& alphaFunc) : FilterEffect() @@ -85,8 +92,91 @@ void FEComponentTransfer::setAlphaFunction(const ComponentTransferFunction& func m_alphaFunc = func; } -void FEComponentTransfer::apply(Filter*) +static void identity(unsigned char*, const ComponentTransferFunction&) +{ +} + +static void table(unsigned char* values, const ComponentTransferFunction& transferFunction) +{ + const Vector<float>& tableValues = transferFunction.tableValues; + unsigned n = tableValues.size(); + if (n < 1) + return; + for (unsigned i = 0; i < 256; ++i) { + double c = i / 255.0; + unsigned k = static_cast<unsigned>(c * (n - 1)); + double v1 = tableValues[k]; + double v2 = tableValues[std::min((k + 1), (n - 1))]; + double val = 255.0 * (v1 + (c * (n - 1) - k) * (v2 - v1)); + val = std::max(0.0, std::min(255.0, val)); + values[i] = static_cast<unsigned char>(val); + } +} + +static void discrete(unsigned char* values, const ComponentTransferFunction& transferFunction) +{ + const Vector<float>& tableValues = transferFunction.tableValues; + unsigned n = tableValues.size(); + if (n < 1) + return; + for (unsigned i = 0; i < 256; ++i) { + unsigned k = static_cast<unsigned>((i * n) / 255.0); + k = std::min(k, n - 1); + double val = 255 * tableValues[k]; + val = std::max(0.0, std::min(255.0, val)); + values[i] = static_cast<unsigned char>(val); + } +} + +static void linear(unsigned char* values, const ComponentTransferFunction& transferFunction) +{ + for (unsigned i = 0; i < 256; ++i) { + double val = transferFunction.slope * i + 255 * transferFunction.intercept; + val = std::max(0.0, std::min(255.0, val)); + values[i] = static_cast<unsigned char>(val); + } +} + +static void gamma(unsigned char* values, const ComponentTransferFunction& transferFunction) +{ + for (unsigned i = 0; i < 256; ++i) { + double val = 255.0 * (transferFunction.amplitude * pow((i / 255.0), transferFunction.exponent) + transferFunction.offset); + val = std::max(0.0, std::min(255.0, val)); + values[i] = static_cast<unsigned char>(val); + } +} + +void FEComponentTransfer::apply(Filter* filter) { + m_in->apply(filter); + if (!m_in->resultImage()) + return; + + if (!getEffectContext()) + return; + + unsigned char rValues[256], gValues[256], bValues[256], aValues[256]; + for (unsigned i = 0; i < 256; ++i) + rValues[i] = gValues[i] = bValues[i] = aValues[i] = i; + unsigned char* tables[] = { rValues, gValues, bValues, aValues }; + ComponentTransferFunction transferFunction[] = {m_redFunc, m_greenFunc, m_blueFunc, m_alphaFunc}; + TransferType callEffect[] = {identity, identity, table, discrete, linear, gamma}; + + for (unsigned channel = 0; channel < 4; channel++) + (*callEffect[transferFunction[channel].type])(tables[channel], transferFunction[channel]); + + IntRect drawingRect = calculateDrawingIntRect(m_in->subRegion()); + RefPtr<ImageData> imageData(m_in->resultImage()->getUnmultipliedImageData(drawingRect)); + CanvasPixelArray* srcPixelArray(imageData->data()); + + for (unsigned pixelOffset = 0; pixelOffset < srcPixelArray->length(); pixelOffset += 4) { + for (unsigned channel = 0; channel < 4; ++channel) { + unsigned char c = srcPixelArray->get(pixelOffset + channel); + imageData->data()->set(pixelOffset + channel, tables[channel][c]); + } + } + + resultImage()->putUnmultipliedImageData(imageData.get(), IntRect(IntPoint(), resultImage()->size()), IntPoint()); } void FEComponentTransfer::dump() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComposite.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComposite.cpp index 070635877..1b4116530 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComposite.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEComposite.cpp @@ -2,6 +2,7 @@ Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2004, 2005 Rob Buis <buis@kde.org> 2005 Eric Seidel <eric@webkit.org> + 2009 Dirk Schulze <krit@webkit.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -24,7 +25,10 @@ #if ENABLE(FILTERS) #include "FEComposite.h" +#include "CanvasPixelArray.h" #include "Filter.h" +#include "GraphicsContext.h" +#include "ImageData.h" namespace WebCore { @@ -97,8 +101,74 @@ void FEComposite::setK4(float k4) m_k4 = k4; } -void FEComposite::apply(Filter*) +inline void arithmetic(const RefPtr<CanvasPixelArray>& srcPixelArrayA, CanvasPixelArray*& srcPixelArrayB, + float k1, float k2, float k3, float k4) { + float scaledK1 = k1 / 255.f; + float scaledK4 = k4 * 255.f; + for (unsigned pixelOffset = 0; pixelOffset < srcPixelArrayA->length(); pixelOffset += 4) { + for (unsigned channel = 0; channel < 4; ++channel) { + unsigned char i1 = srcPixelArrayA->get(pixelOffset + channel); + unsigned char i2 = srcPixelArrayB->get(pixelOffset + channel); + + unsigned char result = scaledK1 * i1 * i2 + k2 * i1 + k3 * i2 + scaledK4; + if (channel == 3 && i1 == 0 && i2 == 0) + result = 0; + srcPixelArrayB->set(pixelOffset + channel, result); + } + } +} + +void FEComposite::apply(Filter* filter) +{ + m_in->apply(filter); + m_in2->apply(filter); + if (!m_in->resultImage() || !m_in2->resultImage()) + return; + + GraphicsContext* filterContext = getEffectContext(); + if (!filterContext) + return; + + FloatRect srcRect = FloatRect(0.f, 0.f, -1.f, -1.f); + switch (m_type) { + case FECOMPOSITE_OPERATOR_OVER: + filterContext->drawImage(m_in2->resultImage()->image(), calculateDrawingRect(m_in2->subRegion())); + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion())); + break; + case FECOMPOSITE_OPERATOR_IN: + filterContext->save(); + filterContext->clipToImageBuffer(calculateDrawingRect(m_in2->subRegion()), m_in2->resultImage()); + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion())); + filterContext->restore(); + break; + case FECOMPOSITE_OPERATOR_OUT: + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion())); + filterContext->drawImage(m_in2->resultImage()->image(), calculateDrawingRect(m_in2->subRegion()), srcRect, CompositeDestinationOut); + break; + case FECOMPOSITE_OPERATOR_ATOP: + filterContext->drawImage(m_in2->resultImage()->image(), calculateDrawingRect(m_in2->subRegion())); + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion()), srcRect, CompositeSourceAtop); + break; + case FECOMPOSITE_OPERATOR_XOR: + filterContext->drawImage(m_in2->resultImage()->image(), calculateDrawingRect(m_in2->subRegion())); + filterContext->drawImage(m_in->resultImage()->image(), calculateDrawingRect(m_in->subRegion()), srcRect, CompositeXOR); + break; + case FECOMPOSITE_OPERATOR_ARITHMETIC: { + IntRect effectADrawingRect = calculateDrawingIntRect(m_in->subRegion()); + RefPtr<CanvasPixelArray> srcPixelArrayA(m_in->resultImage()->getPremultipliedImageData(effectADrawingRect)->data()); + + IntRect effectBDrawingRect = calculateDrawingIntRect(m_in2->subRegion()); + RefPtr<ImageData> imageData(m_in2->resultImage()->getPremultipliedImageData(effectBDrawingRect)); + CanvasPixelArray* srcPixelArrayB(imageData->data()); + + arithmetic(srcPixelArrayA, srcPixelArrayB, m_k1, m_k2, m_k3, m_k4); + resultImage()->putPremultipliedImageData(imageData.get(), IntRect(IntPoint(), resultImage()->size()), IntPoint()); + } + break; + default: + break; + } } void FEComposite::dump() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.cpp new file mode 100644 index 000000000..f480f10fc --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.cpp @@ -0,0 +1,140 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + 2009 Dirk Schulze <krit@webkit.org> + + 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 + aint 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. +*/ + +#include "config.h" + +#if ENABLE(FILTERS) +#include "FEGaussianBlur.h" + +#include "CanvasPixelArray.h" +#include "Filter.h" +#include "GraphicsContext.h" +#include "ImageData.h" +#include <math.h> +#include <wtf/MathExtras.h> + +namespace WebCore { + +FEGaussianBlur::FEGaussianBlur(FilterEffect* in, const float& x, const float& y) + : FilterEffect() + , m_in(in) + , m_x(x) + , m_y(y) +{ +} + +PassRefPtr<FEGaussianBlur> FEGaussianBlur::create(FilterEffect* in, const float& x, const float& y) +{ + return adoptRef(new FEGaussianBlur(in, x, y)); +} + +float FEGaussianBlur::stdDeviationX() const +{ + return m_x; +} + +void FEGaussianBlur::setStdDeviationX(float x) +{ + m_x = x; +} + +float FEGaussianBlur::stdDeviationY() const +{ + return m_y; +} + +void FEGaussianBlur::setStdDeviationY(float y) +{ + m_y = y; +} + +static void boxBlur(CanvasPixelArray*& srcPixelArray, CanvasPixelArray*& dstPixelArray, + unsigned dx, int stride, int strideLine, int effectWidth, int effectHeight, bool alphaImage) +{ + int dxLeft = dx / 2; + int dxRight = dx - dxLeft; + + for (int y = 0; y < effectHeight; ++y) { + int line = y * strideLine; + for (int channel = 3; channel >= 0; --channel) { + int sum = 0; + // Fill the kernel + int maxKernelSize = std::min(dxRight, effectWidth); + for (int i = 0; i < maxKernelSize; ++i) + sum += srcPixelArray->get(line + i * stride + channel); + + // Blurring + for (int x = 0; x < effectWidth; ++x) { + int pixelByteOffset = line + x * stride + channel; + dstPixelArray->set(pixelByteOffset, static_cast<unsigned char>(sum / dx)); + if (x >= dxLeft) + sum -= srcPixelArray->get(pixelByteOffset - dxLeft * stride); + if (x + dxRight < effectWidth) + sum += srcPixelArray->get(pixelByteOffset + dxRight * stride); + } + if (alphaImage) // Source image is black, it just has different alpha values + break; + } + } +} + +void FEGaussianBlur::apply(Filter* filter) +{ + m_in->apply(filter); + if (!m_in->resultImage()) + return; + + if (!getEffectContext()) + return; + + setIsAlphaImage(m_in->isAlphaImage()); + + if (m_x == 0 || m_y == 0) + return; + + unsigned sdx = static_cast<unsigned>(floor(m_x * 3 * sqrt(2 * piDouble) / 4.f + 0.5f)); + unsigned sdy = static_cast<unsigned>(floor(m_y * 3 * sqrt(2 * piDouble) / 4.f + 0.5f)); + + IntRect effectDrawingRect = calculateDrawingIntRect(m_in->subRegion()); + RefPtr<ImageData> srcImageData(m_in->resultImage()->getPremultipliedImageData(effectDrawingRect)); + CanvasPixelArray* srcPixelArray(srcImageData->data()); + + IntRect imageRect(IntPoint(), resultImage()->size()); + RefPtr<ImageData> tmpImageData = ImageData::create(imageRect.width(), imageRect.height()); + CanvasPixelArray* tmpPixelArray(tmpImageData->data()); + + int stride = 4 * imageRect.width(); + for (int i = 0; i < 3; ++i) { + boxBlur(srcPixelArray, tmpPixelArray, sdx, 4, stride, imageRect.width(), imageRect.height(), isAlphaImage()); + boxBlur(tmpPixelArray, srcPixelArray, sdy, stride, 4, imageRect.height(), imageRect.width(), isAlphaImage()); + } + + resultImage()->putPremultipliedImageData(srcImageData.get(), imageRect, IntPoint()); +} + +void FEGaussianBlur::dump() +{ +} + +} // namespace WebCore + +#endif // ENABLE(FILTERS) diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.h b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.h new file mode 100644 index 000000000..ecdb9e3b3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FEGaussianBlur.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + 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 + aint 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 FEGaussianBlur_h +#define FEGaussianBlur_h + +#if ENABLE(FILTERS) +#include "FilterEffect.h" +#include "Filter.h" + +namespace WebCore { + + class FEGaussianBlur : public FilterEffect { + public: + static PassRefPtr<FEGaussianBlur> create(FilterEffect*, const float&, const float&); + + float stdDeviationX() const; + void setStdDeviationX(float); + + float stdDeviationY() const; + void setStdDeviationY(float); + + virtual FloatRect uniteChildEffectSubregions(Filter* filter) { return calculateUnionOfChildEffectSubregions(filter, m_in.get()); } + void apply(Filter*); + void dump(); + + private: + FEGaussianBlur(FilterEffect*, const float&, const float&); + + RefPtr<FilterEffect> m_in; + float m_x; + float m_y; + }; + +} // namespace WebCore + +#endif // ENABLE(FILTERS) + +#endif // FEGaussianBlur_h diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.cpp index 43ebf33b3..68900b51b 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.cpp @@ -25,14 +25,11 @@ namespace WebCore { FilterEffect::FilterEffect() - : m_xBBoxMode(false) - , m_yBBoxMode(false) - , m_widthBBoxMode(false) - , m_heightBBoxMode(false) - , m_hasX(false) + : m_hasX(false) , m_hasY(false) , m_hasWidth(false) , m_hasHeight(false) + , m_alphaImage(false) { } @@ -59,6 +56,13 @@ FloatRect FilterEffect::calculateEffectRect(Filter* filter) return subRegion(); } +IntRect FilterEffect::calculateDrawingIntRect(const FloatRect& effectRect) +{ + IntPoint location = roundedIntPoint(FloatPoint(subRegion().x() - effectRect.x(), + subRegion().y() - effectRect.y())); + return IntRect(location, resultImage()->size()); +} + FloatRect FilterEffect::calculateDrawingRect(const FloatRect& srcRect) { FloatPoint startPoint = FloatPoint(srcRect.x() - subRegion().x(), srcRect.y() - subRegion().y()); @@ -69,7 +73,7 @@ FloatRect FilterEffect::calculateDrawingRect(const FloatRect& srcRect) GraphicsContext* FilterEffect::getEffectContext() { IntRect bufferRect = enclosingIntRect(subRegion()); - m_effectBuffer = ImageBuffer::create(bufferRect.size(), false); + m_effectBuffer = ImageBuffer::create(bufferRect.size(), LinearRGB); return m_effectBuffer->context(); } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.h b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.h index 8dc623393..b30e513b6 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/FilterEffect.h @@ -38,18 +38,6 @@ namespace WebCore { public: virtual ~FilterEffect(); - bool xBoundingBoxMode() const { return m_xBBoxMode; } - void setXBoundingBoxMode(bool bboxMode) { m_xBBoxMode = bboxMode; } - - bool yBoundingBoxMode() const { return m_yBBoxMode; } - void setYBoundingBoxMode(bool bboxMode) { m_yBBoxMode = bboxMode; } - - bool widthBoundingBoxMode() const { return m_widthBBoxMode; } - void setWidthBoundingBoxMode(bool bboxMode) { m_widthBBoxMode = bboxMode; } - - bool heightBoundingBoxMode() const { return m_heightBBoxMode; } - void setHeightBoundingBoxMode(bool bboxMode) { m_heightBBoxMode = bboxMode; } - void setUnionOfChildEffectSubregions(const FloatRect& uniteRect) { m_unionOfChildEffectSubregions = uniteRect; } FloatRect unionOfChildEffectSubregions() const { return m_unionOfChildEffectSubregions; } @@ -77,6 +65,11 @@ namespace WebCore { GraphicsContext* getEffectContext(); FloatRect calculateDrawingRect(const FloatRect&); + IntRect calculateDrawingIntRect(const FloatRect&); + + // black image with different alpha values + bool isAlphaImage() { return m_alphaImage; } + void setIsAlphaImage(bool alphaImage) { m_alphaImage = alphaImage; } virtual FloatRect uniteChildEffectSubregions(Filter* filter) { return filter->filterRegion(); } virtual FloatRect calculateEffectRect(Filter*); @@ -101,6 +94,8 @@ namespace WebCore { bool m_hasWidth : 1; bool m_hasHeight : 1; + bool m_alphaImage; + FloatRect m_subRegion; FloatRect m_unionOfChildEffectSubregions; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.cpp index 646a57b51..1b6309b60 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.cpp @@ -22,6 +22,7 @@ #if ENABLE(FILTERS) #include "SourceAlpha.h" +#include "Color.h" #include "GraphicsContext.h" #include "PlatformString.h" #include "Filter.h" @@ -41,8 +42,30 @@ const AtomicString& SourceAlpha::effectName() return s_effectName; } -void SourceAlpha::apply(Filter*) +FloatRect SourceAlpha::calculateEffectRect(Filter* filter) { + FloatRect clippedSourceRect = filter->sourceImageRect(); + if (filter->sourceImageRect().x() < filter->filterRegion().x()) + clippedSourceRect.setX(filter->filterRegion().x()); + if (filter->sourceImageRect().y() < filter->filterRegion().y()) + clippedSourceRect.setY(filter->filterRegion().y()); + setSubRegion(clippedSourceRect); + return filter->filterRegion(); +} + +void SourceAlpha::apply(Filter* filter) +{ + GraphicsContext* filterContext = getEffectContext(); + if (!filterContext) + return; + + setIsAlphaImage(true); + + FloatRect imageRect(FloatPoint(), filter->sourceImage()->image()->size()); + filterContext->save(); + filterContext->clipToImageBuffer(imageRect, filter->sourceImage()); + filterContext->fillRect(imageRect, Color::black); + filterContext->restore(); } void SourceAlpha::dump() diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.h b/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.h index 5341562ff..172d05a17 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/filters/SourceAlpha.h @@ -35,7 +35,7 @@ namespace WebCore { static const AtomicString& effectName(); virtual bool isSourceInput() { return true; } - virtual FloatRect calculateEffectRect(Filter* filter) { return filter->sourceImageRect(); } + virtual FloatRect calculateEffectRect(Filter*); void apply(Filter*); void dump(); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp index 895887f61..b2e3d922e 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -339,7 +340,10 @@ bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayD return true; } -HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) +// code shared by renameFont and renameAndActivateFont +// adds fontName to the font table in fontData, and writes the new font table to rewrittenFontTable +// returns the size of the name table (which is used by renameAndActivateFont), or 0 on early abort +static size_t renameFontInternal(SharedBuffer* fontData, const String& fontName, Vector<char> &rewrittenFontData) { size_t originalDataSize = fontData->size(); const sfntHeader* sfnt = reinterpret_cast<const sfntHeader*>(fontData->data()); @@ -357,7 +361,7 @@ HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) // Rounded up to a multiple of 4 to simplify the checksum calculation. size_t nameTableSize = ((offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord) + fontName.length() * sizeof(UChar)) & ~3) + 4; - Vector<char> rewrittenFontData(fontData->size() + nameTableSize); + rewrittenFontData.resize(fontData->size() + nameTableSize); char* data = rewrittenFontData.data(); memcpy(data, fontData->data(), originalDataSize); @@ -394,8 +398,42 @@ HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) for (unsigned i = 0; i * sizeof(BigEndianULong) < nameTableSize; ++i) rewrittenSfnt->tables[t].checkSum = rewrittenSfnt->tables[t].checkSum + reinterpret_cast<BigEndianULong*>(name)[i]; + return nameTableSize; +} + +#if PLATFORM(WINCE) +// AddFontMemResourceEx does not exist on WinCE, so we must handle the font data manually +// This function just renames the font and overwrites the old font data with the new +bool renameFont(SharedBuffer* fontData, const String& fontName) +{ + // abort if the data is too small to be a font header with a "tables" entry + if (fontData->size() < offsetof(sfntHeader, tables)) + return false; + + // abort if the data is too small to hold all the tables specified in the header + const sfntHeader* header = reinterpret_cast<const sfntHeader*>(fontData->data()); + if (fontData->size() < offsetof(sfntHeader, tables) + header->numTables * sizeof(TableDirectoryEntry)) + return false; + + Vector<char> rewrittenFontData; + if (!renameFontInternal(fontData, fontName, rewrittenFontData)) + return false; + + fontData->clear(); + fontData->append(rewrittenFontData.data(), rewrittenFontData.size()); + return true; +} +#else +// Rename the font and install the new font data into the system +HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) +{ + Vector<char> rewrittenFontData; + size_t nameTableSize = renameFontInternal(fontData, fontName, rewrittenFontData); + if (!nameTableSize) + return 0; + DWORD numFonts = 0; - HANDLE fontHandle = AddFontMemResourceEx(data, originalDataSize + nameTableSize, 0, &numFonts); + HANDLE fontHandle = AddFontMemResourceEx(rewrittenFontData.data(), fontData->size() + nameTableSize, 0, &numFonts); if (fontHandle && numFonts != 1) { RemoveFontMemResourceEx(fontHandle); @@ -404,5 +442,6 @@ HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) return fontHandle; } +#endif } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.h b/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.h index 13dad6f48..4c753142c 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/opentype/OpenTypeUtilities.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,6 +36,10 @@ struct BigEndianUShort; struct EOTPrefix; class SharedBuffer; +#if PLATFORM(WINCE) +typedef unsigned __int8 UInt8; +#endif + struct EOTHeader { EOTHeader(); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ColorQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ColorQt.cpp index 5d167409b..151766ac3 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ColorQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ColorQt.cpp @@ -40,7 +40,10 @@ Color::Color(const QColor& c) Color::operator QColor() const { - return QColor(red(), green(), blue(), alpha()); + if (m_valid) + return QColor(red(), green(), blue(), alpha()); + else + return QColor(); } } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontCacheQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontCacheQt.cpp index 5d29389c9..469a72ed9 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontCacheQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontCacheQt.cpp @@ -48,7 +48,7 @@ FontCache::FontCache() { } -void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks) +void FontCache::getTraitsInFamily(const AtomicString&, Vector<unsigned>&) { } @@ -58,8 +58,8 @@ class FontPlatformDataCacheKey { public: FontPlatformDataCacheKey(const FontDescription& description) : m_familyName() - , m_bold(false) , m_size(description.computedPixelSize()) + , m_bold(false) , m_italic(description.italic()) , m_smallCaps(description.smallCaps()) , m_hash(0) @@ -177,15 +177,20 @@ typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCac // using Q_GLOBAL_STATIC leads to crash. TODO investigate the way to fix this. static FontPlatformDataCache* gFontPlatformDataCache = 0; -FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& description, const AtomicString& family, bool checkingAlternateName) +FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& description, const AtomicString& family, bool) { if (!gFontPlatformDataCache) gFontPlatformDataCache = new FontPlatformDataCache; - FontPlatformDataCacheKey key(description); + FontDescription descriptionWithResolvedFamily(description); + FontFamily resolvedFamily; + resolvedFamily.setFamily(family); + descriptionWithResolvedFamily.setFamily(resolvedFamily); + + FontPlatformDataCacheKey key(descriptionWithResolvedFamily); FontPlatformData* platformData = gFontPlatformDataCache->get(key); if (!platformData) { - platformData = new FontPlatformData(description); + platformData = new FontPlatformData(descriptionWithResolvedFamily); gFontPlatformDataCache->add(key, platformData); } return platformData; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontFallbackListQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontFallbackListQt.cpp index c29fd56f3..0306abf86 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontFallbackListQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontFallbackListQt.cpp @@ -102,7 +102,7 @@ const FontData* FontFallbackList::fontDataAt(const WebCore::Font* _font, unsigne const FontDescription& description = _font->fontDescription(); const FontFamily* family = &description.family(); while (family) { - if (m_fontSelector) { + if (family->family().length() && m_fontSelector) { FontData* data = m_fontSelector->getFontData(description, family->family()); if (data) { if (data->isLoading()) @@ -130,7 +130,7 @@ const FontData* FontFallbackList::fontDataForCharacters(const WebCore::Font* fon return primaryFontData(font); } -void FontFallbackList::setPlatformFont(const WebCore::FontPlatformData& platformData) +void FontFallbackList::setPlatformFont(const WebCore::FontPlatformData&) { m_familyIndex = cAllFamiliesScanned; } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontQt.cpp index f89ff9f94..c5960ac2a 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontQt.cpp @@ -197,7 +197,7 @@ float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon return w + run.padding(); } -int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const +int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool) const { const QString string = fixSpacing(qstring(run)); QTextLayout layout(string, font()); @@ -221,7 +221,10 @@ FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& QFont Font::font() const { - return primaryFont()->getQtFont(); + QFont f = primaryFont()->getQtFont(); + f.setLetterSpacing(QFont::AbsoluteSpacing, m_letterSpacing); + f.setWordSpacing(m_wordSpacing); + return f; } } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsContextQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsContextQt.cpp index a35c5ac26..57a481ae7 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsContextQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsContextQt.cpp @@ -34,29 +34,29 @@ */ #include "config.h" +#include "GraphicsContext.h" #ifdef Q_WS_WIN #include <windows.h> #endif -#include "TransformationMatrix.h" #include "Color.h" #include "FloatConversion.h" #include "Font.h" -#include "GraphicsContext.h" #include "GraphicsContextPrivate.h" #include "ImageBuffer.h" +#include "NotImplemented.h" #include "Path.h" #include "Pattern.h" #include "Pen.h" -#include "NotImplemented.h" +#include "TransformationMatrix.h" #include <QBrush> #include <QDebug> #include <QGradient> -#include <QPainter> #include <QPaintDevice> #include <QPaintEngine> +#include <QPainter> #include <QPainterPath> #include <QPixmap> #include <QPolygonF> @@ -72,34 +72,35 @@ namespace WebCore { static inline QPainter::CompositionMode toQtCompositionMode(CompositeOperator op) { switch (op) { - case CompositeClear: - return QPainter::CompositionMode_Clear; - case CompositeCopy: - return QPainter::CompositionMode_Source; - case CompositeSourceOver: - return QPainter::CompositionMode_SourceOver; - case CompositeSourceIn: - return QPainter::CompositionMode_SourceIn; - case CompositeSourceOut: - return QPainter::CompositionMode_SourceOut; - case CompositeSourceAtop: - return QPainter::CompositionMode_SourceAtop; - case CompositeDestinationOver: - return QPainter::CompositionMode_DestinationOver; - case CompositeDestinationIn: - return QPainter::CompositionMode_DestinationIn; - case CompositeDestinationOut: - return QPainter::CompositionMode_DestinationOut; - case CompositeDestinationAtop: - return QPainter::CompositionMode_DestinationAtop; - case CompositeXOR: - return QPainter::CompositionMode_Xor; - case CompositePlusDarker: - return QPainter::CompositionMode_SourceOver; - case CompositeHighlight: - return QPainter::CompositionMode_SourceOver; - case CompositePlusLighter: - return QPainter::CompositionMode_Plus; + case CompositeClear: + return QPainter::CompositionMode_Clear; + case CompositeCopy: + return QPainter::CompositionMode_Source; + case CompositeSourceOver: + return QPainter::CompositionMode_SourceOver; + case CompositeSourceIn: + return QPainter::CompositionMode_SourceIn; + case CompositeSourceOut: + return QPainter::CompositionMode_SourceOut; + case CompositeSourceAtop: + return QPainter::CompositionMode_SourceAtop; + case CompositeDestinationOver: + return QPainter::CompositionMode_DestinationOver; + case CompositeDestinationIn: + return QPainter::CompositionMode_DestinationIn; + case CompositeDestinationOut: + return QPainter::CompositionMode_DestinationOut; + case CompositeDestinationAtop: + return QPainter::CompositionMode_DestinationAtop; + case CompositeXOR: + return QPainter::CompositionMode_Xor; + case CompositePlusDarker: + // there is no exact match, but this is the closest + return QPainter::CompositionMode_Darken; + case CompositeHighlight: + return QPainter::CompositionMode_SourceOver; + case CompositePlusLighter: + return QPainter::CompositionMode_Plus; } return QPainter::CompositionMode_SourceOver; @@ -108,12 +109,12 @@ static inline QPainter::CompositionMode toQtCompositionMode(CompositeOperator op static inline Qt::PenCapStyle toQtLineCap(LineCap lc) { switch (lc) { - case ButtCap: - return Qt::FlatCap; - case RoundCap: - return Qt::RoundCap; - case SquareCap: - return Qt::SquareCap; + case ButtCap: + return Qt::FlatCap; + case RoundCap: + return Qt::RoundCap; + case SquareCap: + return Qt::SquareCap; } return Qt::FlatCap; @@ -122,12 +123,12 @@ static inline Qt::PenCapStyle toQtLineCap(LineCap lc) static inline Qt::PenJoinStyle toQtLineJoin(LineJoin lj) { switch (lj) { - case MiterJoin: - return Qt::SvgMiterJoin; - case RoundJoin: - return Qt::RoundJoin; - case BevelJoin: - return Qt::BevelJoin; + case MiterJoin: + return Qt::SvgMiterJoin; + case RoundJoin: + return Qt::RoundJoin; + case BevelJoin: + return Qt::BevelJoin; } return Qt::MiterJoin; @@ -209,8 +210,8 @@ public: return redirect; return painter; - } else - return &layers.top()->painter; + } + return &layers.top()->painter; } bool antiAliasingForRectsAndLines; @@ -410,46 +411,25 @@ void GraphicsContext::drawRect(const IntRect& rect) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines); + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + if (getShadow(shadowSize, shadowBlur, shadowColor)) { + IntRect shadowRect = rect; + shadowRect.move(shadowSize.width(), shadowSize.height()); + shadowRect.inflate(static_cast<int>(p->pen().widthF())); + p->fillRect(shadowRect, QColor(shadowColor)); + } + p->drawRect(rect); p->setRenderHint(QPainter::Antialiasing, antiAlias); } -// FIXME: Now that this is refactored, it should be shared by all contexts. -static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, - const StrokeStyle& penStyle) -{ - // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic - // works out. For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g., - // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave - // us a perfect position, but an odd width gave us a position that is off by exactly 0.5. - if (penStyle == DottedStroke || penStyle == DashedStroke) { - if (p1.x() == p2.x()) { - p1.setY(p1.y() + strokeWidth); - p2.setY(p2.y() - strokeWidth); - } else { - p1.setX(p1.x() + strokeWidth); - p2.setX(p2.x() - strokeWidth); - } - } - - if (((int) strokeWidth) % 2) { - if (p1.x() == p2.x()) { - // We're a vertical line. Adjust our x. - p1.setX(p1.x() + 0.5); - p2.setX(p2.x() + 0.5); - } else { - // We're a horizontal line. Adjust our y. - p1.setY(p1.y() + 0.5); - p2.setY(p2.y() + 0.5); - } - } -} - // This is only used to draw borders. void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) { @@ -467,7 +447,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) FloatPoint p2 = point2; bool isVerticalLine = (p1.x() == p2.x()); - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines); adjustLineToPixelBoundaries(p1, p2, width, style); @@ -478,22 +458,22 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) if (textDrawingMode() == cTextFill && getShadow(shadowSize, shadowBlur, shadowColor)) { p->save(); p->translate(shadowSize.width(), shadowSize.height()); - p->setPen(QColor(shadowColor)); + p->setPen(shadowColor); p->drawLine(p1, p2); p->restore(); } int patWidth = 0; switch (style) { - case NoStroke: - case SolidStroke: - break; - case DottedStroke: - patWidth = (int)width; - break; - case DashedStroke: - patWidth = 3 * (int)width; - break; + case NoStroke: + case SolidStroke: + break; + case DottedStroke: + patWidth = static_cast<int>(width); + break; + case DashedStroke: + patWidth = 3 * static_cast<int>(width); + break; } if (patWidth) { @@ -522,7 +502,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) if (patWidth == 1) patternOffset = 1.0f; else { - bool evenNumberOfSegments = numSegments % 2 == 0; + bool evenNumberOfSegments = !(numSegments % 2); if (remainder) evenNumberOfSegments = !evenNumberOfSegments; if (evenNumberOfSegments) { @@ -570,11 +550,25 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp if (paintingDisabled() || strokeStyle() == NoStroke || strokeThickness() <= 0.0f || !strokeColor().alpha()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, true); - p->drawArc(rect, startAngle * 16, angleSpan * 16); + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + startAngle *= 16; + angleSpan *= 16; + if (getShadow(shadowSize, shadowBlur, shadowColor)) { + p->save(); + p->translate(shadowSize.width(), shadowSize.height()); + QPen pen(p->pen()); + pen.setColor(shadowColor); + p->setPen(pen); + p->drawArc(rect, startAngle, angleSpan); + p->restore(); + } + p->drawArc(rect, startAngle, angleSpan); p->setRenderHint(QPainter::Antialiasing, antiAlias); } @@ -592,9 +586,25 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points for (size_t i = 0; i < npoints; i++) polygon[i] = points[i]; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); p->save(); p->setRenderHint(QPainter::Antialiasing, shouldAntialias); + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + if (getShadow(shadowSize, shadowBlur, shadowColor)) { + p->save(); + p->translate(shadowSize.width(), shadowSize.height()); + if (p->brush().style() != Qt::NoBrush) + p->setBrush(QBrush(shadowColor)); + QPen pen(p->pen()); + if (pen.style() != Qt::NoPen) { + pen.setColor(shadowColor); + p->setPen(pen); + } + p->drawConvexPolygon(polygon); + p->restore(); + } p->drawConvexPolygon(polygon); p->restore(); } @@ -604,34 +614,50 @@ QPen GraphicsContext::pen() if (paintingDisabled()) return QPen(); - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); return p->pen(); } +static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath *path) +{ + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + if (context->getShadow(shadowSize, shadowBlur, shadowColor)) { + p->translate(shadowSize.width(), shadowSize.height()); + p->fillPath(*path, QBrush(shadowColor)); + p->translate(-shadowSize.width(), -shadowSize.height()); + } +} + void GraphicsContext::fillPath() { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPainterPath path = m_data->currentPath; path.setFillRule(toQtFillRule(fillRule())); - switch (m_common->state.fillColorSpace) { - case SolidColorSpace: - if (fillColor().alpha()) - p->fillPath(path, p->brush()); - break; - case PatternColorSpace: { - TransformationMatrix affine; - p->fillPath(path, QBrush(m_common->state.fillPattern->createPlatformPattern(affine))); - break; - } - case GradientColorSpace: - QBrush brush(*m_common->state.fillGradient->platformGradient()); - brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform()); - p->fillPath(path, brush); - break; + if ((m_common->state.fillColorSpace != SolidColorSpace) + || (fillColor().alpha())) { + drawFilledShadowPath(this, p, &path); + switch (m_common->state.fillColorSpace) { + case SolidColorSpace: + if (fillColor().alpha()) + p->fillPath(path, p->brush()); + break; + case PatternColorSpace: { + TransformationMatrix affine; + p->fillPath(path, QBrush(m_common->state.fillPattern->createPlatformPattern(affine))); + break; + } + case GradientColorSpace: + QBrush brush(*m_common->state.fillGradient->platformGradient()); + brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform()); + p->fillPath(path, brush); + break; + } } m_data->currentPath = QPainterPath(); } @@ -641,59 +667,88 @@ void GraphicsContext::strokePath() if (paintingDisabled()) return; - QPainter *p = m_data->p(); - QPen pen = p->pen(); + QPainter* p = m_data->p(); + QPen pen(p->pen()); QPainterPath path = m_data->currentPath; path.setFillRule(toQtFillRule(fillRule())); - switch (m_common->state.strokeColorSpace) { - case SolidColorSpace: - if (strokeColor().alpha()) + if ((m_common->state.strokeColorSpace != SolidColorSpace) + || (strokeColor().alpha())) { + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + if (getShadow(shadowSize, shadowBlur, shadowColor)) { + QTransform t(p->worldTransform()); + p->translate(shadowSize.width(), shadowSize.height()); + QPen shadowPen(pen); + shadowPen.setColor(shadowColor); + p->strokePath(path, shadowPen); + p->setWorldTransform(t); + } + switch (m_common->state.strokeColorSpace) { + case SolidColorSpace: + if (strokeColor().alpha()) + p->strokePath(path, pen); + break; + case PatternColorSpace: { + TransformationMatrix affine; + pen.setBrush(QBrush(m_common->state.strokePattern->createPlatformPattern(affine))); + p->setPen(pen); p->strokePath(path, pen); - break; - case PatternColorSpace: { - TransformationMatrix affine; - pen.setBrush(QBrush(m_common->state.strokePattern->createPlatformPattern(affine))); - p->setPen(pen); - p->strokePath(path, pen); - break; - } - case GradientColorSpace: { - QBrush brush(*m_common->state.strokeGradient->platformGradient()); - brush.setTransform(m_common->state.strokeGradient->gradientSpaceTransform()); - pen.setBrush(brush); - p->setPen(pen); - p->strokePath(path, pen); - break; - } + break; + } + case GradientColorSpace: { + QBrush brush(*m_common->state.strokeGradient->platformGradient()); + brush.setTransform(m_common->state.strokeGradient->gradientSpaceTransform()); + pen.setBrush(brush); + p->setPen(pen); + p->strokePath(path, pen); + break; + } + } } m_data->currentPath = QPainterPath(); } +static inline void drawBorderlessRectShadow(GraphicsContext* context, QPainter* p, const FloatRect& rect) +{ + IntSize shadowSize; + int shadowBlur; + Color shadowColor; + if (context->getShadow(shadowSize, shadowBlur, shadowColor)) { + FloatRect shadowRect(rect); + shadowRect.move(shadowSize.width(), shadowSize.height()); + p->fillRect(shadowRect, QColor(shadowColor)); + } +} + void GraphicsContext::fillRect(const FloatRect& rect) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); - switch (m_common->state.fillColorSpace) { - case SolidColorSpace: - if (fillColor().alpha()) - p->fillRect(rect, p->brush()); - break; - case PatternColorSpace: { - TransformationMatrix affine; - p->fillRect(rect, QBrush(m_common->state.fillPattern->createPlatformPattern(affine))); - break; - } - case GradientColorSpace: - QBrush brush(*m_common->state.fillGradient->platformGradient()); - brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform()); - p->fillRect(rect, brush); - break; + if ((m_common->state.fillColorSpace != SolidColorSpace) + || (fillColor().alpha())) { + drawBorderlessRectShadow(this, p, rect); + switch (m_common->state.fillColorSpace) { + case SolidColorSpace: + if (fillColor().alpha()) + p->fillRect(rect, p->brush()); + break; + case PatternColorSpace: { + TransformationMatrix affine; + p->fillRect(rect, QBrush(m_common->state.fillPattern->createPlatformPattern(affine))); + break; + } + case GradientColorSpace: + QBrush brush(*m_common->state.fillGradient->platformGradient()); + brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform()); + p->fillRect(rect, brush); + break; + } } - m_data->currentPath = QPainterPath(); } void GraphicsContext::fillRect(const FloatRect& rect, const Color& c) @@ -701,8 +756,10 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& c) if (paintingDisabled()) return; - m_data->solidColor.setColor(QColor(c)); - m_data->p()->fillRect(rect, m_data->solidColor); + m_data->solidColor.setColor(c); + QPainter* p = m_data->p(); + drawBorderlessRectShadow(this, p, rect); + p->fillRect(rect, m_data->solidColor); } void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) @@ -711,7 +768,9 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef return; Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight); - m_data->p()->fillPath(*path.platformPath(), QColor(color)); + QPainter* p = m_data->p(); + drawFilledShadowPath(this, p, path.platformPath()); + p->fillPath(*path.platformPath(), QColor(color)); } void GraphicsContext::beginPath() @@ -749,7 +808,7 @@ void GraphicsContext::clipPath(WindRule clipRule) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPainterPath newPath = m_data->currentPath; newPath.setFillRule(clipRule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill); p->setClipPath(newPath); @@ -768,10 +827,10 @@ void GraphicsContext::drawFocusRing(const Color& color) const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); - if (rects.size() == 0) + if (!rects.size()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines); @@ -792,7 +851,7 @@ void GraphicsContext::drawFocusRing(const Color& color) QPainterPath newPath = stroker.createStroke(path); p->strokePath(newPath, nPen); #else - for (int i = 0; i < rectCount; ++i) + for (unsigned i = 0; i < rectCount; ++i) p->drawRect(QRectF(rects[i])); #endif p->setPen(oldPen); @@ -801,7 +860,7 @@ void GraphicsContext::drawFocusRing(const Color& color) p->setRenderHint(QPainter::Antialiasing, antiAlias); } -void GraphicsContext::drawLineForText(const IntPoint& origin, int width, bool printing) +void GraphicsContext::drawLineForText(const IntPoint& origin, int width, bool) { if (paintingDisabled()) return; @@ -810,8 +869,7 @@ void GraphicsContext::drawLineForText(const IntPoint& origin, int width, bool pr drawLine(origin, endPoint); } -void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint&, - int width, bool grammar) +void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint&, int, bool) { if (paintingDisabled()) return; @@ -828,10 +886,16 @@ FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect) return FloatRect(QRectF(result)); } -void GraphicsContext::setPlatformShadow(const IntSize& pos, int blur, const Color &color) +void GraphicsContext::setPlatformShadow(const IntSize& size, int, const Color&) { // Qt doesn't support shadows natively, they are drawn manually in the draw* // functions + + if (m_common->state.shadowsIgnoreTransforms) { + // Meaning that this graphics context is associated with a CanvasRenderingContext + // We flip the height since CG and HTML5 Canvas have opposite Y axis + m_common->state.shadowSize = IntSize(size.width(), -size.height()); + } } void GraphicsContext::clearPlatformShadow() @@ -847,8 +911,8 @@ void GraphicsContext::beginTransparencyLayer(float opacity) int x, y, w, h; x = y = 0; - QPainter *p = m_data->p(); - const QPaintDevice *device = p->device(); + QPainter* p = m_data->p(); + const QPaintDevice* device = p->device(); w = device->width(); h = device->height(); @@ -870,10 +934,10 @@ void GraphicsContext::endTransparencyLayer() if (paintingDisabled()) return; - TransparencyLayer *layer = m_data->layers.pop(); + TransparencyLayer* layer = m_data->layers.pop(); layer->painter.end(); - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); p->save(); p->resetTransform(); p->setOpacity(layer->opacity); @@ -888,7 +952,7 @@ void GraphicsContext::clearRect(const FloatRect& rect) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPainter::CompositionMode currentCompositionMode = p->compositionMode(); if (p->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) p->setCompositionMode(QPainter::CompositionMode_Source); @@ -915,7 +979,7 @@ void GraphicsContext::setLineCap(LineCap lc) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen nPen = p->pen(); nPen.setCapStyle(toQtLineCap(lc)); p->setPen(nPen); @@ -947,7 +1011,7 @@ void GraphicsContext::setLineJoin(LineJoin lj) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen nPen = p->pen(); nPen.setJoinStyle(toQtLineJoin(lj)); p->setPen(nPen); @@ -958,7 +1022,7 @@ void GraphicsContext::setMiterLimit(float limit) if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen nPen = p->pen(); nPen.setMiterLimit(limit); p->setPen(nPen); @@ -968,7 +1032,7 @@ void GraphicsContext::setAlpha(float opacity) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); p->setOpacity(opacity); } @@ -989,20 +1053,29 @@ void GraphicsContext::clip(const Path& path) m_data->p()->setClipPath(*path.platformPath(), Qt::IntersectClip); } +void GraphicsContext::canvasClip(const Path& path) +{ + clip(path); +} + void GraphicsContext::clipOut(const Path& path) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); - QRectF clipBounds = p->clipPath().boundingRect(); + QPainter* p = m_data->p(); QPainterPath clippedOut = *path.platformPath(); QPainterPath newClip; newClip.setFillRule(Qt::OddEvenFill); - newClip.addRect(clipBounds); - newClip.addPath(clippedOut); - - p->setClipPath(newClip, Qt::IntersectClip); + if (p->hasClipping()) { + newClip.addRect(p->clipPath().boundingRect()); + newClip.addPath(clippedOut); + p->setClipPath(newClip, Qt::IntersectClip); + } else { + newClip.addRect(p->window()); + newClip.addPath(clippedOut & newClip); + p->setClipPath(newClip); + } } void GraphicsContext::translate(float x, float y) @@ -1060,14 +1133,21 @@ void GraphicsContext::clipOut(const IntRect& rect) if (paintingDisabled()) return; - QPainter *p = m_data->p(); - QRectF clipBounds = p->clipPath().boundingRect(); + QPainter* p = m_data->p(); QPainterPath newClip; newClip.setFillRule(Qt::OddEvenFill); - newClip.addRect(clipBounds); - newClip.addRect(QRect(rect)); - - p->setClipPath(newClip, Qt::IntersectClip); + if (p->hasClipping()) { + newClip.addRect(p->clipPath().boundingRect()); + newClip.addRect(QRect(rect)); + p->setClipPath(newClip, Qt::IntersectClip); + } else { + QRect clipOutRect(rect); + QRect window(p->window()); + clipOutRect &= window; + newClip.addRect(window); + newClip.addRect(clipOutRect); + p->setClipPath(newClip); + } } void GraphicsContext::clipOutEllipseInRect(const IntRect& rect) @@ -1075,14 +1155,21 @@ void GraphicsContext::clipOutEllipseInRect(const IntRect& rect) if (paintingDisabled()) return; - QPainter *p = m_data->p(); - QRectF clipBounds = p->clipPath().boundingRect(); + QPainter* p = m_data->p(); QPainterPath newClip; newClip.setFillRule(Qt::OddEvenFill); - newClip.addRect(clipBounds); - newClip.addEllipse(QRect(rect)); - - p->setClipPath(newClip, Qt::IntersectClip); + if (p->hasClipping()) { + newClip.addRect(p->clipPath().boundingRect()); + newClip.addEllipse(QRect(rect)); + p->setClipPath(newClip, Qt::IntersectClip); + } else { + QRect clipOutRect(rect); + QRect window(p->window()); + clipOutRect &= window; + newClip.addRect(window); + newClip.addEllipse(clipOutRect); + p->setClipPath(newClip); + } } void GraphicsContext::clipToImageBuffer(const FloatRect&, const ImageBuffer*) @@ -1108,7 +1195,7 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, path.setFillRule(Qt::OddEvenFill); - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, true); @@ -1133,7 +1220,7 @@ void GraphicsContext::concatCTM(const TransformationMatrix& transform) } } -void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) +void GraphicsContext::setURLForRect(const KURL&, const IntRect&) { notImplemented(); } @@ -1142,7 +1229,7 @@ void GraphicsContext::setPlatformStrokeColor(const Color& color) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen newPen(p->pen()); newPen.setColor(color); p->setPen(newPen); @@ -1152,7 +1239,7 @@ void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen newPen(p->pen()); newPen.setStyle(toQPenStyle(strokeStyle)); p->setPen(newPen); @@ -1162,7 +1249,7 @@ void GraphicsContext::setPlatformStrokeThickness(float thickness) { if (paintingDisabled()) return; - QPainter *p = m_data->p(); + QPainter* p = m_data->p(); QPen newPen(p->pen()); newPen.setWidthF(thickness); p->setPen(newPen); @@ -1183,7 +1270,6 @@ void GraphicsContext::setPlatformShouldAntialias(bool enable) } #ifdef Q_WS_WIN -#include <windows.h> HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap) { diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/IconQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/IconQt.cpp index 34c3c472a..98f4606d1 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/IconQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/IconQt.cpp @@ -47,7 +47,7 @@ PassRefPtr<Icon> Icon::createIconForFile(const String& filename) return i.release(); } -PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames) +PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>&) { //FIXME: Implement this return 0; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageBufferQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageBufferQt.cpp index 506a8eaf8..5255428a3 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageBufferQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageBufferQt.cpp @@ -40,6 +40,7 @@ #include <QImageWriter> #include <QPainter> #include <QPixmap> +#include <math.h> namespace WebCore { @@ -67,7 +68,7 @@ ImageBufferData::ImageBufferData(const IntSize& size) painter->setCompositionMode(QPainter::CompositionMode_SourceOver); } -ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success) +ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace, bool& success) : m_data(size) , m_size(size) { @@ -98,12 +99,39 @@ Image* ImageBuffer::image() const return m_image.get(); } -PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const +void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) +{ + bool isPainting = m_data.m_painter->isActive(); + if (isPainting) + m_data.m_painter->end(); + + QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32); + ASSERT(!image.isNull()); + + for (int y = 0; y < m_size.height(); ++y) { + for (int x = 0; x < m_size.width(); x++) { + QRgb value = image.pixel(x, y); + value = qRgba(lookUpTable[qRed(value)], + lookUpTable[qGreen(value)], + lookUpTable[qBlue(value)], + lookUpTable[qAlpha(value)]); + image.setPixel(x, y, value); + } + } + + m_data.m_pixmap = QPixmap::fromImage(image); + + if (isPainting) + m_data.m_painter->begin(&m_data.m_pixmap); +} + +template <Multiply multiplied> +PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& imageData, const IntSize& size) { PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); unsigned char* data = result->data()->data()->data(); - if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > m_size.width() || (rect.y() + rect.height()) > m_size.height()) + if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > size.width() || (rect.y() + rect.height()) > size.height()) memset(data, 0, result->data()->length()); int originx = rect.x(); @@ -113,8 +141,8 @@ PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const originx = 0; } int endx = rect.x() + rect.width(); - if (endx > m_size.width()) - endx = m_size.width(); + if (endx > size.width()) + endx = size.width(); int numColumns = endx - originx; int originy = rect.y(); @@ -124,11 +152,16 @@ PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const originy = 0; } int endy = rect.y() + rect.height(); - if (endy > m_size.height()) - endy = m_size.height(); + if (endy > size.height()) + endy = size.height(); int numRows = endy - originy; - QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32); + QImage image = imageData.m_pixmap.toImage(); + if (multiplied == Unmultiplied) + image = image.convertToFormat(QImage::Format_ARGB32); + else + image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + ASSERT(!image.isNull()); unsigned destBytesPerRow = 4 * rect.width(); @@ -149,7 +182,18 @@ PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const return result; } -void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) +PassRefPtr<ImageData> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const +{ + return getImageData<Unmultiplied>(rect, m_data, m_size); +} + +PassRefPtr<ImageData> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const +{ + return getImageData<Premultiplied>(rect, m_data, m_size); +} + +template <Multiply multiplied> +void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& data, const IntSize& size) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); @@ -157,49 +201,65 @@ void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, con int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); - ASSERT(destx < m_size.width()); + ASSERT(destx < size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); - ASSERT(endx <= m_size.width()); + ASSERT(endx <= size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); - ASSERT(desty < m_size.height()); + ASSERT(desty < size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); - ASSERT(endy <= m_size.height()); + ASSERT(endy <= size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * source->width(); - bool isPainting = m_data.m_painter->isActive(); + bool isPainting = data.m_painter->isActive(); if (isPainting) - m_data.m_painter->end(); + data.m_painter->end(); - QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32); + QImage image = data.m_pixmap.toImage(); + if (multiplied == Unmultiplied) + image = image.convertToFormat(QImage::Format_ARGB32); + else + image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { quint32* scanLine = reinterpret_cast<quint32*>(image.scanLine(y + desty)); for (int x = 0; x < numColumns; x++) { - int basex = x * 4; - scanLine[x + destx] = reinterpret_cast<quint32*>(srcRows + basex)[0]; + // ImageData stores the pixels in RGBA while QImage is ARGB + quint32 pixel = reinterpret_cast<quint32*>(srcRows + 4 * x)[0]; + pixel = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00); + scanLine[x + destx] = pixel; } srcRows += srcBytesPerRow; } - m_data.m_pixmap = QPixmap::fromImage(image); + data.m_pixmap = QPixmap::fromImage(image); if (isPainting) - m_data.m_painter->begin(&m_data.m_pixmap); + data.m_painter->begin(&data.m_pixmap); +} + +void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) +{ + putImageData<Unmultiplied>(source, sourceRect, destPoint, m_data, m_size); +} + +void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) +{ + putImageData<Premultiplied>(source, sourceRect, destPoint, m_data, m_size); } // We get a mimeType here but QImageWriter does not support mimetypes but diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp index 669be1c0d..b6823dd25 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp @@ -35,303 +35,205 @@ #include <QtGui/QImageReader> #include <qdebug.h> -namespace { - const QImage::Format DesiredFormat = QImage::Format_ARGB32; - const bool debugImageDecoderQt = false; -} - namespace WebCore { -ImageDecoderQt::ImageData::ImageData(const QImage& image, ImageState imageState, int duration) : - m_image(image), m_imageState(imageState), m_duration(duration) -{ -} - -// Context, maintains IODevice on a data buffer. -class ImageDecoderQt::ReadContext { -public: - enum LoadMode { - // Load images incrementally. This is still experimental and - // will cause the image plugins to report errors. - // Also note that as of Qt 4.2.2, the JPEG loader does not return error codes - // on "preliminary end of data". - LoadIncrementally, - // Load images only if all data have been received - LoadComplete }; - - ReadContext(const IncomingData & data, LoadMode loadMode, ImageList &target); - - enum ReadResult { ReadEOF, ReadFailed, ReadPartial, ReadComplete }; +ImageDecoder* ImageDecoder::create(const SharedBuffer& data) +{ + // We need at least 4 bytes to figure out what kind of image we're dealing with. + if (data.size() < 4) + return 0; - // Append data and read out all images. Returns the result - // of the last read operation, so, even if ReadPartial is returned, - // a few images might have been read. - ReadResult read(bool allDataReceived); + return new ImageDecoderQt; +} - QImageReader *reader() { return &m_reader; } +ImageDecoderQt::ImageDecoderQt() + : m_buffer(0) + , m_reader(0) + , m_repetitionCount(cAnimationNone) +{ +} -private: - enum IncrementalReadResult { IncrementalReadFailed, IncrementalReadPartial, IncrementalReadComplete }; - // Incrementally read an image - IncrementalReadResult readImageLines(ImageData &); +ImageDecoderQt::~ImageDecoderQt() +{ + delete m_reader; + delete m_buffer; +} - const LoadMode m_loadMode; +void ImageDecoderQt::setData(SharedBuffer* data, bool allDataReceived) +{ + if (m_failed) + return; - QByteArray m_data; - QBuffer m_buffer; - QImageReader m_reader; + // No progressive loading possible + if (!allDataReceived) + return; - ImageList &m_target; + // Cache our own new data. + ImageDecoder::setData(data, allDataReceived); - // Detected data format of the stream - enum QImage::Format m_dataFormat; - QSize m_size; + // We expect to be only called once with allDataReceived + ASSERT(!m_buffer); + ASSERT(!m_reader); -}; + // Attempt to load the data + QByteArray imageData = QByteArray::fromRawData(m_data->data(), m_data->size()); + m_buffer = new QBuffer; + m_buffer->setData(imageData); + m_buffer->open(QBuffer::ReadOnly); + m_reader = new QImageReader(m_buffer, m_format); +} -ImageDecoderQt::ReadContext::ReadContext(const IncomingData & data, LoadMode loadMode, ImageList &target) - : m_loadMode(loadMode) - , m_data(data.data(), data.size()) - , m_buffer(&m_data) - , m_reader(&m_buffer) - , m_target(target) - , m_dataFormat(QImage::Format_Invalid) +bool ImageDecoderQt::isSizeAvailable() { - m_buffer.open(QIODevice::ReadOnly); -} + if (!ImageDecoder::isSizeAvailable() && m_reader) + internalDecodeSize(); + return ImageDecoder::isSizeAvailable(); +} -ImageDecoderQt::ReadContext::ReadResult - ImageDecoderQt::ReadContext::read(bool allDataReceived) +size_t ImageDecoderQt::frameCount() { - // Complete mode: Read only all all data received - if (m_loadMode == LoadComplete && !allDataReceived) - return ReadPartial; - - // Attempt to read out all images - while (true) { - if (m_target.empty() || m_target.back().m_imageState == ImageComplete) { - // Start a new image. - if (!m_reader.canRead()) - return ReadEOF; - - // Attempt to construct an empty image of the matching size and format - // for efficient reading - QImage newImage = m_dataFormat != QImage::Format_Invalid ? - QImage(m_size, m_dataFormat) : QImage(); - m_target.push_back(ImageData(newImage)); - } + if (m_frameBufferCache.isEmpty() && m_reader) { + if (m_reader->supportsAnimation()) { + int imageCount = m_reader->imageCount(); - // read chunks - switch (readImageLines(m_target.back())) { - case IncrementalReadFailed: - m_target.pop_back(); - return ReadFailed; - case IncrementalReadPartial: - return ReadPartial; - case IncrementalReadComplete: - m_target.back().m_imageState = ImageComplete; - //store for next - m_dataFormat = m_target.back().m_image.format(); - m_size = m_target.back().m_image.size(); - const bool supportsAnimation = m_reader.supportsAnimation(); - - if (debugImageDecoderQt) - qDebug() << "readImage(): #" << m_target.size() << " complete, " << m_size - << " format " << m_dataFormat << " supportsAnimation=" << supportsAnimation; - // No point in readinfg further - if (!supportsAnimation) - return ReadComplete; - - break; + // Fixup for Qt decoders... imageCount() is wrong + // and jumpToNextImage does not work either... so + // we will have to parse everything... + if (imageCount == 0) + forceLoadEverything(); + else + m_frameBufferCache.resize(imageCount); + } else { + m_frameBufferCache.resize(1); } } - return ReadComplete; + + return m_frameBufferCache.size(); } +int ImageDecoderQt::repetitionCount() const +{ + if (m_reader && m_reader->supportsAnimation()) + m_repetitionCount = qMax(0, m_reader->loopCount()); + return m_repetitionCount; +} -ImageDecoderQt::ReadContext::IncrementalReadResult - ImageDecoderQt::ReadContext::readImageLines(ImageData &imageData) +String ImageDecoderQt::filenameExtension() const { - // TODO: Implement incremental reading here, - // set state to reflect complete header, etc. - // For now, we read the whole image. - - const qint64 startPos = m_buffer.pos(); - // Oops, failed. Rewind. - if (!m_reader.read(&imageData.m_image)) { - m_buffer.seek(startPos); - const bool gotHeader = imageData.m_image.size().width(); - - if (debugImageDecoderQt) - qDebug() << "readImageLines(): read() failed: " << m_reader.errorString() - << " got header=" << gotHeader; - // [Experimental] Did we manage to read the header? - if (gotHeader) { - imageData.m_imageState = ImageHeaderValid; - return IncrementalReadPartial; - } - return IncrementalReadFailed; - } - imageData.m_duration = m_reader.nextImageDelay(); - return IncrementalReadComplete; -} + return String(m_format.constData(), m_format.length()); +}; -ImageDecoderQt* ImageDecoderQt::create(const SharedBuffer& data) +RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index) { - // We need at least 4 bytes to figure out what kind of image we're dealing with. - if (data.size() < 4) - return 0; + // In case the ImageDecoderQt got recreated we don't know + // yet how many images we are going to have and need to + // find that out now. + int count = m_frameBufferCache.size(); + if (!m_failed && count == 0) { + internalDecodeSize(); + count = frameCount(); + } - QByteArray bytes = QByteArray::fromRawData(data.data(), data.size()); - QBuffer buffer(&bytes); - if (!buffer.open(QBuffer::ReadOnly)) + if (index >= static_cast<size_t>(count)) return 0; - QString imageFormat = QString::fromLatin1(QImageReader::imageFormat(&buffer).toLower()); - if (imageFormat.isEmpty()) - return 0; // Image format not supported - - return new ImageDecoderQt(imageFormat); + RGBA32Buffer& frame = m_frameBufferCache[index]; + if (frame.status() != RGBA32Buffer::FrameComplete && m_reader) + internalReadImage(index); + return &frame; } -ImageDecoderQt::ImageDecoderQt(const QString &imageFormat) - : m_hasAlphaChannel(false) - , m_imageFormat(imageFormat) +void ImageDecoderQt::clearFrameBufferCache(size_t /*index*/) { } -ImageDecoderQt::~ImageDecoderQt() +void ImageDecoderQt::internalDecodeSize() { -} + ASSERT(m_reader); -bool ImageDecoderQt::hasFirstImageHeader() const -{ - return !m_imageList.empty() && m_imageList[0].m_imageState >= ImageHeaderValid; -} + // If we have a QSize() something failed + QSize size = m_reader->size(); + if (size.isEmpty()) + return failRead(); -void ImageDecoderQt::reset() -{ - m_hasAlphaChannel = false; - m_failed = false; - m_imageList.clear(); - m_pixmapCache.clear(); - m_loopCount = cAnimationNone; + m_format = m_reader->format(); + setSize(size.width(), size.height()); } -void ImageDecoderQt::setData(const IncomingData &data, bool allDataReceived) +void ImageDecoderQt::internalReadImage(size_t frameIndex) { - reset(); - ReadContext readContext(data, ReadContext::LoadComplete, m_imageList); - - if (debugImageDecoderQt) - qDebug() << " setData " << data.size() << " image bytes, complete=" << allDataReceived; - - const ReadContext::ReadResult readResult = readContext.read(allDataReceived); - - if (hasFirstImageHeader()) - m_hasAlphaChannel = m_imageList[0].m_image.hasAlphaChannel(); - - if (debugImageDecoderQt) - qDebug() << " read returns " << readResult; - - switch (readResult) { - case ReadContext::ReadFailed: - m_failed = true; - break; - case ReadContext::ReadEOF: - case ReadContext::ReadPartial: - case ReadContext::ReadComplete: - // Did we read anything - try to set the size. - if (hasFirstImageHeader()) { - QSize imgSize = m_imageList[0].m_image.size(); - setSize(imgSize.width(), imgSize.height()); - - if (readContext.reader()->supportsAnimation()) { - if (readContext.reader()->loopCount() != -1) - m_loopCount = readContext.reader()->loopCount(); - else - m_loopCount = 0; //loop forever - } - } - break; - } -} + ASSERT(m_reader); + if (m_reader->supportsAnimation()) + m_reader->jumpToImage(frameIndex); + else if (frameIndex != 0) + return failRead(); -bool ImageDecoderQt::isSizeAvailable() -{ - if (debugImageDecoderQt) - qDebug() << " ImageDecoderQt::isSizeAvailable() returns" << ImageDecoder::isSizeAvailable(); - return ImageDecoder::isSizeAvailable(); -} + internalHandleCurrentImage(frameIndex); -int ImageDecoderQt::frameCount() const -{ - if (debugImageDecoderQt) - qDebug() << " ImageDecoderQt::frameCount() returns" << m_imageList.size(); - return m_imageList.size(); -} + // Attempt to return some memory + for (int i = 0; i < m_frameBufferCache.size(); ++i) + if (m_frameBufferCache[i].status() != RGBA32Buffer::FrameComplete) + return; -int ImageDecoderQt::repetitionCount() const -{ - if (debugImageDecoderQt) - qDebug() << " ImageDecoderQt::repetitionCount() returns" << m_loopCount; - return m_loopCount; + delete m_reader; + delete m_buffer; + m_buffer = 0; + m_reader = 0; } -bool ImageDecoderQt::supportsAlpha() const +void ImageDecoderQt::internalHandleCurrentImage(size_t frameIndex) { - return m_hasAlphaChannel; -} + // Now get the QImage from Qt and place it in the RGBA32Buffer + QImage img; + if (!m_reader->read(&img)) + return failRead(); -int ImageDecoderQt::duration(size_t index) const -{ - if (index >= m_imageList.size()) - return 0; - return m_imageList[index].m_duration; + // now into the RGBA32Buffer - even if the image is not + QSize imageSize = img.size(); + RGBA32Buffer* const buffer = &m_frameBufferCache[frameIndex]; + buffer->setRect(m_reader->currentImageRect()); + buffer->setStatus(RGBA32Buffer::FrameComplete); + buffer->setDuration(m_reader->nextImageDelay()); + buffer->setDecodedImage(img); } -String ImageDecoderQt::filenameExtension() const -{ - if (debugImageDecoderQt) - qDebug() << " ImageDecoderQt::filenameExtension() returns" << m_imageFormat; - return m_imageFormat; -}; +// The QImageIOHandler is not able to tell us how many frames +// we have and we need to parse every image. We do this by +// increasing the m_frameBufferCache by one and try to parse +// the image. We stop when QImage::read fails and then need +// to resize the m_frameBufferCache to the final size and update +// the m_failed. In case we failed to decode the first image +// we want to keep m_failed set to true. -RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index) -{ - Q_ASSERT("use imageAtIndex instead"); - return 0; -} - -QPixmap* ImageDecoderQt::imageAtIndex(size_t index) const +// TODO: Do not increment the m_frameBufferCache.size() by one but more than one +void ImageDecoderQt::forceLoadEverything() { - if (debugImageDecoderQt) - qDebug() << "ImageDecoderQt::imageAtIndex(" << index << ')'; + int imageCount = 0; - if (index >= m_imageList.size()) - return 0; - - if (!m_pixmapCache.contains(index)) { - m_pixmapCache.insert(index, - QPixmap::fromImage(m_imageList[index].m_image)); + do { + m_frameBufferCache.resize(++imageCount); + internalHandleCurrentImage(imageCount - 1); + } while(!m_failed); - // store null image since the converted pixmap is already in pixmap cache - Q_ASSERT(m_imageList[index].m_imageState == ImageComplete); - m_imageList[index].m_image = QImage(); - } - return &m_pixmapCache[index]; + // If we failed decoding the first image we actually + // have no images and need to keep m_failed set to + // true otherwise we want to reset it and forget about + // the last attempt to decode a image. + m_frameBufferCache.resize(imageCount - 1); + m_failed = imageCount == 1; } -void ImageDecoderQt::clearFrame(size_t index) +void ImageDecoderQt::failRead() { - if (m_imageList.size() < (int)index) - m_imageList[index].m_image = QImage(); - m_pixmapCache.take(index); + setFailed(); + delete m_reader; + delete m_buffer; + m_reader = 0; + m_buffer = 0; } - } // vim: ts=4 sw=4 et diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.h b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.h index ece0e48f1..d11b93849 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.h @@ -28,10 +28,11 @@ #define ImageDecoderQt_h #include "ImageDecoder.h" -#include <QtGui/QImage> +#include <QtGui/QImageReader> #include <QtGui/QPixmap> #include <QtCore/QList> #include <QtCore/QHash> +#include <QtCore/QBuffer> namespace WebCore { @@ -39,54 +40,35 @@ namespace WebCore { class ImageDecoderQt : public ImageDecoder { public: - static ImageDecoderQt* create(const SharedBuffer& data); + ImageDecoderQt(); ~ImageDecoderQt(); - typedef Vector<char> IncomingData; - - virtual void setData(const IncomingData& data, bool allDataReceived); + virtual void setData(SharedBuffer* data, bool allDataReceived); virtual bool isSizeAvailable(); - virtual int frameCount() const; + virtual size_t frameCount(); virtual int repetitionCount() const; virtual RGBA32Buffer* frameBufferAtIndex(size_t index); - QPixmap* imageAtIndex(size_t index) const; - virtual bool supportsAlpha() const; - int duration(size_t index) const; virtual String filenameExtension() const; - void clearFrame(size_t index); + virtual void clearFrameBufferCache(size_t clearBeforeFrame); private: - ImageDecoderQt(const QString &imageFormat); ImageDecoderQt(const ImageDecoderQt&); ImageDecoderQt &operator=(const ImageDecoderQt&); - class ReadContext; - void reset(); - bool hasFirstImageHeader() const; - - enum ImageState { - // Started image reading - ImagePartial, - // Header (size / alpha) are known - ImageHeaderValid, - // Image is complete - ImageComplete }; - - struct ImageData { - ImageData(const QImage& image, ImageState imageState = ImagePartial, int duration=0); - QImage m_image; - ImageState m_imageState; - int m_duration; - }; - - bool m_hasAlphaChannel; - typedef QList<ImageData> ImageList; - mutable ImageList m_imageList; - mutable QHash<int, QPixmap> m_pixmapCache; - int m_loopCount; - QString m_imageFormat; +private: + void internalDecodeSize(); + void internalReadImage(size_t); + void internalHandleCurrentImage(size_t); + void forceLoadEverything(); + void failRead(); + +private: + QByteArray m_format; + QBuffer* m_buffer; + QImageReader* m_reader; + mutable int m_repetitionCount; }; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageQt.cpp index 5d40e26ad..b67110750 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageQt.cpp @@ -76,6 +76,7 @@ bool FrameData::clear(bool clearMetadata) m_haveMetadata = false; if (m_frame) { + delete m_frame; m_frame = 0; return true; } @@ -119,6 +120,38 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const imageObserver()->didDraw(this); } +BitmapImage::BitmapImage(QPixmap* pixmap, ImageObserver* observer) + : Image(observer) + , m_currentFrame(0) + , m_frames(0) + , m_frameTimer(0) + , m_repetitionCount(cAnimationNone) + , m_repetitionCountStatus(Unknown) + , m_repetitionsComplete(0) + , m_isSolidColor(false) + , m_checkedForSolidColor(false) + , m_animationFinished(true) + , m_allDataReceived(true) + , m_haveSize(true) + , m_sizeAvailable(true) + , m_decodedSize(0) + , m_haveFrameCount(true) + , m_frameCount(1) +{ + initPlatformData(); + + int width = pixmap->width(); + int height = pixmap->height(); + m_decodedSize = width * height * 4; + m_size = IntSize(width, height); + + m_frames.grow(1); + m_frames[0].m_frame = pixmap; + m_frames[0].m_hasAlpha = pixmap->hasAlpha(); + m_frames[0].m_haveMetadata = true; + checkForSolidColor(); +} + void BitmapImage::initPlatformData() { } @@ -180,6 +213,13 @@ void BitmapImage::checkForSolidColor() m_solidColor = QColor::fromRgba(framePixmap->toImage().pixel(0, 0)); } +#if PLATFORM(WIN_OS) +PassRefPtr<BitmapImage> BitmapImage::create(HBITMAP hBitmap) +{ + return BitmapImage::create(new QPixmap(QPixmap::fromWinHBITMAP(hBitmap))); +} +#endif + } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp index 76b14943a..9faa23403 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.cpp @@ -27,6 +27,7 @@ #include "FrameView.h" #include "GraphicsContext.h" #include "NotImplemented.h" +#include "TimeRanges.h" #include "Widget.h" #include <wtf/HashSet.h> @@ -37,9 +38,12 @@ #include <QUrl> #include <QEvent> -#include <Phonon/AudioOutput> -#include <Phonon/MediaObject> -#include <Phonon/VideoWidget> +#if defined (__SYMBIAN32__) +#include <phonon/path.h> +#endif +#include <audiooutput.h> +#include <mediaobject.h> +#include <videowidget.h> using namespace Phonon; @@ -100,15 +104,15 @@ MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player) foreach (QWidget* widget, qFindChildren<QWidget*>(m_videoWidget)) widget->installEventFilter(this); - connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), - this, SLOT(stateChanged(Phonon::State, Phonon::State))); + connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(stateChanged(Phonon::State,Phonon::State))); connect(m_mediaObject, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged())); connect(m_mediaObject, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool))); connect(m_mediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); connect(m_mediaObject, SIGNAL(bufferStatus(int)), this, SLOT(bufferStatus(int))); connect(m_mediaObject, SIGNAL(finished()), this, SLOT(finished())); - connect(m_mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource&)), - this, SLOT(currentSourceChanged(const Phonon::MediaSource&))); + connect(m_mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)), + this, SLOT(currentSourceChanged(Phonon::MediaSource))); connect(m_mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish())); connect(m_mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); } @@ -146,7 +150,7 @@ void MediaPlayerPrivate::getSupportedTypes(HashSet<String>&) notImplemented(); } -MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs) +MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String&, const String&) { // FIXME: do the real thing notImplemented(); @@ -160,6 +164,14 @@ bool MediaPlayerPrivate::hasVideo() const return hasVideo; } +bool MediaPlayerPrivate::hasAudio() const +{ + // FIXME: Phonon::MediaObject does not have such a hasAudio() function + bool hasAudio = true; + LOG(Media, "MediaPlayerPrivatePhonon::hasAudio() -> %s", hasAudio ? "true" : "false"); + return hasAudio; +} + void MediaPlayerPrivate::load(const String& url) { LOG(Media, "MediaPlayerPrivatePhonon::load(\"%s\")", url.utf8().data()); @@ -247,15 +259,15 @@ float MediaPlayerPrivate::currentTime() const return currentTime; } -void MediaPlayerPrivate::setEndTime(float endTime) +void MediaPlayerPrivate::setEndTime(float) { notImplemented(); } -float MediaPlayerPrivate::maxTimeBuffered() const +PassRefPtr<TimeRanges> MediaPlayerPrivate::buffered() const { notImplemented(); - return 0.0f; + return TimeRanges::create(); } float MediaPlayerPrivate::maxTimeSeekable() const diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h b/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h index 9572d6151..e1193b6c9 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/MediaPlayerPrivatePhonon.h @@ -80,6 +80,7 @@ namespace WebCore { IntSize naturalSize() const; bool hasVideo() const; + bool hasAudio() const; void load(const String &url); void cancelLoad(); @@ -104,7 +105,7 @@ namespace WebCore { MediaPlayer::NetworkState networkState() const; MediaPlayer::ReadyState readyState() const; - float maxTimeBuffered() const; + PassRefPtr<TimeRanges> buffered() const; float maxTimeSeekable() const; unsigned bytesLoaded() const; bool totalBytesKnown() const; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/PathQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/PathQt.cpp index 39e243ecb..e5cecc833 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/PathQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/PathQt.cpp @@ -92,7 +92,7 @@ bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer // on each call. - OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1), false); + OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1)); GraphicsContext* gc = scratchImage->context(); QPainterPathStroker stroke; applier->strokeStyle(gc); @@ -124,7 +124,7 @@ FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) { // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer // on each call. - OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1), false); + OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1)); GraphicsContext* gc = scratchImage->context(); QPainterPathStroker stroke; if (applier) { diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp index f823f8421..f093d7db8 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp @@ -33,7 +33,7 @@ void SimpleFontData::determinePitch() m_treatAsFixedPitch = m_platformData.font().fixedPitch(); } -bool SimpleFontData::containsCharacters(const UChar*, int length) const +bool SimpleFontData::containsCharacters(const UChar*, int) const { return true; } diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/StillImageQt.h b/src/3rdparty/webkit/WebCore/platform/graphics/qt/StillImageQt.h index 2b2c1f733..6c417b14a 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/StillImageQt.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/StillImageQt.h @@ -41,7 +41,7 @@ namespace WebCore { // FIXME: StillImages are underreporting decoded sizes and will be unable // to prune because these functions are not implemented yet. - virtual void destroyDecodedData(bool destroyAll = true) { } + virtual void destroyDecodedData(bool destroyAll = true) { Q_UNUSED(destroyAll); } virtual unsigned decodedSize() const { return 0; } virtual IntSize size() const; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.cpp index ab3413bb2..230be3c93 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.cpp @@ -47,7 +47,7 @@ PassRefPtr<TransformOperation> Matrix3DTransformOperation::blend(const Transform apply(toT, size); if (blendToIdentity) - swap(fromT, toT); + std::swap(fromT, toT); toT.blend(fromT, progress); return Matrix3DTransformOperation::create(toT); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/MatrixTransformOperation.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/MatrixTransformOperation.cpp index 4934fa65b..0eaccea2c 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/MatrixTransformOperation.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/MatrixTransformOperation.cpp @@ -43,7 +43,7 @@ PassRefPtr<TransformOperation> MatrixTransformOperation::blend(const TransformOp } if (blendToIdentity) - swap(fromT, toT); + std::swap(fromT, toT); toT.blend(fromT, progress); return MatrixTransformOperation::create(toT.a(), toT.b(), toT.c(), toT.d(), toT.e(), toT.f()); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformOperations.h b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformOperations.h index 11605e854..dd5640843 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformOperations.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformOperations.h @@ -60,6 +60,9 @@ public: Vector<RefPtr<TransformOperation> >& operations() { return m_operations; } const Vector<RefPtr<TransformOperation> >& operations() const { return m_operations; } + size_t size() const { return m_operations.size(); } + const TransformOperation* at(size_t index) const { return index < m_operations.size() ? m_operations.at(index).get() : 0; } + private: Vector<RefPtr<TransformOperation> > m_operations; }; diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.cpp index a358aaf9d..13ef28131 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2009 Torch Mobile, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -865,6 +866,16 @@ TransformationMatrix& TransformationMatrix::applyPerspective(double p) return *this; } +TransformationMatrix TransformationMatrix::rectToRect(const FloatRect& from, const FloatRect& to) +{ + ASSERT(!from.isEmpty()); + return TransformationMatrix(to.width() / from.width(), + 0, 0, + to.height() / from.height(), + to.x() - from.x(), + to.y() - from.y()); +} + // // *this = mat * *this // diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.h b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.h index 36e4b7055..83719d21b 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.h +++ b/src/3rdparty/webkit/WebCore/platform/graphics/transforms/TransformationMatrix.h @@ -225,6 +225,9 @@ public: TransformationMatrix& applyPerspective(double p); bool hasPerspective() const { return m_matrix[2][3] != 0.0f; } + // returns a transformation that maps a rect to a rect + static TransformationMatrix rectToRect(const FloatRect&, const FloatRect&); + bool isInvertible() const; // This method returns the identity matrix if it is not invertible. @@ -284,7 +287,7 @@ public: } // result = *this * t (i.e., a multRight) - TransformationMatrix operator*(const TransformationMatrix& t) + TransformationMatrix operator*(const TransformationMatrix& t) const { TransformationMatrix result = t; result.multLeft(*this); |