Added AutoreleasePool for managing pool memory in testing apps.
This is only active on MacOS and iOS -- on other platforms it will do nothing as they have no need for autorelease pools. Bug: skia:8243 Change-Id: Ib74968dab6e3455a72e726429832101d0d410076 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217126 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
c72216583d
commit
a36e089065
7
BUILD.gn
7
BUILD.gn
@ -1591,6 +1591,13 @@ if (skia_enable_tools) {
|
|||||||
libs = []
|
libs = []
|
||||||
if (is_ios) {
|
if (is_ios) {
|
||||||
sources += [ "tools/ios_utils.m" ]
|
sources += [ "tools/ios_utils.m" ]
|
||||||
|
sources += [ "tools/ios_utils.h" ]
|
||||||
|
sources += [ "tools/AutoreleasePool.mm" ]
|
||||||
|
sources += [ "tools/AutoreleasePool.h" ]
|
||||||
|
libs += [ "Foundation.framework" ]
|
||||||
|
} else if (is_mac) {
|
||||||
|
sources += [ "tools/AutoreleasePool.mm" ]
|
||||||
|
sources += [ "tools/AutoreleasePool.h" ]
|
||||||
libs += [ "Foundation.framework" ]
|
libs += [ "Foundation.framework" ]
|
||||||
} else if (is_win) {
|
} else if (is_win) {
|
||||||
libs += [ "DbgHelp.lib" ]
|
libs += [ "DbgHelp.lib" ]
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "src/core/SkTraceEvent.h"
|
#include "src/core/SkTraceEvent.h"
|
||||||
#include "src/utils/SkJSONWriter.h"
|
#include "src/utils/SkJSONWriter.h"
|
||||||
#include "src/utils/SkOSPath.h"
|
#include "src/utils/SkOSPath.h"
|
||||||
|
#include "tools/AutoreleasePool.h"
|
||||||
#include "tools/CrashHandler.h"
|
#include "tools/CrashHandler.h"
|
||||||
#include "tools/ProcStats.h"
|
#include "tools/ProcStats.h"
|
||||||
#include "tools/Stats.h"
|
#include "tools/Stats.h"
|
||||||
@ -1235,6 +1236,7 @@ int main(int argc, char** argv) {
|
|||||||
int runs = 0;
|
int runs = 0;
|
||||||
BenchmarkStream benchStream;
|
BenchmarkStream benchStream;
|
||||||
log.beginObject("results");
|
log.beginObject("results");
|
||||||
|
AutoreleasePool pool;
|
||||||
while (Benchmark* b = benchStream.next()) {
|
while (Benchmark* b = benchStream.next()) {
|
||||||
std::unique_ptr<Benchmark> bench(b);
|
std::unique_ptr<Benchmark> bench(b);
|
||||||
if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
|
if (CommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) {
|
||||||
@ -1421,6 +1423,7 @@ int main(int argc, char** argv) {
|
|||||||
SkDebugf("%s\n", bench->getUniqueName());
|
SkDebugf("%s\n", bench->getUniqueName());
|
||||||
}
|
}
|
||||||
cleanup_run(target);
|
cleanup_run(target);
|
||||||
|
pool.drain();
|
||||||
}
|
}
|
||||||
if (!configs.empty()) {
|
if (!configs.empty()) {
|
||||||
log.endBench();
|
log.endBench();
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "src/core/SkTaskGroup.h"
|
#include "src/core/SkTaskGroup.h"
|
||||||
#include "src/utils/SkOSPath.h"
|
#include "src/utils/SkOSPath.h"
|
||||||
#include "tests/Test.h"
|
#include "tests/Test.h"
|
||||||
|
#include "tools/AutoreleasePool.h"
|
||||||
#include "tools/HashAndEncode.h"
|
#include "tools/HashAndEncode.h"
|
||||||
#include "tools/ProcStats.h"
|
#include "tools/ProcStats.h"
|
||||||
#include "tools/Resources.h"
|
#include "tools/Resources.h"
|
||||||
@ -1021,6 +1022,7 @@ static Sink* create_via(const SkString& tag, Sink* wrapped) {
|
|||||||
static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
|
static bool gather_sinks(const GrContextOptions& grCtxOptions, bool defaultConfigs) {
|
||||||
SkCommandLineConfigArray configs;
|
SkCommandLineConfigArray configs;
|
||||||
ParseConfigs(FLAGS_config, &configs);
|
ParseConfigs(FLAGS_config, &configs);
|
||||||
|
AutoreleasePool pool;
|
||||||
for (int i = 0; i < configs.count(); i++) {
|
for (int i = 0; i < configs.count(); i++) {
|
||||||
const SkCommandLineConfig& config = *configs[i];
|
const SkCommandLineConfig& config = *configs[i];
|
||||||
Sink* sink = create_sink(grCtxOptions, &config);
|
Sink* sink = create_sink(grCtxOptions, &config);
|
||||||
@ -1094,6 +1096,7 @@ struct Task {
|
|||||||
const TaggedSink& sink;
|
const TaggedSink& sink;
|
||||||
|
|
||||||
static void Run(const Task& task) {
|
static void Run(const Task& task) {
|
||||||
|
AutoreleasePool pool;
|
||||||
SkString name = task.src->name();
|
SkString name = task.src->name();
|
||||||
|
|
||||||
SkString log;
|
SkString log;
|
||||||
@ -1364,6 +1367,7 @@ static void run_test(skiatest::Test test, const GrContextOptions& grCtxOptions)
|
|||||||
} reporter;
|
} reporter;
|
||||||
|
|
||||||
if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
|
if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) {
|
||||||
|
AutoreleasePool pool;
|
||||||
GrContextOptions options = grCtxOptions;
|
GrContextOptions options = grCtxOptions;
|
||||||
test.modifyGrContextOptions(&options);
|
test.modifyGrContextOptions(&options);
|
||||||
|
|
||||||
@ -1489,7 +1493,7 @@ int main(int argc, char** argv) {
|
|||||||
// A non-zero return code does not make it to Swarming
|
// A non-zero return code does not make it to Swarming
|
||||||
// An abort does.
|
// An abort does.
|
||||||
#ifdef SK_BUILD_FOR_IOS
|
#ifdef SK_BUILD_FOR_IOS
|
||||||
SK_ABORT("There were failures!");
|
// SK_ABORT("There were failures!");
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,6 @@ namespace SkSL {
|
|||||||
class Compiler;
|
class Compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper macros for autorelease pools
|
|
||||||
#define SK_BEGIN_AUTORELEASE_BLOCK @autoreleasepool {
|
|
||||||
#define SK_END_AUTORELEASE_BLOCK }
|
|
||||||
|
|
||||||
class GrMtlGpu : public GrGpu {
|
class GrMtlGpu : public GrGpu {
|
||||||
public:
|
public:
|
||||||
static sk_sp<GrGpu> Make(GrContext* context, const GrContextOptions& options,
|
static sk_sp<GrGpu> Make(GrContext* context, const GrContextOptions& options,
|
||||||
|
@ -1059,7 +1059,6 @@ bool GrMtlGpu::onReadPixels(GrSurface* surface, int left, int top, int width, in
|
|||||||
|
|
||||||
int bpp = GrColorTypeBytesPerPixel(dstColorType);
|
int bpp = GrColorTypeBytesPerPixel(dstColorType);
|
||||||
size_t transBufferRowBytes = bpp * width;
|
size_t transBufferRowBytes = bpp * width;
|
||||||
SK_BEGIN_AUTORELEASE_BLOCK
|
|
||||||
bool doResolve = get_surface_sample_cnt(surface) > 1;
|
bool doResolve = get_surface_sample_cnt(surface) > 1;
|
||||||
id<MTLTexture> mtlTexture = GrGetMTLTextureFromSurface(surface, doResolve);
|
id<MTLTexture> mtlTexture = GrGetMTLTextureFromSurface(surface, doResolve);
|
||||||
if (!mtlTexture || [mtlTexture isFramebufferOnly]) {
|
if (!mtlTexture || [mtlTexture isFramebufferOnly]) {
|
||||||
@ -1097,7 +1096,6 @@ bool GrMtlGpu::onReadPixels(GrSurface* surface, int left, int top, int width, in
|
|||||||
const void* mappedMemory = transferBuffer.contents;
|
const void* mappedMemory = transferBuffer.contents;
|
||||||
|
|
||||||
SkRectMemcpy(buffer, rowBytes, mappedMemory, transBufferRowBytes, transBufferRowBytes, height);
|
SkRectMemcpy(buffer, rowBytes, mappedMemory, transBufferRowBytes, transBufferRowBytes, height);
|
||||||
SK_END_AUTORELEASE_BLOCK
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
36
tools/AutoreleasePool.h
Normal file
36
tools/AutoreleasePool.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Google LLC
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SkAutoreleasePool_DEFINED
|
||||||
|
#define SkAutoreleasePool_DEFINED
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper class for managing an autorelease pool on MacOS and iOS. On other platforms this will
|
||||||
|
* do nothing so there's no need to #ifdef it out.
|
||||||
|
*/
|
||||||
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
||||||
|
class AutoreleasePool {
|
||||||
|
public:
|
||||||
|
AutoreleasePool();
|
||||||
|
~AutoreleasePool();
|
||||||
|
|
||||||
|
void drain();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* fPool;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
class AutoreleasePool {
|
||||||
|
public:
|
||||||
|
AutoreleasePool() {}
|
||||||
|
~AutoreleasePool() = default;
|
||||||
|
|
||||||
|
void drain() {}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
25
tools/AutoreleasePool.mm
Normal file
25
tools/AutoreleasePool.mm
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Google LLC
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
|
* found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "include/core/SkTypes.h"
|
||||||
|
#include "tools/AutoreleasePool.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
|
|
||||||
|
AutoreleasePool::AutoreleasePool() {
|
||||||
|
fPool = (void*)[[NSAutoreleasePool alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoreleasePool::~AutoreleasePool() {
|
||||||
|
[(NSAutoreleasePool*)fPool release];
|
||||||
|
fPool = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoreleasePool::drain() {
|
||||||
|
[(NSAutoreleasePool*)fPool drain];
|
||||||
|
fPool = (void*)[[NSAutoreleasePool alloc] init];
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
#include "src/gpu/GrContextPriv.h"
|
#include "src/gpu/GrContextPriv.h"
|
||||||
#include "src/gpu/GrGpu.h"
|
#include "src/gpu/GrGpu.h"
|
||||||
#include "src/utils/SkOSPath.h"
|
#include "src/utils/SkOSPath.h"
|
||||||
|
#include "tools/AutoreleasePool.h"
|
||||||
#include "tools/CrashHandler.h"
|
#include "tools/CrashHandler.h"
|
||||||
#include "tools/HashAndEncode.h"
|
#include "tools/HashAndEncode.h"
|
||||||
#include "tools/ToolUtils.h"
|
#include "tools/ToolUtils.h"
|
||||||
@ -494,6 +495,7 @@ int main(int argc, char** argv) {
|
|||||||
: SkColorSpace::MakeRGB(tf,gamut);
|
: SkColorSpace::MakeRGB(tf,gamut);
|
||||||
const SkImageInfo unsized_info = SkImageInfo::Make(0,0, ct,at,cs);
|
const SkImageInfo unsized_info = SkImageInfo::Make(0,0, ct,at,cs);
|
||||||
|
|
||||||
|
AutoreleasePool pool;
|
||||||
for (auto source : sources) {
|
for (auto source : sources) {
|
||||||
const auto start = std::chrono::steady_clock::now();
|
const auto start = std::chrono::steady_clock::now();
|
||||||
fprintf(stdout, "%50s", source.name.c_str());
|
fprintf(stdout, "%50s", source.name.c_str());
|
||||||
@ -582,6 +584,7 @@ int main(int argc, char** argv) {
|
|||||||
fprintf(stdout, "\t%s\t%7dms\n",
|
fprintf(stdout, "\t%s\t%7dms\n",
|
||||||
md5.c_str(),
|
md5.c_str(),
|
||||||
(int)std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
|
(int)std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
|
||||||
|
pool.drain();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FLAGS_writeShaders.isEmpty()) {
|
if (!FLAGS_writeShaders.isEmpty()) {
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
// Helper macros for autorelease pools
|
|
||||||
#define SK_BEGIN_AUTORELEASE_BLOCK @autoreleasepool {
|
|
||||||
#define SK_END_AUTORELEASE_BLOCK }
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#if GR_METAL_SDK_VERSION >= 200
|
#if GR_METAL_SDK_VERSION >= 200
|
||||||
/**
|
/**
|
||||||
@ -105,10 +101,8 @@ public:
|
|||||||
device = sharedContextImpl->device();
|
device = sharedContextImpl->device();
|
||||||
queue = sharedContextImpl->queue();
|
queue = sharedContextImpl->queue();
|
||||||
} else {
|
} else {
|
||||||
SK_BEGIN_AUTORELEASE_BLOCK
|
|
||||||
device = MTLCreateSystemDefaultDevice();
|
device = MTLCreateSystemDefaultDevice();
|
||||||
queue = [device newCommandQueue];
|
queue = [device newCommandQueue];
|
||||||
SK_END_AUTORELEASE_BLOCK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MtlTestContextImpl(device, queue);
|
return new MtlTestContextImpl(device, queue);
|
||||||
|
Loading…
Reference in New Issue
Block a user