Null check before queueing deletion of Skia objects (flutter/engine#3298)
Fixes https://github.com/flutter/flutter/issues/7182
This commit is contained in:
@@ -16,7 +16,9 @@ PictureLayer::~PictureLayer() {
|
||||
// The picture may contain references to textures that are associated
|
||||
// with the IO thread's context.
|
||||
SkPicture* picture = picture_.release();
|
||||
blink::Threads::IO()->PostTask([picture]() { picture->unref(); });
|
||||
if (picture) {
|
||||
blink::Threads::IO()->PostTask([picture]() { picture->unref(); });
|
||||
}
|
||||
}
|
||||
|
||||
void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
|
||||
@@ -42,6 +42,7 @@ source_set("ui") {
|
||||
"painting/rrect.h",
|
||||
"painting/shader.cc",
|
||||
"painting/shader.h",
|
||||
"painting/utils.h",
|
||||
"semantics/semantics_node.cc",
|
||||
"semantics/semantics_node.h",
|
||||
"semantics/semantics_update.cc",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "flutter/lib/ui/painting/image.h"
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/lib/ui/painting/utils.h"
|
||||
#include "lib/tonic/dart_args.h"
|
||||
#include "lib/tonic/dart_binding_macros.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
@@ -32,8 +33,7 @@ CanvasImage::CanvasImage() {}
|
||||
CanvasImage::~CanvasImage() {
|
||||
// Skia objects must be deleted on the IO thread so that any associated GL
|
||||
// objects will be cleaned up through the IO thread's GL context.
|
||||
SkImage* image = image_.release();
|
||||
Threads::IO()->PostTask([image]() { image->unref(); });
|
||||
SkiaUnrefOnIOThread(&image_);
|
||||
}
|
||||
|
||||
void CanvasImage::dispose() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "flutter/lib/ui/painting/mask_filter.h"
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/lib/ui/painting/utils.h"
|
||||
#include "lib/tonic/dart_args.h"
|
||||
#include "lib/tonic/dart_binding_macros.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
@@ -38,8 +39,7 @@ MaskFilter::MaskFilter(sk_sp<SkMaskFilter> filter)
|
||||
MaskFilter::~MaskFilter() {
|
||||
// Skia objects must be deleted on the IO thread so that any associated GL
|
||||
// objects will be cleaned up through the IO thread's GL context.
|
||||
SkMaskFilter* filter = filter_.release();
|
||||
Threads::IO()->PostTask([filter]() { filter->unref(); });
|
||||
SkiaUnrefOnIOThread(&filter_);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/lib/ui/painting/canvas.h"
|
||||
#include "flutter/lib/ui/painting/utils.h"
|
||||
#include "lib/tonic/dart_args.h"
|
||||
#include "lib/tonic/dart_binding_macros.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
@@ -28,8 +29,7 @@ Picture::Picture(sk_sp<SkPicture> picture) : picture_(std::move(picture)) {}
|
||||
Picture::~Picture() {
|
||||
// Skia objects must be deleted on the IO thread so that any associated GL
|
||||
// objects will be cleaned up through the IO thread's GL context.
|
||||
SkPicture* picture = picture_.release();
|
||||
Threads::IO()->PostTask([picture]() { picture->unref(); });
|
||||
SkiaUnrefOnIOThread(&picture_);
|
||||
}
|
||||
|
||||
void Picture::dispose() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "flutter/lib/ui/painting/shader.h"
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/lib/ui/painting/utils.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@@ -16,8 +17,7 @@ Shader::Shader(sk_sp<SkShader> shader) : shader_(shader) {
|
||||
Shader::~Shader() {
|
||||
// Skia objects must be deleted on the IO thread so that any associated GL
|
||||
// objects will be cleaned up through the IO thread's GL context.
|
||||
SkShader* shader = shader_.release();
|
||||
Threads::IO()->PostTask([shader]() { shader->unref(); });
|
||||
SkiaUnrefOnIOThread(&shader_);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
17
engine/src/flutter/lib/ui/painting/utils.h
Normal file
17
engine/src/flutter/lib/ui/painting/utils.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
template <typename T> void SkiaUnrefOnIOThread(sk_sp<T>* sp) {
|
||||
T* object = sp->release();
|
||||
if (object) {
|
||||
Threads::IO()->PostTask([object]() { object->unref(); });
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
Reference in New Issue
Block a user