Diff
Modified: trunk/Source/Platform/ChangeLog (124391 => 124392)
--- trunk/Source/Platform/ChangeLog 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/Platform/ChangeLog 2012-08-02 00:22:05 UTC (rev 124392)
@@ -1,3 +1,29 @@
+2012-08-01 Antoine Labour <[email protected]>
+
+ [chromium] factor out the optimization pass in CCRenderSurfaceFilters::apply
+ https://bugs.webkit.org/show_bug.cgi?id=92453
+
+ Reviewed by James Robinson.
+
+ This separates the "optimization" pass in CCRenderSurfaceFilters::apply
+ to resolve a succession of color matrix filters into a single operation.
+ This allows testing of that code.
+ This introduces a new generic color matrix WebFilterOperation, which can
+ also be used on its own.
+
+ * Platform.gypi:
+ * chromium/public/WebFilterOperation.h:
+ (WebKit::WebFilterOperation::matrix):
+ (WebKit::WebFilterOperation::createColorMatrixFilter):
+ (WebFilterOperation):
+ (WebKit::WebFilterOperation::WebFilterOperation):
+ * chromium/src/WebFilterOperation.cpp: Copied from Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.h.
+ (WebKit):
+ (WebKit::WebFilterOperation::equals):
+ (WebKit::WebFilterOperation::WebFilterOperation):
+ * chromium/src/WebFilterOperations.cpp:
+ (WebKit::WebFilterOperations::hasFilterThatAffectsOpacity):
+
2012-08-01 Tommy Widenflycht <[email protected]>
MediaStream API: Add ExtraData capability to MediaStreamSource
Modified: trunk/Source/Platform/Platform.gyp/Platform.gyp (124391 => 124392)
--- trunk/Source/Platform/Platform.gyp/Platform.gyp 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/Platform/Platform.gyp/Platform.gyp 2012-08-02 00:22:05 UTC (rev 124392)
@@ -39,6 +39,7 @@
'type': 'static_library',
'dependencies': [
'../../WTF/WTF.gyp/WTF.gyp:wtf',
+ '<(DEPTH)/skia/skia.gyp:skia',
],
'include_dirs': [
'../chromium',
Modified: trunk/Source/Platform/Platform.gypi (124391 => 124392)
--- trunk/Source/Platform/Platform.gypi 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/Platform/Platform.gypi 2012-08-02 00:22:05 UTC (rev 124392)
@@ -151,6 +151,7 @@
'chromium/public/win/WebThemeEngine.h',
'chromium/src/Platform.cpp',
'chromium/src/WebCString.cpp',
+ 'chromium/src/WebFilterOperation.cpp',
'chromium/src/WebFilterOperations.cpp',
'chromium/src/WebFloatQuad.cpp',
'chromium/src/WebPrerenderingSupport.cpp',
Modified: trunk/Source/Platform/chromium/public/WebFilterOperation.h (124391 => 124392)
--- trunk/Source/Platform/chromium/public/WebFilterOperation.h 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/Platform/chromium/public/WebFilterOperation.h 2012-08-02 00:22:05 UTC (rev 124392)
@@ -26,8 +26,8 @@
#ifndef WebFilterOperation_h
#define WebFilterOperation_h
+#include "SkScalar.h"
#include "WebCommon.h"
-
#include "WebColor.h"
#include "WebPoint.h"
@@ -46,6 +46,7 @@
FilterTypeOpacity,
FilterTypeBlur,
FilterTypeDropShadow,
+ FilterTypeColorMatrix,
};
FilterType type() const { return m_type; }
@@ -64,6 +65,10 @@
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
return m_dropShadowColor;
}
+ const SkScalar* matrix() const
+ {
+ return m_matrix;
+ }
#define WEBKIT_HAS_NEW_WEBFILTEROPERATION_API 1
static WebFilterOperation createGrayscaleFilter(float amount) { return WebFilterOperation(FilterTypeGrayscale, amount); }
@@ -76,13 +81,9 @@
static WebFilterOperation createOpacityFilter(float amount) { return WebFilterOperation(FilterTypeOpacity, amount); }
static WebFilterOperation createBlurFilter(float amount) { return WebFilterOperation(FilterTypeBlur, amount); }
static WebFilterOperation createDropShadowFilter(WebPoint offset, float stdDeviation, WebColor color) { return WebFilterOperation(FilterTypeDropShadow, offset, stdDeviation, color); }
+ static WebFilterOperation createColorMatrixFilter(SkScalar matrix[20]) { return WebFilterOperation(FilterTypeColorMatrix, matrix); }
- bool equals(const WebFilterOperation& other) const
- {
- return m_amount == other.m_amount
- && m_dropShadowOffset == other.m_dropShadowOffset
- && m_dropShadowColor == other.m_dropShadowColor;
- }
+ bool equals(const WebFilterOperation& other) const;
private:
FilterType m_type;
@@ -90,10 +91,11 @@
float m_amount;
WebPoint m_dropShadowOffset;
WebColor m_dropShadowColor;
+ SkScalar m_matrix[20];
WebFilterOperation(FilterType type, float amount)
{
- WEBKIT_ASSERT(type != FilterTypeDropShadow);
+ WEBKIT_ASSERT(type != FilterTypeDropShadow && type != FilterTypeColorMatrix);
m_type = type;
m_amount = amount;
m_dropShadowColor = 0;
@@ -107,6 +109,8 @@
m_dropShadowOffset = offset;
m_dropShadowColor = color;
}
+
+ WebFilterOperation(FilterType, SkScalar matrix[20]);
};
inline bool operator==(const WebFilterOperation& a, const WebFilterOperation& b)
Copied: trunk/Source/Platform/chromium/src/WebFilterOperation.cpp (from rev 124391, trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.h) (0 => 124392)
--- trunk/Source/Platform/chromium/src/WebFilterOperation.cpp (rev 0)
+++ trunk/Source/Platform/chromium/src/WebFilterOperation.cpp 2012-08-02 00:22:05 UTC (rev 124392)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include <public/WebFilterOperation.h>
+
+#include <string.h>
+
+namespace WebKit {
+
+bool WebFilterOperation::equals(const WebFilterOperation& other) const
+{
+ if (m_type != other.m_type)
+ return false;
+ if (m_type == FilterTypeColorMatrix)
+ return !memcmp(m_matrix, other.m_matrix, sizeof(m_matrix));
+ if (m_type == FilterTypeDropShadow) {
+ return m_amount == other.m_amount
+ && m_dropShadowOffset == other.m_dropShadowOffset
+ && m_dropShadowColor == other.m_dropShadowColor;
+ } else
+ return m_amount == other.m_amount;
+}
+
+WebFilterOperation::WebFilterOperation(FilterType type, SkScalar matrix[20])
+{
+ WEBKIT_ASSERT(type == FilterTypeColorMatrix);
+ m_type = type;
+ memcpy(m_matrix, matrix, sizeof(m_matrix));
+}
+
+} // namespace WebKit
Modified: trunk/Source/Platform/chromium/src/WebFilterOperations.cpp (124391 => 124392)
--- trunk/Source/Platform/chromium/src/WebFilterOperations.cpp 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/Platform/chromium/src/WebFilterOperations.cpp 2012-08-02 00:22:05 UTC (rev 124392)
@@ -133,6 +133,14 @@
case WebFilterOperation::FilterTypeBlur:
case WebFilterOperation::FilterTypeDropShadow:
return true;
+ case WebFilterOperation::FilterTypeColorMatrix: {
+ const SkScalar* matrix = op.matrix();
+ return matrix[15]
+ || matrix[16]
+ || matrix[17]
+ || matrix[18] != 1
+ || matrix[19];
+ }
default:
break;
}
Modified: trunk/Source/WebCore/ChangeLog (124391 => 124392)
--- trunk/Source/WebCore/ChangeLog 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/WebCore/ChangeLog 2012-08-02 00:22:05 UTC (rev 124392)
@@ -1,3 +1,25 @@
+2012-08-01 Antoine Labour <[email protected]>
+
+ [chromium] factor out the optimization pass in CCRenderSurfaceFilters::apply
+ https://bugs.webkit.org/show_bug.cgi?id=92453
+
+ Reviewed by James Robinson.
+
+ This separates the "optimization" pass in CCRenderSurfaceFilters::apply
+ to resolve a succession of color matrix filters into a single operation.
+ This allows testing of that code.
+ This introduces a new generic color matrix WebFilterOperation, which can
+ also be used on its own.
+
+ New test: CCRenderSurfaceFiltersTest.
+
+ * platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp:
+ (WebCore::CCRenderSurfaceFilters::optimize):
+ (WebCore):
+ (WebCore::CCRenderSurfaceFilters::apply):
+ * platform/graphics/chromium/cc/CCRenderSurfaceFilters.h:
+ (CCRenderSurfaceFilters):
+
2012-08-01 Jian Li <[email protected]>
Add new CSS property "-webkit-widget-region" to expose dashboard region support for other port
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp (124391 => 124392)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.cpp 2012-08-02 00:22:05 UTC (rev 124392)
@@ -245,6 +245,10 @@
getOpacityMatrix(op.amount(), matrix);
return true;
}
+ case WebKit::WebFilterOperation::FilterTypeColorMatrix: {
+ memcpy(matrix, op.matrix(), sizeof(SkScalar[20]));
+ return true;
+ }
default:
return false;
}
@@ -254,6 +258,7 @@
public:
FilterBufferState(GrContext* grContext, const WebCore::FloatSize& size, unsigned textureId)
: m_grContext(grContext)
+ , m_currentTexture(0)
{
// Wrap the source texture in a Ganesh platform texture.
GrPlatformTextureDesc platformTextureDescription;
@@ -269,6 +274,24 @@
~FilterBufferState() { }
+ bool init(int filterCount)
+ {
+ int scratchCount = std::min(2, filterCount);
+ GrTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+ desc.fSampleCnt = 0;
+ desc.fWidth = m_source.width();
+ desc.fHeight = m_source.height();
+ desc.fConfig = kSkia8888_PM_GrPixelConfig;
+ for (int i = 0; i < scratchCount; ++i) {
+ GrAutoScratchTexture scratchTexture(m_grContext, desc, GrContext::kExact_ScratchTexMatch);
+ m_scratchTextures[i].reset(scratchTexture.detach());
+ if (!m_scratchTextures[i].get())
+ return false;
+ }
+ return true;
+ }
+
SkCanvas* canvas()
{
if (!m_canvas.get())
@@ -283,68 +306,35 @@
m_canvas.reset(0);
m_device.reset(0);
- m_source.setPixelRef(new SkGrTexturePixelRef(m_destinationTexture.get()))->unref();
-
- SkAutoTUnref<GrTexture> temp;
- temp.reset(m_freeTexture.detach());
- m_freeTexture.reset(m_destinationTexture.detach());
- m_destinationTexture.reset(temp.detach());
+ m_source.setPixelRef(new SkGrTexturePixelRef(m_scratchTextures[m_currentTexture].get()))->unref();
+ m_currentTexture = 1 - m_currentTexture;
}
private:
void createCanvas()
{
- if (!m_destinationTexture.get()) {
- GrTextureDesc desc;
- desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
- desc.fSampleCnt = 0;
- desc.fWidth = m_source.width();
- desc.fHeight = m_source.height();
- desc.fConfig = kSkia8888_PM_GrPixelConfig;
- GrAutoScratchTexture scratchTexture(m_grContext, desc, GrContext::kExact_ScratchTexMatch);
- m_destinationTexture.reset(scratchTexture.detach());
- if (!m_destinationTexture.get())
- return;
- }
- m_device.reset(new SkGpuDevice(m_grContext, m_destinationTexture.get()));
+ ASSERT(m_scratchTextures[m_currentTexture].get());
+ m_device.reset(new SkGpuDevice(m_grContext, m_scratchTextures[m_currentTexture].get()));
m_canvas.reset(new SkCanvas(m_device.get()));
m_canvas->clear(0x0);
}
GrContext* m_grContext;
SkBitmap m_source;
- SkAutoTUnref<GrTexture> m_destinationTexture;
- SkAutoTUnref<GrTexture> m_freeTexture;
+ SkAutoTUnref<GrTexture> m_scratchTextures[2];
+ int m_currentTexture;
SkAutoTUnref<SkGpuDevice> m_device;
SkAutoTUnref<SkCanvas> m_canvas;
};
-bool applyColorMatrix(FilterBufferState* state, SkScalar matrix[20])
-{
- SkCanvas* canvas = state->canvas();
- if (!canvas)
- return false;
- SkPaint paint;
- paint.setColorFilter(new SkColorMatrixFilter(matrix))->unref();
- canvas->drawBitmap(state->source(), 0, 0, &paint);
- state->swap();
- return true;
}
-}
-
namespace WebCore {
-SkBitmap CCRenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const FloatSize& size, GraphicsContext3D* context3D)
+WebKit::WebFilterOperations CCRenderSurfaceFilters::optimize(const WebKit::WebFilterOperations& filters)
{
- if (!context3D)
- return SkBitmap();
+ WebKit::WebFilterOperations newList;
- GrContext* grContext = context3D->grContext();
- if (!grContext)
- return SkBitmap();
- FilterBufferState state(grContext, size, textureId);
-
SkScalar accumulatedColorMatrix[20];
bool haveAccumulatedColorMatrix = false;
for (unsigned i = 0; i < filters.size(); ++i) {
@@ -369,27 +359,64 @@
continue;
}
- if (haveAccumulatedColorMatrix && !applyColorMatrix(&state, accumulatedColorMatrix))
- return SkBitmap();
+ if (haveAccumulatedColorMatrix)
+ newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accumulatedColorMatrix));
haveAccumulatedColorMatrix = false;
switch (op.type()) {
+ case WebKit::WebFilterOperation::FilterTypeBlur:
+ case WebKit::WebFilterOperation::FilterTypeDropShadow:
+ newList.append(op);
+ break;
+ case WebKit::WebFilterOperation::FilterTypeBrightness:
+ case WebKit::WebFilterOperation::FilterTypeContrast:
+ case WebKit::WebFilterOperation::FilterTypeGrayscale:
+ case WebKit::WebFilterOperation::FilterTypeSepia:
+ case WebKit::WebFilterOperation::FilterTypeSaturate:
+ case WebKit::WebFilterOperation::FilterTypeHueRotate:
+ case WebKit::WebFilterOperation::FilterTypeInvert:
+ case WebKit::WebFilterOperation::FilterTypeOpacity:
+ case WebKit::WebFilterOperation::FilterTypeColorMatrix:
+ break;
+ }
+ }
+ if (haveAccumulatedColorMatrix)
+ newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accumulatedColorMatrix));
+ return newList;
+}
+
+SkBitmap CCRenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const FloatSize& size, GraphicsContext3D* context3D)
+{
+ if (!context3D)
+ return SkBitmap();
+
+ GrContext* grContext = context3D->grContext();
+ if (!grContext)
+ return SkBitmap();
+ WebKit::WebFilterOperations optimizedFilters = optimize(filters);
+ FilterBufferState state(grContext, size, textureId);
+ if (!state.init(optimizedFilters.size()))
+ return SkBitmap();
+
+ for (unsigned i = 0; i < optimizedFilters.size(); ++i) {
+ const WebKit::WebFilterOperation& op = optimizedFilters.at(i);
+ SkCanvas* canvas = state.canvas();
+ switch (op.type()) {
+ case WebKit::WebFilterOperation::FilterTypeColorMatrix: {
+ SkPaint paint;
+ paint.setColorFilter(new SkColorMatrixFilter(op.matrix()))->unref();
+ canvas->drawBitmap(state.source(), 0, 0, &paint);
+ break;
+ }
case WebKit::WebFilterOperation::FilterTypeBlur: {
- SkCanvas* canvas = state.canvas();
- if (!canvas)
- return SkBitmap();
float stdDeviation = op.amount();
SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(stdDeviation, stdDeviation));
SkPaint paint;
paint.setImageFilter(filter.get());
canvas->drawSprite(state.source(), 0, 0, &paint);
- state.swap();
break;
}
case WebKit::WebFilterOperation::FilterTypeDropShadow: {
- SkCanvas* canvas = state.canvas();
- if (!canvas)
- return SkBitmap();
SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(op.amount(), op.amount()));
SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(op.dropShadowColor(), SkXfermode::kSrcIn_Mode));
SkPaint paint;
@@ -400,7 +427,6 @@
canvas->drawBitmap(state.source(), op.dropShadowOffset().x, -op.dropShadowOffset().y);
canvas->restore();
canvas->drawBitmap(state.source(), 0, 0);
- state.swap();
break;
}
case WebKit::WebFilterOperation::FilterTypeBrightness:
@@ -411,11 +437,11 @@
case WebKit::WebFilterOperation::FilterTypeHueRotate:
case WebKit::WebFilterOperation::FilterTypeInvert:
case WebKit::WebFilterOperation::FilterTypeOpacity:
+ ASSERT_NOT_REACHED();
break;
}
+ state.swap();
}
- if (haveAccumulatedColorMatrix && !applyColorMatrix(&state, accumulatedColorMatrix))
- return SkBitmap();
context3D->flush();
return state.source();
}
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.h (124391 => 124392)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.h 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCRenderSurfaceFilters.h 2012-08-02 00:22:05 UTC (rev 124392)
@@ -42,6 +42,7 @@
class CCRenderSurfaceFilters {
public:
static SkBitmap apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const FloatSize&, GraphicsContext3D*);
+ static WebKit::WebFilterOperations optimize(const WebKit::WebFilterOperations& filters);
private:
CCRenderSurfaceFilters();
};
Modified: trunk/Source/WebKit/chromium/ChangeLog (124391 => 124392)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-08-02 00:22:05 UTC (rev 124392)
@@ -1,3 +1,22 @@
+2012-08-01 Antoine Labour <[email protected]>
+
+ [chromium] factor out the optimization pass in CCRenderSurfaceFilters::apply
+ https://bugs.webkit.org/show_bug.cgi?id=92453
+
+ Reviewed by James Robinson.
+
+ This separates the "optimization" pass in CCRenderSurfaceFilters::apply
+ to resolve a succession of color matrix filters into a single operation.
+ This allows testing of that code.
+ This introduces a new generic color matrix WebFilterOperation, which can
+ also be used on its own.
+
+ * WebKit.gypi:
+ * tests/CCRenderSurfaceFiltersTest.cpp: Added.
+ (WebKit):
+ (WebKit::isCombined):
+ (WebKit::TEST):
+
2012-08-01 Daniel Murphy <[email protected]>
Fix for drawing invalid layers in WebViewBenchmarkSupportImpl
Modified: trunk/Source/WebKit/chromium/WebKit.gypi (124391 => 124392)
--- trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-02 00:20:08 UTC (rev 124391)
+++ trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-02 00:22:05 UTC (rev 124392)
@@ -77,6 +77,7 @@
'tests/CCOcclusionTrackerTest.cpp',
'tests/CCOcclusionTrackerTestCommon.h',
'tests/CCQuadCullerTest.cpp',
+ 'tests/CCRenderSurfaceFiltersTest.cpp',
'tests/CCRenderSurfaceTest.cpp',
'tests/CCResourceProviderTest.cpp',
'tests/CCSchedulerStateMachineTest.cpp',
Added: trunk/Source/WebKit/chromium/tests/CCRenderSurfaceFiltersTest.cpp (0 => 124392)
--- trunk/Source/WebKit/chromium/tests/CCRenderSurfaceFiltersTest.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCRenderSurfaceFiltersTest.cpp 2012-08-02 00:22:05 UTC (rev 124392)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "cc/CCRenderSurfaceFilters.h"
+
+#include "CompositorFakeWebGraphicsContext3D.h"
+#include "GraphicsContext3DPrivate.h"
+#include <gtest/gtest.h>
+#include <public/WebFilterOperation.h>
+#include <public/WebFilterOperations.h>
+#include <wtf/RefPtr.h>
+
+using namespace WebCore;
+using namespace WebKit;
+
+namespace {
+
+// Checks whether op can be combined with a following color matrix.
+bool isCombined(const WebFilterOperation& op)
+{
+ WebFilterOperations filters;
+ filters.append(op);
+ filters.append(WebFilterOperation::createBrightnessFilter(0)); // brightness(0) is identity.
+ WebFilterOperations optimized = CCRenderSurfaceFilters::optimize(filters);
+ return optimized.size() == 1;
+}
+
+TEST(CCRenderSurfaceFiltersTest, testColorMatrixFiltersCombined)
+{
+ // Several filters should always combine for any amount between 0 and 1:
+ // grayscale, saturate, invert, contrast, opacity.
+ EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0.3)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0.5)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(1)));
+
+ EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0.3)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0.5)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(1)));
+
+ EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0.3)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0.5)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(1)));
+
+ EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0.3)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0.5)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(1)));
+
+ EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0.3)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0.5)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(1)));
+
+ // Several filters should never combine: brightness(amount > 0), blur, drop-shadow.
+ EXPECT_FALSE(isCombined(WebFilterOperation::createBrightnessFilter(0.5)));
+ EXPECT_FALSE(isCombined(WebFilterOperation::createBrightnessFilter(1)));
+ EXPECT_FALSE(isCombined(WebFilterOperation::createBlurFilter(3)));
+ EXPECT_FALSE(isCombined(WebFilterOperation::createDropShadowFilter(WebPoint(2, 2), 3, 0xffffffff)));
+
+ // sepia and hue may or may not combine depending on the value.
+ EXPECT_TRUE(isCombined(WebFilterOperation::createSepiaFilter(0)));
+ EXPECT_FALSE(isCombined(WebFilterOperation::createSepiaFilter(1)));
+ EXPECT_TRUE(isCombined(WebFilterOperation::createHueRotateFilter(0)));
+ EXPECT_FALSE(isCombined(WebFilterOperation::createHueRotateFilter(180)));
+
+ float matrix1[20] = {
+ 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0,
+ };
+ EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix1)));
+
+ float matrix2[20] = {
+ 1, 1, 0, 0, 0,
+ 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0,
+ };
+ EXPECT_FALSE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix2)));
+
+ float matrix3[20] = {
+ 0.25, 0, 0, 0, 255*0.75,
+ 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0,
+ };
+ EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix3)));
+
+ float matrix4[20] = {
+ -0.25, 0.75, 0, 0, 255*0.25,
+ 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0,
+ };
+ EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix4)));
+}
+
+TEST(CCRenderSurfaceFiltersTest, testOptimize)
+{
+ WebFilterOperation combines(WebFilterOperation::createBrightnessFilter(0));
+ WebFilterOperation doesntCombine(WebFilterOperation::createBrightnessFilter(1));
+
+ WebFilterOperations filters;
+ WebFilterOperations optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(0u, optimized.size());
+
+ filters.append(combines);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(1u, optimized.size());
+
+ filters.append(combines);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(1u, optimized.size());
+
+ filters.append(doesntCombine);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(1u, optimized.size());
+
+ filters.append(combines);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(2u, optimized.size());
+
+ filters.append(doesntCombine);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(2u, optimized.size());
+
+ filters.append(doesntCombine);
+ optimized = CCRenderSurfaceFilters::optimize(filters);
+ EXPECT_EQ(3u, optimized.size());
+}
+
+} // namespace