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

Unified Diff: ui/gfx/image/mojo/image_skia_struct_traits.cc

Issue 2772113004: Make skia.mojom.Bitmap use shared buffer (Closed)
Patch Set: fix gn check Created 3 years, 9 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: ui/gfx/image/mojo/image_skia_struct_traits.cc
diff --git a/ui/gfx/image/mojo/image_skia_struct_traits.cc b/ui/gfx/image/mojo/image_skia_struct_traits.cc
index 98ef823b9720a52e6a7216f177f38848630eb841..ec5e60ae6b59956b53aadbedab181105c2bf4c73 100644
--- a/ui/gfx/image/mojo/image_skia_struct_traits.cc
+++ b/ui/gfx/image/mojo/image_skia_struct_traits.cc
@@ -11,76 +11,6 @@
namespace mojo {
-StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::Context::Context() = default;
-StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::Context::~Context() = default;
-
-// static
-void* StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::SetUpContext(const SkBitmap& input) {
- // Shared buffer is not a good way for huge images. Consider alternatives.
- DCHECK_LT(input.width() * input.height(), 4000 * 4000);
-
- const std::vector<uint8_t> serialized_sk_bitmap(
- skia::mojom::Bitmap::Serialize(&input));
-
- // Use a context to serialize the bitmap to a shared buffer only once.
- Context* context = new Context;
- context->buffer_byte_size = serialized_sk_bitmap.size();
- context->shared_buffer_handle =
- mojo::SharedBufferHandle::Create(context->buffer_byte_size);
- mojo::ScopedSharedBufferMapping mapping =
- context->shared_buffer_handle->Map(context->buffer_byte_size);
- memcpy(mapping.get(), serialized_sk_bitmap.data(), context->buffer_byte_size);
- return context;
-}
-
-// static
-void StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::TearDownContext(const SkBitmap& input,
- void* context) {
- delete static_cast<Context*>(context);
-}
-
-// static
-mojo::ScopedSharedBufferHandle
-StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::shared_buffer_handle(const SkBitmap& input,
- void* context) {
- return (static_cast<Context*>(context))
- ->shared_buffer_handle->Clone(
- mojo::SharedBufferHandle::AccessMode::READ_ONLY);
-}
-
-// static
-uint64_t StructTraits<gfx::mojom::SharedBufferSkBitmapDataView,
- SkBitmap>::buffer_byte_size(const SkBitmap& input,
- void* context) {
- return (static_cast<Context*>(context))->buffer_byte_size;
-}
-
-// static
-bool StructTraits<gfx::mojom::SharedBufferSkBitmapDataView, SkBitmap>::Read(
- gfx::mojom::SharedBufferSkBitmapDataView data,
- SkBitmap* out) {
- mojo::ScopedSharedBufferHandle shared_buffer_handle =
- data.TakeSharedBufferHandle();
- if (!shared_buffer_handle.is_valid())
- return false;
-
- mojo::ScopedSharedBufferMapping mapping =
- shared_buffer_handle->Map(data.buffer_byte_size());
- if (!mapping)
- return false;
-
- const std::vector<uint8_t> serialized_sk_bitmap(
- static_cast<uint8_t*>(mapping.get()),
- static_cast<uint8_t*>(mapping.get()) + data.buffer_byte_size());
-
- return skia::mojom::Bitmap::Deserialize(serialized_sk_bitmap, out);
-}
-
// static
float StructTraits<gfx::mojom::ImageSkiaRepDataView, gfx::ImageSkiaRep>::scale(
const gfx::ImageSkiaRep& input) {

Powered by Google App Engine
This is Rietveld 408576698