1 /* 2 * Copyright (C) 2013 Adobe Systems Incorporated. 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 * 8 * 1. Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following 13 * disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27 * OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef RasterShape_h 31 #define RasterShape_h 32 33 #include "core/rendering/shapes/Shape.h" 34 #include "core/rendering/shapes/ShapeInterval.h" 35 #include "platform/geometry/FloatRect.h" 36 #include "wtf/Assertions.h" 37 #include "wtf/Vector.h" 38 39 namespace WebCore { 40 41 class RasterShapeIntervals { 42 public: 43 RasterShapeIntervals(unsigned size, unsigned shapeMargin = 0) 44 : m_shapeMargin(shapeMargin) 45 { 46 m_intervalLists.resize(size + shapeMargin * 2); 47 } 48 49 const IntRect& bounds() const { return m_bounds; } 50 bool isEmpty() const { return m_bounds.isEmpty(); } 51 void appendInterval(int y, int x1, int x2); 52 53 void getIncludedIntervals(int y1, int y2, IntShapeIntervals& result) const; 54 void getExcludedIntervals(int y1, int y2, IntShapeIntervals& result) const; 55 bool firstIncludedIntervalY(int minY, const IntSize& minSize, LayoutUnit& result) const; 56 PassOwnPtr<RasterShapeIntervals> computeShapeMarginIntervals(unsigned shapeMargin) const; 57 58 private: 59 int size() const { return m_intervalLists.size(); } 60 61 IntShapeIntervals& intervalsAt(int y) 62 { 63 ASSERT(y + m_shapeMargin >= 0 && y + m_shapeMargin < m_intervalLists.size()); 64 return m_intervalLists[y + m_shapeMargin]; 65 } 66 67 const IntShapeIntervals& intervalsAt(int y) const 68 { 69 ASSERT(y + m_shapeMargin >= 0 && y + m_shapeMargin < m_intervalLists.size()); 70 return m_intervalLists[y + m_shapeMargin]; 71 } 72 73 IntShapeInterval limitIntervalAt(int y) const 74 { 75 const IntShapeIntervals& intervals = intervalsAt(y); 76 return intervals.size() ? IntShapeInterval(intervals[0].x1(), intervals.last().x2()) : IntShapeInterval(); 77 } 78 79 bool contains(const IntRect&) const; 80 bool getIntervalX1Values(int minY, int maxY, int minIntervalWidth, Vector<int>& result) const; 81 void uniteMarginInterval(int y, const IntShapeInterval&); 82 IntRect m_bounds; 83 Vector<IntShapeIntervals> m_intervalLists; 84 unsigned m_shapeMargin; 85 }; 86 87 class RasterShape : public Shape { 88 WTF_MAKE_NONCOPYABLE(RasterShape); 89 public: 90 RasterShape(PassOwnPtr<RasterShapeIntervals> intervals, const IntSize& imageSize) 91 : Shape() 92 , m_intervals(intervals) 93 , m_imageSize(imageSize) 94 { 95 } 96 97 virtual LayoutRect shapeMarginLogicalBoundingBox() const OVERRIDE { return static_cast<LayoutRect>(marginIntervals().bounds()); } 98 virtual LayoutRect shapePaddingLogicalBoundingBox() const OVERRIDE { return static_cast<LayoutRect>(paddingIntervals().bounds()); } 99 virtual bool isEmpty() const OVERRIDE { return m_intervals->isEmpty(); } 100 virtual void getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE; 101 virtual void getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList&) const OVERRIDE; 102 virtual bool firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize& minLogicalIntervalSize, LayoutUnit&) const OVERRIDE; 103 104 private: 105 const RasterShapeIntervals& marginIntervals() const; 106 const RasterShapeIntervals& paddingIntervals() const; 107 108 OwnPtr<RasterShapeIntervals> m_intervals; 109 mutable OwnPtr<RasterShapeIntervals> m_marginIntervals; 110 IntSize m_imageSize; 111 }; 112 113 } // namespace WebCore 114 115 #endif // RasterShape_h 116