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

Unified Diff: components/arc/video_accelerator/video_accelerator_struct_traits.cc

Issue 2513973002: Use mojo typemap to simplify the code using DmabufPlane (Closed)
Patch Set: Created 4 years, 1 month 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
Index: components/arc/video_accelerator/video_accelerator_struct_traits.cc
diff --git a/components/arc/video_accelerator/video_accelerator_struct_traits.cc b/components/arc/video_accelerator/video_accelerator_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a3dc2815425bcfdec9961ed3612cd052e621169
--- /dev/null
+++ b/components/arc/video_accelerator/video_accelerator_struct_traits.cc
@@ -0,0 +1,36 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
Yusuke Sato 2016/11/29 21:34:28 The implementation doesn't make sense... I guess y
yoshiki 2016/11/30 17:25:44 Yes, this is mistake. Removed.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/arc/bitmap/bitmap_struct_traits.h"
+
+namespace mojo {
+
+bool StructTraits<arc::mojom::ArcVideoAcceleratorDmabufPlaneDataView,
+ ArcVideoAcceleratorDmabufPlane>::
+ Read(arc::mojom::ArcVideoAcceleratorDmabufPlaneDataView data,
+ ArcVideoAcceleratorDmabufPlane* out) {
+ 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.
+ return bitmap.copyTo(out, kN32_SkColorType);
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698