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.
This commit is contained in:
parent
9326ce8cfd
commit
89c1b8043f
1 changed files with 41 additions and 3 deletions
|
@ -8,10 +8,47 @@
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.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 "ui/base/clipboard/scoped_clipboard_writer.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.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 atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -167,12 +204,13 @@ gfx::Image Clipboard::ReadImage(mate::Arguments* args) {
|
||||||
|
|
||||||
void Clipboard::WriteImage(const gfx::Image& image, mate::Arguments* args) {
|
void Clipboard::WriteImage(const gfx::Image& image, mate::Arguments* args) {
|
||||||
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
||||||
|
SkBitmap orig = image.AsBitmap();
|
||||||
SkBitmap bmp;
|
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);
|
writer.WriteImage(bmp);
|
||||||
} else {
|
} else {
|
||||||
writer.WriteImage(image.AsBitmap());
|
writer.WriteImage(orig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue