From 89c1b8043f0faf9e3d1ce73ab0f14c21c00e6561 Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Fri, 15 Sep 2017 01:53:32 +0300 Subject: [PATCH] Do not use `SkBitmap.deepCopyTo()`, it was removed Copy of the `sk_tool_utils::copy_to()` is used instead. Probsbly we should use the function itself. --- atom/common/api/atom_api_clipboard.cc | 44 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/atom/common/api/atom_api_clipboard.cc b/atom/common/api/atom_api_clipboard.cc index 3f923c9ddb8b..e8e804e92861 100644 --- a/atom/common/api/atom_api_clipboard.cc +++ b/atom/common/api/atom_api_clipboard.cc @@ -8,10 +8,47 @@ #include "atom/common/native_mate_converters/string16_converter.h" #include "base/strings/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkImageInfo.h" +#include "third_party/skia/include/core/SkPixmap.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" #include "atom/common/node_includes.h" +namespace { + +// TODO(alexeykuzmin): It is a copy of `sk_tool_utils::copy_to()`, +// use the original function if possible, skia doesn't export it. +bool copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) { + SkPixmap srcPM; + if (!src.peekPixels(&srcPM)) { + return false; + } + + SkBitmap tmpDst; + SkImageInfo dstInfo = srcPM.info().makeColorType(dstColorType); + if (!tmpDst.setInfo(dstInfo)) { + return false; + } + + if (!tmpDst.tryAllocPixels()) { + return false; + } + + SkPixmap dstPM; + if (!tmpDst.peekPixels(&dstPM)) { + return false; + } + + if (!srcPM.readPixels(dstPM)) { + return false; + } + + dst->swap(tmpDst); + return true; +} + +} // namespace + namespace atom { namespace api { @@ -167,12 +204,13 @@ gfx::Image Clipboard::ReadImage(mate::Arguments* args) { void Clipboard::WriteImage(const gfx::Image& image, mate::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardType(args)); + SkBitmap orig = image.AsBitmap(); SkBitmap bmp; - // TODO(ferreus): Replace with sk_tools_utils::copy_to (chrome60) - if (image.AsBitmap().deepCopyTo(&bmp)) { + + if (copy_to(&bmp, orig.colorType(), orig)) { writer.WriteImage(bmp); } else { - writer.WriteImage(image.AsBitmap()); + writer.WriteImage(orig); } }