OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ | 5 #ifndef SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ |
6 #define SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ | 6 #define SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/array_traits.h" | 8 #include "mojo/public/cpp/bindings/array_traits.h" |
9 #include "skia/public/interfaces/bitmap.mojom.h" | 9 #include "skia/public/interfaces/bitmap.mojom.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 | 13 |
14 // A buffer used to read pixel data directly from BitmapDataView to SkBitmap. | 14 // A buffer used to read pixel data directly from BitmapDataView to SkBitmap. |
15 struct BitmapBuffer { | 15 using BitmapBuffer = CArray<uint8_t>; |
16 uint8_t* data = nullptr; | |
17 size_t size = 0; | |
18 }; | |
19 | |
20 // ArrayTraits needed for ReadPixelData use with BitmapBuffer. | |
21 template <> | |
22 struct ArrayTraits<BitmapBuffer> { | |
23 using Element = uint8_t; | |
24 static size_t GetSize(const BitmapBuffer& b); | |
25 static uint8_t* GetData(BitmapBuffer& b); | |
26 static const uint8_t* GetData(const BitmapBuffer& b); | |
27 static uint8_t& GetAt(BitmapBuffer& b, size_t i); | |
28 static const uint8_t& GetAt(const BitmapBuffer& b, size_t i); | |
29 static bool Resize(BitmapBuffer& b, size_t size); | |
30 }; | |
31 | 16 |
32 // Struct traits to use SkBitmap for skia::mojom::Bitmap in Chrome C++ code. | 17 // Struct traits to use SkBitmap for skia::mojom::Bitmap in Chrome C++ code. |
33 template <> | 18 template <> |
34 struct StructTraits<skia::mojom::Bitmap, SkBitmap> { | 19 struct StructTraits<skia::mojom::Bitmap, SkBitmap> { |
35 static bool IsNull(const SkBitmap& b); | 20 static bool IsNull(const SkBitmap& b); |
36 static void SetToNull(SkBitmap* b); | 21 static void SetToNull(SkBitmap* b); |
37 static skia::mojom::ColorType color_type(const SkBitmap& b); | 22 static skia::mojom::ColorType color_type(const SkBitmap& b); |
38 static skia::mojom::AlphaType alpha_type(const SkBitmap& b); | 23 static skia::mojom::AlphaType alpha_type(const SkBitmap& b); |
39 static skia::mojom::ColorProfileType profile_type(const SkBitmap& b); | 24 static skia::mojom::ColorProfileType profile_type(const SkBitmap& b); |
40 static uint32_t width(const SkBitmap& b); | 25 static uint32_t width(const SkBitmap& b); |
41 static uint32_t height(const SkBitmap& b); | 26 static uint32_t height(const SkBitmap& b); |
42 static BitmapBuffer pixel_data(const SkBitmap& b); | 27 static BitmapBuffer pixel_data(const SkBitmap& b); |
43 static bool Read(skia::mojom::BitmapDataView data, SkBitmap* b); | 28 static bool Read(skia::mojom::BitmapDataView data, SkBitmap* b); |
44 static void* SetUpContext(const SkBitmap& b); | 29 static void* SetUpContext(const SkBitmap& b); |
45 static void TearDownContext(const SkBitmap& b, void* context); | 30 static void TearDownContext(const SkBitmap& b, void* context); |
46 }; | 31 }; |
47 | 32 |
48 } // namespace mojo | 33 } // namespace mojo |
49 | 34 |
50 #endif // SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ | 35 #endif // SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ |
OLD | NEW |