Reviewed by Zack and Darin
Fix the Qt build again after the latest Image changes.
Also make some of the methods implemented in ImageCG
crossplatform.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18911 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9351ac4..45c270f 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2007-01-17 Lars Knoll <lars@trolltech.com>
+
+ Reviewed by Zack and Darin
+
+ Fix the Qt build again after the latest Image changes.
+ Also make some of the methods implemented in ImageCG
+ crossplatform.
+
+ * platform/graphics/BitmapImage.h:
+ * platform/graphics/Image.cpp:
+ (WebCore::Image::fillWithSolidColor):
+ (WebCore::calculatePatternScale):
+ (WebCore::Image::drawTiled):
+ * platform/graphics/Image.h:
+ * platform/graphics/cg/ImageCG.cpp:
+ (WebCore::BitmapImage::draw):
+ * platform/graphics/qt/ImageQt.cpp:
+ (WebCore::Image::loadPlatformResource):
+ (WebCore::Image::drawPattern):
+ (WebCore::BitmapImage::initPlatformData):
+ (WebCore::BitmapImage::invalidatePlatformData):
+ (WebCore::BitmapImage::draw):
+ (WebCore::BitmapImage::drawPattern):
+ * platform/qt/TemporaryLinkStubs.cpp:
+
2007-01-17 Darin Adler <darin@apple.com>
- quick attempt to fix the Qt build
diff --git a/WebCore/platform/graphics/BitmapImage.h b/WebCore/platform/graphics/BitmapImage.h
index 8ae38d3..5e00b02 100644
--- a/WebCore/platform/graphics/BitmapImage.h
+++ b/WebCore/platform/graphics/BitmapImage.h
@@ -119,7 +119,10 @@
private:
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
-
+#if PLATFORM(QT)
+ virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
+ const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
+#endif
size_t currentFrame() const { return m_currentFrame; }
size_t frameCount();
NativeImagePtr frameAtIndex(size_t);
diff --git a/WebCore/platform/graphics/Image.cpp b/WebCore/platform/graphics/Image.cpp
index a156ce6..9e2c21b 100644
--- a/WebCore/platform/graphics/Image.cpp
+++ b/WebCore/platform/graphics/Image.cpp
@@ -27,9 +27,13 @@
#include "config.h"
#include "Image.h"
+#include "AffineTransform.h"
+#include "GraphicsContext.h"
#include "IntRect.h"
#include "MimeTypeRegistry.h"
+#include <math.h>
+
#if PLATFORM(CG)
#include <CoreFoundation/CoreFoundation.h>
#endif
@@ -98,4 +102,100 @@
return size().height();
}
+void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op)
+{
+ if (color.alpha() <= 0)
+ return;
+
+ ctxt->save();
+ ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
+ ctxt->fillRect(dstRect, color);
+ ctxt->restore();
+}
+
+static inline FloatSize calculatePatternScale(const FloatRect& dstRect, const FloatRect& srcRect, Image::TileRule hRule, Image::TileRule vRule)
+{
+ float scaleX = 1.0f, scaleY = 1.0f;
+
+ if (hRule == Image::StretchTile)
+ scaleX = dstRect.width() / srcRect.width();
+ if (vRule == Image::StretchTile)
+ scaleY = dstRect.height() / srcRect.height();
+
+ if (hRule == Image::RepeatTile)
+ scaleX = scaleY;
+ if (vRule == Image::RepeatTile)
+ scaleY = scaleX;
+
+ return FloatSize(scaleX, scaleY);
+}
+
+
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, CompositeOperator op)
+{
+ if (!nativeImageForCurrentFrame())
+ return;
+
+ if (mayFillWithSolidColor()) {
+ fillWithSolidColor(ctxt, destRect, solidColor(), op);
+ return;
+ }
+
+ FloatSize intrinsicTileSize = size();
+ FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
+ scaledTileSize.height() / intrinsicTileSize.height());
+ AffineTransform patternTransform = AffineTransform().scale(scale.width(), scale.height());
+
+ FloatRect oneTileRect;
+ oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), scaledTileSize.width()) - scaledTileSize.width(), scaledTileSize.width()));
+ oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), scaledTileSize.height()) - scaledTileSize.height(), scaledTileSize.height()));
+ oneTileRect.setSize(scaledTileSize);
+
+ // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
+ if (oneTileRect.contains(destRect)) {
+ FloatRect visibleSrcRect;
+ visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
+ visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
+ visibleSrcRect.setWidth(destRect.width() / scale.width());
+ visibleSrcRect.setHeight(destRect.height() / scale.height());
+ draw(ctxt, destRect, visibleSrcRect, op);
+ return;
+ }
+
+ FloatRect tileRect(FloatPoint(), intrinsicTileSize);
+ drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), op, destRect);
+
+ startAnimation();
+}
+
+// FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things.
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator op)
+{
+ if (!nativeImageForCurrentFrame())
+ return;
+
+ if (mayFillWithSolidColor()) {
+ fillWithSolidColor(ctxt, dstRect, solidColor(), op);
+ return;
+ }
+
+ FloatSize scale = calculatePatternScale(dstRect, srcRect, hRule, vRule);
+ AffineTransform patternTransform = AffineTransform().scale(scale.width(), scale.height());
+
+ // We want to construct the phase such that the pattern is centered (when stretch is not
+ // set for a particular rule).
+ float hPhase = scale.width() * srcRect.x();
+ float vPhase = scale.height() * (srcRect.height() - srcRect.y());
+ if (hRule == Image::RepeatTile)
+ hPhase -= fmodf(dstRect.width(), scale.width() * srcRect.width()) / 2.0f;
+ if (vRule == Image::RepeatTile)
+ vPhase -= fmodf(dstRect.height(), scale.height() * srcRect.height()) / 2.0f;
+ FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase);
+
+ drawPattern(ctxt, srcRect, patternTransform, patternPhase, op, dstRect);
+
+ startAnimation();
+}
+
+
}
diff --git a/WebCore/platform/graphics/Image.h b/WebCore/platform/graphics/Image.h
index 5197a58..9a744a4 100644
--- a/WebCore/platform/graphics/Image.h
+++ b/WebCore/platform/graphics/Image.h
@@ -107,11 +107,14 @@
virtual bool getHBITMAP(HBITMAP) { return false; }
#endif
+protected:
+ static void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op);
+
private:
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator) = 0;
void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator);
void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator);
-
+
// Supporting tiled drawing
virtual bool mayFillWithSolidColor() const { return false; }
virtual Color solidColor() const { return Color(); }
@@ -120,11 +123,11 @@
virtual void startAnimation() { }
+ virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
+ const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
#if PLATFORM(CG)
// These are private to CG. Ideally they would be only in the .cpp file, but the callback requires access
// to the private function nativeImageForCurrentFrame()
- void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
- const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
static void drawPatternCallback(void* info, CGContext*);
#endif
diff --git a/WebCore/platform/graphics/cg/ImageCG.cpp b/WebCore/platform/graphics/cg/ImageCG.cpp
index 4c38dcf..c45b646 100644
--- a/WebCore/platform/graphics/cg/ImageCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageCG.cpp
@@ -88,17 +88,6 @@
return frameAtIndex(0);
}
-void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op)
-{
- if (color.alpha() <= 0)
- return;
-
- ctxt->save();
- ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
- ctxt->fillRect(dstRect, color);
- ctxt->restore();
-}
-
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp)
{
if (!m_source.initialized())
@@ -214,88 +203,6 @@
CGPatternRelease(pattern);
}
-static inline FloatSize caculatePatternScale(const FloatRect& dstRect, const FloatRect& srcRect, Image::TileRule hRule, Image::TileRule vRule)
-{
- float scaleX = 1.0f, scaleY = 1.0f;
-
- if (hRule == Image::StretchTile)
- scaleX = dstRect.width() / srcRect.width();
- if (vRule == Image::StretchTile)
- scaleY = dstRect.height() / srcRect.height();
-
- if (hRule == Image::RepeatTile)
- scaleX = scaleY;
- if (vRule == Image::RepeatTile)
- scaleY = scaleX;
-
- return FloatSize(scaleX, scaleY);
-}
-
-void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, CompositeOperator op)
-{
- if (!nativeImageForCurrentFrame())
- return;
-
- if (mayFillWithSolidColor()) {
- fillWithSolidColor(ctxt, destRect, solidColor(), op);
- return;
- }
-
- FloatSize intrinsicTileSize = size();
- FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
- scaledTileSize.height() / intrinsicTileSize.height());
- AffineTransform patternTransform = AffineTransform().scale(scale.width(), scale.height());
-
- FloatRect oneTileRect;
- oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), scaledTileSize.width()) - scaledTileSize.width(), scaledTileSize.width()));
- oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), scaledTileSize.height()) - scaledTileSize.height(), scaledTileSize.height()));
- oneTileRect.setSize(scaledTileSize);
-
- // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
- if (oneTileRect.contains(destRect)) {
- FloatRect visibleSrcRect;
- visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
- visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
- visibleSrcRect.setWidth(destRect.width() / scale.width());
- visibleSrcRect.setHeight(destRect.height() / scale.height());
- draw(ctxt, destRect, visibleSrcRect, op);
- return;
- }
-
- FloatRect tileRect(FloatPoint(), intrinsicTileSize);
- drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), op, destRect);
-
- startAnimation();
-}
-
-// FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things.
-void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator op)
-{
- if (!nativeImageForCurrentFrame())
- return;
-
- if (mayFillWithSolidColor()) {
- fillWithSolidColor(ctxt, dstRect, solidColor(), op);
- return;
- }
-
- FloatSize scale = caculatePatternScale(dstRect, srcRect, hRule, vRule);
- AffineTransform patternTransform = AffineTransform().scale(scale.width(), scale.height());
-
- // We want to construct the phase such that the pattern is centered (when stretch is not
- // set for a particular rule).
- float hPhase = scale.width() * srcRect.x();
- float vPhase = scale.height() * (srcRect.height() - srcRect.y());
- if (hRule == Image::RepeatTile)
- hPhase -= fmodf(dstRect.width(), scale.width() * srcRect.width()) / 2.0f;
- if (vRule == Image::RepeatTile)
- vPhase -= fmodf(dstRect.height(), scale.height() * srcRect.height()) / 2.0f;
- FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase);
-
- drawPattern(ctxt, srcRect, patternTransform, patternPhase, op, dstRect);
-
- startAnimation();
-}
}
diff --git a/WebCore/platform/graphics/qt/ImageQt.cpp b/WebCore/platform/graphics/qt/ImageQt.cpp
index f062bc9..82b04e8 100644
--- a/WebCore/platform/graphics/qt/ImageQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageQt.cpp
@@ -34,16 +34,20 @@
#include "FloatRect.h"
#include "PlatformString.h"
#include "GraphicsContext.h"
+#include "AffineTransform.h"
#include <QPixmap>
#include <QPainter>
#include <QImage>
#include <QImageReader>
+#include <QTransform>
-#include <QtDebug>
+#include <QDebug>
#include <math.h>
+#define notImplemented() qDebug("FIXME: UNIMPLEMENTED: %s:%d (%s)", __FILE__, __LINE__, __FUNCTION__)
+
// This function loads resources from WebKit
Vector<char> loadResourceIntoArray(const char*);
@@ -58,18 +62,12 @@
}
}
+
+
// ================================================
// Image Class
// ================================================
-void BitmapImage::initPlatformData()
-{
-}
-
-void BitmapImage::invalidatePlatformData()
-{
-}
-
Image* Image::loadPlatformResource(const char* name)
{
Vector<char> arr = loadResourceIntoArray(name);
@@ -78,16 +76,34 @@
return img;
}
+
+void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
+ const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
+{
+ notImplemented();
+}
+
+
+void BitmapImage::initPlatformData()
+{
+}
+
+void BitmapImage::invalidatePlatformData()
+{
+}
+
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
- const FloatRect& src, CompositeOperator op)
+ const FloatRect& src, CompositeOperator op)
{
- if (!m_source.initialized())
+ QPixmap* image = nativeImageForCurrentFrame();
+ if (!image)
return;
-
- QPixmap* image = frameAtIndex(m_currentFrame);
- if (!image) // If it's too early we won't have an image yet.
+
+ if (mayFillWithSolidColor()) {
+ fillWithSolidColor(ctxt, dst, solidColor(), op);
return;
+ }
IntSize selfSize = size();
FloatRect srcRect(src);
@@ -109,50 +125,30 @@
startAnimation();
}
-void BitmapImage::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatPoint& srcPoint,
- const FloatSize& tileSize, CompositeOperator op)
+void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
+ const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
- if (!m_source.initialized())
+ QPixmap* framePixmap = nativeImageForCurrentFrame();
+ if (!framePixmap) // If it's too early we won't have an image yet.
return;
-
- QPixmap* image = frameAtIndex(m_currentFrame);
- QPixmap pix;
- if (!image) // If it's too early we won't have an image yet.
- return;
-
- IntSize intrinsicImageSize = size();
-
- if (!qFuzzyCompare(tileSize.width(), intrinsicImageSize.width()) ||
- !qFuzzyCompare(tileSize.height(), intrinsicImageSize.height())) {
-
- QPixmap img((int)tileSize.width(), (int)tileSize.height());
-
- QPainter p(&img);
- p.drawPixmap(QRectF(0, 0, tileSize.width(), tileSize.height()),
- *image, QRectF(srcPoint.x(), srcPoint.y(),
- tileSize.width() - srcPoint.x(),
- tileSize.height()- srcPoint.y()));
- p.end();
-
- pix = img;
- }
-
+
+ QPixmap pixmap = *framePixmap;
+ QRect tr = QRectF(tileRect).toRect();
+ if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
+ pixmap = pixmap.copy(tr);
+
+ QBrush b(pixmap);
+ b.setMatrix(patternTransform);
+
ctxt->save();
-
+
// Set the compositing operation.
ctxt->setCompositeOperation(op);
QPainter* p = ctxt->platformContext();
- p->drawTiledPixmap(dstRect, pix);
-
- ctxt->restore();
+ p->setBrushOrigin(phase);
+ p->fillRect(tileRect, b);
- startAnimation();
-}
-
-void BitmapImage::drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect,
- CompositeOperator op)
-{
- // FIXME: no implemented
+ ctxt->restore();
}
void BitmapImage::checkForSolidColor()
diff --git a/WebCore/platform/qt/TemporaryLinkStubs.cpp b/WebCore/platform/qt/TemporaryLinkStubs.cpp
index 4643985..5f87627 100644
--- a/WebCore/platform/qt/TemporaryLinkStubs.cpp
+++ b/WebCore/platform/qt/TemporaryLinkStubs.cpp
@@ -77,8 +77,6 @@
Color WebCore::focusRingColor() { notImplemented(); return 0xFF0000FF; }
-void Image::drawTiled(GraphicsContext*, const FloatRect&, const FloatRect&, TileRule, TileRule, CompositeOperator) { notImplemented(); }
-
namespace WebCore {
Scrollbar::Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize) { notImplemented(); }