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

Unified Diff: skia/public/interfaces/bitmap_skbitmap_struct_traits.h

Issue 2014013002: Add SkBitmap StructTraits for skia::mojo::Bitmap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix empty image handling; avoid resetting info. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: skia/public/interfaces/bitmap_skbitmap_struct_traits.h
diff --git a/skia/public/interfaces/bitmap_skbitmap_struct_traits.h b/skia/public/interfaces/bitmap_skbitmap_struct_traits.h
new file mode 100644
index 0000000000000000000000000000000000000000..262a9fa8e01494b8ba8c83e8d72e19cb35dcab55
--- /dev/null
+++ b/skia/public/interfaces/bitmap_skbitmap_struct_traits.h
@@ -0,0 +1,50 @@
+// 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 SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_
+#define SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_
+
+#include "mojo/public/cpp/bindings/array_traits.h"
+#include "skia/public/interfaces/bitmap.mojom.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace mojo {
+
+// A buffer used to read pixel data directly from BitmapDataView to SkBitmap.
+struct BitmapBuffer {
+ uint8_t* data = nullptr;
+ size_t size = 0;
+};
+
+// ArrayTraits needed for ReadPixelData use with BitmapBuffer.
+template <>
+struct ArrayTraits<BitmapBuffer> {
+ using Element = uint8_t;
+ static bool IsNull(const BitmapBuffer& b);
+ static void SetToNull(BitmapBuffer* b);
+ static size_t GetSize(const BitmapBuffer& b);
+ static uint8_t* GetData(BitmapBuffer& b);
+ static const uint8_t* GetData(const BitmapBuffer& b);
+ static uint8_t& GetAt(BitmapBuffer& b, size_t i);
+ static const uint8_t& GetAt(const BitmapBuffer& b, size_t i);
+ static void Resize(BitmapBuffer& b, size_t size);
+};
+
+// Struct traits to use SkBitmap for skia::mojom::Bitmap in Chrome C++ code.
+template <>
+struct StructTraits<skia::mojom::Bitmap, SkBitmap> {
+ static skia::mojom::ColorType color_type(const SkBitmap& r);
yzshen1 2016/05/31 23:17:36 I had a previous comment about adding IsNull and S
msw 2016/05/31 23:53:41 Done. Sorry I somehow neglected that! Though, I wo
+ static skia::mojom::AlphaType alpha_type(const SkBitmap& r);
+ static skia::mojom::ColorProfileType profile_type(const SkBitmap& r);
+ static uint32_t width(const SkBitmap& r);
+ static uint32_t height(const SkBitmap& r);
+ static BitmapBuffer pixel_data(const SkBitmap& r);
+ static bool Read(skia::mojom::BitmapDataView data, SkBitmap* out);
+ static void* SetUpContext(const SkBitmap& r);
+ static void TearDownContext(const SkBitmap& r, void* context);
+};
+
+} // namespace mojo
+
+#endif // SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_

Powered by Google App Engine
This is Rietveld 408576698