Skip to content

Commit

Permalink
[chromium] Add setters to WebFilterOperation for IPC pickling
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=97147

Reviewed by James Robinson.

Source/Platform:

These methods allow us to restore a WebFilterOperation from a blob
of opaque data. The pickling code needs to be able to create an
empty object and then fill in the pieces, so these setters allow it
to do so.

Test: WebFilterOperationsTest.saveAndRestore

* chromium/public/WebFilterOperation.h:
(WebKit::WebFilterOperation::amount):
(WebKit::WebFilterOperation::dropShadowOffset):
(WebKit::WebFilterOperation::matrix):
(WebKit::WebFilterOperation::zoomRect):
(WebFilterOperation):
(WebKit::WebFilterOperation::createEmptyFilter):
(WebKit::WebFilterOperation::setType):
(WebKit::WebFilterOperation::setAmount):
(WebKit::WebFilterOperation::setDropShadowOffset):
(WebKit::WebFilterOperation::setDropShadowColor):
(WebKit::WebFilterOperation::setMatrix):
(WebKit::WebFilterOperation::setZoomRect):
* chromium/src/WebFilterOperation.cpp:

Source/WebKit/chromium:

* tests/FilterOperationsTest.cpp:
(WebKit):
(WebKit::TEST):


Canonical link: https://commits.webkit.org/115401@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129373 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
danakj committed Sep 24, 2012
1 parent ab01a20 commit 4ae8a12
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Source/Platform/ChangeLog
@@ -1,3 +1,32 @@
2012-09-24 Dana Jansens <danakj@chromium.org>

[chromium] Add setters to WebFilterOperation for IPC pickling
https://bugs.webkit.org/show_bug.cgi?id=97147

Reviewed by James Robinson.

These methods allow us to restore a WebFilterOperation from a blob
of opaque data. The pickling code needs to be able to create an
empty object and then fill in the pieces, so these setters allow it
to do so.

Test: WebFilterOperationsTest.saveAndRestore

* chromium/public/WebFilterOperation.h:
(WebKit::WebFilterOperation::amount):
(WebKit::WebFilterOperation::dropShadowOffset):
(WebKit::WebFilterOperation::matrix):
(WebKit::WebFilterOperation::zoomRect):
(WebFilterOperation):
(WebKit::WebFilterOperation::createEmptyFilter):
(WebKit::WebFilterOperation::setType):
(WebKit::WebFilterOperation::setAmount):
(WebKit::WebFilterOperation::setDropShadowOffset):
(WebKit::WebFilterOperation::setDropShadowColor):
(WebKit::WebFilterOperation::setMatrix):
(WebKit::WebFilterOperation::setZoomRect):
* chromium/src/WebFilterOperation.cpp:

2012-09-24 Yury Semikhatsky <yurys@chromium.org>

Unreviewed, rolling out r122243.
Expand Down
57 changes: 54 additions & 3 deletions Source/Platform/chromium/public/WebFilterOperation.h
Expand Up @@ -55,12 +55,23 @@ class WebFilterOperation {

float amount() const
{
WEBKIT_ASSERT(m_type == FilterTypeGrayscale
|| m_type == FilterTypeSepia
|| m_type == FilterTypeSaturate
|| m_type == FilterTypeHueRotate
|| m_type == FilterTypeInvert
|| m_type == FilterTypeBrightness
|| m_type == FilterTypeContrast
|| m_type == FilterTypeOpacity
|| m_type == FilterTypeBlur
|| m_type == FilterTypeDropShadow
|| m_type == FilterTypeZoom);
return m_amount;
}
WebPoint dropShadowOffset() const
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
return WebPoint(m_dropShadowOffset);
return m_dropShadowOffset;
}
WebColor dropShadowColor() const
{
Expand All @@ -69,16 +80,16 @@ class WebFilterOperation {
}
const SkScalar* matrix() const
{
WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
return m_matrix;
}

WebRect zoomRect() const
{
WEBKIT_ASSERT(m_type == FilterTypeZoom);
return WebRect(m_zoomRect);
return m_zoomRect;
}

#define WEBKIT_HAS_NEW_WEBFILTEROPERATION_API 1
static WebFilterOperation createGrayscaleFilter(float amount) { return WebFilterOperation(FilterTypeGrayscale, amount); }
static WebFilterOperation createSepiaFilter(float amount) { return WebFilterOperation(FilterTypeSepia, amount); }
static WebFilterOperation createSaturateFilter(float amount) { return WebFilterOperation(FilterTypeSaturate, amount); }
Expand All @@ -94,6 +105,46 @@ class WebFilterOperation {

bool equals(const WebFilterOperation& other) const;

// Methods for restoring a WebFilterOperation.
static WebFilterOperation createEmptyFilter() { return WebFilterOperation(FilterTypeGrayscale, 0.0); }
void setType(FilterType type) { m_type = type; }
void setAmount(float amount)
{
WEBKIT_ASSERT(m_type == FilterTypeGrayscale
|| m_type == FilterTypeSepia
|| m_type == FilterTypeSaturate
|| m_type == FilterTypeHueRotate
|| m_type == FilterTypeInvert
|| m_type == FilterTypeBrightness
|| m_type == FilterTypeContrast
|| m_type == FilterTypeOpacity
|| m_type == FilterTypeBlur
|| m_type == FilterTypeDropShadow
|| m_type == FilterTypeZoom);
m_amount = amount;
}
void setDropShadowOffset(WebPoint offset)
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
m_dropShadowOffset = offset;
}
void setDropShadowColor(WebColor color)
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
m_dropShadowColor = color;
}
void setMatrix(const SkScalar matrix[20])
{
WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
for (unsigned i = 0; i < 20; ++i)
m_matrix[i] = matrix[i];
}
void setZoomRect(WebRect rect)
{
WEBKIT_ASSERT(m_type == FilterTypeZoom);
m_zoomRect = rect;
}

