diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 22:31:35 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 22:31:35 +0000 |
commit | de56f378336660dcc848763c80267a5e063ae47d (patch) | |
tree | 7f551b88923b35bc4022ce6ab3a3f602fb60d91c /webkit/pending/GraphicsContext.h | |
parent | dc4f63c80cb90efe594131030aad6776e5945fcc (diff) | |
download | chromium_src-de56f378336660dcc848763c80267a5e063ae47d.zip chromium_src-de56f378336660dcc848763c80267a5e063ae47d.tar.gz chromium_src-de56f378336660dcc848763c80267a5e063ae47d.tar.bz2 |
Merge the chrome_webkit_merge_branch back on to trunk. This brings us
up to webkit@36102.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/pending/GraphicsContext.h')
-rw-r--r-- | webkit/pending/GraphicsContext.h | 209 |
1 files changed, 127 insertions, 82 deletions
diff --git a/webkit/pending/GraphicsContext.h b/webkit/pending/GraphicsContext.h index 87452b7..e6cdc8f 100644 --- a/webkit/pending/GraphicsContext.h +++ b/webkit/pending/GraphicsContext.h @@ -34,20 +34,14 @@ #include <wtf/Noncopyable.h> #include <wtf/Platform.h> -#ifdef ANDROID_CANVAS_IMPL - #include "CanvasGradient.h" - #include "graphics/PlatformGraphics.h" -#endif - #if PLATFORM(CG) typedef struct CGContext PlatformGraphicsContext; -#elif PLATFORM(CAIRO) || PLATFORM(SKIA) -// TODO(jhaas) -// We're currently masquerading as Cairo. Change to use PLATFORM(SKIA) -//typedef struct _cairo PlatformGraphicsContext; -typedef class PlatformContextSkia PlatformGraphicsContext; +#elif PLATFORM(CAIRO) +typedef struct _cairo PlatformGraphicsContext; #elif PLATFORM(QT) +QT_BEGIN_NAMESPACE class QPainter; +QT_END_NAMESPACE typedef QPainter PlatformGraphicsContext; #elif PLATFORM(WX) class wxGCDC; @@ -68,16 +62,27 @@ class wxWindowDC; #else typedef wxWindowDC PlatformGraphicsContext; #endif +#elif PLATFORM(SKIA) +typedef class PlatformContextSkia PlatformGraphicsContext; #else typedef void PlatformGraphicsContext; #endif #if PLATFORM(GTK) typedef struct _GdkDrawable GdkDrawable; +typedef struct _GdkEventExpose GdkEventExpose; #endif #if PLATFORM(WIN) typedef struct HDC__* HDC; +#if !PLATFORM(CG) +// UInt8 is defined in CoreFoundation/CFBase.h +typedef unsigned char UInt8; +#endif +#endif + +#if PLATFORM(QT) && defined(Q_WS_WIN) +#include <windows.h> #endif namespace WebCore { @@ -88,10 +93,14 @@ namespace WebCore { class AffineTransform; class Font; + class Generator; + class Gradient; class GraphicsContextPrivate; class GraphicsContextPlatformPrivate; + class ImageBuffer; class KURL; class Path; + class Pattern; class TextRun; // These bits can be ORed together for a total of 8 possible text drawing modes. @@ -107,6 +116,14 @@ namespace WebCore { DashedStroke }; + enum InterpolationQuality { + InterpolationDefault, + InterpolationNone, + InterpolationLow, + InterpolationMedium, + InterpolationHigh + }; + class GraphicsContext : Noncopyable { public: GraphicsContext(PlatformGraphicsContext*); @@ -123,72 +140,40 @@ namespace WebCore { void setStrokeStyle(const StrokeStyle& style); Color strokeColor() const; void setStrokeColor(const Color&); + void setStrokePattern(PassRefPtr<Pattern>); + void setStrokeGradient(PassRefPtr<Gradient>); + WindRule fillRule() const; + void setFillRule(WindRule); Color fillColor() const; void setFillColor(const Color&); - + void setFillPattern(PassRefPtr<Pattern>); + void setFillGradient(PassRefPtr<Gradient>); + void save(); void restore(); - + // These draw methods will do both stroking and filling. void drawRect(const IntRect&); void drawLine(const IntPoint&, const IntPoint&); void drawEllipse(const IntRect&); void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false); -#ifdef ANDROID_CANVAS_IMPL - void fillPath(const Path&, PlatformGradient*, PlatformPattern*); - void strokePath(const Path&, PlatformGradient*, PlatformPattern*); - void fillPath(PlatformPath*, PlatformGradient*, PlatformPattern*); - void strokePath(PlatformPath*, PlatformGradient*, PlatformPattern*); - void fillRect(const FloatRect&, PlatformGradient*, PlatformPattern*); - void strokeRect(const FloatRect&, float lineWidth, PlatformGradient*, PlatformPattern*); - - static PlatformGradient* newPlatformLinearGradient( - const FloatPoint& p0, const FloatPoint& p1, - const CanvasGradient::ColorStop* stopData, size_t count); - static PlatformGradient* newPlatformRadialGradient( - const FloatPoint& p0, float r0, - const FloatPoint& p1, float r1, - const CanvasGradient::ColorStop* stopData, size_t count); - - static void freePlatformGradient(PlatformGradient*); - - static PlatformPattern* newPlatformPattern(Image* image, - Image::TileRule hRule, Image::TileRule vRule); - static void freePlatformPattern(PlatformPattern*); - - /** platform-specific factory method to return a bitmap graphicscontext, - called by <canvas> when we need to draw offscreen. The caller is - responsible for deleting the pointer. - */ - static GraphicsContext* createOffscreenContext(int width, int height); - /** Called with a context returned by createOffscreenContext. Draw the underlying - bitmap to the current context. Similar to drawImage(), but this hides how - to extract the bitmap from ctx from the portable code. - If srcRect is NULL, it is assumed that we want to draw the entire bitmap represented - by the GraphicsContext. - */ - void drawOffscreenContext(GraphicsContext* ctx, const WebCore::FloatRect*, const WebCore::FloatRect&); - /** Return the clip bounds in local coordinates. It can be an approximation, as long as - the returned bounds completely enclose the actual clip. - */ - FloatRect getClipLocalBounds() const; - /** Gets the bounding box of a path, if it were stroked with the current style - */ - FloatRect getPathBoundingBox(const Path&) const; - /** Determines if a given point is contained in a path stroked with the current style - */ - bool strokeContains(const Path&, const FloatPoint&) const; -#endif + void drawPath(); + void fillPath(); + void strokePath(); // Arc drawing (used by border-radius in CSS) just supports stroking at the moment. void strokeArc(const IntRect&, int startAngle, int angleSpan); - - void fillRect(const IntRect&, const Color&); + + void fillRect(const FloatRect&); void fillRect(const FloatRect&, const Color&); + void fillRect(const FloatRect&, Generator&); void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&); + void clearRect(const FloatRect&); + + void strokeRect(const FloatRect&); void strokeRect(const FloatRect&, float lineWidth); void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver); @@ -202,26 +187,23 @@ namespace WebCore { void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile, CompositeOperator = CompositeSourceOver); -#if PLATFORM(CG) - void setUseLowQualityImageInterpolation(bool = true); - bool useLowQualityImageInterpolation() const; -#else - void setUseLowQualityImageInterpolation(bool = true) {} - bool useLowQualityImageInterpolation() const { return false; } -#endif - void clip(const IntRect&); + void setImageInterpolationQuality(InterpolationQuality); + InterpolationQuality imageInterpolationQuality() const; + + void clip(const FloatRect&); void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight); void addInnerRoundedRectClip(const IntRect&, int thickness); void clipOut(const IntRect&); void clipOutEllipseInRect(const IntRect&); void clipOutRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight); + void clipToImageBuffer(const FloatRect&, const ImageBuffer*); int textDrawingMode(); void setTextDrawingMode(int); void drawText(const TextRun&, const IntPoint&, int from = 0, int to = -1); - void drawBidiText(const TextRun&, const IntPoint&); + void drawBidiText(const TextRun&, const FloatPoint&); void drawHighlightForText(const TextRun&, const IntPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1); FloatRect roundToDevicePixels(const FloatRect&); @@ -239,6 +221,7 @@ namespace WebCore { void endTransparencyLayer(); void setShadow(const IntSize&, int blur, const Color&); + bool getShadow(IntSize&, int&, Color&) const; void clearShadow(); void initFocusRing(int width, int offset); @@ -273,39 +256,101 @@ namespace WebCore { void setUseAntialiasing(bool = true); - void setShouldDelete(bool should_delete); - #if PLATFORM(WIN) - GraphicsContext(HDC); // FIXME: To be removed. + GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed. bool inTransparencyLayer() const; - HDC getWindowsContext(bool supportAlphaBlend = false, const IntRect* = 0); // The passed in rect is used to create a bitmap for compositing inside transparency layers. - void releaseWindowsContext(HDC, bool supportAlphaBlend = false, const IntRect* = 0); // The passed in HDC should be the one handed back by getWindowsContext. + 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. + void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); // The passed in HDC should be the one handed back by getWindowsContext. + + class WindowsBitmap : public Noncopyable { + public: + WindowsBitmap(HDC, IntSize); + ~WindowsBitmap(); + + HDC hdc() const { return m_hdc; } + UInt8* buffer() const { return m_bitmapBuffer; } + unsigned bufferLength() const { return m_bitmapBufferLength; } + IntSize size() const { return m_size; } + unsigned bytesPerRow() const { return m_bytesPerRow; } + + private: + HDC m_hdc; + HBITMAP m_bitmap; + UInt8* m_bitmapBuffer; + unsigned m_bitmapBufferLength; + IntSize m_size; + unsigned m_bytesPerRow; + }; + + WindowsBitmap* createWindowsBitmap(IntSize); + // The bitmap should be non-premultiplied. + void drawWindowsBitmap(WindowsBitmap*, const IntPoint&); #endif -#if PLATFORM(QT) - void setFillRule(WindRule); - PlatformPath* currentPath(); +#if PLATFORM(QT) && defined(Q_WS_WIN) + HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); + void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); #endif -#if PLATFORM(CAIRO) || PLATFORM(SKIA) - void setFillRule(WindRule); +#if PLATFORM(QT) + bool inTransparencyLayer() const; PlatformPath* currentPath(); #endif #if PLATFORM(GTK) - void setGdkDrawable(GdkDrawable*); - GdkDrawable *gdkDrawable() const; + void setGdkExposeEvent(GdkEventExpose*); + GdkDrawable* gdkDrawable() const; + GdkEventExpose* gdkExposeEvent() const; +#endif + +#if PLATFORM(SKIA) + /** platform-specific factory method to return a bitmap graphicscontext, + called by <canvas> when we need to draw offscreen. The caller is + responsible for deleting the pointer. + */ + static GraphicsContext* createOffscreenContext(int width, int height); + + /** Called with a context returned by createOffscreenContext. Draw the underlying + bitmap to the current context. Similar to drawImage(), but this hides how + to extract the bitmap from ctx from the portable code. + If srcRect is NULL, it is assumed that we want to draw the entire bitmap represented + by the GraphicsContext. + */ + void drawOffscreenContext(GraphicsContext* ctx, const WebCore::FloatRect*, const WebCore::FloatRect&); + + /** Return the clip bounds in local coordinates. It can be an approximation, as long as + the returned bounds completely enclose the actual clip. + */ + FloatRect getClipLocalBounds() const; + FloatRect getBoundingBoxForCurrentPath(bool includStroke = false) const; + + /** Determines if a given point is contained in a path stroked with the current style + */ + bool strokeContains(const Path&, const FloatPoint&) const; + + // FIXME: This hack should be removed. + void setShouldDelete(bool should_delete); #endif private: void savePlatformState(); void restorePlatformState(); + void setPlatformTextDrawingMode(int); + void setPlatformFont(const Font& font); + void setPlatformStrokeColor(const Color&); + void setPlatformStrokePattern(Pattern*); + void setPlatformStrokeGradient(Gradient*); void setPlatformStrokeStyle(const StrokeStyle&); void setPlatformStrokeThickness(float); + void setPlatformFillColor(const Color&); - void setPlatformFont(const Font& font); + void setPlatformFillPattern(Pattern*); + void setPlatformFillGradient(Gradient*); + + void setPlatformShadow(const IntSize&, int blur, const Color&); + void clearPlatformShadow(); int focusRingWidth() const; int focusRingOffset() const; @@ -315,7 +360,7 @@ namespace WebCore { static void destroyGraphicsContextPrivate(GraphicsContextPrivate*); GraphicsContextPrivate* m_common; - GraphicsContextPlatformPrivate* m_data; + GraphicsContextPlatformPrivate* m_data; // Deprecated; m_commmon can just be downcasted. To be removed. }; } // namespace WebCore |