Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 UI_GFX_IMAGE_MOJO_IMAGE_SKIA_STRUCT_TRAITS_H_ | |
| 6 #define UI_GFX_IMAGE_MOJO_IMAGE_SKIA_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | |
| 14 #include "ui/gfx/image/image_skia_rep.h" | |
| 15 #include "ui/gfx/image/mojo/image_skia.mojom-shared.h" | |
| 16 | |
| 17 namespace mojo { | |
| 18 | |
| 19 template <> | |
| 20 struct StructTraits<gfx::mojom::ImageSkiaRepDataView, gfx::ImageSkiaRep> { | |
| 21 struct Context { | |
| 22 Context(); | |
| 23 ~Context(); | |
| 24 | |
| 25 mojo::ScopedSharedBufferHandle shared_buffer_handle; | |
| 26 uint32_t buffer_byte_size = 0; | |
| 27 }; | |
| 28 | |
| 29 static void* SetUpContext(const gfx::ImageSkiaRep& input); | |
| 30 static void TearDownContext(const gfx::ImageSkiaRep& input, void* context); | |
| 31 static mojo::ScopedSharedBufferHandle shared_buffer_handle( | |
| 32 const gfx::ImageSkiaRep& input, | |
| 33 void* context); | |
| 34 static uint32_t buffer_byte_size(const gfx::ImageSkiaRep& input, | |
| 35 void* context); | |
| 36 static float scale(const gfx::ImageSkiaRep& input) { return input.scale(); } | |
| 37 | |
| 38 static bool IsNull(const gfx::ImageSkiaRep& input) { | |
| 39 return input.sk_bitmap().drawsNothing(); | |
|
msw
2017/03/23 20:47:52
nit: use ImageSkiaRep::is_null() or input.sk_bitma
xiyuan
2017/03/24 05:45:21
is_null does not check empty bitmap (0x0 image). d
| |
| 40 } | |
| 41 static void SetToNull(gfx::ImageSkiaRep* out) { *out = gfx::ImageSkiaRep(); } | |
| 42 | |
| 43 static bool Read(gfx::mojom::ImageSkiaRepDataView data, | |
| 44 gfx::ImageSkiaRep* out); | |
| 45 }; | |
| 46 | |
| 47 template <> | |
| 48 struct StructTraits<gfx::mojom::ImageSkiaDataView, gfx::ImageSkia> { | |
| 49 static void* SetUpContext(const gfx::ImageSkia& input); | |
| 50 static void TearDownContext(const gfx::ImageSkia& input, void* context); | |
| 51 static const std::vector<gfx::ImageSkiaRep>& image_reps( | |
| 52 const gfx::ImageSkia& input, | |
| 53 void* context); | |
| 54 | |
| 55 static bool IsNull(const gfx::ImageSkia& input) { | |
| 56 return input.image_reps().empty(); | |
|
msw
2017/03/23 20:47:52
q: I wonder if it's always safe to call this; imag
xiyuan
2017/03/24 05:45:22
CanRead() only fails if ImageSkia is not marked as
| |
| 57 } | |
| 58 static void SetToNull(gfx::ImageSkia* out) { *out = gfx::ImageSkia(); } | |
| 59 | |
| 60 static bool Read(gfx::mojom::ImageSkiaDataView data, gfx::ImageSkia* out); | |
| 61 }; | |
| 62 | |
| 63 } // namespace mojo | |
| 64 | |
| 65 #endif // UI_GFX_IMAGE_MOJO_IMAGE_SKIA_STRUCT_TRAITS_H_ | |
| OLD | NEW |