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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
6 #define COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
7
8 #include "components/arc/common/bitmap.mojom.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10
11 namespace mojo {
12
13 template <>
14 struct StructTraits<arc::mojom::ArcBitmapDataView, SkBitmap> {
15 static mojo::Array<uint8_t> pixel_data(const SkBitmap& r) {
16 DCHECK(!r.drawsNothing());
17
18 const SkImageInfo& info = r.info();
19 DCHECK_EQ(info.colorType(), kRGBA_8888_SkColorType);
20
21 mojo::Array<uint8_t> pixel_data(r.getSize());
22 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.
23 return pixel_data;
24 }
25
26 static uint32_t width(const SkBitmap& r) {
27 return r.width();
28 }
29
30 static uint32_t height(const SkBitmap& r) {
31 return r.height();
32 }
33
34 static bool Read(arc::mojom::ArcBitmapDataView data, SkBitmap* out) {
35 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.
36
37 mojo::Array<uint8_t> pixel_data;
38 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.
39 // Can't read the pixel data.
40 out->reset();
dcheng 2016/09/09 21:46:33 No need to reset here and elsewhere.
yoshiki 2016/09/12 17:35:44 Done.
41 return false;
42 }
43
44 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.
45 // Valid empty data.
46 out->reset();
47 return true;
48 }
49
50 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
51 data.width(), data.height(),
52 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
53 if (info.getSafeSize(info.minRowBytes()) > pixel_data.size()) {
54 // Insufficient buffer size.
55 out->reset();
56 return false;
57 }
58
59 // Create the SkBitmap object which wraps the arc bitmap pixels.
60 SkBitmap bitmap;
61 if (!bitmap.installPixels(info,
62 const_cast<uint8_t*>(pixel_data.storage().data()),
63 info.minRowBytes())) {
64 // Error in installing pixels.
65 out->reset();
66 return false;
67 }
68
69 // Copy the pixels with converting color type.
70 if (!bitmap.copyTo(out, kN32_SkColorType)) {
71 // Error in copying.
72 out->reset();
73 return false;
74 }
75
76 return true;
77 }
78 };
79
80 }
81
82 #endif // COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_
OLDNEW
« 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