diff options
author | spang@chromium.org <spang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 21:31:08 +0000 |
---|---|---|
committer | spang@chromium.org <spang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 21:31:08 +0000 |
commit | ffff5b38ceebdfa99e6c1ac0cd4d9fa3d1d4de02 (patch) | |
tree | c9bf707901af555c824eeacd0b848832e1bc70a6 | |
parent | b2a5bccd1e0294cde4d64c1ecd7d73f0ef7f9f35 (diff) | |
download | chromium_src-ffff5b38ceebdfa99e6c1ac0cd4d9fa3d1d4de02.zip chromium_src-ffff5b38ceebdfa99e6c1ac0cd4d9fa3d1d4de02.tar.gz chromium_src-ffff5b38ceebdfa99e6c1ac0cd4d9fa3d1d4de02.tar.bz2 |
Move IPC traits for SkBitmap, gfx_geometry into ui/gfx/ipc
We need these outside of content (under ui/ozone), so move them. No
functional change.
BUG=377497
TEST=chrome --ozone-platform=gbm
Review URL: https://codereview.chromium.org/343003003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279825 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 473 insertions, 342 deletions
diff --git a/android_webview/DEPS b/android_webview/DEPS index 91ac0f5..ed5c849 100644 --- a/android_webview/DEPS +++ b/android_webview/DEPS @@ -16,5 +16,6 @@ include_rules = [ "+third_party/skia/include", "+ui/android", "+ui/base", + "+ui/gfx", "+webkit", ] diff --git a/android_webview/common/print_messages.h b/android_webview/common/print_messages.h index 32d5790b..6da90de 100644 --- a/android_webview/common/print_messages.h +++ b/android_webview/common/print_messages.h @@ -16,6 +16,7 @@ #include "printing/page_size_margins.h" #include "printing/print_job_constants.h" #include "third_party/WebKit/public/web/WebPrintScalingOption.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index dc9e02e..aab8a0a 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -313,6 +313,7 @@ '<(DEPTH)/third_party/libxml/libxml.gyp:libxml', '<(DEPTH)/third_party/sqlite/sqlite.gyp:sqlite', '<(DEPTH)/third_party/zlib/google/zip.gyp:zip', + '<(DEPTH)/ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '<(DEPTH)/ui/resources/ui_resources.gyp:ui_resources', '<(DEPTH)/url/url.gyp:url_lib', ], diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h index d8e40c6..5a7019b 100644 --- a/chrome/common/chrome_utility_messages.h +++ b/chrome/common/chrome_utility_messages.h @@ -21,6 +21,7 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #define IPC_MESSAGE_START ChromeUtilityMsgStart diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h index cfeb66d..709be0e 100644 --- a/chrome/common/print_messages.h +++ b/chrome/common/print_messages.h @@ -14,6 +14,7 @@ #include "printing/page_size_margins.h" #include "printing/print_job_constants.h" #include "third_party/WebKit/public/web/WebPrintScalingOption.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 13a445d..45c9056 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -32,10 +32,11 @@ #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" -#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebConsoleMessage.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/window_open_disposition.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/rect.h" // Singly-included section for enums and custom IPC traits. diff --git a/components/autofill.gypi b/components/autofill.gypi index b2abb11..eac417e 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -284,6 +284,7 @@ '../ipc/ipc.gyp:ipc', '../third_party/WebKit/public/blink.gyp:blink_minimal', '../ui/gfx/gfx.gyp:gfx', + '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', ], 'include_dirs': [ '..', diff --git a/components/autofill/content/common/autofill_messages.h b/components/autofill/content/common/autofill_messages.h index c19f068..d1c325a 100644 --- a/components/autofill/content/common/autofill_messages.h +++ b/components/autofill/content/common/autofill_messages.h @@ -22,6 +22,7 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" #include "third_party/WebKit/public/web/WebFormElement.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/rect.h" #include "url/gurl.h" diff --git a/content/child/plugin_messages.h b/content/child/plugin_messages.h index b71441e..2e17c98 100644 --- a/content/child/plugin_messages.h +++ b/content/child/plugin_messages.h @@ -12,6 +12,7 @@ #include "content/public/common/common_param_traits.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" diff --git a/content/common/browser_plugin/browser_plugin_messages.h b/content/common/browser_plugin/browser_plugin_messages.h index 74cb01d..8b92d36 100644 --- a/content/common/browser_plugin/browser_plugin_messages.h +++ b/content/common/browser_plugin/browser_plugin_messages.h @@ -23,6 +23,7 @@ #include "third_party/WebKit/public/web/WebDragOperation.h" #include "third_party/WebKit/public/web/WebDragStatus.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index da416eb..23714b4 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -29,6 +29,7 @@ #include "content/common/content_export.h" #include "gpu/ipc/gpu_command_buffer_traits.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #ifndef CONTENT_COMMON_CC_MESSAGES_H_ #define CONTENT_COMMON_CC_MESSAGES_H_ diff --git a/content/common/common_param_traits_unittest.cc b/content/common/common_param_traits_unittest.cc index 956695071..080e1cf 100644 --- a/content/common/common_param_traits_unittest.cc +++ b/content/common/common_param_traits_unittest.cc @@ -15,6 +15,7 @@ #include "printing/page_range.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/rect.h" #include "url/gurl.h" diff --git a/content/common/frame_messages.h b/content/common/frame_messages.h index 4d531e0..583a1ac 100644 --- a/content/common/frame_messages.h +++ b/content/common/frame_messages.h @@ -17,6 +17,7 @@ #include "content/public/common/javascript_message_type.h" #include "content/public/common/page_state.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "url/gurl.h" #undef IPC_MESSAGE_EXPORT diff --git a/content/common/frame_param_macros.h b/content/common/frame_param_macros.h index 023cfd6..32be0ad 100644 --- a/content/common/frame_param_macros.h +++ b/content/common/frame_param_macros.h @@ -13,10 +13,11 @@ #ifndef CONTENT_COMMON_FRAME_PARAM_MACROS_H_ #define CONTENT_COMMON_FRAME_PARAM_MACROS_H_ -#include "cc/output/compositor_frame_ack.h" #include "cc/output/compositor_frame.h" +#include "cc/output/compositor_frame_ack.h" #include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #undef IPC_MESSAGE_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT diff --git a/content/common/input_messages.h b/content/common/input_messages.h index aa6c4f1..f91ac6b 100644 --- a/content/common/input_messages.h +++ b/content/common/input_messages.h @@ -19,11 +19,12 @@ #include "content/common/input/synthetic_pinch_gesture_params.h" #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" #include "content/common/input/synthetic_tap_gesture_params.h" -#include "content/public/common/common_param_traits.h" #include "content/common/input/touch_action.h" +#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "ui/events/ipc/latency_info_param_traits.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/point.h" #include "ui/gfx/range/range.h" #include "ui/gfx/rect.h" diff --git a/content/common/plugin_process_messages.h b/content/common/plugin_process_messages.h index 5eb7544..9cb5e2c 100644 --- a/content/common/plugin_process_messages.h +++ b/content/common/plugin_process_messages.h @@ -10,6 +10,7 @@ #include "content/public/common/common_param_traits.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 5896ebb..5160e05 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -14,6 +14,7 @@ #include "content/common/content_export.h" #include "content/common/content_param_traits.h" #include "content/common/cookie_data.h" +#include "content/common/date_time_suggestion.h" #include "content/common/navigation_gesture.h" #include "content/common/pepper_renderer_instance_data.h" #include "content/common/view_message_enums.h" @@ -29,7 +30,6 @@ #include "content/public/common/stop_find_action.h" #include "content/public/common/three_d_api_types.h" #include "content/public/common/window_container_type.h" -#include "content/common/date_time_suggestion.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" @@ -49,6 +49,7 @@ #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" #include "ui/base/ui_base_types.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/point.h" #include "ui/gfx/range/range.h" #include "ui/gfx/rect.h" diff --git a/content/content_common.gypi b/content/content_common.gypi index a67b53a..7a4d32b 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -17,6 +17,7 @@ '../ui/events/ipc/events_ipc.gyp:events_ipc', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', + '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs', '../url/url.gyp:url_lib', ], diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 39a7aab..f750cce 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -57,6 +57,7 @@ '../ui/events/events.gyp:events_base', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', + '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '../ui/gl/gl.gyp:gl', '../url/url.gyp:url_lib', '../v8/tools/gyp/v8.gyp:v8', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index c33825d..66f6dda 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -363,6 +363,7 @@ '../ui/base/ui_base.gyp:ui_base', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', + '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', ], 'include_dirs': [ '..', diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc index 956801a..f4f9a08 100644 --- a/content/public/common/common_param_traits.cc +++ b/content/public/common/common_param_traits.cc @@ -12,44 +12,6 @@ #include "content/public/common/url_utils.h" #include "net/base/host_port_pair.h" #include "net/base/ip_endpoint.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/rect_f.h" - -namespace { - -struct SkBitmap_Data { - // The configuration for the bitmap (bits per pixel, etc). - SkBitmap::Config fConfig; - - // The width of the bitmap in pixels. - uint32 fWidth; - - // The height of the bitmap in pixels. - uint32 fHeight; - - void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { - fConfig = bitmap.config(); - fWidth = bitmap.width(); - fHeight = bitmap.height(); - } - - // Returns whether |bitmap| successfully initialized. - bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, - size_t total_pixels) const { - if (total_pixels) { - bitmap->setConfig(fConfig, fWidth, fHeight, 0); - if (!bitmap->allocPixels()) - return false; - if (total_pixels != bitmap->getSize()) - return false; - memcpy(bitmap->getPixels(), pixels, total_pixels); - } - return true; - } -}; - -} // namespace namespace IPC { @@ -177,220 +139,6 @@ void ParamTraits<content::PageState>::Log( l->append(")"); } -void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { - m->WriteInt(p.x()); - m->WriteInt(p.y()); -} - -bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, - gfx::Point* r) { - int x, y; - if (!m->ReadInt(iter, &x) || - !m->ReadInt(iter, &y)) - return false; - r->set_x(x); - r->set_y(y); - return true; -} - -void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { - l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); -} - -void ParamTraits<gfx::PointF>::Write(Message* m, const gfx::PointF& v) { - ParamTraits<float>::Write(m, v.x()); - ParamTraits<float>::Write(m, v.y()); -} - -bool ParamTraits<gfx::PointF>::Read(const Message* m, - PickleIterator* iter, - gfx::PointF* r) { - float x, y; - if (!ParamTraits<float>::Read(m, iter, &x) || - !ParamTraits<float>::Read(m, iter, &y)) - return false; - r->set_x(x); - r->set_y(y); - return true; -} - -void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) { - l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); -} - -void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { - DCHECK_GE(p.width(), 0); - DCHECK_GE(p.height(), 0); - int values[2] = { p.width(), p.height() }; - m->WriteBytes(&values, sizeof(int) * 2); -} - -bool ParamTraits<gfx::Size>::Read(const Message* m, - PickleIterator* iter, - gfx::Size* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) - return false; - const int* values = reinterpret_cast<const int*>(char_values); - if (values[0] < 0 || values[1] < 0) - return false; - r->set_width(values[0]); - r->set_height(values[1]); - return true; -} - -void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { - l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); -} - -void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { - float values[2] = { p.width(), p.height() }; - m->WriteBytes(&values, sizeof(float) * 2); -} - -bool ParamTraits<gfx::SizeF>::Read(const Message* m, - PickleIterator* iter, - gfx::SizeF* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) - return false; - const float* values = reinterpret_cast<const float*>(char_values); - r->set_width(values[0]); - r->set_height(values[1]); - return true; -} - -void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { - l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); -} - -void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { - int values[2] = { p.x(), p.y() }; - m->WriteBytes(&values, sizeof(int) * 2); -} - -bool ParamTraits<gfx::Vector2d>::Read(const Message* m, - PickleIterator* iter, - gfx::Vector2d* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) - return false; - const int* values = reinterpret_cast<const int*>(char_values); - r->set_x(values[0]); - r->set_y(values[1]); - return true; -} - -void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { - l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); -} - -void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { - float values[2] = { p.x(), p.y() }; - m->WriteBytes(&values, sizeof(float) * 2); -} - -bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, - PickleIterator* iter, - gfx::Vector2dF* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) - return false; - const float* values = reinterpret_cast<const float*>(char_values); - r->set_x(values[0]); - r->set_y(values[1]); - return true; -} - -void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { - l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); -} - -void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { - int values[4] = { p.x(), p.y(), p.width(), p.height() }; - m->WriteBytes(&values, sizeof(int) * 4); -} - -bool ParamTraits<gfx::Rect>::Read(const Message* m, - PickleIterator* iter, - gfx::Rect* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(int) * 4)) - return false; - const int* values = reinterpret_cast<const int*>(char_values); - if (values[2] < 0 || values[3] < 0) - return false; - r->SetRect(values[0], values[1], values[2], values[3]); - return true; -} - -void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { - l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), - p.width(), p.height())); -} - -void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { - float values[4] = { p.x(), p.y(), p.width(), p.height() }; - m->WriteBytes(&values, sizeof(float) * 4); -} - -bool ParamTraits<gfx::RectF>::Read(const Message* m, - PickleIterator* iter, - gfx::RectF* r) { - const char* char_values; - if (!m->ReadBytes(iter, &char_values, sizeof(float) * 4)) - return false; - const float* values = reinterpret_cast<const float*>(char_values); - r->SetRect(values[0], values[1], values[2], values[3]); - return true; -} - -void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { - l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), - p.width(), p.height())); -} - -void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { - size_t fixed_size = sizeof(SkBitmap_Data); - SkBitmap_Data bmp_data; - bmp_data.InitSkBitmapDataForTransfer(p); - m->WriteData(reinterpret_cast<const char*>(&bmp_data), - static_cast<int>(fixed_size)); - size_t pixel_size = p.getSize(); - SkAutoLockPixels p_lock(p); - m->WriteData(reinterpret_cast<const char*>(p.getPixels()), - static_cast<int>(pixel_size)); -} - -bool ParamTraits<SkBitmap>::Read(const Message* m, - PickleIterator* iter, - SkBitmap* r) { - const char* fixed_data; - int fixed_data_size = 0; - if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || - (fixed_data_size <= 0)) { - NOTREACHED(); - return false; - } - if (fixed_data_size != sizeof(SkBitmap_Data)) - return false; // Message is malformed. - - const char* variable_data; - int variable_data_size = 0; - if (!m->ReadData(iter, &variable_data, &variable_data_size) || - (variable_data_size < 0)) { - NOTREACHED(); - return false; - } - const SkBitmap_Data* bmp_data = - reinterpret_cast<const SkBitmap_Data*>(fixed_data); - return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); -} - -void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { - l->append("<SkBitmap>"); -} - } // namespace IPC // Generate param traits write methods. diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h index f527f16..657ef64 100644 --- a/content/public/common/common_param_traits.h +++ b/content/public/common/common_param_traits.h @@ -25,20 +25,10 @@ #include "url/gurl.h" #include "url/origin.h" -class SkBitmap; - namespace content { class PageState; } -namespace gfx { -class Point; -class Rect; -class RectF; -class Size; -class Vector2d; -} // namespace gfx - namespace net { class HostPortPair; class IPEndPoint; @@ -87,70 +77,6 @@ struct CONTENT_EXPORT ParamTraits<content::PageState> { }; template <> -struct CONTENT_EXPORT ParamTraits<gfx::Point> { - typedef gfx::Point param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::PointF> { - typedef gfx::PointF param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::Size> { - typedef gfx::Size param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::SizeF> { - typedef gfx::SizeF param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::Vector2d> { - typedef gfx::Vector2d param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::Vector2dF> { - typedef gfx::Vector2dF param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::Rect> { - typedef gfx::Rect param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct CONTENT_EXPORT ParamTraits<gfx::RectF> { - typedef gfx::RectF param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> struct ParamTraits<gfx::NativeWindow> { typedef gfx::NativeWindow param_type; static void Write(Message* m, const param_type& p) { @@ -204,18 +130,6 @@ struct ParamTraits<TransportDIB::Id> { }; #endif -template <> -struct CONTENT_EXPORT ParamTraits<SkBitmap> { - typedef SkBitmap param_type; - static void Write(Message* m, const param_type& p); - - // Note: This function expects parameter |r| to be of type &SkBitmap since - // r->SetConfig() and r->SetPixels() are called. - static bool Read(const Message* m, PickleIterator* iter, param_type* r); - - static void Log(const param_type& p, std::string* l); -}; - } // namespace IPC #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ diff --git a/content/shell/common/shell_messages.h b/content/shell/common/shell_messages.h index 077099a..cdef18a2 100644 --- a/content/shell/common/shell_messages.h +++ b/content/shell/common/shell_messages.h @@ -13,6 +13,7 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #define IPC_MESSAGE_START ShellMsgStart diff --git a/extensions/common/extension_messages.h b/extensions/common/extension_messages.h index ffdf7760..25dfa4d 100644 --- a/extensions/common/extension_messages.h +++ b/extensions/common/extension_messages.h @@ -24,6 +24,7 @@ #include "extensions/common/url_pattern_set.h" #include "extensions/common/view_type.h" #include "ipc/ipc_message_macros.h" +#include "ui/gfx/ipc/gfx_param_traits.h" #include "url/gurl.h" #define IPC_MESSAGE_START ExtensionMsgStart diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index aad3a2f..9e5bb56 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -23,6 +23,7 @@ '../third_party/re2/re2.gyp:re2', '../ui/base/ui_base.gyp:ui_base', '../ui/gfx/gfx.gyp:gfx_geometry', + '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '../url/url.gyp:url_lib', 'common/api/api.gyp:extensions_api', 'extensions_strings.gyp:extensions_strings', diff --git a/extensions/renderer/set_icon_natives.cc b/extensions/renderer/set_icon_natives.cc index c9a222f..2ef12dc 100644 --- a/extensions/renderer/set_icon_natives.cc +++ b/extensions/renderer/set_icon_natives.cc @@ -12,6 +12,7 @@ #include "extensions/renderer/script_context.h" #include "ipc/ipc_message_utils.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/ipc/gfx_param_traits.h" namespace { diff --git a/ui/gfx/ipc/OWNERS b/ui/gfx/ipc/OWNERS new file mode 100644 index 0000000..16e98c2 --- /dev/null +++ b/ui/gfx/ipc/OWNERS @@ -0,0 +1,14 @@ +per-file gfx_param_traits.cc=set noparent +per-file gfx_param_traits.cc=cevans@chromium.org +per-file gfx_param_traits.cc=tsepez@chromium.org + +per-file *param_traits*.h=set noparent +per-file *param_traits*.h=cevans@chromium.org +per-file *param_traits*.h=dcheng@chromium.org +per-file *param_traits*.h=inferno@chromium.org +per-file *param_traits*.h=jln@chromium.org +per-file *param_traits*.h=jschuh@chromium.org +per-file *param_traits*.h=kenrb@chromium.org +per-file *param_traits*.h=nasko@chromium.org +per-file *param_traits*.h=palmer@chromium.org +per-file *param_traits*.h=tsepez@chromium.org diff --git a/ui/gfx/ipc/gfx_ipc.gyp b/ui/gfx/ipc/gfx_ipc.gyp new file mode 100644 index 0000000..1facce5 --- /dev/null +++ b/ui/gfx/ipc/gfx_ipc.gyp @@ -0,0 +1,31 @@ +# Copyright 2014 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. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets': [ + { + 'target_name': 'gfx_ipc', + 'type': '<(component)', + 'dependencies': [ + '../../../base/base.gyp:base', + '../../../ipc/ipc.gyp:ipc', + '../../../skia/skia.gyp:skia', + '../gfx.gyp:gfx_geometry', + ], + 'defines': [ + 'GFX_IPC_IMPLEMENTATION', + ], + 'include_dirs': [ + '../../..', + ], + 'sources': [ + 'gfx_param_traits.cc', + 'gfx_param_traits.h', + ], + }, + ], +} diff --git a/ui/gfx/ipc/gfx_ipc_export.h b/ui/gfx/ipc/gfx_ipc_export.h new file mode 100644 index 0000000..4c6b703 --- /dev/null +++ b/ui/gfx/ipc/gfx_ipc_export.h @@ -0,0 +1,29 @@ +// Copyright 2014 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 GFX_IPC_EXPORT_H_ +#define GFX_IPC_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(GFX_IPC_IMPLEMENTATION) +#define GFX_IPC_EXPORT __declspec(dllexport) +#else +#define GFX_IPC_EXPORT __declspec(dllimport) +#endif // defined(GFX_IPC_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(GFX_IPC_IMPLEMENTATION) +#define GFX_IPC_EXPORT __attribute__((visibility("default"))) +#else +#define GFX_IPC_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define GFX_IPC_EXPORT +#endif + +#endif // GFX_IPC_EXPORT_H_ diff --git a/ui/gfx/ipc/gfx_param_traits.cc b/ui/gfx/ipc/gfx_param_traits.cc new file mode 100644 index 0000000..f3550d5 --- /dev/null +++ b/ui/gfx/ipc/gfx_param_traits.cc @@ -0,0 +1,264 @@ +// Copyright 2014 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 "ui/gfx/ipc/gfx_param_traits.h" + +#include <string> + +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/rect_f.h" + +namespace { + +struct SkBitmap_Data { + // The configuration for the bitmap (bits per pixel, etc). + SkBitmap::Config fConfig; + + // The width of the bitmap in pixels. + uint32 fWidth; + + // The height of the bitmap in pixels. + uint32 fHeight; + + void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { + fConfig = bitmap.config(); + fWidth = bitmap.width(); + fHeight = bitmap.height(); + } + + // Returns whether |bitmap| successfully initialized. + bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, + size_t total_pixels) const { + if (total_pixels) { + bitmap->setConfig(fConfig, fWidth, fHeight, 0); + if (!bitmap->allocPixels()) + return false; + if (total_pixels != bitmap->getSize()) + return false; + memcpy(bitmap->getPixels(), pixels, total_pixels); + } + return true; + } +}; + +} // namespace + +namespace IPC { + +void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { + m->WriteInt(p.x()); + m->WriteInt(p.y()); +} + +bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, + gfx::Point* r) { + int x, y; + if (!m->ReadInt(iter, &x) || + !m->ReadInt(iter, &y)) + return false; + r->set_x(x); + r->set_y(y); + return true; +} + +void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { + l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); +} + +void ParamTraits<gfx::PointF>::Write(Message* m, const gfx::PointF& v) { + ParamTraits<float>::Write(m, v.x()); + ParamTraits<float>::Write(m, v.y()); +} + +bool ParamTraits<gfx::PointF>::Read(const Message* m, + PickleIterator* iter, + gfx::PointF* r) { + float x, y; + if (!ParamTraits<float>::Read(m, iter, &x) || + !ParamTraits<float>::Read(m, iter, &y)) + return false; + r->set_x(x); + r->set_y(y); + return true; +} + +void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) { + l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); +} + +void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { + DCHECK_GE(p.width(), 0); + DCHECK_GE(p.height(), 0); + int values[2] = { p.width(), p.height() }; + m->WriteBytes(&values, sizeof(int) * 2); +} + +bool ParamTraits<gfx::Size>::Read(const Message* m, + PickleIterator* iter, + gfx::Size* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) + return false; + const int* values = reinterpret_cast<const int*>(char_values); + if (values[0] < 0 || values[1] < 0) + return false; + r->set_width(values[0]); + r->set_height(values[1]); + return true; +} + +void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { + l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); +} + +void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { + float values[2] = { p.width(), p.height() }; + m->WriteBytes(&values, sizeof(float) * 2); +} + +bool ParamTraits<gfx::SizeF>::Read(const Message* m, + PickleIterator* iter, + gfx::SizeF* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) + return false; + const float* values = reinterpret_cast<const float*>(char_values); + r->set_width(values[0]); + r->set_height(values[1]); + return true; +} + +void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { + l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); +} + +void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { + int values[2] = { p.x(), p.y() }; + m->WriteBytes(&values, sizeof(int) * 2); +} + +bool ParamTraits<gfx::Vector2d>::Read(const Message* m, + PickleIterator* iter, + gfx::Vector2d* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) + return false; + const int* values = reinterpret_cast<const int*>(char_values); + r->set_x(values[0]); + r->set_y(values[1]); + return true; +} + +void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { + l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); +} + +void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { + float values[2] = { p.x(), p.y() }; + m->WriteBytes(&values, sizeof(float) * 2); +} + +bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, + PickleIterator* iter, + gfx::Vector2dF* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) + return false; + const float* values = reinterpret_cast<const float*>(char_values); + r->set_x(values[0]); + r->set_y(values[1]); + return true; +} + +void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { + l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); +} + +void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { + int values[4] = { p.x(), p.y(), p.width(), p.height() }; + m->WriteBytes(&values, sizeof(int) * 4); +} + +bool ParamTraits<gfx::Rect>::Read(const Message* m, + PickleIterator* iter, + gfx::Rect* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(int) * 4)) + return false; + const int* values = reinterpret_cast<const int*>(char_values); + if (values[2] < 0 || values[3] < 0) + return false; + r->SetRect(values[0], values[1], values[2], values[3]); + return true; +} + +void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { + l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), + p.width(), p.height())); +} + +void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { + float values[4] = { p.x(), p.y(), p.width(), p.height() }; + m->WriteBytes(&values, sizeof(float) * 4); +} + +bool ParamTraits<gfx::RectF>::Read(const Message* m, + PickleIterator* iter, + gfx::RectF* r) { + const char* char_values; + if (!m->ReadBytes(iter, &char_values, sizeof(float) * 4)) + return false; + const float* values = reinterpret_cast<const float*>(char_values); + r->SetRect(values[0], values[1], values[2], values[3]); + return true; +} + +void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { + l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), + p.width(), p.height())); +} + +void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { + size_t fixed_size = sizeof(SkBitmap_Data); + SkBitmap_Data bmp_data; + bmp_data.InitSkBitmapDataForTransfer(p); + m->WriteData(reinterpret_cast<const char*>(&bmp_data), + static_cast<int>(fixed_size)); + size_t pixel_size = p.getSize(); + SkAutoLockPixels p_lock(p); + m->WriteData(reinterpret_cast<const char*>(p.getPixels()), + static_cast<int>(pixel_size)); +} + +bool ParamTraits<SkBitmap>::Read(const Message* m, + PickleIterator* iter, + SkBitmap* r) { + const char* fixed_data; + int fixed_data_size = 0; + if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || + (fixed_data_size <= 0)) { + NOTREACHED(); + return false; + } + if (fixed_data_size != sizeof(SkBitmap_Data)) + return false; // Message is malformed. + + const char* variable_data; + int variable_data_size = 0; + if (!m->ReadData(iter, &variable_data, &variable_data_size) || + (variable_data_size < 0)) { + NOTREACHED(); + return false; + } + const SkBitmap_Data* bmp_data = + reinterpret_cast<const SkBitmap_Data*>(fixed_data); + return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); +} + +void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { + l->append("<SkBitmap>"); +} + +} // namespace IPC diff --git a/ui/gfx/ipc/gfx_param_traits.h b/ui/gfx/ipc/gfx_param_traits.h new file mode 100644 index 0000000..2a8ef44 --- /dev/null +++ b/ui/gfx/ipc/gfx_param_traits.h @@ -0,0 +1,107 @@ +// Copyright 2014 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 UI_GFX_IPC_GFX_PARAM_TRAITS_H_ +#define UI_GFX_IPC_GFX_PARAM_TRAITS_H_ + +#include <string> + +#include "ipc/ipc_message_utils.h" +#include "ui/gfx/ipc/gfx_ipc_export.h" +#include "ui/gfx/ipc/gfx_param_traits.h" + +class SkBitmap; + +namespace gfx { +class Point; +class PointF; +class Rect; +class RectF; +class Size; +class SizeF; +class Vector2d; +class Vector2dF; +} // namespace gfx + +namespace IPC { + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::Point> { + typedef gfx::Point param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::PointF> { + typedef gfx::PointF param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::Size> { + typedef gfx::Size param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::SizeF> { + typedef gfx::SizeF param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::Vector2d> { + typedef gfx::Vector2d param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::Vector2dF> { + typedef gfx::Vector2dF param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::Rect> { + typedef gfx::Rect param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<gfx::RectF> { + typedef gfx::RectF param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct GFX_IPC_EXPORT ParamTraits<SkBitmap> { + typedef SkBitmap param_type; + static void Write(Message* m, const param_type& p); + + // Note: This function expects parameter |r| to be of type &SkBitmap since + // r->SetConfig() and r->SetPixels() are called. + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // UI_GFX_IPC_GFX_PARAM_TRAITS_H_ |