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

Unified Diff: components/arc/bitmap/bitmap_struct_traits.h

Issue 2308663002: Migrate ArcBitmap to use typemapping (Closed)
Patch Set: Addressed comments Created 4 years, 3 months 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 | « components/arc/bitmap/OWNERS ('k') | components/arc/bitmap/bitmap_type_converters.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/bitmap/bitmap_struct_traits.h
diff --git a/components/arc/bitmap/bitmap_struct_traits.h b/components/arc/bitmap/bitmap_struct_traits.h
new file mode 100644
index 0000000000000000000000000000000000000000..031b5b0a0d89f1de4df56c43a09ffb85d6aa7da3
--- /dev/null
+++ b/components/arc/bitmap/bitmap_struct_traits.h
@@ -0,0 +1,67 @@
+// 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 COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
+#define COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
+
+#include "components/arc/common/bitmap.mojom.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace mojo {
+
+template <>
+struct StructTraits<arc::mojom::ArcBitmapDataView, SkBitmap> {
+ static const mojo::CArray<uint8_t> pixel_data(const SkBitmap& r) {
+ DCHECK(!r.drawsNothing());
+
+ const SkImageInfo& info = r.info();
+ DCHECK_EQ(info.colorType(), kRGBA_8888_SkColorType);
+
+ return mojo::CArray<uint8_t>(
+ r.getSize(), r.getSize(), static_cast<uint8_t*>(r.getPixels()));
+ }
+
+ static uint32_t width(const SkBitmap& r) {
+ return r.width();
+ }
+
+ static uint32_t height(const SkBitmap& r) {
+ return r.height();
+ }
+
+ static bool Read(arc::mojom::ArcBitmapDataView data, SkBitmap* out) {
dcheng 2016/09/13 01:13:09 Please out-of-line and place the definition of thi
yoshiki 2016/09/13 18:01:43 Done.
+ mojo::ArrayDataView<uint8_t> pixel_data;
+ data.GetPixelDataDataView(&pixel_data);
+
+ SkImageInfo info = SkImageInfo::Make(
+ data.width(), data.height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ if (info.getSafeSize(info.minRowBytes()) > pixel_data.size()) {
+ // Insufficient buffer size.
+ return false;
+ }
+
+ // Create the SkBitmap object which wraps the arc bitmap pixels. This
+ // doesn't copy and |data| and |bitmap| share the buffer.
+ SkBitmap bitmap;
+ if (!bitmap.installPixels(info,
+ const_cast<uint8_t*>(pixel_data.data()),
+ info.minRowBytes())) {
+ // Error in installing pixels.
+ return false;
+ }
+
+ // Copy the pixels with converting color type.
+ if (!bitmap.copyTo(out, kN32_SkColorType)) {
+ // Error in copying or converting the color type.
+ return false;
+ }
+
+ return true;
+ }
+};
+
+}
+
+#endif // COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
« no previous file with comments | « components/arc/bitmap/OWNERS ('k') | components/arc/bitmap/bitmap_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698