refactor: remove redundant NativeImage::GetBitmap() (#46696)

* refactor: remove redundant NativeImage::GetBitmap()

* docs: mark NativeImage.getBitmap() as deprecated

* have getBitmap() emit a deprecation warning

* docs: update obsolete refefence to getBitmap()

* test: update obsolete refefences to getBitmap()

---------

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
Charles Kerr 2025-04-23 04:00:43 -05:00 committed by GitHub
parent dd03cceda0
commit 686ae47696
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 22 deletions

View file

@ -287,17 +287,16 @@ std::string NativeImage::ToDataURL(gin::Arguments* args) {
}
v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
float scale_factor = GetScaleFactorFromOptions(args);
static bool deprecated_warning_issued = false;
const SkBitmap bitmap =
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap();
SkPixelRef* ref = bitmap.pixelRef();
if (!ref)
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
return node::Buffer::Copy(args->isolate(),
reinterpret_cast<char*>(ref->pixels()),
bitmap.computeByteSize())
.ToLocalChecked();
if (!deprecated_warning_issued) {
deprecated_warning_issued = true;
util::EmitWarning(isolate_,
"getBitmap() is deprecated, use toBitmap() instead.",
"DeprecationWarning");
}
return ToBitmap(args);
}
v8::Local<v8::Value> NativeImage::GetNativeHandle(