Commit a176567b authored by sugoi@chromium.org's avatar sugoi@chromium.org

Added SkImageFilter serialization

BUG=164084

Review URL: https://chromiumcodereview.appspot.com/21271002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217117 0039d316-1c4b-4281-b951-d872f2087c98
parent d912cb99
...@@ -67,6 +67,7 @@ std::string DeriveCommandLine(const GURL& start_url, ...@@ -67,6 +67,7 @@ std::string DeriveCommandLine(const GURL& start_url,
DCHECK_NE(&base_command_line, command_line); DCHECK_NE(&base_command_line, command_line);
static const char* kForwardSwitches[] = { static const char* kForwardSwitches[] = {
::switches::kAllowFiltersOverIPC,
::switches::kAllowWebUICompositing, ::switches::kAllowWebUICompositing,
::switches::kDeviceManagementUrl, ::switches::kDeviceManagementUrl,
::switches::kDisableAccelerated2dCanvas, ::switches::kDisableAccelerated2dCanvas,
......
...@@ -871,6 +871,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( ...@@ -871,6 +871,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
// Propagate the following switches to the renderer command line (along // Propagate the following switches to the renderer command line (along
// with any associated values) if present in the browser command line. // with any associated values) if present in the browser command line.
static const char* const kSwitchNames[] = { static const char* const kSwitchNames[] = {
switches::kAllowFiltersOverIPC,
switches::kAudioBufferSize, switches::kAudioBufferSize,
switches::kAuditAllHandles, switches::kAuditAllHandles,
switches::kAuditHandles, switches::kAuditHandles,
......
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
#include "content/common/cc_messages.h" #include "content/common/cc_messages.h"
#include "base/command_line.h"
#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame.h"
#include "cc/output/filter_operations.h" #include "cc/output/filter_operations.h"
#include "content/public/common/common_param_traits.h" #include "content/public/common/common_param_traits.h"
#include "content/public/common/content_switches.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
namespace IPC { namespace IPC {
...@@ -185,6 +189,41 @@ void ParamTraits<cc::FilterOperations>::Log( ...@@ -185,6 +189,41 @@ void ParamTraits<cc::FilterOperations>::Log(
l->append(")"); l->append(")");
} }
void ParamTraits<skia::RefPtr<SkImageFilter> >::Write(
Message* m, const param_type& p) {
SkImageFilter* filter = p.get();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (filter && command_line.HasSwitch(switches::kAllowFiltersOverIPC)) {
skia::RefPtr<SkData> data = skia::AdoptRef(SkSerializeFlattenable(filter));
m->WriteData(static_cast<const char*>(data->data()), data->size());
} else {
m->WriteData(0, 0);
}
}
bool ParamTraits<skia::RefPtr<SkImageFilter> >::Read(
const Message* m, PickleIterator* iter, param_type* r) {
const char* data = 0;
int length = 0;
if (!m->ReadData(iter, &data, &length))
return false;
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if ((length > 0) && command_line.HasSwitch(switches::kAllowFiltersOverIPC)) {
SkFlattenable* flattenable = SkDeserializeFlattenable(data, length);
*r = skia::AdoptRef(static_cast<SkImageFilter*>(flattenable));
} else {
r->clear();
}
return true;
}
void ParamTraits<skia::RefPtr<SkImageFilter> >::Log(
const param_type& p, std::string* l) {
l->append("(");
LogParam(p.get() ? p->countInputs() : 0, l);
l->append(")");
}
void ParamTraits<gfx::Transform>::Write( void ParamTraits<gfx::Transform>::Write(
Message* m, const param_type& p) { Message* m, const param_type& p) {
WriteParam(m, p.matrix().getDouble(0, 0)); WriteParam(m, p.matrix().getDouble(0, 0));
......
...@@ -55,6 +55,14 @@ struct ParamTraits<cc::FilterOperations> { ...@@ -55,6 +55,14 @@ struct ParamTraits<cc::FilterOperations> {
static void Log(const param_type& p, std::string* l); static void Log(const param_type& p, std::string* l);
}; };
template <>
struct ParamTraits<skia::RefPtr<SkImageFilter> > {
typedef skia::RefPtr<SkImageFilter> 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 <> template <>
struct ParamTraits<gfx::Transform> { struct ParamTraits<gfx::Transform> {
typedef gfx::Transform param_type; typedef gfx::Transform param_type;
...@@ -148,8 +156,7 @@ IPC_STRUCT_TRAITS_BEGIN(cc::RenderPassDrawQuad) ...@@ -148,8 +156,7 @@ IPC_STRUCT_TRAITS_BEGIN(cc::RenderPassDrawQuad)
IPC_STRUCT_TRAITS_MEMBER(contents_changed_since_last_frame) IPC_STRUCT_TRAITS_MEMBER(contents_changed_since_last_frame)
IPC_STRUCT_TRAITS_MEMBER(mask_uv_rect) IPC_STRUCT_TRAITS_MEMBER(mask_uv_rect)
IPC_STRUCT_TRAITS_MEMBER(filters) IPC_STRUCT_TRAITS_MEMBER(filters)
// TODO(piman): filter isn't being serialized. IPC_STRUCT_TRAITS_MEMBER(filter)
// IPC_STRUCT_TRAITS_MEMBER(filter)
IPC_STRUCT_TRAITS_MEMBER(background_filters) IPC_STRUCT_TRAITS_MEMBER(background_filters)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
......
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
#include <string.h> #include <string.h>
#include "base/command_line.h"
#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/effects/SkBlurImageFilter.h"
using cc::CheckerboardDrawQuad; using cc::CheckerboardDrawQuad;
using cc::DelegatedFrameData; using cc::DelegatedFrameData;
...@@ -134,7 +137,10 @@ class CCMessagesTest : public testing::Test { ...@@ -134,7 +137,10 @@ class CCMessagesTest : public testing::Test {
b->contents_changed_since_last_frame); b->contents_changed_since_last_frame);
EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString()); EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString());
EXPECT_EQ(a->filters, b->filters); EXPECT_EQ(a->filters, b->filters);
EXPECT_EQ(a->filter, b->filter); if (!a->filter || !b->filter)
EXPECT_EQ(a->filter, b->filter);
else
EXPECT_EQ(a->filter->countInputs(), b->filter->countInputs());
EXPECT_EQ(a->background_filters, b->background_filters); EXPECT_EQ(a->background_filters, b->background_filters);
} }
...@@ -188,6 +194,10 @@ class CCMessagesTest : public testing::Test { ...@@ -188,6 +194,10 @@ class CCMessagesTest : public testing::Test {
}; };
TEST_F(CCMessagesTest, AllQuads) { TEST_F(CCMessagesTest, AllQuads) {
CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kAllowFiltersOverIPC))
command_line.AppendSwitch(switches::kAllowFiltersOverIPC);
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
Transform arbitrary_matrix; Transform arbitrary_matrix;
...@@ -220,6 +230,7 @@ TEST_F(CCMessagesTest, AllQuads) { ...@@ -220,6 +230,7 @@ TEST_F(CCMessagesTest, AllQuads) {
ResourceProvider::ResourceId arbitrary_resourceid2 = 47; ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
ResourceProvider::ResourceId arbitrary_resourceid3 = 23; ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
ResourceProvider::ResourceId arbitrary_resourceid4 = 16; ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
FilterOperations arbitrary_filters1; FilterOperations arbitrary_filters1;
arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter( arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
...@@ -229,8 +240,8 @@ TEST_F(CCMessagesTest, AllQuads) { ...@@ -229,8 +240,8 @@ TEST_F(CCMessagesTest, AllQuads) {
arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter( arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
arbitrary_float2)); arbitrary_float2));
// TODO(danakj): filter is not serialized. skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
skia::RefPtr<SkImageFilter> arbitrary_filter; new SkBlurImageFilter(arbitrary_sigma, arbitrary_sigma));
scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create(); scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create();
shared_state1_in->SetAll(arbitrary_matrix, shared_state1_in->SetAll(arbitrary_matrix,
...@@ -290,7 +301,7 @@ TEST_F(CCMessagesTest, AllQuads) { ...@@ -290,7 +301,7 @@ TEST_F(CCMessagesTest, AllQuads) {
arbitrary_rect1, arbitrary_rect1,
arbitrary_rectf1, arbitrary_rectf1,
arbitrary_filters1, arbitrary_filters1,
arbitrary_filter, // TODO(piman): not serialized. arbitrary_filter,
arbitrary_filters2); arbitrary_filters2);
scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy( scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy(
renderpass_in->shared_quad_state, renderpass_in->render_pass_id); renderpass_in->shared_quad_state, renderpass_in->render_pass_id);
......
...@@ -935,4 +935,7 @@ extern const char kTestCompositor[] = "test-compositor"; ...@@ -935,4 +935,7 @@ extern const char kTestCompositor[] = "test-compositor";
// Don't dump stuff here, follow the same order as the header. // Don't dump stuff here, follow the same order as the header.
// Allows filters (SkImageFilter objects) to be sent between processes over IPC
const char kAllowFiltersOverIPC[] = "allow-filters-over-ipc";
} // namespace switches } // namespace switches
...@@ -283,6 +283,8 @@ CONTENT_EXPORT extern const char kTestCompositor[]; ...@@ -283,6 +283,8 @@ CONTENT_EXPORT extern const char kTestCompositor[];
// DON'T ADD RANDOM STUFF HERE. Put it in the main section above in // DON'T ADD RANDOM STUFF HERE. Put it in the main section above in
// alphabetical order, or in one of the ifdefs (also in order in each section). // alphabetical order, or in one of the ifdefs (also in order in each section).
CONTENT_EXPORT extern const char kAllowFiltersOverIPC[];
} // namespace switches } // namespace switches
#endif // CONTENT_PUBLIC_COMMON_CONTENT_SWITCHES_H_ #endif // CONTENT_PUBLIC_COMMON_CONTENT_SWITCHES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment