aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2018-04-20 11:04:32 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-20 16:55:15 +0000
commit37819d03fe1a270a0713b016254d66efaae29af7 (patch)
treeaea2aeb8d6a589a098eb6aaa2ff105932a1c55ec /src
parentbbdee1befaf9a908d44c58a0dd58d48316afc108 (diff)
Reduce threads used for DNG decodes on Android
Bug: b/78120086 DNG files require lots of memory to decode. We recently removed the limit on how much SkRawCodec can allocate, allowing it to decode large warped DNG files, so long as the device has enough memory. But in practice, running too many threads at once with each thread allocating a lot of memory results in crashing on Android. Reduce the number of threads so we save memory and do not crash. Change-Id: I464b5a21c019463d2ec31e333f25ebb0b81605bd Reviewed-on: https://skia-review.googlesource.com/122786 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/codec/SkRawCodec.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index e8b49f8bfa..bc3efcbf5f 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -98,16 +98,12 @@ public:
explicit SkDngHost(dng_memory_allocator* allocater) : dng_host(allocater) {}
void PerformAreaTask(dng_area_task& task, const dng_rect& area) override {
- // The area task gets split up into max_tasks sub-tasks. The max_tasks is defined by the
- // dng-sdks default implementation of dng_area_task::MaxThreads() which returns 8 or 32
- // sub-tasks depending on the architecture.
- const int maxTasks = static_cast<int>(task.MaxThreads());
-
SkTaskGroup taskGroup;
// tileSize is typically 256x256
const dng_point tileSize(task.FindTileSize(area));
- const std::vector<dng_rect> taskAreas = compute_task_areas(maxTasks, area, tileSize);
+ const std::vector<dng_rect> taskAreas = compute_task_areas(this->PerformAreaTaskThreads(),
+ area, tileSize);
const int numTasks = static_cast<int>(taskAreas.size());
SkMutex mutex;
@@ -130,15 +126,25 @@ public:
taskGroup.wait();
task.Finish(numTasks);
- // Currently we only re-throw the first catched exception.
+ // We only re-throw the first exception.
if (!exceptions.empty()) {
Throw_dng_error(exceptions.front().ErrorCode(), nullptr, nullptr);
}
}
uint32 PerformAreaTaskThreads() override {
- // FIXME: Need to get the real amount of available threads used in the SkTaskGroup.
+#ifdef SK_BUILD_FOR_ANDROID
+ // According to https://codereview.chromium.org/1634763002/diff/20001/src/codec/SkRawCodec.cpp#newcode71,
+ // having more tasks than CPU threads typically helps performance due
+ // to uneven task runtime. Today's Android devices tend to only have two
+ // cores, so above two should be enough. Too many threads raises the risk
+ // of running out of memory, as each task may allocate a large amount of
+ // memory, so keep this low. This value allows a marlin to decode a
+ // memory-intensive dng file successfully.
+ return 4;
+#else
return kMaxMPThreads;
+#endif
}
private: