summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/ipc/skia
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/gfx/ipc/skia')
-rw-r--r--chromium/ui/gfx/ipc/skia/BUILD.gn23
-rw-r--r--chromium/ui/gfx/ipc/skia/gfx_ipc_skia.gyp34
-rw-r--r--chromium/ui/gfx/ipc/skia/gfx_skia_ipc_export.h29
-rw-r--r--chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.cc135
-rw-r--r--chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.h49
5 files changed, 270 insertions, 0 deletions
diff --git a/chromium/ui/gfx/ipc/skia/BUILD.gn b/chromium/ui/gfx/ipc/skia/BUILD.gn
new file mode 100644
index 00000000000..60718d2eeae
--- /dev/null
+++ b/chromium/ui/gfx/ipc/skia/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright 2014 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.
+
+component("skia") {
+ output_name = "gfx_ipc_skia"
+
+ sources = [
+ "gfx_skia_param_traits.cc",
+ "gfx_skia_param_traits.h",
+ ]
+
+ defines = [ "GFX_SKIA_IPC_IMPLEMENTATION" ]
+
+ deps = [
+ "//base",
+ "//ipc",
+ "//skia",
+ "//ui/gfx",
+ "//ui/gfx/geometry",
+ "//ui/gfx/ipc",
+ ]
+}
diff --git a/chromium/ui/gfx/ipc/skia/gfx_ipc_skia.gyp b/chromium/ui/gfx/ipc/skia/gfx_ipc_skia.gyp
new file mode 100644
index 00000000000..337858def71
--- /dev/null
+++ b/chromium/ui/gfx/ipc/skia/gfx_ipc_skia.gyp
@@ -0,0 +1,34 @@
+# Copyright 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.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'targets': [
+ {
+ # GN version: //ui/gfx/ipc/skia
+ 'target_name': 'gfx_ipc_skia',
+ 'type': '<(component)',
+ 'dependencies': [
+ '../../../../base/base.gyp:base',
+ '../../../../ipc/ipc.gyp:ipc',
+ '../../../../skia/skia.gyp:skia',
+ '../../gfx.gyp:gfx',
+ '../../gfx.gyp:gfx_geometry',
+ '../gfx_ipc.gyp:gfx_ipc',
+ ],
+ 'defines': [
+ 'GFX_SKIA_IPC_IMPLEMENTATION',
+ ],
+ 'include_dirs': [
+ '../../../..',
+ ],
+ 'sources': [
+ 'gfx_skia_param_traits.cc',
+ 'gfx_skia_param_traits.h',
+ ],
+ },
+ ],
+}
diff --git a/chromium/ui/gfx/ipc/skia/gfx_skia_ipc_export.h b/chromium/ui/gfx/ipc/skia/gfx_skia_ipc_export.h
new file mode 100644
index 00000000000..dc29fb945d6
--- /dev/null
+++ b/chromium/ui/gfx/ipc/skia/gfx_skia_ipc_export.h
@@ -0,0 +1,29 @@
+// Copyright 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.
+
+#ifndef UI_GFX_IPC_GFX_SKIA_IPC_EXPORT_H_
+#define UI_GFX_IPC_GFX_SKIA_IPC_EXPORT_H_
+
+#if defined(COMPONENT_BUILD)
+#if defined(WIN32)
+
+#if defined(GFX_SKIA_IPC_IMPLEMENTATION)
+#define GFX_SKIA_IPC_EXPORT __declspec(dllexport)
+#else
+#define GFX_SKIA_IPC_EXPORT __declspec(dllimport)
+#endif // defined(GFX_SKIA_IPC_IMPLEMENTATION)
+
+#else // defined(WIN32)
+#if defined(GFX_SKIA_IPC_IMPLEMENTATION)
+#define GFX_SKIA_IPC_EXPORT __attribute__((visibility("default")))
+#else
+#define GFX_SKIA_IPC_EXPORT
+#endif
+#endif
+
+#else // defined(COMPONENT_BUILD)
+#define GFX_SKIA_IPC_EXPORT
+#endif
+
+#endif // UI_GFX_IPC_GFX_SKIA_IPC_EXPORT_H_
diff --git a/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.cc b/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.cc
new file mode 100644
index 00000000000..033590c4060
--- /dev/null
+++ b/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.cc
@@ -0,0 +1,135 @@
+// Copyright 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/ipc/skia/gfx_skia_param_traits.h"
+
+#include <string>
+
+#include "base/pickle.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkImageInfo.h"
+#include "ui/gfx/transform.h"
+
+namespace {
+
+struct SkBitmap_Data {
+ // The color type for the bitmap (bits per pixel, etc).
+ SkColorType color_type;
+
+ // The alpha type for the bitmap (opaque, premul, unpremul).
+ SkAlphaType alpha_type;
+
+ // The width of the bitmap in pixels.
+ uint32_t width;
+
+ // The height of the bitmap in pixels.
+ uint32_t height;
+
+ void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) {
+ const SkImageInfo& info = bitmap.info();
+ color_type = info.colorType();
+ alpha_type = info.alphaType();
+ width = info.width();
+ height = info.height();
+ }
+
+ // Returns whether |bitmap| successfully initialized.
+ bool InitSkBitmapFromData(SkBitmap* bitmap,
+ const char* pixels,
+ size_t pixels_size) const {
+ if (!bitmap->tryAllocPixels(
+ SkImageInfo::Make(width, height, color_type, alpha_type)))
+ return false;
+ if (pixels_size != bitmap->getSize())
+ return false;
+ memcpy(bitmap->getPixels(), pixels, pixels_size);
+ return true;
+ }
+};
+
+} // namespace
+
+namespace IPC {
+
+void ParamTraits<SkBitmap>::Write(base::Pickle* m, const SkBitmap& p) {
+ size_t fixed_size = sizeof(SkBitmap_Data);
+ SkBitmap_Data bmp_data;
+ bmp_data.InitSkBitmapDataForTransfer(p);
+ m->WriteData(reinterpret_cast<const char*>(&bmp_data),
+ static_cast<int>(fixed_size));
+ size_t pixel_size = p.getSize();
+ SkAutoLockPixels p_lock(p);
+ m->WriteData(reinterpret_cast<const char*>(p.getPixels()),
+ static_cast<int>(pixel_size));
+}
+
+bool ParamTraits<SkBitmap>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ SkBitmap* r) {
+ const char* fixed_data;
+ int fixed_data_size = 0;
+ if (!iter->ReadData(&fixed_data, &fixed_data_size) ||
+ (fixed_data_size <= 0)) {
+ return false;
+ }
+ if (fixed_data_size != sizeof(SkBitmap_Data))
+ return false; // Message is malformed.
+
+ const char* variable_data;
+ int variable_data_size = 0;
+ if (!iter->ReadData(&variable_data, &variable_data_size) ||
+ (variable_data_size < 0)) {
+ return false;
+ }
+ const SkBitmap_Data* bmp_data =
+ reinterpret_cast<const SkBitmap_Data*>(fixed_data);
+ return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
+}
+
+void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) {
+ l->append("<SkBitmap>");
+}
+
+void ParamTraits<gfx::Transform>::Write(base::Pickle* m, const param_type& p) {
+#ifdef SK_MSCALAR_IS_FLOAT
+ float column_major_data[16];
+ p.matrix().asColMajorf(column_major_data);
+#else
+ double column_major_data[16];
+ p.matrix().asColMajord(column_major_data);
+#endif
+ // We do this in a single write for performance reasons.
+ m->WriteBytes(&column_major_data, sizeof(SkMScalar) * 16);
+}
+
+bool ParamTraits<gfx::Transform>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r) {
+ const char* column_major_data;
+ if (!iter->ReadBytes(&column_major_data, sizeof(SkMScalar) * 16))
+ return false;
+ r->matrix().setColMajor(
+ reinterpret_cast<const SkMScalar*>(column_major_data));
+ return true;
+}
+
+void ParamTraits<gfx::Transform>::Log(
+ const param_type& p, std::string* l) {
+#ifdef SK_MSCALAR_IS_FLOAT
+ float row_major_data[16];
+ p.matrix().asRowMajorf(row_major_data);
+#else
+ double row_major_data[16];
+ p.matrix().asRowMajord(row_major_data);
+#endif
+ l->append("(");
+ for (int i = 0; i < 16; ++i) {
+ if (i > 0)
+ l->append(", ");
+ LogParam(row_major_data[i], l);
+ }
+ l->append(") ");
+}
+
+} // namespace IPC
diff --git a/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.h b/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.h
new file mode 100644
index 00000000000..d3acc930865
--- /dev/null
+++ b/chromium/ui/gfx/ipc/skia/gfx_skia_param_traits.h
@@ -0,0 +1,49 @@
+// Copyright 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.
+
+#ifndef UI_GFX_IPC_GFX_SKIA_PARAM_TRAITS_H_
+#define UI_GFX_IPC_GFX_SKIA_PARAM_TRAITS_H_
+
+#include <string>
+
+#include "ipc/ipc_message_utils.h"
+#include "ipc/ipc_param_traits.h"
+#include "ui/gfx/ipc/skia/gfx_skia_ipc_export.h"
+
+class SkBitmap;
+
+namespace base {
+class Pickle;
+class PickleIterator;
+}
+
+namespace gfx {
+class Transform;
+}
+
+namespace IPC {
+
+template <>
+struct GFX_SKIA_IPC_EXPORT ParamTraits<SkBitmap> {
+ using param_type = SkBitmap;
+ static void Write(base::Pickle* m, const param_type& p);
+ static bool Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template <>
+struct GFX_SKIA_IPC_EXPORT ParamTraits<gfx::Transform> {
+ using param_type = gfx::Transform;
+ static void Write(base::Pickle* m, const param_type& p);
+ static bool Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+} // namespace IPC
+
+#endif // UI_GFX_IPC_GFX_SKIA_PARAM_TRAITS_H_