File indexing completed on 2024-12-22 04:12:50
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Jouni Pentikäinen <joupent@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_animation_frame_cache_test.h" 0008 0009 #include <simpletest.h> 0010 #include <testutil.h> 0011 0012 #include "kis_animation_frame_cache.h" 0013 #include "kis_image_animation_interface.h" 0014 #include "opengl/kis_opengl_image_textures.h" 0015 #include "kis_time_span.h" 0016 #include "kis_keyframe_channel.h" 0017 #include "kistest.h" 0018 0019 #include "kundo2command.h" 0020 0021 void verifyRangeIsCachedStatus(KisAnimationFrameCacheSP cache, int start, int end, KisAnimationFrameCache::CacheStatus status) 0022 { 0023 for (int t = start; t <= end; t++) { 0024 QVERIFY2( 0025 cache->frameStatus(t) == status, 0026 qPrintable(QString("Expected status %1 for frame %2 in range %3 to %4").arg(status == KisAnimationFrameCache::Cached ? "Cached" : "Uncached").arg(t).arg(start).arg(end)) 0027 ); 0028 } 0029 } 0030 0031 void KisAnimationFrameCacheTest::testCache() 0032 { 0033 TestUtil::MaskParent p; 0034 KisImageSP image = p.image; 0035 KisImageAnimationInterface *animation = image->animationInterface(); 0036 KisPaintLayerSP layer1 = p.layer; 0037 KisPaintLayerSP layer2 = new KisPaintLayer(p.image, "", OPACITY_OPAQUE_U8); 0038 KisPaintLayerSP layer3 = new KisPaintLayer(p.image, "", OPACITY_OPAQUE_U8); 0039 image->addNode(layer2); 0040 image->addNode(layer3); 0041 0042 KUndo2Command parentCommand; 0043 0044 KisKeyframeChannel *rasterChannel2 = layer2->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true); 0045 rasterChannel2->addKeyframe(10, &parentCommand); 0046 rasterChannel2->addKeyframe(20, &parentCommand); 0047 rasterChannel2->addKeyframe(30, &parentCommand); 0048 0049 KisKeyframeChannel *rasterChannel3 = layer2->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true); 0050 rasterChannel3->addKeyframe(17, &parentCommand); 0051 0052 KisOpenGLImageTexturesSP glTex = KisOpenGLImageTextures::getImageTextures(image, 0, KoColorConversionTransformation::IntentPerceptual, KoColorConversionTransformation::Empty); 0053 KisAnimationFrameCacheSP cache = new KisAnimationFrameCache(glTex); 0054 glTex->testingForceInitialized(); 0055 0056 m_globalAnimationCache = cache.data(); 0057 connect(animation, SIGNAL(sigFrameReady(int)), this, SLOT(slotFrameGenerationFinished(int))); 0058 0059 int t; 0060 animation->saveAndResetCurrentTime(11, &t); 0061 animation->notifyFrameReady(); 0062 0063 QCOMPARE(cache->frameStatus(9), KisAnimationFrameCache::Uncached); 0064 verifyRangeIsCachedStatus(cache, 10, 16, KisAnimationFrameCache::Cached); 0065 QCOMPARE(cache->frameStatus(17), KisAnimationFrameCache::Uncached); 0066 0067 animation->saveAndResetCurrentTime(30, &t); 0068 animation->notifyFrameReady(); 0069 0070 QCOMPARE(cache->frameStatus(29), KisAnimationFrameCache::Uncached); 0071 verifyRangeIsCachedStatus(cache, 30, 40, KisAnimationFrameCache::Cached); 0072 QCOMPARE(cache->frameStatus(9999), KisAnimationFrameCache::Cached); 0073 0074 image->invalidateFrames(KisTimeSpan::fromTimeToTime(10, 12), QRect()); 0075 verifyRangeIsCachedStatus(cache, 10, 12, KisAnimationFrameCache::Uncached); 0076 verifyRangeIsCachedStatus(cache, 13, 16, KisAnimationFrameCache::Cached); 0077 0078 image->invalidateFrames(KisTimeSpan::fromTimeToTime(15, 20), QRect()); 0079 verifyRangeIsCachedStatus(cache, 13, 14, KisAnimationFrameCache::Cached); 0080 verifyRangeIsCachedStatus(cache, 15, 20, KisAnimationFrameCache::Uncached); 0081 0082 image->invalidateFrames(KisTimeSpan::infinite(100), QRect()); 0083 verifyRangeIsCachedStatus(cache, 90, 99, KisAnimationFrameCache::Cached); 0084 verifyRangeIsCachedStatus(cache, 100, 110, KisAnimationFrameCache::Uncached); 0085 0086 image->invalidateFrames(KisTimeSpan::fromTimeToTime(90, 100), QRect()); 0087 verifyRangeIsCachedStatus(cache, 80, 89, KisAnimationFrameCache::Cached); 0088 verifyRangeIsCachedStatus(cache, 90, 100, KisAnimationFrameCache::Uncached); 0089 0090 image->invalidateFrames(KisTimeSpan::infinite(14), QRect()); 0091 QCOMPARE(cache->frameStatus(13), KisAnimationFrameCache::Cached); 0092 verifyRangeIsCachedStatus(cache, 15, 100, KisAnimationFrameCache::Uncached); 0093 0094 } 0095 0096 void KisAnimationFrameCacheTest::slotFrameGenerationFinished(int time) 0097 { 0098 KisImageSP image = m_globalAnimationCache->image(); 0099 KisOpenGLUpdateInfoSP info = m_globalAnimationCache->fetchFrameData(time, image, KisRegion(image->bounds())); 0100 m_globalAnimationCache->addConvertedFrameData(info, time); 0101 0102 } 0103 0104 KISTEST_MAIN(KisAnimationFrameCacheTest)