diff --git a/ash/sysui/BUILD.gn b/ash/sysui/BUILD.gn index 943623c44db564..caf72649e8c7b6 100644 --- a/ash/sysui/BUILD.gn +++ b/ash/sysui/BUILD.gn @@ -40,12 +40,10 @@ source_set("lib") { "//components/mus/public/interfaces", "//components/user_manager", "//device/bluetooth", - "//mash/shelf/public/interfaces", "//mojo/common:common_base", "//services/catalog/public/cpp", "//services/shell/public/cpp", "//services/tracing/public/cpp", - "//skia/public", "//ui/app_list/presenter", "//ui/app_list/presenter:mojom", "//ui/aura", @@ -64,6 +62,10 @@ source_set("lib") { "//ui/views/mus:for_mojo_application", ] + public_deps = [ + "//mash/shelf/public/interfaces", + ] + if (is_chromeos) { deps += [ "//chromeos" ] } diff --git a/ash/sysui/DEPS b/ash/sysui/DEPS index 6bdfff452107a0..c9bcddd44f46c4 100644 --- a/ash/sysui/DEPS +++ b/ash/sysui/DEPS @@ -11,6 +11,5 @@ include_rules = [ "+services/catalog/public", "+services/shell/public", "+services/tracing/public", - "+skia/public", "+third_party/khronos/GLES2/gl2.h", ] diff --git a/ash/sysui/shelf_delegate_mus.cc b/ash/sysui/shelf_delegate_mus.cc index 1d8a4073a70a5c..40a69115b145e4 100644 --- a/ash/sysui/shelf_delegate_mus.cc +++ b/ash/sysui/shelf_delegate_mus.cc @@ -21,7 +21,6 @@ #include "components/mus/public/cpp/window_property.h" #include "mojo/common/common_type_converters.h" #include "services/shell/public/cpp/connector.h" -#include "skia/public/type_converters.h" #include "ui/aura/mus/mus_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image_skia.h" @@ -314,7 +313,7 @@ void ShelfDelegateMus::PinItem( ShelfItem shelf_item; shelf_item.type = TYPE_APP_SHORTCUT; shelf_item.status = STATUS_CLOSED; - shelf_item.image = GetShelfIconFromBitmap(item->image.To()); + shelf_item.image = GetShelfIconFromBitmap(item->image); model_->Add(shelf_item); std::unique_ptr item_delegate( @@ -341,14 +340,14 @@ void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { } void ShelfDelegateMus::SetItemImage(const mojo::String& app_id, - skia::mojom::BitmapPtr image) { + const SkBitmap& image) { if (!app_id_to_shelf_id_.count(app_id.To())) return; ShelfID shelf_id = app_id_to_shelf_id_[app_id.To()]; int index = model_->ItemIndexByID(shelf_id); DCHECK_GE(index, 0); ShelfItem item = *model_->ItemByID(shelf_id); - item.image = GetShelfIconFromBitmap(image.To()); + item.image = GetShelfIconFromBitmap(image); model_->Set(index, item); } diff --git a/ash/sysui/shelf_delegate_mus.h b/ash/sysui/shelf_delegate_mus.h index 4164318658d7dd..81077691a0f4ad 100644 --- a/ash/sysui/shelf_delegate_mus.h +++ b/ash/sysui/shelf_delegate_mus.h @@ -54,8 +54,7 @@ class ShelfDelegateMus : public ShelfDelegate, mash::shelf::mojom::ShelfItemPtr item, mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override; void UnpinItem(const mojo::String& app_id) override; - void SetItemImage(const mojo::String& app_id, - skia::mojom::BitmapPtr image) override; + void SetItemImage(const mojo::String& app_id, const SkBitmap& image) override; // mojom::UserWindowObserver: void OnUserWindowObserverAdded( diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index f079086b034c39..38304436904041 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -383,7 +383,6 @@ source_set("browser") { "//net:extras", "//net:net_with_v8", "//services/shell/public/cpp", - "//skia/public", "//storage/browser", "//storage/common", "//third_party/WebKit/public:image_resources", diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 6a5f9176a024c6..106f00dfb47e58 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -47,7 +47,6 @@ include_rules = [ "+rlz", "+sandbox/win/src", # The path doesn't say it, but this is the Windows sandbox. "+skia/ext", - "+skia/public", "+sync/api", # Sync API files. "+sync/internal_api/public/attachments", # Needed for tests. "+sync/internal_api/public/base", diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc index e1de584848d053..adb15c3fcb7784 100644 --- a/chrome/browser/image_decoder.cc +++ b/chrome/browser/image_decoder.cc @@ -13,7 +13,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/utility_process_host.h" #include "content/public/common/service_registry.h" -#include "skia/public/type_converters.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/l10n/l10n_util.h" @@ -32,16 +31,13 @@ const int kBatchModeTimeoutSeconds = 5; void OnDecodeImageDone( base::Callback fail_callback, base::Callback success_callback, - int request_id, skia::mojom::BitmapPtr image) { + int request_id, + const SkBitmap& image) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - if (image) { - SkBitmap bitmap = image.To(); - if (!bitmap.empty()) { - success_callback.Run(bitmap, request_id); - return; - } - } - fail_callback.Run(request_id); + if (!image.isNull() && !image.empty()) + success_callback.Run(image, request_id); + else + fail_callback.Run(request_id); } } // namespace diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn index 03ed5be7c33eb7..50d3ac6e31b3bd 100644 --- a/chrome/browser/ui/BUILD.gn +++ b/chrome/browser/ui/BUILD.gn @@ -268,7 +268,6 @@ source_set("ui") { "//ash/strings", "//components/user_manager", "//mash/shelf/public/interfaces", - "//skia/public", "//ui/app_list/presenter", "//ui/app_list/presenter:mojom", "//ui/keyboard:mojom", diff --git a/chrome/browser/ui/ash/DEPS b/chrome/browser/ui/ash/DEPS index b63a301c93293a..5807ad4af82160 100644 --- a/chrome/browser/ui/ash/DEPS +++ b/chrome/browser/ui/ash/DEPS @@ -4,5 +4,4 @@ include_rules = [ "+components/user_manager", "+mash/shelf/public/interfaces", "+media", - "+skia/public", ] diff --git a/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc index 58e43d6c4202bc..58a49c6ddc66f6 100644 --- a/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc +++ b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc @@ -16,7 +16,6 @@ #include "extensions/grit/extensions_browser_resources.h" #include "mojo/common/common_type_converters.h" #include "services/shell/public/cpp/connector.h" -#include "skia/public/type_converters.h" #include "ui/base/resource/resource_bundle.h" #include "ui/display/display.h" #include "ui/display/screen.h" @@ -125,7 +124,7 @@ void ChromeMashShelfController::PinAppsFromPrefs() { item->app_title = mojo::String::From(helper_.GetAppTitle(profile, app)); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON); - item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); + item->image = *image.ToSkBitmap(); std::unique_ptr delegate( new ChromeShelfItemDelegate(app)); shelf_controller_->PinItem(std::move(item), @@ -169,6 +168,5 @@ void ChromeMashShelfController::OnAutoHideBehaviorChanged( void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id, const gfx::ImageSkia& image) { - shelf_controller_->SetItemImage(app_id, - skia::mojom::Bitmap::From(*image.bitmap())); + shelf_controller_->SetItemImage(app_id, *image.bitmap()); } diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 7aea68295b2b77..ae24e7ac0de0dd 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -649,20 +649,35 @@ }, 'includes': [ '../build/protoc.gypi' ], }, + { + 'target_name': 'common_mojo_bindings_mojom', + 'type': 'none', + 'variables': { + 'mojom_files': [ + 'common/image_decoder.mojom', + 'common/resource_usage_reporter.mojom', + ], + 'mojom_typemaps': [ + '../skia/public/interfaces/skbitmap.typemap', + ], + }, + 'dependencies': [ + '../mojo/mojo_public.gyp:mojo_cpp_bindings', + '../skia/skia.gyp:skia_mojo', + ], + 'includes': [ '../mojo/mojom_bindings_generator_explicit.gypi' ], + }, { # GN version: //chrome/common:mojo_bindings 'target_name': 'common_mojo_bindings', 'type': 'static_library', - 'includes': [ - '../mojo/mojom_bindings_generator.gypi' - ], - 'sources': [ - 'common/image_decoder.mojom', - 'common/resource_usage_reporter.mojom', - ], 'dependencies': [ + 'common_mojo_bindings_mojom', '../mojo/mojo_public.gyp:mojo_cpp_bindings', - '../skia/skia.gyp:skia_mojo', + '../skia/skia.gyp:skia', + ], + 'export_dependent_settings': [ + '../skia/skia.gyp:skia', ], }, ], diff --git a/chrome/utility/BUILD.gn b/chrome/utility/BUILD.gn index bd325fc23a6499..a7fd3ae05975f3 100644 --- a/chrome/utility/BUILD.gn +++ b/chrome/utility/BUILD.gn @@ -42,7 +42,6 @@ static_library("utility") { "//media", "//net:net_with_v8", "//skia", - "//skia/public", "//sql", "//third_party/libxml", ] diff --git a/chrome/utility/DEPS b/chrome/utility/DEPS index 6ab47a9cdea206..7bf6ee2aa164fb 100644 --- a/chrome/utility/DEPS +++ b/chrome/utility/DEPS @@ -8,7 +8,6 @@ include_rules = [ "+extensions/common", "+media", "+skia/ext", - "+skia/public", "+third_party/libxml", "+third_party/zlib/google", ] diff --git a/chrome/utility/image_decoder_impl.cc b/chrome/utility/image_decoder_impl.cc index 2873b51e2a60d0..4215e6e9a0ea5b 100644 --- a/chrome/utility/image_decoder_impl.cc +++ b/chrome/utility/image_decoder_impl.cc @@ -12,7 +12,6 @@ #include "content/public/child/image_decoder_utils.h" #include "ipc/ipc_channel.h" #include "skia/ext/image_operations.h" -#include "skia/public/type_converters.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/geometry/size.h" @@ -42,9 +41,9 @@ void ImageDecoderImpl::DecodeImage( mojo::Array encoded_data, mojom::ImageCodec codec, bool shrink_to_fit, - const mojo::Callback& callback) { + const mojo::Callback& callback) { if (encoded_data.size() == 0) { - callback.Run(nullptr); + callback.Run(SkBitmap()); return; } @@ -99,8 +98,5 @@ void ImageDecoderImpl::DecodeImage( } } - if (decoded_image.isNull()) - callback.Run(nullptr); - else - callback.Run(skia::mojom::Bitmap::From(decoded_image)); + callback.Run(decoded_image); } diff --git a/chrome/utility/image_decoder_impl.h b/chrome/utility/image_decoder_impl.h index f81fcecd39ce2a..d6226f6fc77155 100644 --- a/chrome/utility/image_decoder_impl.h +++ b/chrome/utility/image_decoder_impl.h @@ -21,7 +21,7 @@ class ImageDecoderImpl : public mojom::ImageDecoder { mojo::Array encoded_data, mojom::ImageCodec codec, bool shrink_to_fit, - const mojo::Callback& callback) override; + const mojo::Callback& callback) override; private: int64_t max_message_size_; diff --git a/chrome/utility/image_decoder_impl_unittest.cc b/chrome/utility/image_decoder_impl_unittest.cc index 45f257c8699d52..f89977e86da5a5 100644 --- a/chrome/utility/image_decoder_impl_unittest.cc +++ b/chrome/utility/image_decoder_impl_unittest.cc @@ -8,7 +8,6 @@ #include "base/bind.h" #include "ipc/ipc_channel.h" -#include "skia/public/type_converters.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/jpeg_codec.h" @@ -46,15 +45,13 @@ class Request { shrink, base::Bind(&Request::OnRequestDone, base::Unretained(this))); } - const skia::mojom::BitmapPtr& bitmap() const { return bitmap_; } + const SkBitmap& bitmap() const { return bitmap_; } private: - void OnRequestDone(skia::mojom::BitmapPtr result_image) { - bitmap_ = std::move(result_image); - } + void OnRequestDone(const SkBitmap& result_image) { bitmap_ = result_image; } ImageDecoderImpl* decoder_; - skia::mojom::BitmapPtr bitmap_; + SkBitmap bitmap_; }; } // namespace @@ -83,24 +80,23 @@ TEST(ImageDecoderImplTest, DecodeImageSizeLimit) { Request request(&decoder); request.DecodeImage(jpg, true); - ASSERT_FALSE(request.bitmap().is_null()); - SkBitmap bitmap = request.bitmap().To(); + ASSERT_FALSE(request.bitmap().isNull()); // Check that image has been shrunk appropriately - EXPECT_LT(bitmap.computeSize64() + base_msg_size, + EXPECT_LT(request.bitmap().computeSize64() + base_msg_size, static_cast(kTestMessageSize)); // Android does its own image shrinking for memory conservation deeper in // the decode, so more specific tests here won't work. #if !defined(OS_ANDROID) - EXPECT_EQ(widths[i] >> i, bitmap.width()); - EXPECT_EQ(heights[i] >> i, bitmap.height()); + EXPECT_EQ(widths[i] >> i, request.bitmap().width()); + EXPECT_EQ(heights[i] >> i, request.bitmap().height()); // Check that if resize not requested and image exceeds IPC size limit, // an empty image is returned if (heights[i] > max_height_for_msg) { Request request(&decoder); request.DecodeImage(jpg, false); - EXPECT_TRUE(request.bitmap().is_null()); + EXPECT_TRUE(request.bitmap().isNull()); } #endif } @@ -116,7 +112,7 @@ TEST(ImageDecoderImplTest, DecodeImageFailed) { Request request(&decoder); request.DecodeImage(jpg, false); - EXPECT_TRUE(request.bitmap().is_null()); + EXPECT_TRUE(request.bitmap().isNull()); } } // namespace mojom diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index a810ce5a5a93cd..cab0cc60b98a66 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -81,7 +81,6 @@ source_set("browser") { "//services/user/public/cpp", "//services/user/public/interfaces", "//skia", - "//skia/public", "//sql", "//storage/browser", "//storage/common", diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index e67fc30d38417a..7268a272ef5e00 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -120,7 +120,6 @@ #include "net/http/http_transaction_factory.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" -#include "skia/public/type_converters.h" #include "third_party/WebKit/public/web/WebSandboxFlags.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/accessibility/ax_tree_combiner.h" @@ -4846,7 +4845,7 @@ void WebContentsImpl::OnDidDownloadImage( int id, const GURL& image_url, int32_t http_status_code, - mojo::Array images, + mojo::Array images, mojo::Array original_image_sizes) { const std::vector bitmaps = images.To>(); diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 371bcb2c4a1157..bfd6a000a2413f 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -865,7 +865,7 @@ class CONTENT_EXPORT WebContentsImpl int id, const GURL& image_url, int32_t http_status_code, - mojo::Array images, + mojo::Array images, mojo::Array original_image_sizes); // Callback function when showing JavaScript dialogs. Takes in a routing ID diff --git a/content/content_common_mojo_bindings.gyp b/content/content_common_mojo_bindings.gyp index 46d841f7d9bc2a..7708406280455c 100644 --- a/content/content_common_mojo_bindings.gyp +++ b/content/content_common_mojo_bindings.gyp @@ -20,6 +20,7 @@ 'common/storage_partition_service.mojom', ], 'mojom_typemaps': [ + '../skia/public/interfaces/skbitmap.typemap', '../ui/gfx/geometry/mojo/geometry.typemap', '../url/mojo/gurl.typemap', '../url/mojo/origin.typemap', @@ -43,9 +44,11 @@ }, 'dependencies': [ '../url/url.gyp:url_mojom', + '../skia/skia.gyp:skia', 'content_common_mojo_bindings_mojom', ], 'export_dependent_settings': [ + '../skia/skia.gyp:skia', '../url/url.gyp:url_mojom', ], }, diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn index 329cac7ac67688..b8cb0f720eb4e5 100644 --- a/content/renderer/BUILD.gn +++ b/content/renderer/BUILD.gn @@ -71,7 +71,6 @@ source_set("renderer") { "//services/shell/public/cpp", "//services/shell/public/interfaces", "//skia", - "//skia/public", "//storage/common", "//third_party/WebKit/public:blink", "//third_party/WebKit/public:mojo_bindings", diff --git a/content/renderer/image_downloader/image_downloader_impl.cc b/content/renderer/image_downloader/image_downloader_impl.cc index 9a8b09df412807..b08decf0cc53ef 100644 --- a/content/renderer/image_downloader/image_downloader_impl.cc +++ b/content/renderer/image_downloader/image_downloader_impl.cc @@ -16,7 +16,6 @@ #include "mojo/common/url_type_converters.h" #include "net/base/data_url.h" #include "skia/ext/image_operations.h" -#include "skia/public/type_converters.h" #include "third_party/WebKit/public/platform/WebURLRequest.h" #include "third_party/WebKit/public/platform/WebVector.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" @@ -219,8 +218,7 @@ void ImageDownloaderImpl::ReplyDownloadResult( const std::vector& result_images, const std::vector& result_original_image_sizes, const DownloadImageCallback& callback) { - callback.Run(http_status_code, - mojo::Array::From(result_images), + callback.Run(http_status_code, mojo::Array::From(result_images), result_original_image_sizes); } diff --git a/mash/shelf/public/interfaces/BUILD.gn b/mash/shelf/public/interfaces/BUILD.gn index 9d87ca48f54095..5e285e528744d6 100644 --- a/mash/shelf/public/interfaces/BUILD.gn +++ b/mash/shelf/public/interfaces/BUILD.gn @@ -10,7 +10,7 @@ mojom("interfaces") { "shelf_constants.mojom", ] - deps = [ + public_deps = [ "//skia/public/interfaces", ] } diff --git a/mojo/public/tools/bindings/chromium_bindings_configuration.gni b/mojo/public/tools/bindings/chromium_bindings_configuration.gni index 5b3004e34abee5..ef5f5141c591df 100644 --- a/mojo/public/tools/bindings/chromium_bindings_configuration.gni +++ b/mojo/public/tools/bindings/chromium_bindings_configuration.gni @@ -9,6 +9,7 @@ _typemap_imports = [ "//media/mojo/interfaces/typemaps.gni", "//mojo/common/typemaps.gni", "//mojo/public/cpp/bindings/tests/chromium_typemaps.gni", + "//skia/public/interfaces/typemaps.gni", "//ui/gfx/typemaps.gni", "//url/mojo/typemaps.gni", ] diff --git a/skia/public/BUILD.gn b/skia/public/BUILD.gn deleted file mode 100644 index bcc7a289dd85af..00000000000000 --- a/skia/public/BUILD.gn +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2015 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. - -source_set("public") { - sources = [ - "type_converters.cc", - "type_converters.h", - ] - - public_deps = [ - "//skia/public/interfaces", - ] - - deps = [ - "//base", - "//mojo/public/cpp/bindings", - "//skia", - ] -} diff --git a/skia/public/interfaces/bitmap_skbitmap_struct_traits.cc b/skia/public/interfaces/bitmap_skbitmap_struct_traits.cc new file mode 100644 index 00000000000000..7d19bb6715d2ca --- /dev/null +++ b/skia/public/interfaces/bitmap_skbitmap_struct_traits.cc @@ -0,0 +1,242 @@ +// 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 "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" + +namespace mojo { + +namespace { + +SkColorType MojoColorTypeToSk(skia::mojom::ColorType type) { + switch (type) { + case skia::mojom::ColorType::UNKNOWN: + return kUnknown_SkColorType; + case skia::mojom::ColorType::ALPHA_8: + return kAlpha_8_SkColorType; + case skia::mojom::ColorType::RGB_565: + return kRGB_565_SkColorType; + case skia::mojom::ColorType::ARGB_4444: + return kARGB_4444_SkColorType; + case skia::mojom::ColorType::RGBA_8888: + return kRGBA_8888_SkColorType; + case skia::mojom::ColorType::BGRA_8888: + return kBGRA_8888_SkColorType; + case skia::mojom::ColorType::INDEX_8: + return kIndex_8_SkColorType; + case skia::mojom::ColorType::GRAY_8: + return kGray_8_SkColorType; + } + NOTREACHED(); + return kUnknown_SkColorType; +} + +SkAlphaType MojoAlphaTypeToSk(skia::mojom::AlphaType type) { + switch (type) { + case skia::mojom::AlphaType::UNKNOWN: + return kUnknown_SkAlphaType; + case skia::mojom::AlphaType::ALPHA_TYPE_OPAQUE: + return kOpaque_SkAlphaType; + case skia::mojom::AlphaType::PREMUL: + return kPremul_SkAlphaType; + case skia::mojom::AlphaType::UNPREMUL: + return kUnpremul_SkAlphaType; + } + NOTREACHED(); + return kUnknown_SkAlphaType; +} + +SkColorProfileType MojoProfileTypeToSk(skia::mojom::ColorProfileType type) { + switch (type) { + case skia::mojom::ColorProfileType::LINEAR: + return kLinear_SkColorProfileType; + case skia::mojom::ColorProfileType::SRGB: + return kSRGB_SkColorProfileType; + } + NOTREACHED(); + return kLinear_SkColorProfileType; +} + +skia::mojom::ColorType SkColorTypeToMojo(SkColorType type) { + switch (type) { + case kUnknown_SkColorType: + return skia::mojom::ColorType::UNKNOWN; + case kAlpha_8_SkColorType: + return skia::mojom::ColorType::ALPHA_8; + case kRGB_565_SkColorType: + return skia::mojom::ColorType::RGB_565; + case kARGB_4444_SkColorType: + return skia::mojom::ColorType::ARGB_4444; + case kRGBA_8888_SkColorType: + return skia::mojom::ColorType::RGBA_8888; + case kBGRA_8888_SkColorType: + return skia::mojom::ColorType::BGRA_8888; + case kIndex_8_SkColorType: + return skia::mojom::ColorType::INDEX_8; + case kGray_8_SkColorType: + return skia::mojom::ColorType::GRAY_8; + case kRGBA_F16_SkColorType: + NOTREACHED(); + return skia::mojom::ColorType::UNKNOWN; + } + NOTREACHED(); + return skia::mojom::ColorType::UNKNOWN; +} + +skia::mojom::AlphaType SkAlphaTypeToMojo(SkAlphaType type) { + switch (type) { + case kUnknown_SkAlphaType: + return skia::mojom::AlphaType::UNKNOWN; + case kOpaque_SkAlphaType: + return skia::mojom::AlphaType::ALPHA_TYPE_OPAQUE; + case kPremul_SkAlphaType: + return skia::mojom::AlphaType::PREMUL; + case kUnpremul_SkAlphaType: + return skia::mojom::AlphaType::UNPREMUL; + } + NOTREACHED(); + return skia::mojom::AlphaType::UNKNOWN; +} + +skia::mojom::ColorProfileType SkProfileTypeToMojo(SkColorProfileType type) { + switch (type) { + case kLinear_SkColorProfileType: + return skia::mojom::ColorProfileType::LINEAR; + case kSRGB_SkColorProfileType: + return skia::mojom::ColorProfileType::SRGB; + } + NOTREACHED(); + return skia::mojom::ColorProfileType::LINEAR; +} + +} // namespace + +// static +size_t ArrayTraits::GetSize(const BitmapBuffer& b) { + return b.size; +} + +// static +uint8_t* ArrayTraits::GetData(BitmapBuffer& b) { + return b.data; +} + +// static +const uint8_t* ArrayTraits::GetData(const BitmapBuffer& b) { + return b.data; +} + +// static +uint8_t& ArrayTraits::GetAt(BitmapBuffer& b, size_t i) { + return *(b.data + i); +} + +// static +const uint8_t& ArrayTraits::GetAt(const BitmapBuffer& b, + size_t i) { + return *(b.data + i); +} + +// static +void ArrayTraits::Resize(BitmapBuffer& b, size_t size) { + CHECK_EQ(size, b.size); +} + +// static +bool StructTraits::IsNull(const SkBitmap& b) { + return b.isNull(); +} + +// static +void StructTraits::SetToNull(SkBitmap* b) { + b->reset(); +} + +// static +skia::mojom::ColorType StructTraits::color_type( + const SkBitmap& b) { + return SkColorTypeToMojo(b.colorType()); +} + +// static +skia::mojom::AlphaType StructTraits::alpha_type( + const SkBitmap& b) { + return SkAlphaTypeToMojo(b.alphaType()); +} + +// static +skia::mojom::ColorProfileType +StructTraits::profile_type(const SkBitmap& b) { + return SkProfileTypeToMojo(b.profileType()); +} + +// static +uint32_t StructTraits::width(const SkBitmap& b) { + return b.width() < 0 ? 0 : static_cast(b.width()); +} + +// static +uint32_t StructTraits::height( + const SkBitmap& b) { + return b.height() < 0 ? 0 : static_cast(b.height()); +} + +// static +BitmapBuffer StructTraits::pixel_data( + const SkBitmap& b) { + BitmapBuffer bitmap_buffer; + bitmap_buffer.data = static_cast(b.getPixels()); + bitmap_buffer.size = b.getSize(); + return bitmap_buffer; +} + +// static +bool StructTraits::Read( + skia::mojom::BitmapDataView data, + SkBitmap* b) { + // TODO: Ensure width and height are reasonable, eg. <= kMaxBitmapSize? + *b = SkBitmap(); + if (!b->tryAllocPixels(SkImageInfo::Make( + data.width(), data.height(), MojoColorTypeToSk(data.color_type()), + MojoAlphaTypeToSk(data.alpha_type()), + MojoProfileTypeToSk(data.profile_type())))) { + return false; + } + + // If the image is empty, return success after setting the image info. + if (data.width() == 0 || data.height() == 0) + return true; + + SkAutoPixmapUnlock pixmap; + if (static_cast(b->width()) != data.width() || + static_cast(b->height()) != data.height() || + !b->requestLock(&pixmap) || !b->lockPixelsAreWritable() || + !b->readyToDraw()) { + return false; + } + + BitmapBuffer bitmap_buffer; + bitmap_buffer.data = static_cast(b->getPixels()); + bitmap_buffer.size = b->getSize(); + if (!data.ReadPixelData(&bitmap_buffer)) + return false; + + b->notifyPixelsChanged(); + return true; +} + +// static +void* StructTraits::SetUpContext( + const SkBitmap& b) { + b.lockPixels(); + return nullptr; +} + +// static +void StructTraits::TearDownContext( + const SkBitmap& b, + void* context) { + b.unlockPixels(); +} + +} // namespace mojo 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 00000000000000..b7e72af9fb2a2e --- /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 { + using Element = uint8_t; + 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 { + static bool IsNull(const SkBitmap& b); + static void SetToNull(SkBitmap* b); + static skia::mojom::ColorType color_type(const SkBitmap& b); + static skia::mojom::AlphaType alpha_type(const SkBitmap& b); + static skia::mojom::ColorProfileType profile_type(const SkBitmap& b); + static uint32_t width(const SkBitmap& b); + static uint32_t height(const SkBitmap& b); + static BitmapBuffer pixel_data(const SkBitmap& b); + static bool Read(skia::mojom::BitmapDataView data, SkBitmap* b); + static void* SetUpContext(const SkBitmap& b); + static void TearDownContext(const SkBitmap& b, void* context); +}; + +} // namespace mojo + +#endif // SKIA_PUBLIC_INTERFACES_BITMAP_SKBITMAP_STRUCT_TRAITS_H_ diff --git a/skia/public/interfaces/skbitmap.typemap b/skia/public/interfaces/skbitmap.typemap new file mode 100644 index 00000000000000..df9d171930a38e --- /dev/null +++ b/skia/public/interfaces/skbitmap.typemap @@ -0,0 +1,11 @@ +# 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. + +mojom = "//skia/public/interfaces/bitmap.mojom" +public_headers = [ "//third_party/skia/include/core/SkBitmap.h" ] +traits_headers = [ "//skia/public/interfaces/bitmap_skbitmap_struct_traits.h" ] +sources = [ "//skia/public/interfaces/bitmap_skbitmap_struct_traits.cc" ] +deps = [ "//mojo/public/cpp/bindings" ] +public_deps = [ "//skia" ] +type_mappings = [ "skia.mojom.Bitmap=SkBitmap" ] diff --git a/skia/public/interfaces/typemaps.gni b/skia/public/interfaces/typemaps.gni new file mode 100644 index 00000000000000..8a308234406343 --- /dev/null +++ b/skia/public/interfaces/typemaps.gni @@ -0,0 +1,5 @@ +# 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. + +typemaps = [ "//skia/public/interfaces/skbitmap.typemap" ] diff --git a/skia/public/type_converters.cc b/skia/public/type_converters.cc deleted file mode 100644 index 939bf6db14b404..00000000000000 --- a/skia/public/type_converters.cc +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2015 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 "skia/public/type_converters.h" - -#include -#include -#include - -#include "base/logging.h" -#include "third_party/skia/include/core/SkBitmap.h" - -namespace mojo { - -namespace { - -SkColorType MojoColorTypeToSk(skia::mojom::ColorType type) { - switch (type) { - case skia::mojom::ColorType::UNKNOWN: - return kUnknown_SkColorType; - case skia::mojom::ColorType::ALPHA_8: - return kAlpha_8_SkColorType; - case skia::mojom::ColorType::RGB_565: - return kRGB_565_SkColorType; - case skia::mojom::ColorType::ARGB_4444: - return kARGB_4444_SkColorType; - case skia::mojom::ColorType::RGBA_8888: - return kRGBA_8888_SkColorType; - case skia::mojom::ColorType::BGRA_8888: - return kBGRA_8888_SkColorType; - case skia::mojom::ColorType::INDEX_8: - return kIndex_8_SkColorType; - case skia::mojom::ColorType::GRAY_8: - return kGray_8_SkColorType; - default: - NOTREACHED(); - } - return kUnknown_SkColorType; -} - -SkAlphaType MojoAlphaTypeToSk(skia::mojom::AlphaType type) { - switch (type) { - case skia::mojom::AlphaType::UNKNOWN: - return kUnknown_SkAlphaType; - case skia::mojom::AlphaType::ALPHA_TYPE_OPAQUE: - return kOpaque_SkAlphaType; - case skia::mojom::AlphaType::PREMUL: - return kPremul_SkAlphaType; - case skia::mojom::AlphaType::UNPREMUL: - return kUnpremul_SkAlphaType; - default: - NOTREACHED(); - } - return kUnknown_SkAlphaType; -} - -skia::mojom::ColorType SkColorTypeToMojo(SkColorType type) { - switch (type) { - case kUnknown_SkColorType: - return skia::mojom::ColorType::UNKNOWN; - case kAlpha_8_SkColorType: - return skia::mojom::ColorType::ALPHA_8; - case kRGB_565_SkColorType: - return skia::mojom::ColorType::RGB_565; - case kARGB_4444_SkColorType: - return skia::mojom::ColorType::ARGB_4444; - case kRGBA_8888_SkColorType: - return skia::mojom::ColorType::RGBA_8888; - case kBGRA_8888_SkColorType: - return skia::mojom::ColorType::BGRA_8888; - case kIndex_8_SkColorType: - return skia::mojom::ColorType::INDEX_8; - case kGray_8_SkColorType: - return skia::mojom::ColorType::GRAY_8; - default: - NOTREACHED(); - } - return skia::mojom::ColorType::UNKNOWN; -} - -skia::mojom::AlphaType SkAlphaTypeToMojo(SkAlphaType type) { - switch (type) { - case kUnknown_SkAlphaType: - return skia::mojom::AlphaType::UNKNOWN; - case kOpaque_SkAlphaType: - return skia::mojom::AlphaType::ALPHA_TYPE_OPAQUE; - case kPremul_SkAlphaType: - return skia::mojom::AlphaType::PREMUL; - case kUnpremul_SkAlphaType: - return skia::mojom::AlphaType::UNPREMUL; - default: - NOTREACHED(); - } - return skia::mojom::AlphaType::UNKNOWN; -} - -} // namespace - -SkBitmap TypeConverter::Convert( - const skia::mojom::BitmapPtr& image) { - SkBitmap bitmap; - if (image.is_null()) - return bitmap; - if (!bitmap.tryAllocPixels(SkImageInfo::Make( - image->width, image->height, MojoColorTypeToSk(image->color_type), - MojoAlphaTypeToSk(image->alpha_type)))) { - return SkBitmap(); - } - if (bitmap.getSize() != image->pixel_data.size() || !bitmap.getPixels()) { - return SkBitmap(); - } - - memcpy(bitmap.getPixels(), &image->pixel_data[0], bitmap.getSize()); - return bitmap; -} - -skia::mojom::BitmapPtr TypeConverter::Convert( - const SkBitmap& bitmap) { - if (bitmap.isNull()) - return nullptr; - - // NOTE: This code doesn't correctly serialize Index8 bitmaps. - const SkImageInfo& info = bitmap.info(); - DCHECK_NE(info.colorType(), kIndex_8_SkColorType); - if (info.colorType() == kIndex_8_SkColorType) - return nullptr; - skia::mojom::BitmapPtr result = skia::mojom::Bitmap::New(); - result->color_type = SkColorTypeToMojo(info.colorType()); - result->alpha_type = SkAlphaTypeToMojo(info.alphaType()); - result->width = info.width(); - result->height = info.height(); - size_t size = bitmap.getSize(); - size_t row_bytes = bitmap.rowBytes(); - result->pixel_data = mojo::Array::New(size); - if (!bitmap.readPixels(info, &result->pixel_data[0], row_bytes, 0, 0)) - return nullptr; - return result; -} - -} // namespace mojo diff --git a/skia/public/type_converters.h b/skia/public/type_converters.h deleted file mode 100644 index a7f71d8e02edb7..00000000000000 --- a/skia/public/type_converters.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 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_TYPE_CONVERTERS_H_ -#define SKIA_PUBLIC_TYPE_CONVERTERS_H_ - -#include "skia/public/interfaces/bitmap.mojom.h" - -class SkBitmap; - -namespace mojo { - -template <> -struct TypeConverter { - static SkBitmap Convert(const skia::mojom::BitmapPtr& image); -}; - -template <> -struct TypeConverter { - static skia::mojom::BitmapPtr Convert(const SkBitmap& bitmap); -}; - -} // namespace mojo - -#endif // SKIA_PUBLIC_TYPE_CONVERTERS_H_ diff --git a/skia/skia.gyp b/skia/skia.gyp index 2103c4bd76df56..4baf2b0d892091 100644 --- a/skia/skia.gyp +++ b/skia/skia.gyp @@ -170,6 +170,19 @@ '../build/android/increase_size_for_speed.gypi', ], }, + { + 'target_name': 'skia_interfaces_mojom', + 'type': 'none', + 'variables': { + 'mojom_files': [ + 'public/interfaces/bitmap.mojom', + ], + 'mojom_typemaps': [ + 'public/interfaces/skbitmap.typemap', + ], + }, + 'includes': [ '../mojo/mojom_bindings_generator_explicit.gypi' ], + }, { 'target_name': 'skia_mojo', 'type': 'static_library', @@ -180,17 +193,16 @@ 'variables': { 'optimize': 'max', }, + 'sources': [ + '../skia/public/interfaces/bitmap_skbitmap_struct_traits.cc', + ], 'dependencies': [ 'skia', + 'skia_interfaces_mojom', '../base/base.gyp:base', ], - 'includes': [ - '../mojo/mojom_bindings_generator.gypi', - ], - 'sources': [ - # Note: file list duplicated in GN build. - 'public/interfaces/bitmap.mojom', - 'public/type_converters.cc', + 'export_dependent_settings': [ + 'skia', ], }, ],