Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/memorychecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ void MemoryChecker::sGetFreeKB(intKB& procFreeKB,
(task_info_t)&vm_info,
&vm_info_count) == KERN_SUCCESS) {
bytes_in_use_by_app = vm_info.phys_footprint;
} else {
task_basic_info_data_t basic_info;
mach_msg_type_number_t basic_info_count = TASK_BASIC_INFO_COUNT;
if (task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&basic_info,
&basic_info_count) == KERN_SUCCESS) {
bytes_in_use_by_app = basic_info.resident_size;
} else {
RuntimeThrow("Could not retrieve process memory usage");
}
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions src/core/Boxes/boundingbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ void BoundingBox::planUpdate(const UpdateReason reason) {
if(reason == UpdateReason::userChange) {
mStateId++;
mRenderDataHandler.clear();
if(const auto canvas = enve_cast<Canvas*>(this)) {
canvas->invalidateSceneFramesCache();
}
}

mDrawRenderContainer.setExpired(true);
Expand Down
2 changes: 1 addition & 1 deletion src/core/CacheHandlers/hddcachablecachehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CORE_EXPORT HddCachableCacheHandler {
}

auto begin() const { return mConts.begin(); }
auto end() const { return mConts.begin(); }
auto end() const { return mConts.end(); }
private:
RangeMap<stdsptr<Cont>> mConts;
UsedRange mUsedRange;
Expand Down
18 changes: 18 additions & 0 deletions src/core/CacheHandlers/hddcachablecont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ eTask *HddCachableCont::scheduleDeleteTmpFile() {
eTask *HddCachableCont::scheduleSaveToTmpFile() {
if(mTmpSaveTask || mTmpFile) return nullptr;
mTmpSaveTask = createTmpFileDataSaver();
if(!mTmpSaveTask) {
tmpFileSaveFailed();
return nullptr;
}
mTmpSaveTask->queTask();
return mTmpSaveTask.get();
}
Expand All @@ -59,6 +63,10 @@ eTask *HddCachableCont::scheduleLoadFromTmpFile() {
if(!mTmpSaveTask && !mTmpFile) return nullptr;

mTmpLoadTask = createTmpFileDataLoader();
if(!mTmpLoadTask) {
tmpFileLoadFailed();
return nullptr;
}
if(mTmpSaveTask)
mTmpSaveTask->addDependent(mTmpLoadTask.get());
mTmpLoadTask->queTask();
Expand All @@ -70,6 +78,16 @@ void HddCachableCont::setDataSavedToTmpFile(const qsptr<QTemporaryFile> &tmpFile
mTmpFile = tmpFile;
}

void HddCachableCont::tmpFileSaveFailed() {
mTmpSaveTask.reset();
if(!mDataInMemory && !mTmpFile) noDataLeft_k();
}

void HddCachableCont::tmpFileLoadFailed() {
mTmpLoadTask.reset();
if(!mDataInMemory && !mTmpFile && !mTmpSaveTask) noDataLeft_k();
}

void HddCachableCont::afterDataLoadedFromTmpFile() {
setDataInMemory(true);
mTmpLoadTask.reset();
Expand Down
2 changes: 2 additions & 0 deletions src/core/CacheHandlers/hddcachablecont.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CORE_EXPORT HddCachableCont : public CacheContainer {
eTask* scheduleLoadFromTmpFile();

void setDataSavedToTmpFile(const qsptr<QTemporaryFile> &tmpFile);
void tmpFileSaveFailed();
void tmpFileLoadFailed();

bool storesDataInMemory() const { return mDataInMemory; }
qsptr<QTemporaryFile> getTmpFile() const { return mTmpFile; }
Expand Down
5 changes: 5 additions & 0 deletions src/core/CacheHandlers/imagecachecontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ int ImageCacheContainer::getByteCount() {
}

void ImageCacheContainer::setDataLoadedFromTmpFile(const sk_sp<SkImage> &img) {
if(!img) {
tmpFileLoadFailed();
return;
}
replaceImage(img);
afterDataLoadedFromTmpFile();
}
Expand All @@ -58,6 +62,7 @@ int ImageCacheContainer::clearMemory() {
}

stdsptr<eHddTask> ImageCacheContainer::createTmpFileDataSaver() {
if(!getImage()) return nullptr;
return enve::make_shared<ImgSaver>(this, getImage());
}

Expand Down
1 change: 1 addition & 0 deletions src/core/CacheHandlers/imagecachecontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CORE_EXPORT ImgSaver : public TmpSaver {
TmpSaver(target), mImage(image) {}

void write(eWriteStream& dst) {
if(!mImage) return;
SkiaHelpers::writeImg(mImage, dst);
}
private:
Expand Down
1 change: 1 addition & 0 deletions src/core/CacheHandlers/soundcachecontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SoundCacheContainer::SoundCacheContainer(const stdsptr<Samples>& samples,
}

stdsptr<eHddTask> SoundCacheContainer::createTmpFileDataSaver() {
if(!mSamples) return nullptr;
return enve::make_shared<SoundContainerTmpFileDataSaver>(mSamples, this);
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/CacheHandlers/soundtmpfilehandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ void SoundContainerTmpFileDataLoader::read(eReadStream& src) {
}

void SoundContainerTmpFileDataLoader::afterProcessing() {
if(!mSamples) {
if(mTarget) mTarget->tmpFileLoadFailed();
return;
}
mTarget->setDataLoadedFromTmpFile(mSamples);
}

Expand All @@ -45,5 +49,6 @@ SoundContainerTmpFileDataSaver::SoundContainerTmpFileDataSaver(
TmpSaver(target), mSamples(samples) {}

void SoundContainerTmpFileDataSaver::write(eWriteStream& dst) {
if(!mSamples) return;
mSamples->write(dst);
}
2 changes: 1 addition & 1 deletion src/core/CacheHandlers/tmploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TmpLoader::TmpLoader(const qsptr<QTemporaryFile> &file,
mTmpFile(file), mTarget(target) {}

void TmpLoader::process() {
if(!mTmpFile) return;
if(!mTmpFile) RuntimeThrow("Temporary cache file is missing.");
if(mTmpFile->open()) {
eReadStream src(mTmpFile.get());
read(src);
Expand Down
17 changes: 15 additions & 2 deletions src/core/CacheHandlers/tmpsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@
// Fork of enve - Copyright (C) 2016-2020 Maurycy Liebner

#include "tmpsaver.h"
#include "appsupport.h"

#include <QDir>

TmpSaver::TmpSaver(HddCachableCont* const target) :
mTarget(target) {}

void TmpSaver::process() {
mTmpFile = qsptr<QTemporaryFile>(new QTemporaryFile());
QDir().mkpath(AppSupport::getAppTempPath());
const QString templ = AppSupport::getAppTempPath() +
"/friction-cache-XXXXXX.tmp";
mTmpFile = qsptr<QTemporaryFile>(new QTemporaryFile(templ));
if(mTmpFile->open()) {
eWriteStream dst(mTmpFile.get());
write(dst);
Expand All @@ -42,6 +48,13 @@ void TmpSaver::process() {

void TmpSaver::afterProcessing() {
if(!mTarget) return;
if(!mSavingSuccessful) return;
if(!mSavingSuccessful) {
mTarget->tmpFileSaveFailed();
return;
}
mTarget->setDataSavedToTmpFile(mTmpFile);
}

void TmpSaver::afterCanceled() {
if(mTarget) mTarget->tmpFileSaveFailed();
}
1 change: 1 addition & 0 deletions src/core/CacheHandlers/tmpsaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CORE_EXPORT TmpSaver : public eHddTask {

void process();
void afterProcessing();
void afterCanceled();
private:
const stdptr<HddCachableCont> mTarget;
bool mSavingSuccessful = false;
Expand Down
10 changes: 10 additions & 0 deletions src/core/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,21 @@ qreal Canvas::getResolution() const

void Canvas::setResolution(const qreal percent)
{
if(isZero6Dec(mResolution - percent)) return;
mResolution = percent;
invalidateSceneFramesCache();
prp_afterWholeInfluenceRangeChanged();
updateAllBoxes(UpdateReason::userChange);
}

void Canvas::invalidateSceneFramesCache()
{
mSceneFrame.reset();
mLoadingSceneFrame.reset();
mSceneFrameOutdated = true;
mSceneFramesHandler.clear();
}

void Canvas::setCurrentGroupParentAsCurrentGroup()
{
setCurrentBoxesGroup(mCurrentContainer->getParentGroup());
Expand Down
1 change: 1 addition & 0 deletions src/core/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class CORE_EXPORT Canvas : public CanvasBase
void setWorldToScreen(const QTransform& transform,
qreal devicePixelRatio);
void setResolution(const qreal percent);
void invalidateSceneFramesCache();

void applyCurrentTransformToSelected();
QPointF getSelectedPointsAbsPivotPos();
Expand Down
21 changes: 13 additions & 8 deletions src/core/videoencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,14 @@ static void addVideoStream(OutputStream * const ost,
static AVFrame *getVideoFrame(OutputStream * const ost,
const sk_sp<SkImage> &image)
{
AVCodecContext *c = ost->fCodec;
if(!image) RuntimeThrow("Missing image for video frame");

if (c->width != image->width() || c->height != image->height()) {
RuntimeThrow("Image size don't match codec size");
}
AVCodecContext *c = ost->fCodec;

/* rely on cache manager to produce fSwsCtx if it hasn't already
* been produced. */
ost->fSwsCtx = sws_getCachedContext(ost->fSwsCtx,
c->width, c->height,
image->width(), image->height(),
AV_PIX_FMT_RGBA,
c->width, c->height,
c->pix_fmt, SWS_BICUBIC,
Expand All @@ -297,7 +295,13 @@ static AVFrame *getVideoFrame(OutputStream * const ost,
SkPixmap pixmap;
SkBitmap unpremulBitmap;

image->peekPixels(&pixmap);
sk_sp<SkImage> rasterImage;
if(!image->peekPixels(&pixmap)) {
rasterImage = image->makeRasterImage();
if(!rasterImage || !rasterImage->peekPixels(&pixmap)) {
RuntimeThrow("Could not peek image pixels");
}
}

// check if we need to convert to "unpremultiplied"
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->pix_fmt);
Expand All @@ -323,12 +327,13 @@ static AVFrame *getVideoFrame(OutputStream * const ost,
const uint8_t * const dstSk[] = {static_cast<uint8_t*>(pixmap.writable_addr())};
int linesizesSk[4];

av_image_fill_linesizes(linesizesSk, AV_PIX_FMT_RGBA, image->width());
av_image_fill_linesizes(linesizesSk, AV_PIX_FMT_RGBA, pixmap.width());
linesizesSk[0] = static_cast<int>(pixmap.rowBytes());
const int ret = av_frame_make_writable(ost->fDstFrame) ;
if (ret < 0) { AV_RuntimeThrow(ret, "Could not make AVFrame writable") }

sws_scale(ost->fSwsCtx, dstSk,
linesizesSk, 0, c->height,
linesizesSk, 0, pixmap.height(),
ost->fDstFrame->data,
ost->fDstFrame->linesize);

Expand Down
Loading