Skip to content

Commit

Permalink
Add more unit tests for qsgcanvasitem and fix unstable tests
Browse files Browse the repository at this point in the history
Change-Id:I5fc11a5874d55ad423dc1fb9c3e1b75a38003465
Reviewed-on: http://codereview.qt-project.org/5962
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Charles Yin <charles.yin@nokia.com>
  • Loading branch information
yinyunqiao authored and Qt by Nokia committed Oct 6, 2011
1 parent 8a1b17f commit fdc8714
Show file tree
Hide file tree
Showing 25 changed files with 6,304 additions and 251 deletions.
33 changes: 19 additions & 14 deletions src/declarative/items/context2d/qsgcanvasitem.cpp
Expand Up @@ -85,7 +85,7 @@ QSGCanvasItemPrivate::QSGCanvasItemPrivate()
, hasTileSize(false)
, hasCanvasWindow(false)
, componentCompleted(false)
, renderTarget(QSGCanvasItem::Image)
, renderTarget(QSGCanvasItem::FramebufferObject)
{
}

Expand Down Expand Up @@ -512,7 +512,9 @@ void QSGCanvasItem::createContext()
QDeclarativeV8Handle QSGCanvasItem::getContext(const QString &contextId)
{
Q_D(QSGCanvasItem);
Q_UNUSED(contextId);

if (contextId.toLower() != QLatin1String("2d"))
return QDeclarativeV8Handle::fromHandle(v8::Undefined());

if (!d->context)
createContext();
Expand Down Expand Up @@ -552,7 +554,9 @@ void QSGCanvasItem::markDirty(const QRectF& region)
*/
bool QSGCanvasItem::save(const QString &filename) const
{
return toImage().save(filename);
Q_D(const QSGCanvasItem);
QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename));
return toImage().save(url.toLocalFile());
}

QImage QSGCanvasItem::loadedImage(const QUrl& url)
Expand Down Expand Up @@ -683,24 +687,25 @@ QString QSGCanvasItem::toDataURL(const QString& mimeType) const
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
QString mime = mimeType;
QString mime = mimeType.toLower();
QString type;
if (mimeType == QLatin1Literal("image/bmp"))
if (mime == QLatin1Literal("image/png")) {
type = QLatin1Literal("PNG");
} else if (mime == QLatin1Literal("image/bmp"))
type = QLatin1Literal("BMP");
else if (mimeType == QLatin1Literal("image/jpeg"))
else if (mime == QLatin1Literal("image/jpeg"))
type = QLatin1Literal("JPEG");
else if (mimeType == QLatin1Literal("image/x-portable-pixmap"))
else if (mime == QLatin1Literal("image/x-portable-pixmap"))
type = QLatin1Literal("PPM");
else if (mimeType == QLatin1Literal("image/tiff"))
else if (mime == QLatin1Literal("image/tiff"))
type = QLatin1Literal("TIFF");
else if (mimeType == QLatin1Literal("image/xbm"))
else if (mime == QLatin1Literal("image/xbm"))
type = QLatin1Literal("XBM");
else if (mimeType == QLatin1Literal("image/xpm"))
else if (mime == QLatin1Literal("image/xpm"))
type = QLatin1Literal("XPM");
else {
type = QLatin1Literal("PNG");
mime = QLatin1Literal("image/png");
}
else
return QLatin1Literal("data:,");

image.save(&buffer, type.toAscii());
buffer.close();
QString dataUrl = QLatin1Literal("data:%1;base64,%2");
Expand Down

0 comments on commit fdc8714

Please sign in to comment.