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())) { | |
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 !buffer.empty() && | |
35 dst->write(&buffer[0], buffer.size()); | |
36 case SkEncodedImageFormat::kJPEG: | |
37 return gfx::JPEGCodec::Encode( | |
38 reinterpret_cast<const unsigned char*>(pixmap.addr()), | |
39 gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(), | |
40 pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality, | |
41 &buffer) && | |
42 !buffer.empty() && | |
43 dst->write(&buffer[0], buffer.size()); | |
44 default: | |
45 return false; | |
46 } | |
47 } | |
48 | |
49 void gfx::InstallCodecsIntoSkia() { | |
50 // FIXME: What is the chromium version of SkOnce? | |
51 static base::Lock lock; | |
dcheng
2016/12/01 06:22:38
Unfortunately, this doesn't work.
Our lock implem
hal.canary
2016/12/20 16:51:13
Okay. I have removed this for now.
| |
52 static bool g_done = false; | |
53 base::AutoLock autoLock(lock); | |
54 if (!g_done) { | |
55 skia::SetImageEncoder(&Encode); | |
56 g_done = true; | |
57 } | |
58 } | |
OLD | NEW |