Chromium Code Reviews| Index: ui/gfx/codec/install_skia_codec.cc |
| diff --git a/ui/gfx/codec/install_skia_codec.cc b/ui/gfx/codec/install_skia_codec.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45f6346b73154d197be54b994370e7c0965890dd |
| --- /dev/null |
| +++ b/ui/gfx/codec/install_skia_codec.cc |
| @@ -0,0 +1,46 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/codec/install_skia_codec.h" |
| + |
| +#include "base/synchronization/lock.h" |
| +#include "skia/ext/skia_encode_image.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "third_party/skia/include/core/SkEncodedImageFormat.h" |
| +#include "third_party/skia/include/core/SkStream.h" |
| +#include "ui/gfx/codec/jpeg_codec.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| + |
| +static bool Encode(SkWStream* dst, |
| + const SkPixmap& pixmap, |
| + SkEncodedImageFormat format, |
| + int quality) { |
| + SkBitmap bitmap; |
|
scroggo
2016/11/29 14:52:54
This is only used in the PNG case - why not move i
hal.canary
2016/11/29 18:24:27
Done.
|
| + std::vector<unsigned char> buffer; |
| + switch (format) { |
| + case SkEncodedImageFormat::kPNG: |
| + return bitmap.installPixels(pixmap) && |
| + gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &buffer) && |
| + dst->write(&buffer[0], buffer.size()); |
| + case SkEncodedImageFormat::kJPEG: |
| + return gfx::JPEGCodec::Encode((const unsigned char*)pixmap.addr(), |
|
scroggo
2016/11/29 14:52:54
reinterpret_cast?
hal.canary
2016/11/29 18:24:27
Done.
|
| + gfx::JPEGCodec::FORMAT_SkBitmap, |
| + pixmap.width(), pixmap.height(), |
| + (int)pixmap.rowBytes(), quality, &buffer) && |
|
scroggo
2016/11/29 14:52:54
static_cast?
hal.canary
2016/11/29 18:24:27
Done.
|
| + dst->write(&buffer[0], buffer.size()); |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| +void gfx::InstallCodecsIntoSkia() { |
| + // FIXME: What is the chromium version of SkOnce? |
| + base::Lock lock; |
| + base::AutoLock autoLock(lock); |
| + static bool g_done = false; |
| + if (!g_done) { |
| + skia::SetEmageEncoder(&Encode); |
| + g_done = true; |
| + } |
| +} |