From 5c690ea46e0e6a06ec85e93813253a8eeeaceb9c Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 04:29:16 +0200 Subject: [PATCH] don't store isolate_ in NativeImage and tune size hints --- atom/common/api/atom_api_native_image.cc | 25 ++++++++++++------------ atom/common/api/atom_api_native_image.h | 1 - 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index a2e86186e7ae..6bc012bc3abd 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -200,30 +200,34 @@ void Noop(char*, void*) { } // namespace NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image) - : image_(image), isolate_(isolate) { - Init(isolate_); - isolate_->AdjustAmountOfExternalAllocatedMemory( - image_.Width() * image_.Height() * 4); + : image_(image) { + Init(isolate); + if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { + isolate->AdjustAmountOfExternalAllocatedMemory( + image_.ToImageSkia()->bitmap()->getSize()); + } MarkHighMemoryUsage(); } #if defined(OS_WIN) NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) - : hicon_path_(hicon_path), isolate_(isolate) { + : hicon_path_(hicon_path) { // Use the 256x256 icon as fallback icon. gfx::ImageSkia image_skia; ReadImageSkiaFromICO(&image_skia, GetHICON(256)); image_ = gfx::Image(image_skia); Init(isolate); - isolate_->AdjustAmountOfExternalAllocatedMemory( - image_.Width() * image_.Height() * 4); + isolate->AdjustAmountOfExternalAllocatedMemory( + image_.ToImageSkia()->bitmap()->getSize()); MarkHighMemoryUsage(); } #endif NativeImage::~NativeImage() { - isolate_->AdjustAmountOfExternalAllocatedMemory( - - image_.Width() * image_.Height() * 4); + if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { + isolate()->AdjustAmountOfExternalAllocatedMemory( + - static_cast(image_.ToImageSkia()->bitmap()->getSize())); + } } #if defined(OS_WIN) @@ -362,9 +366,6 @@ mate::Handle NativeImage::Resize( bool height_set = options.GetInteger("height", &height); size.SetSize(width, height); - isolate_->AdjustAmountOfExternalAllocatedMemory( - (width_set * height_set - width * height) * 4); - if (width_set && !height_set) { // Scale height to preserve original aspect ratio size.set_height(width); diff --git a/atom/common/api/atom_api_native_image.h b/atom/common/api/atom_api_native_image.h index 0c2890d86f5c..6ff7a0e29f37 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -99,7 +99,6 @@ class NativeImage : public mate::Wrappable { #endif gfx::Image image_; - v8::Isolate* isolate_; DISALLOW_COPY_AND_ASSIGN(NativeImage); };