diff options
Diffstat (limited to 'chromium/components/arc/bitmap')
5 files changed, 68 insertions, 56 deletions
diff --git a/chromium/components/arc/bitmap/OWNERS b/chromium/components/arc/bitmap/OWNERS new file mode 100644 index 00000000000..bb6511619b7 --- /dev/null +++ b/chromium/components/arc/bitmap/OWNERS @@ -0,0 +1,2 @@ +per-file *_struct_traits*.*=set noparent +per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS diff --git a/chromium/components/arc/bitmap/bitmap_struct_traits.cc b/chromium/components/arc/bitmap/bitmap_struct_traits.cc new file mode 100644 index 00000000000..51aa30f44f0 --- /dev/null +++ b/chromium/components/arc/bitmap/bitmap_struct_traits.cc @@ -0,0 +1,36 @@ +// 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. + +#include "components/arc/bitmap/bitmap_struct_traits.h" + +namespace mojo { + +bool StructTraits<arc::mojom::ArcBitmapDataView, SkBitmap>:: + Read(arc::mojom::ArcBitmapDataView data, SkBitmap* 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 diff --git a/chromium/components/arc/bitmap/bitmap_struct_traits.h b/chromium/components/arc/bitmap/bitmap_struct_traits.h new file mode 100644 index 00000000000..e4e61e3c1e4 --- /dev/null +++ b/chromium/components/arc/bitmap/bitmap_struct_traits.h @@ -0,0 +1,30 @@ +// 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 const mojo::CArray<uint8_t> pixel_data(const SkBitmap& r) { + const SkImageInfo& info = r.info(); + DCHECK_EQ(info.colorType(), kRGBA_8888_SkColorType); + + return mojo::CArray<uint8_t>( + r.getSize(), r.getSize(), static_cast<uint8_t*>(r.getPixels())); + } + 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); +}; + +} + +#endif // COMPONENT_ARC_BITMAP_BITMAP_STRUCT_TRAITS_H_ diff --git a/chromium/components/arc/bitmap/bitmap_type_converters.cc b/chromium/components/arc/bitmap/bitmap_type_converters.cc deleted file mode 100644 index ab9e58b3bf2..00000000000 --- a/chromium/components/arc/bitmap/bitmap_type_converters.cc +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -#include "components/arc/bitmap/bitmap_type_converters.h" - -namespace mojo { - -SkBitmap TypeConverter<SkBitmap, arc::mojom::ArcBitmapPtr>::Convert( - const arc::mojom::ArcBitmapPtr& arcBitmap) { - if (arcBitmap.is_null()) - return SkBitmap(); - - SkImageInfo info = SkImageInfo::Make( - arcBitmap->width, arcBitmap->height, - kRGBA_8888_SkColorType, kPremul_SkAlphaType); - if (info.getSafeSize(info.minRowBytes()) > arcBitmap->pixel_data.size()) - return SkBitmap(); - - // Create the SkBitmap object which wraps the arc bitmap pixels. - SkBitmap bitmap; - if (!bitmap.installPixels(info, - const_cast<uint8_t*>(arcBitmap->pixel_data.storage().data()), - info.minRowBytes())) { - return SkBitmap(); - } - - // Copy the pixels with converting color type. - SkBitmap nativeColorBitmap; - if (!bitmap.copyTo(&nativeColorBitmap, kN32_SkColorType)) - return SkBitmap(); - - return nativeColorBitmap; -} - -} // namespace mojo diff --git a/chromium/components/arc/bitmap/bitmap_type_converters.h b/chromium/components/arc/bitmap/bitmap_type_converters.h deleted file mode 100644 index 815b96513e1..00000000000 --- a/chromium/components/arc/bitmap/bitmap_type_converters.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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 COMPONENTS_ARC_BITMAP_BITMAP_TYPE_CONVERTERS_H_ -#define COMPONENTS_ARC_BITMAP_BITMAP_TYPE_CONVERTERS_H_ - -#include "components/arc/common/bitmap.mojom.h" -#include "third_party/skia/include/core/SkBitmap.h" - -namespace mojo { - -template <> -struct TypeConverter<SkBitmap, arc::mojom::ArcBitmapPtr> { - static SkBitmap Convert(const arc::mojom::ArcBitmapPtr& bitmap); -}; - -} // namespace mojo - -#endif // COMPONENTS_ARC_BITMAP_BITMAP_TYPE_CONVERTERS_H_ |