Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some crash issues. #2540

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"url": "${PAG_GROUP}/tgfx.git",
"commit": "9d6b7464dd22e3a0aa9aa22e0a789cbfed1fed73",
"commit": "57dea46bc27c4815af6fcb14d47eb5faa9cfe360",
"dir": "third_party/tgfx"
},
{
Expand Down
26 changes: 14 additions & 12 deletions src/platform/ios/PAGImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,13 @@ - (BOOL)setPath:(NSString*)newPath {

- (BOOL)setPath:(NSString*)path maxFrameRate:(float)maxFrameRate {
std::lock_guard<std::mutex> autoLock(imageViewLock);
if ([filePath isEqualToString:path]) {
return YES;
}
if (filePath) {
[filePath release];
filePath = nil;
if (![filePath isEqualToString:path]) {
if (filePath != nil) {
[filePath release];
filePath = nil;
}
filePath = [path retain];
}
filePath = [path retain];
PAGFile* file = [PAGFile Load:path];
[self setCompositionInternal:file maxFrameRate:maxFrameRate];
return file != nil;
Expand All @@ -519,14 +518,17 @@ - (void)setPathAsync:(NSString*)path completionBlock:(void (^)(PAGFile*))callbac
- (void)setPathAsync:(NSString*)path
maxFrameRate:(float)maxFrameRate
completionBlock:(void (^)(PAGFile*))callback {
if (filePath != nil) {
[filePath release];
filePath = nil;
if (![filePath isEqualToString:path]) {
if (filePath != nil) {
[filePath release];
filePath = nil;
}
filePath = [path retain];
}
filePath = [path retain];
[PAGFile LoadAsync:path
completionBlock:^(PAGFile* pagFile) {
[self setComposition:pagFile maxFrameRate:maxFrameRate];
std::lock_guard<std::mutex> autoLock(imageViewLock);
[self setCompositionInternal:pagFile maxFrameRate:maxFrameRate];
callback(pagFile);
}];
}
Expand Down
35 changes: 18 additions & 17 deletions src/platform/ios/PAGView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@implementation PAGView {
PAGPlayer* pagPlayer;
PAGSurface* pagSurface;
PAGFile* pagFile;
NSString* filePath;
PAGAnimator* animator;
BOOL _isVisible;
Expand All @@ -40,7 +39,6 @@ - (instancetype)initWithFrame:(CGRect)frame {

- (void)initPAG {
_isVisible = FALSE;
pagFile = nil;
filePath = nil;
self.contentScaleFactor = [UIScreen mainScreen].scale;
self.backgroundColor = [UIColor clearColor];
Expand All @@ -65,7 +63,6 @@ - (void)dealloc {
[animator release];
[pagPlayer release];
[pagSurface release];
[pagFile release];
[filePath release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
Expand Down Expand Up @@ -199,25 +196,29 @@ - (NSString*)getPath {
}

- (BOOL)setPath:(NSString*)path {
if (filePath != nil) {
[filePath release];
filePath = nil;
if (![filePath isEqualToString:path]) {
if (filePath != nil) {
[filePath release];
filePath = nil;
}
filePath = [path retain];
}
PAGFile* file = [PAGFile Load:path];
[self setComposition:file];
filePath = [path retain];
[self setCompositionInternal:file];
return file != nil;
}

- (void)setPathAsync:(NSString*)path completionBlock:(void (^)(PAGFile*))callback {
if (filePath != nil) {
[filePath release];
filePath = nil;
if (![filePath isEqualToString:path]) {
if (filePath != nil) {
[filePath release];
filePath = nil;
}
filePath = [path retain];
}
filePath = [path retain];
[PAGFile LoadAsync:path
completionBlock:^(PAGFile* file) {
[self setComposition:file];
[self setCompositionInternal:file];
callback(file);
}];
}
Expand All @@ -231,10 +232,10 @@ - (void)setComposition:(PAGComposition*)newComposition {
[filePath release];
filePath = nil;
}
if (pagFile != nil) {
[pagFile release];
pagFile = nil;
}
[self setCompositionInternal:newComposition];
}

- (void)setCompositionInternal:(PAGComposition*)newComposition {
[pagPlayer setComposition:newComposition];
[animator setProgress:[pagPlayer getProgress]];
if (_isVisible) {
Expand Down
4 changes: 4 additions & 0 deletions src/rendering/caches/DiskCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "DiskCache.h"
#include <filesystem>
#include "pag/pag.h"
#include "platform/Platform.h"
#include "rendering/utils/Directory.h"
Expand Down Expand Up @@ -73,6 +74,9 @@ DiskCache::DiskCache() {
if (!cacheDir.empty()) {
configPath = Directory::JoinPath(cacheDir, "cache.cfg");
cacheFolder = Directory::JoinPath(cacheDir, "files");
if (!std::filesystem::exists(cacheFolder)) {
Directory::CreateRecursively(cacheFolder);
}
if (!readConfig()) {
Directory::VisitFiles(cacheFolder,
[&](const std::string& path, size_t) { remove(path.c_str()); });
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/caches/RenderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ void RenderCache::beginFrame() {
}

void RenderCache::attachToContext(tgfx::Context* current, bool forDrawing) {
if (deviceID > 0 && deviceID != current->device()->uniqueID()) {
if (contextID > 0 && contextID != current->uniqueID()) {
// Context 改变需要清理内部所有缓存,这里用 uniqueID
// 而不用指针比较,是因为指针析构后再创建可能会地址重合。
releaseAll();
}
context = current;
context->setCacheLimit(MAX_GRAPHICS_MEMORY);
deviceID = context->device()->uniqueID();
contextID = context->uniqueID();
isDrawingFrame = forDrawing;
if (!isDrawingFrame) {
return;
Expand Down Expand Up @@ -199,7 +199,7 @@ void RenderCache::releaseAll() {
motionBlurFilter = nullptr;
delete transform3DFilter;
transform3DFilter = nullptr;
deviceID = 0;
contextID = 0;
}

void RenderCache::detachFromContext() {
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/caches/RenderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class RenderCache : public Performance {
private:
ID _uniqueID = 0;
PAGStage* stage = nullptr;
uint32_t deviceID = 0;
uint32_t contextID = 0;
tgfx::Context* context = nullptr;
std::queue<std::chrono::steady_clock::time_point> timestamps = {};
bool isDrawingFrame = false;
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/graphics/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ tgfx::Surface* Canvas::getSurface() const {
return canvas->getSurface();
}

const tgfx::SurfaceOptions* Canvas::surfaceOptions() const {
uint32_t Canvas::renderFlags() const {
auto surface = canvas->getSurface();
return surface ? surface->options() : nullptr;
return surface ? surface->renderFlags() : 0;
}

void Canvas::save() {
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/graphics/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#pragma once

#include "tgfx/core/Canvas.h"
#include "tgfx/core/SurfaceOptions.h"
#include "tgfx/core/RenderFlags.h"

namespace pag {
class RenderCache;
Expand All @@ -39,7 +39,7 @@ class Canvas {

tgfx::Surface* getSurface() const;

const tgfx::SurfaceOptions* surfaceOptions() const;
uint32_t renderFlags() const;

void save();

Expand Down
12 changes: 6 additions & 6 deletions src/rendering/graphics/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class ImageProxyPicture : public Picture {
canvas->drawImage(std::move(image));
return;
}
auto options = canvas->surfaceOptions();
if (options && !options->cacheDisabled()) {
auto renderFlags = canvas->renderFlags();
if (!(renderFlags & tgfx::RenderFlags::DisableCache)) {
auto snapshot = cache->getSnapshot(this);
if (snapshot) {
canvas->drawImage(snapshot->getImage(), snapshot->getMatrix());
Expand Down Expand Up @@ -168,8 +168,8 @@ class SnapshotPicture : public Picture {
}

void draw(Canvas* canvas) const override {
auto options = canvas->surfaceOptions();
if (options && options->cacheDisabled()) {
auto renderFlags = canvas->renderFlags();
if (renderFlags & tgfx::RenderFlags::DisableCache) {
graphic->draw(canvas);
return;
}
Expand All @@ -192,9 +192,9 @@ class SnapshotPicture : public Picture {
graphic->measureBounds(&bounds);
auto width = static_cast<int>(ceilf(bounds.width() * scaleFactor));
auto height = static_cast<int>(ceilf(bounds.height() * scaleFactor));
tgfx::SurfaceOptions options(tgfx::RenderFlags::DisableCache);
auto renderFlags = tgfx::RenderFlags::DisableCache;
auto surface =
tgfx::Surface::Make(cache->getContext(), width, height, false, 1, mipmapped, &options);
tgfx::Surface::Make(cache->getContext(), width, height, false, 1, mipmapped, renderFlags);
if (surface == nullptr) {
return nullptr;
}
Expand Down
Loading