Skip to content

Instantly share code, notes, and snippets.

@chinmaygarde
Created July 16, 2019 03:16
Show Gist options
  • Save chinmaygarde/290371619903921022beae271e52c1dc to your computer and use it in GitHub Desktop.
Save chinmaygarde/290371619903921022beae271e52c1dc to your computer and use it in GitHub Desktop.
diff --git a/lib/ui/painting/codec.cc b/lib/ui/painting/codec.cc
index b181837e3..fc31f3f32 100644
--- a/lib/ui/painting/codec.cc
+++ b/lib/ui/painting/codec.cc
@@ -4,6 +4,8 @@
#include "flutter/lib/ui/painting/codec.h"
+#include <sys/mman.h>
+
#include <variant>
#include "flutter/common/task_runners.h"
@@ -129,7 +131,16 @@ static void InstantiateImageCodec(Dart_NativeArguments args) {
Dart_SetReturnValue(args, exception);
return;
}
- buffer = SkData::MakeWithCopy(list.data(), list.num_elements());
+ auto allocation = ::mmap(nullptr, list.num_elements(),
+ PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0);
+ ::memcpy(allocation, list.data(), list.num_elements());
+ auto size = new int(list.num_elements());
+ SkData::ReleaseProc proc = [](const void* ptr, void* context) {
+ int* size = reinterpret_cast<int*>(context);
+ ::munmap(const_cast<void*>(ptr), *size);
+ delete size;
+ };
+ buffer = SkData::MakeWithProc(allocation, list.num_elements(), proc, size);
}
if (image_info) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment