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

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..8d40ef2f8fafa2eaf38a79a7acf7d8d5aabcac9a
--- /dev/null
+++ b/components/arc/bitmap/bitmap_struct_traits.h
@@ -0,0 +1,82 @@
+// 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 mojo::Array<uint8_t> pixel_data(const SkBitmap& r) {
+ DCHECK(!r.drawsNothing());
+
+ const SkImageInfo& info = r.info();
+ DCHECK_EQ(info.colorType(), kRGBA_8888_SkColorType);
+
+ mojo::Array<uint8_t> pixel_data(r.getSize());
+ r.readPixels(info, &pixel_data[0], r.rowBytes(), 0, 0);
dcheng 2016/09/09 21:46:32 Let's return a mojo::CArray here to avoid copying
yoshiki 2016/09/12 17:35:43 Done.
+ return pixel_data;
+ }
+
+ 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) {
+ DCHECK_NE(out, nullptr);
dcheng 2016/09/09 21:46:32 This should be out-of-lined, and the DCHECK is unn
yoshiki 2016/09/12 17:35:43 Done.
+
+ mojo::Array<uint8_t> pixel_data;
+ if (!data.ReadPixelData(&pixel_data)) {
dcheng 2016/09/09 21:46:33 Let's use the data view to avoid copying the pixel
yoshiki 2016/09/12 17:35:43 Done.
+ // Can't read the pixel data.
+ out->reset();
dcheng 2016/09/09 21:46:33 No need to reset here and elsewhere.
yoshiki 2016/09/12 17:35:44 Done.
+ return false;
+ }
+
+ if (data.width() == 0 || data.height() == 0) {
dcheng 2016/09/09 21:46:32 I don't think there's any particular need to make
yoshiki 2016/09/12 17:35:43 Done.
+ // Valid empty data.
+ out->reset();
+ return true;
+ }
+
+ SkImageInfo info = SkImageInfo::Make(
dcheng 2016/09/09 21:46:33 I would recommend structuring this like https://cs
yoshiki 2016/09/12 17:35:43 That code can't be reused here, since we need to c
dcheng 2016/09/13 01:13:09 Can we make our input and output pixel formats mat
yoshiki 2016/09/13 18:01:43 It's impossible. Android uses kRGBA_8888_SkColorTy
dcheng 2016/09/13 23:39:16 What does that mean "standard format"? I don't thi
+ data.width(), data.height(),
+ kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+ if (info.getSafeSize(info.minRowBytes()) > pixel_data.size()) {
+ // Insufficient buffer size.
+ out->reset();
+ return false;
+ }
+
+ // Create the SkBitmap object which wraps the arc bitmap pixels.
+ SkBitmap bitmap;
+ if (!bitmap.installPixels(info,
+ const_cast<uint8_t*>(pixel_data.storage().data()),
+ info.minRowBytes())) {
+ // Error in installing pixels.
+ out->reset();
+ return false;
+ }
+
+ // Copy the pixels with converting color type.
+ if (!bitmap.copyTo(out, kN32_SkColorType)) {
+ // Error in copying.
+ out->reset();
+ 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