don't store isolate_ in NativeImage and tune size hints

This commit is contained in:
Heilig Benedek 2017-05-02 04:29:16 +02:00
parent 576b702e8b
commit 5c690ea46e
2 changed files with 13 additions and 13 deletions

View file

@ -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<int64_t>(image_.ToImageSkia()->bitmap()->getSize()));
}
}
#if defined(OS_WIN)
@ -362,9 +366,6 @@ mate::Handle<NativeImage> 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);