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

Side by Side Diff: components/arc/bitmap/bitmap_struct_traits.cc

Issue 2308663002: Migrate ArcBitmap to use typemapping (Closed)
Patch Set: . 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 unified diff | Download patch
OLDNEW
(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 if (!bitmap.copyTo(out, kN32_SkColorType)) {
dcheng 2016/09/13 23:39:16 return bitmap.CopyTo(...);
34 // Error in copying or converting the color type.
35 return false;
36 }
37
38 return true;
39 }
40
41 } // namespace mojo
OLDNEW
« no previous file with comments | « components/arc/bitmap/bitmap_struct_traits.h ('k') | components/arc/bitmap/bitmap_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698