Title: [129243] trunk/Source
Revision
129243
Author
[email protected]
Date
2012-09-21 11:47:16 -0700 (Fri, 21 Sep 2012)

Log Message

[chromium] Add setters to WebFilterOperation for IPC pickling
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):

Modified Paths

Diff

Modified: trunk/Source/Platform/ChangeLog (129242 => 129243)


--- trunk/Source/Platform/ChangeLog	2012-09-21 18:13:47 UTC (rev 129242)
+++ trunk/Source/Platform/ChangeLog	2012-09-21 18:47:16 UTC (rev 129243)
@@ -1,3 +1,32 @@
+2012-09-21  Dana Jansens  <[email protected]>
+
+        [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-20  Keishi Hattori  <[email protected]>
 
         [Chromium ] Add new localized string, OtherDateLabel, to be used in input type=date datalist UI

Modified: trunk/Source/Platform/chromium/public/WebFilterOperation.h (129242 => 129243)


--- trunk/Source/Platform/chromium/public/WebFilterOperation.h	2012-09-21 18:13:47 UTC (rev 129242)
+++ trunk/Source/Platform/chromium/public/WebFilterOperation.h	2012-09-21 18:47:16 UTC (rev 129243)
@@ -55,12 +55,23 @@
 
     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
     {
@@ -69,16 +80,16 @@
     }
     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); }
@@ -94,6 +105,46 @@
 
     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;
 

Modified: trunk/Source/WebKit/chromium/ChangeLog (129242 => 129243)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-09-21 18:13:47 UTC (rev 129242)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-09-21 18:47:16 UTC (rev 129243)
@@ -1,3 +1,14 @@
+2012-09-21  Dana Jansens  <[email protected]>
+
+        [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-21  Tony Chang  <[email protected]>
 
         [chromium] Unreviewed, remove duplicate section of WebKit.gyp pointed out by Nico.

Modified: trunk/Source/WebKit/chromium/tests/FilterOperationsTest.cpp (129242 => 129243)


--- trunk/Source/WebKit/chromium/tests/FilterOperationsTest.cpp	2012-09-21 18:13:47 UTC (rev 129242)
+++ trunk/Source/WebKit/chromium/tests/FilterOperationsTest.cpp	2012-09-21 18:47:16 UTC (rev 129243)
@@ -89,5 +89,108 @@
     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 };
+    SAVE_RESTORE_MATRIX(ColorMatrix, matrix);
+
+    SAVE_RESTORE_ZOOMRECT_AMOUNT(Zoom, WebRect(20, 19, 18, 17), 32);
 }
 
+}
+
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to