Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Unified Diff: ui/gfx/codec/install_skia_codec.cc

Issue 2527833002: Implement SkEncodeImage() (Closed)
Patch Set: 2016-11-30 (Wednesday) 12:18:52 EST Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/codec/install_skia_codec.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2b884a8a47bc4152d7564af68baf5e62826ada93
--- /dev/null
+++ b/ui/gfx/codec/install_skia_codec.cc
@@ -0,0 +1,58 @@
+// 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"
+#include "ui/gfx/geometry/size.h"
+
+static bool Encode(SkWStream* dst,
+ const SkPixmap& pixmap,
+ SkEncodedImageFormat format,
+ int quality) {
+ if (kN32_SkColorType != pixmap.colorType() ||
+ (kPremul_SkAlphaType != pixmap.alphaType() &&
+ kOpaque_SkAlphaType != pixmap.alphaType())) {
+ return false;
+ }
+ std::vector<unsigned char> buffer;
+ switch (format) {
+ case SkEncodedImageFormat::kPNG:
+ return gfx::PNGCodec::Encode(
+ reinterpret_cast<const unsigned char*>(pixmap.addr()),
+ gfx::PNGCodec::FORMAT_SkBitmap,
+ gfx::Size(pixmap.width(), pixmap.height()),
+ static_cast<int>(pixmap.rowBytes()), false,
+ std::vector<gfx::PNGCodec::Comment>(), &buffer) &&
+ !buffer.empty() &&
+ dst->write(&buffer[0], buffer.size());
+ case SkEncodedImageFormat::kJPEG:
+ return gfx::JPEGCodec::Encode(
+ reinterpret_cast<const unsigned char*>(pixmap.addr()),
+ gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(),
+ pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality,
+ &buffer) &&
+ !buffer.empty() &&
+ dst->write(&buffer[0], buffer.size());
+ default:
+ return false;
+ }
+}
+
+void gfx::InstallCodecsIntoSkia() {
+ // FIXME: What is the chromium version of SkOnce?
+ 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.
+ static bool g_done = false;
+ base::AutoLock autoLock(lock);
+ if (!g_done) {
+ skia::SetImageEncoder(&Encode);
+ g_done = true;
+ }
+}
« no previous file with comments | « ui/gfx/codec/install_skia_codec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698