| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions | 5  * modification, are permitted provided that the following conditions | 
| 6  * are met: | 6  * are met: | 
| 7  * 1.  Redistributions of source code must retain the above copyright | 7  * 1.  Redistributions of source code must retain the above copyright | 
| 8  *     notice, this list of conditions and the following disclaimer. | 8  *     notice, this list of conditions and the following disclaimer. | 
| 9  * 2.  Redistributions in binary form must reproduce the above copyright | 9  * 2.  Redistributions in binary form must reproduce the above copyright | 
| 10  *     notice, this list of conditions and the following disclaimer in the | 10  *     notice, this list of conditions and the following disclaimer in the | 
| 11  *     documentation and/or other materials provided with the distribution. | 11  *     documentation and/or other materials provided with the distribution. | 
| 12  * | 12  * | 
| 13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
     Y | 13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
     Y | 
| 14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 
| 15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| 16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
     Y | 16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
     Y | 
| 17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 
| 18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
| 19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
     N | 19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
     N | 
| 20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 
| 22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 23  */ | 23  */ | 
| 24 | 24 | 
| 25 #include "SkImageFilter.h" | 25 #include "SkImageFilter.h" | 
| 26 #include "core/platform/graphics/filters/FEBlend.h" | 26 #include "core/platform/graphics/filters/FEBlend.h" | 
| 27 #include "core/platform/graphics/filters/FEGaussianBlur.h" | 27 #include "core/platform/graphics/filters/FEGaussianBlur.h" | 
| 28 #include "core/platform/graphics/filters/FEMerge.h" | 28 #include "core/platform/graphics/filters/FEMerge.h" | 
| 29 #include "core/platform/graphics/filters/FilterOperations.h" | 29 #include "core/platform/graphics/filters/FilterOperations.h" | 
|  | 30 #include "core/platform/graphics/filters/ReferenceFilter.h" | 
| 30 #include "core/platform/graphics/filters/SkiaImageFilterBuilder.h" | 31 #include "core/platform/graphics/filters/SkiaImageFilterBuilder.h" | 
| 31 #include "core/platform/graphics/filters/SourceGraphic.h" | 32 #include "core/platform/graphics/filters/SourceGraphic.h" | 
| 32 #include "core/rendering/FilterEffectRenderer.h" |  | 
| 33 #include <gtest/gtest.h> | 33 #include <gtest/gtest.h> | 
| 34 | 34 | 
| 35 using testing::Test; | 35 using testing::Test; | 
| 36 using namespace WebCore; | 36 using namespace WebCore; | 
| 37 | 37 | 
| 38 class ImageFilterBuilderTest : public Test { | 38 class ImageFilterBuilderTest : public Test { | 
| 39 protected: | 39 protected: | 
| 40     void colorSpaceTest() | 40     void colorSpaceTest() | 
| 41     { | 41     { | 
| 42         FilterOperations filterOps; |  | 
| 43 |  | 
| 44         // Build filter tree | 42         // Build filter tree | 
| 45         Vector<RefPtr<FilterOperation> >& ops = filterOps.operations(); | 43         RefPtr<ReferenceFilter> referenceFilter = ReferenceFilter::create(); | 
| 46 |  | 
| 47         const String dummyUrl, dummyFragment; |  | 
| 48 |  | 
| 49         RefPtr<FilterEffectRenderer> dummyFilterEffectRenderer = FilterEffectRen
     derer::create(); |  | 
| 50 | 44 | 
| 51         // Add a dummy source graphic input | 45         // Add a dummy source graphic input | 
| 52         RefPtr<FilterEffect> sourceEffect = | 46         RefPtr<FilterEffect> sourceEffect = referenceFilter->sourceGraphic(); | 
| 53             SourceGraphic::create(dummyFilterEffectRenderer.get()); |  | 
| 54         sourceEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | 47         sourceEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | 
| 55 | 48 | 
| 56         // Add a blur effect (with input : source) | 49         // Add a blur effect (with input : source) | 
| 57         RefPtr<ReferenceFilterOperation> blurOperation = |  | 
| 58             ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper
     ation::REFERENCE); |  | 
| 59         RefPtr<FilterEffect> blurEffect = | 50         RefPtr<FilterEffect> blurEffect = | 
| 60             FEGaussianBlur::create(dummyFilterEffectRenderer.get(), 3.0f, 3.0f); | 51             FEGaussianBlur::create(referenceFilter.get(), 3.0f, 3.0f); | 
| 61         blurEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | 52         blurEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | 
| 62         blurOperation->setFilterEffect(blurEffect, dummyFilterEffectRenderer); |  | 
| 63         blurEffect->inputEffects().append(sourceEffect); | 53         blurEffect->inputEffects().append(sourceEffect); | 
| 64         ops.append(blurOperation); |  | 
| 65 | 54 | 
| 66         // Add a blend effect (with inputs : blur, source) | 55         // Add a blend effect (with inputs : blur, source) | 
| 67         RefPtr<ReferenceFilterOperation> blendOperation = |  | 
| 68             ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper
     ation::REFERENCE); |  | 
| 69         RefPtr<FilterEffect> blendEffect = | 56         RefPtr<FilterEffect> blendEffect = | 
| 70             FEBlend::create(dummyFilterEffectRenderer.get(), FEBLEND_MODE_NORMAL
     ); | 57             FEBlend::create(referenceFilter.get(), FEBLEND_MODE_NORMAL); | 
| 71         blendEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | 58         blendEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | 
| 72         FilterEffectVector& blendInputs = blendEffect->inputEffects(); | 59         FilterEffectVector& blendInputs = blendEffect->inputEffects(); | 
| 73         blendInputs.reserveCapacity(2); | 60         blendInputs.reserveCapacity(2); | 
| 74         blendInputs.append(sourceEffect); | 61         blendInputs.append(sourceEffect); | 
| 75         blendInputs.append(blurEffect); | 62         blendInputs.append(blurEffect); | 
| 76         blendOperation->setFilterEffect(blendEffect, dummyFilterEffectRenderer); |  | 
| 77         ops.append(blendOperation); |  | 
| 78 | 63 | 
| 79         // Add a merge effect (with inputs : blur, blend) | 64         // Add a merge effect (with inputs : blur, blend) | 
| 80         RefPtr<ReferenceFilterOperation> mergeOperation = | 65         RefPtr<FilterEffect> mergeEffect = FEMerge::create(referenceFilter.get()
     ); | 
| 81             ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper
     ation::REFERENCE); |  | 
| 82         RefPtr<FilterEffect> mergeEffect = |  | 
| 83             FEMerge::create(dummyFilterEffectRenderer.get()); |  | 
| 84         mergeEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | 66         mergeEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | 
| 85         FilterEffectVector& mergeInputs = mergeEffect->inputEffects(); | 67         FilterEffectVector& mergeInputs = mergeEffect->inputEffects(); | 
| 86         mergeInputs.reserveCapacity(2); | 68         mergeInputs.reserveCapacity(2); | 
| 87         mergeInputs.append(blurEffect); | 69         mergeInputs.append(blurEffect); | 
| 88         mergeInputs.append(blendEffect); | 70         mergeInputs.append(blendEffect); | 
| 89         mergeOperation->setFilterEffect(mergeEffect, dummyFilterEffectRenderer); | 71         referenceFilter->setLastEffect(mergeEffect); | 
| 90         ops.append(mergeOperation); |  | 
| 91 | 72 | 
| 92         // Get SkImageFilter resulting tree | 73         // Get SkImageFilter resulting tree | 
| 93         SkiaImageFilterBuilder builder; | 74         SkiaImageFilterBuilder builder; | 
| 94         SkAutoTUnref<SkImageFilter> filter(builder.build(filterOps)); | 75         SkAutoTUnref<SkImageFilter> filter(builder.build(referenceFilter->lastEf
     fect(), ColorSpaceDeviceRGB)); | 
| 95 | 76 | 
| 96         // Let's check that the resulting tree looks like this : | 77         // Let's check that the resulting tree looks like this : | 
| 97         //      ColorSpace (Linear->Device) : CS (L->D) | 78         //      ColorSpace (Linear->Device) : CS (L->D) | 
| 98         //                | | 79         //                | | 
| 99         //             Merge (L) | 80         //             Merge (L) | 
| 100         //              |     | | 81         //              |     | | 
| 101         //              |    CS (D->L) | 82         //              |    CS (D->L) | 
| 102         //              |          | | 83         //              |          | | 
| 103         //              |      Blend (D) | 84         //              |      Blend (D) | 
| 104         //              |       /    | | 85         //              |       /    | | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 133 }; | 114 }; | 
| 134 | 115 | 
| 135 namespace { | 116 namespace { | 
| 136 | 117 | 
| 137 TEST_F(ImageFilterBuilderTest, testColorSpace) | 118 TEST_F(ImageFilterBuilderTest, testColorSpace) | 
| 138 { | 119 { | 
| 139     colorSpaceTest(); | 120     colorSpaceTest(); | 
| 140 } | 121 } | 
| 141 | 122 | 
| 142 } // namespace | 123 } // namespace | 
| OLD | NEW | 
|---|