private:
FilterType m_type;

Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/chromium/ChangeLog
@@ -1,3 +1,14 @@
2012-09-24 Dana Jansens <danakj@chromium.org>

[chromium] Add setters to WebFilterOperation for IPC pickling
https://bugs.webkit.org/show_bug.cgi?id=97147

Reviewed by James Robinson.

* tests/FilterOperationsTest.cpp:
(WebKit):
(WebKit::TEST):

2012-09-24 Patrick Gansterer <paroga@webkit.org>

Remove remaining WTF_DEPRECATED_STRING_OPERATORS from cpp files
Expand Down
103 changes: 103 additions & 0 deletions Source/WebKit/chromium/tests/FilterOperationsTest.cpp
Expand Up @@ -89,5 +89,108 @@ TEST(WebFilterOperationsTest, getOutsetsDropShadow)
EXPECT_EQ(54, left);
}

#define SAVE_RESTORE_AMOUNT(Type, a) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.amount()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.amount()); \
\
op2.setAmount(a); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.amount()); \
}

#define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(Type, a, b, c) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b, c); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.dropShadowOffset()); \
EXPECT_EQ(b, op.amount()); \
EXPECT_EQ(c, op.dropShadowColor()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.dropShadowOffset()); \
EXPECT_NE(b, op2.amount()); \
EXPECT_NE(c, op2.dropShadowColor()); \
\
op2.setDropShadowOffset(a); \
op2.setAmount(b); \
op2.setDropShadowColor(c); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.dropShadowOffset()); \
EXPECT_EQ(b, op2.amount()); \
EXPECT_EQ(c, op2.dropShadowColor()); \
}

#define SAVE_RESTORE_MATRIX(Type, a) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
for (unsigned i = 0; i < 20; ++i) \
EXPECT_EQ(a[i], op.matrix()[i]); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
for (unsigned i = 0; i < 20; ++i) \
EXPECT_NE(a[i], op2.matrix()[i]); \
\
op2.setMatrix(a); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
for (unsigned i = 0; i < 20; ++i) \
EXPECT_EQ(a[i], op.matrix()[i]); \
}

#define SAVE_RESTORE_ZOOMRECT_AMOUNT(Type, a, b) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.zoomRect()); \
EXPECT_EQ(b, op.amount()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.zoomRect()); \
EXPECT_NE(b, op2.amount()); \
\
op2.setZoomRect(a); \
op2.setAmount(b); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.zoomRect()); \
EXPECT_EQ(b, op2.amount()); \
}


TEST(WebFilterOperationsTest, saveAndRestore)
{
SAVE_RESTORE_AMOUNT(Grayscale, 0.6f);
SAVE_RESTORE_AMOUNT(Sepia, 0.6f);
SAVE_RESTORE_AMOUNT(Saturate, 0.6f);
SAVE_RESTORE_AMOUNT(HueRotate, 0.6f);
SAVE_RESTORE_AMOUNT(Invert, 0.6f);
SAVE_RESTORE_AMOUNT(Brightness, 0.6f);
SAVE_RESTORE_AMOUNT(Contrast, 0.6f);
SAVE_RESTORE_AMOUNT(Opacity, 0.6f);
SAVE_RESTORE_AMOUNT(Blur, 0.6f);
SAVE_RESTORE_OFFSET_AMOUNT_COLOR(DropShadow, WebPoint(3, 4), 0.4f, 0xffffff00);

SkScalar matrix[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
SAVE_RESTORE_MATRIX(ColorMatrix, matrix);

SAVE_RESTORE_ZOOMRECT_AMOUNT(Zoom, WebRect(20, 19, 18, 17), 32);
}

}

0 comments on commit 4ae8a12

Please sign in to comment.