| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/arc/bitmap/bitmap_struct_traits.h" |
| 6 |
| 7 namespace mojo { |
| 8 |
| 9 bool StructTraits<arc::mojom::ArcBitmapDataView, SkBitmap>:: |
| 10 Read(arc::mojom::ArcBitmapDataView data, SkBitmap* out) { |
| 11 mojo::ArrayDataView<uint8_t> pixel_data; |
| 12 data.GetPixelDataDataView(&pixel_data); |
| 13 |
| 14 SkImageInfo info = SkImageInfo::Make( |
| 15 data.width(), data.height(), |
| 16 kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 17 if (info.getSafeSize(info.minRowBytes()) > pixel_data.size()) { |
| 18 // Insufficient buffer size. |
| 19 return false; |
| 20 } |
| 21 |
| 22 // Create the SkBitmap object which wraps the arc bitmap pixels. This |
| 23 // doesn't copy and |data| and |bitmap| share the buffer. |
| 24 SkBitmap bitmap; |
| 25 if (!bitmap.installPixels(info, |
| 26 const_cast<uint8_t*>(pixel_data.data()), |
| 27 info.minRowBytes())) { |
| 28 // Error in installing pixels. |
| 29 return false; |
| 30 } |
| 31 |
| 32 // Copy the pixels with converting color type. |
| 33 return bitmap.copyTo(out, kN32_SkColorType); |
| 34 } |
| 35 |
| 36 } // namespace mojo |
| OLD | NEW |