Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gfx/codec/install_skia_codec.h" | |
| 6 | |
| 7 #include "base/synchronization/lock.h" | |
| 8 #include "skia/ext/skia_encode_image.h" | |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "third_party/skia/include/core/SkEncodedImageFormat.h" | |
| 11 #include "third_party/skia/include/core/SkStream.h" | |
| 12 #include "ui/gfx/codec/jpeg_codec.h" | |
| 13 #include "ui/gfx/codec/png_codec.h" | |
| 14 #include "ui/gfx/geometry/size.h" | |
| 15 | |
| 16 static bool Encode(SkWStream* dst, | |
| 17 const SkPixmap& pixmap, | |
| 18 SkEncodedImageFormat format, | |
| 19 int quality) { | |
| 20 if (kN32_SkColorType != pixmap.colorType() || | |
| 21 (kPremul_SkAlphaType != pixmap.alphaType() && | |
| 22 kOpaque_SkAlphaType != pixmap.alphaType())) { | |
|
scroggo
2016/11/29 20:15:24
Why not support unpremul? It looks like PNGCodec::
hal.canary
2016/11/29 20:27:04
Fixing gfx::PNGCodec::Encode() to allow unpremulip
| |
| 23 return false; | |
| 24 } | |
| 25 std::vector<unsigned char> buffer; | |
| 26 switch (format) { | |
| 27 case SkEncodedImageFormat::kPNG: | |
| 28 return gfx::PNGCodec::Encode( | |
| 29 reinterpret_cast<const unsigned char*>(pixmap.addr()), | |
| 30 gfx::PNGCodec::FORMAT_SkBitmap, | |
| 31 gfx::Size(pixmap.width(), pixmap.height()), | |
| 32 static_cast<int>(pixmap.rowBytes()), false, | |
| 33 std::vector<gfx::PNGCodec::Comment>(), &buffer) && | |
| 34 dst->write(&buffer[0], buffer.size()); | |
|
dcheng
2016/11/29 23:37:43
Is it guaranteed that |buffer.size()| > 0 here and
hal.canary
2016/11/30 18:24:06
Done.
dcheng
2016/12/01 06:22:38
Rather than the conditional, I think it's probably
| |
| 35 case SkEncodedImageFormat::kJPEG: | |
| 36 return gfx::JPEGCodec::Encode( | |
| 37 reinterpret_cast<const unsigned char*>(pixmap.addr()), | |
| 38 gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(), | |
| 39 pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality, | |
| 40 &buffer) && | |
| 41 dst->write(&buffer[0], buffer.size()); | |
| 42 default: | |
| 43 return false; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void gfx::InstallCodecsIntoSkia() { | |
| 48 // FIXME: What is the chromium version of SkOnce? | |
|
dcheng
2016/11/29 23:37:43
There is no Chromium version: the base::Lock here
hal.canary
2016/11/30 18:24:06
d'oh! That's what I meant to do.
| |
| 49 base::Lock lock; | |
| 50 base::AutoLock autoLock(lock); | |
| 51 static bool g_done = false; | |
| 52 if (!g_done) { | |
| 53 skia::SetImageEncoder(&Encode); | |
| 54 g_done = true; | |
| 55 } | |
| 56 } | |
| OLD | NEW |