Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 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 | |
| 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 | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 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 | |
| 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 | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 */ | |
| 24 | |
| 25 #include "SkImageFilter.h" | |
| 26 #include "core/platform/graphics/filters/FEBlend.h" | |
| 27 #include "core/platform/graphics/filters/FEGaussianBlur.h" | |
| 28 #include "core/platform/graphics/filters/FEMerge.h" | |
| 29 #include "core/platform/graphics/filters/FilterOperations.h" | |
| 30 #include "core/platform/graphics/filters/SkiaImageFilterBuilder.h" | |
| 31 #include "core/platform/graphics/filters/SourceGraphic.h" | |
| 32 #include "core/rendering/FilterEffectRenderer.h" | |
| 33 #include <gtest/gtest.h> | |
| 34 | |
| 35 using testing::Test; | |
| 36 using namespace WebCore; | |
| 37 | |
| 38 class ImageFilterBuilderTest : public Test { | |
| 39 protected: | |
| 40 void colorSpaceTest() | |
| 41 { | |
| 42 FilterOperations filterOps; | |
| 43 | |
| 44 // Build filter tree | |
| 45 Vector<RefPtr<FilterOperation> >& ops = filterOps.operations(); | |
| 46 | |
| 47 const String dummyUrl, dummyFragment; | |
| 48 | |
| 49 RefPtr<FilterEffectRenderer> dummyFilterEffectRenderer = FilterEffectRen derer::create(); | |
| 50 | |
| 51 // Add a dummy source graphic input | |
| 52 RefPtr<FilterEffect> sourceEffect = | |
| 53 SourceGraphic::create(dummyFilterEffectRenderer.get()); | |
| 54 sourceEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | |
| 55 | |
| 56 // Add a blur effect (with input : source) | |
| 57 RefPtr<ReferenceFilterOperation> blurOperation = | |
| 58 ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper ation::REFERENCE); | |
| 59 RefPtr<FilterEffect> blurEffect = | |
| 60 FEGaussianBlur::create(dummyFilterEffectRenderer.get(), 3.0f, 3.0f); | |
| 61 blurEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | |
| 62 blurOperation->setFilterEffect(blurEffect); | |
| 63 blurEffect->inputEffects().append(sourceEffect); | |
| 64 ops.append(blurOperation); | |
| 65 | |
| 66 // Add a blend effect (with inputs : blur, source) | |
| 67 RefPtr<ReferenceFilterOperation> blendOperation = | |
| 68 ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper ation::REFERENCE); | |
| 69 RefPtr<FilterEffect> blendEffect = | |
| 70 FEBlend::create(dummyFilterEffectRenderer.get(), FEBLEND_MODE_NORMAL ); | |
| 71 blendEffect->setOperatingColorSpace(ColorSpaceDeviceRGB); | |
| 72 FilterEffectVector& blendInputs = blendEffect->inputEffects(); | |
| 73 blendInputs.reserveCapacity(2); | |
| 74 blendInputs.append(sourceEffect); | |
| 75 blendInputs.append(blurEffect); | |
| 76 blendOperation->setFilterEffect(blendEffect); | |
| 77 ops.append(blendOperation); | |
| 78 | |
| 79 // Add a merge effect (with inputs : blur, blend) | |
| 80 RefPtr<ReferenceFilterOperation> mergeOperation = | |
| 81 ReferenceFilterOperation::create(dummyUrl, dummyFragment, FilterOper ation::REFERENCE); | |
| 82 RefPtr<FilterEffect> mergeEffect = | |
| 83 FEMerge::create(dummyFilterEffectRenderer.get()); | |
| 84 mergeEffect->setOperatingColorSpace(ColorSpaceLinearRGB); | |
| 85 FilterEffectVector& mergeInputs = mergeEffect->inputEffects(); | |
| 86 mergeInputs.reserveCapacity(2); | |
| 87 mergeInputs.append(blurEffect); | |
| 88 mergeInputs.append(blendEffect); | |
| 89 mergeOperation->setFilterEffect(mergeEffect); | |
| 90 ops.append(mergeOperation); | |
| 91 | |
| 92 // Get SkImageFilter resulting tree | |
| 93 SkiaImageFilterBuilder builder; | |
| 94 SkAutoTUnref<SkImageFilter> filter(builder.build(filterOps)); | |
| 95 | |
| 96 // Let's check that the resulting tree looks like this : | |
| 97 // ColorSpace (Linear->Device) : CS (L->D) | |
| 98 // | | |
| 99 // Merge (L) | |
| 100 // | | | |
| 101 // | CS (D->L) | |
| 102 // | | | |
| 103 // | Blend (D) | |
| 104 // | / | | |
| 105 // | CS (L->D) | | |
| 106 // | / | | |
| 107 // Blur (L) | | |
| 108 // \ | | |
| 109 // CS (D->L) | | |
| 110 // \ | | |
| 111 // Source Graphic (D) | |
|
sugoi1
2013/05/10 14:58:03
The bots didn't like my ASCII art when a line ende
| |
| 112 | |
| 113 EXPECT_EQ(filter->countInputs(), 1); // Should be CS (L->D) | |
| 114 SkImageFilter* child = filter->getInput(0); // Should be Merge | |
| 115 EXPECT_EQ(child->asColorFilter(0), false); | |
| 116 EXPECT_EQ(child->countInputs(), 2); | |
| 117 child = child->getInput(1); // Should be CS (D->L) | |
| 118 EXPECT_EQ(child->asColorFilter(0), true); | |
| 119 EXPECT_EQ(child->countInputs(), 1); | |
| 120 child = child->getInput(0); // Should be Blend | |
| 121 EXPECT_EQ(child->asColorFilter(0), false); | |
| 122 EXPECT_EQ(child->countInputs(), 2); | |
| 123 child = child->getInput(0); // Should be CS (L->D) | |
| 124 EXPECT_EQ(child->asColorFilter(0), true); | |
| 125 EXPECT_EQ(child->countInputs(), 1); | |
| 126 child = child->getInput(0); // Should be Blur | |
| 127 EXPECT_EQ(child->asColorFilter(0), false); | |
| 128 EXPECT_EQ(child->countInputs(), 1); | |
| 129 child = child->getInput(0); // Should be CS (D->L) | |
| 130 EXPECT_EQ(child->asColorFilter(0), true); | |
| 131 EXPECT_EQ(child->countInputs(), 1); | |
| 132 } | |
| 133 }; | |
| 134 | |
| 135 namespace { | |
| 136 | |
| 137 TEST_F(ImageFilterBuilderTest, testColorSpace) | |
| 138 { | |
| 139 colorSpaceTest(); | |
| 140 } | |
| 141 | |
| 142 } // namespace | |
| OLD | NEW |