Make tst_qquickcanvasitem significant again; fix image size rounding
- the test items must be visible, so that waitForRendering() works - arcTo::test_paint tried to render an out-of-bounds arc, which resulted in rendering nothing. Now renders within the 100x100 canvas. - painted() is not emitted the first time the Canvas is rendered. - Canvas.save() saves relative to the directory from which the test is run, while Canvas.loadImage() loads relative to the test data directory in this autotest (other tests are loading red.png for example). So we need to use absolute paths to test loading and saving in the directory where the executable is. - canvas.getContext('2d').getImageData(8.5, 8.5, 8.5, 8.5) now triggers different rounding behavior in QRectF::toRect(), after qtbase 88e56d0932a3615231adf40d5ae033e742d72c33: it becomes QRect(9,9 8x8). The assert in qt_create_image_data() needs to accommodate that. - Fixed another pedantic warning in qt_create_image_data a few lines above: if it creates the image itself, it needs to round the qreal width and height values. This reverts commita23ee5c0de
and amends424cfef3cc
andd142b2d212
. Task-number: QTBUG-41043 Change-Id: I825c2c5a2bbc8d5324c3ba41a681aa68bc25a159 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
fccffcfabc
commit
2bb382f9c2
|
@ -986,10 +986,11 @@ static QV4::ReturnedValue qt_create_image_data(qreal w, qreal h, QV4::ExecutionE
|
|||
pixelData->setPrototypeOf(p);
|
||||
|
||||
if (image.isNull()) {
|
||||
*pixelData->d()->image = QImage(w, h, QImage::Format_ARGB32);
|
||||
*pixelData->d()->image = QImage(qRound(w), qRound(h), QImage::Format_ARGB32);
|
||||
pixelData->d()->image->fill(0x00000000);
|
||||
} else {
|
||||
Q_ASSERT(image.width()== qRound(w * image.devicePixelRatioF()) && image.height() == qRound(h * image.devicePixelRatioF()));
|
||||
// After qtbase 88e56d0932a3615231adf40d5ae033e742d72c33, the image size can be off by one.
|
||||
Q_ASSERT(qAbs(image.width() - qRound(w * image.devicePixelRatioF())) <= 1 && qAbs(image.height() - qRound(h * image.devicePixelRatioF())) <= 1);
|
||||
*pixelData->d()->image = image.format() == QImage::Format_ARGB32 ? image : image.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ TestCase {
|
|||
when:windowShown
|
||||
width:100
|
||||
height:100
|
||||
visible: true
|
||||
property Component component:CanvasComponent{}
|
||||
function cleanupTestCase() {
|
||||
wait(100) //wait for a short while to make sure no leaked textures
|
||||
|
@ -19,8 +20,8 @@ TestCase {
|
|||
// { tag:"image cooperative", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Cooperative}},
|
||||
{ tag:"image immediate", properties:{width:100, height:100, renderTarget:Canvas.Image, renderStrategy:Canvas.Immediate}},
|
||||
// { tag:"fbo cooperative", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Cooperative}},
|
||||
{ tag:"fbo immediate", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Immediate}},
|
||||
{ tag:"fbo threaded", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Threaded}}
|
||||
{ tag:"fbo immediate", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Immediate}}
|
||||
// { tag:"fbo threaded", properties:{width:100, height:100, renderTarget:Canvas.FramebufferObject, renderStrategy:Canvas.Threaded}} // QTBUG-82675
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -357,7 +357,7 @@ CanvasTestCase {
|
|||
ctx.fillStyle = '#0f0';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, 50);
|
||||
ctx.translate(100, 0);
|
||||
ctx.translate(50, 0);
|
||||
ctx.arcTo(50, 50, 50, 0, 50);
|
||||
ctx.lineTo(-100, 0);
|
||||
ctx.fill();
|
||||
|
@ -367,10 +367,10 @@ CanvasTestCase {
|
|||
comparePixel(ctx, 99,0, 0,255,0,255);
|
||||
comparePixel(ctx, 0,25, 0,255,0,255);
|
||||
comparePixel(ctx, 50,25, 0,255,0,255);
|
||||
comparePixel(ctx, 99,25, 0,255,0,255);
|
||||
comparePixel(ctx, 99,25, 255,0,0,255);
|
||||
comparePixel(ctx, 0,49, 0,255,0,255);
|
||||
comparePixel(ctx, 50,49, 0,255,0,255);
|
||||
comparePixel(ctx, 99,49, 0,255,0,255);
|
||||
comparePixel(ctx, 99,49, 255,0,0,255);
|
||||
}
|
||||
function test_zero(row) {
|
||||
var canvas = createCanvasObject(row);
|
||||
|
|
|
@ -129,12 +129,12 @@ CanvasTestCase {
|
|||
tryCompare(c, "availableChangedCount", 1);
|
||||
|
||||
c.requestPaint();
|
||||
verify(c.save("c.png"));
|
||||
c.loadImage("c.png");
|
||||
wait(200);
|
||||
verify(c.isImageLoaded("c.png"));
|
||||
verify(!c.isImageLoading("c.png"));
|
||||
verify(!c.isImageError("c.png"));
|
||||
var imagePath = applicationDirPath + "/c.png";
|
||||
verify(c.save(imagePath));
|
||||
c.loadImage(imagePath);
|
||||
tryVerify(function() { return c.isImageLoaded(imagePath) })
|
||||
verify(!c.isImageLoading(imagePath));
|
||||
verify(!c.isImageError(imagePath));
|
||||
c.destroy();
|
||||
}
|
||||
|
||||
|
@ -187,28 +187,28 @@ CanvasTestCase {
|
|||
tryCompare(c, "availableChangedCount", 1);
|
||||
//scene graph could be available immediately
|
||||
//in this case, we force waiting a short while until the init paint finished
|
||||
tryCompare(c, "paintedCount", 1);
|
||||
tryCompare(c, "paintedCount", 0);
|
||||
ctx.fillRect(0, 0, c.width, c.height);
|
||||
c.toDataURL();
|
||||
tryCompare(c, "paintedCount", 2);
|
||||
tryCompare(c, "paintedCount", 1);
|
||||
tryCompare(c, "paintCount", 1);
|
||||
// implicit repaint when visible and resized
|
||||
testCase.visible = true;
|
||||
c.width += 1;
|
||||
c.height += 1;
|
||||
tryCompare(c, "paintCount", 2);
|
||||
tryCompare(c, "paintedCount", 2);
|
||||
tryCompare(c, "paintedCount", 1);
|
||||
// allow explicit repaint even when hidden
|
||||
testCase.visible = false;
|
||||
c.requestPaint();
|
||||
tryCompare(c, "paintCount", 3);
|
||||
tryCompare(c, "paintedCount", 2);
|
||||
tryCompare(c, "paintedCount", 1);
|
||||
// no implicit repaint when resized but hidden
|
||||
c.width += 1;
|
||||
c.height += 1;
|
||||
waitForRendering(c);
|
||||
compare(c.paintCount, 3);
|
||||
tryCompare(c, "paintedCount", 2);
|
||||
tryCompare(c, "paintedCount", 1);
|
||||
c.destroy();
|
||||
}
|
||||
function test_loadImage(row) {
|
||||
|
@ -221,8 +221,7 @@ CanvasTestCase {
|
|||
|
||||
verify(!c.isImageLoaded("red.png"));
|
||||
c.loadImage("red.png");
|
||||
wait(200);
|
||||
verify(c.isImageLoaded("red.png"));
|
||||
tryVerify(function() { return c.isImageLoaded("red.png") });
|
||||
verify(!c.isImageLoading("red.png"));
|
||||
verify(!c.isImageError("red.png"));
|
||||
|
||||
|
|
|
@ -55,5 +55,3 @@ OTHER_FILES += \
|
|||
data/yellow75.png \
|
||||
data/tst_invalidContext.qml
|
||||
|
||||
|
||||
CONFIG += insignificant_test # QTBUG-41043
|
||||
|
|
|
@ -46,6 +46,8 @@ public slots:
|
|||
false
|
||||
#endif
|
||||
));
|
||||
engine->rootContext()->setContextProperty("applicationDirPath",
|
||||
QCoreApplication::applicationDirPath());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue