/work/obj-fuzz/dist/include/ImageRegion.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef mozilla_image_ImageRegion_h |
7 | | #define mozilla_image_ImageRegion_h |
8 | | |
9 | | #include "gfxRect.h" |
10 | | #include "mozilla/gfx/Types.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace image { |
14 | | |
15 | | /** |
16 | | * An axis-aligned rectangle in tiled image space, with an optional sampling |
17 | | * restriction rect. The drawing code ensures that if a sampling restriction |
18 | | * rect is present, any pixels sampled during the drawing process are found |
19 | | * within that rect. |
20 | | * |
21 | | * The sampling restriction rect exists primarily for callers which perform |
22 | | * pixel snapping. Other callers should generally use one of the Create() |
23 | | * overloads. |
24 | | */ |
25 | | class ImageRegion |
26 | | { |
27 | | typedef mozilla::gfx::ExtendMode ExtendMode; |
28 | | |
29 | | public: |
30 | | static ImageRegion Empty() |
31 | 0 | { |
32 | 0 | return ImageRegion(gfxRect(), ExtendMode::CLAMP); |
33 | 0 | } |
34 | | |
35 | | static ImageRegion Create(const gfxRect& aRect, |
36 | | ExtendMode aExtendMode = ExtendMode::CLAMP) |
37 | | { |
38 | | return ImageRegion(aRect, aExtendMode); |
39 | | } |
40 | | |
41 | | static ImageRegion Create(const gfxSize& aSize, |
42 | | ExtendMode aExtendMode = ExtendMode::CLAMP) |
43 | 0 | { |
44 | 0 | return ImageRegion(gfxRect(0, 0, aSize.width, aSize.height), aExtendMode); |
45 | 0 | } |
46 | | |
47 | | static ImageRegion Create(const nsIntSize& aSize, |
48 | | ExtendMode aExtendMode = ExtendMode::CLAMP) |
49 | | { |
50 | | return ImageRegion(gfxRect(0, 0, aSize.width, aSize.height), aExtendMode); |
51 | | } |
52 | | |
53 | | static ImageRegion CreateWithSamplingRestriction(const gfxRect& aRect, |
54 | | const gfxRect& aRestriction, |
55 | | ExtendMode aExtendMode = ExtendMode::CLAMP) |
56 | | { |
57 | | return ImageRegion(aRect, aRestriction, aExtendMode); |
58 | | } |
59 | | |
60 | 0 | bool IsRestricted() const { return mIsRestricted; } |
61 | 0 | const gfxRect& Rect() const { return mRect; } |
62 | | |
63 | | const gfxRect& Restriction() const |
64 | 0 | { |
65 | 0 | MOZ_ASSERT(mIsRestricted); |
66 | 0 | return mRestriction; |
67 | 0 | } |
68 | | |
69 | | bool RestrictionContains(const gfxRect& aRect) const |
70 | 0 | { |
71 | 0 | if (!mIsRestricted) { |
72 | 0 | return true; |
73 | 0 | } |
74 | 0 | return mRestriction.Contains(aRect); |
75 | 0 | } |
76 | | |
77 | | ImageRegion Intersect(const gfxRect& aRect) const |
78 | | { |
79 | | if (mIsRestricted) { |
80 | | return CreateWithSamplingRestriction(aRect.Intersect(mRect), |
81 | | aRect.Intersect(mRestriction)); |
82 | | } |
83 | | return Create(aRect.Intersect(mRect)); |
84 | | } |
85 | | |
86 | | gfxRect IntersectAndRestrict(const gfxRect& aRect) const |
87 | 0 | { |
88 | 0 | gfxRect intersection = mRect.Intersect(aRect); |
89 | 0 | if (mIsRestricted) { |
90 | 0 | intersection = mRestriction.Intersect(intersection); |
91 | 0 | } |
92 | 0 | return intersection; |
93 | 0 | } |
94 | | |
95 | | void MoveBy(gfxFloat dx, gfxFloat dy) |
96 | | { |
97 | | mRect.MoveBy(dx, dy); |
98 | | if (mIsRestricted) { |
99 | | mRestriction.MoveBy(dx, dy); |
100 | | } |
101 | | } |
102 | | |
103 | | void Scale(gfxFloat sx, gfxFloat sy) |
104 | | { |
105 | | mRect.Scale(sx, sy); |
106 | | if (mIsRestricted) { |
107 | | mRestriction.Scale(sx, sy); |
108 | | } |
109 | | } |
110 | | |
111 | | void TransformBy(const gfxMatrix& aMatrix) |
112 | 0 | { |
113 | 0 | mRect = aMatrix.TransformRect(mRect); |
114 | 0 | if (mIsRestricted) { |
115 | 0 | mRestriction = aMatrix.TransformRect(mRestriction); |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | void TransformBoundsBy(const gfxMatrix& aMatrix) |
120 | | { |
121 | | mRect = aMatrix.TransformBounds(mRect); |
122 | | if (mIsRestricted) { |
123 | | mRestriction = aMatrix.TransformBounds(mRestriction); |
124 | | } |
125 | | } |
126 | | |
127 | | ImageRegion operator-(const gfxPoint& aPt) const |
128 | 0 | { |
129 | 0 | if (mIsRestricted) { |
130 | 0 | return CreateWithSamplingRestriction(mRect - aPt, mRestriction - aPt); |
131 | 0 | } |
132 | 0 | return Create(mRect - aPt); |
133 | 0 | } |
134 | | |
135 | | ImageRegion operator+(const gfxPoint& aPt) const |
136 | 0 | { |
137 | 0 | if (mIsRestricted) { |
138 | 0 | return CreateWithSamplingRestriction(mRect + aPt, mRestriction + aPt); |
139 | 0 | } |
140 | 0 | return Create(mRect + aPt); |
141 | 0 | } |
142 | | |
143 | | gfx::ExtendMode GetExtendMode() const |
144 | 0 | { |
145 | 0 | return mExtendMode; |
146 | 0 | } |
147 | | |
148 | | /* ImageRegion() : mIsRestricted(false) { } */ |
149 | | |
150 | | private: |
151 | | explicit ImageRegion(const gfxRect& aRect, ExtendMode aExtendMode) |
152 | | : mRect(aRect) |
153 | | , mExtendMode(aExtendMode) |
154 | | , mIsRestricted(false) |
155 | | { } |
156 | | |
157 | | ImageRegion(const gfxRect& aRect, const gfxRect& aRestriction, ExtendMode aExtendMode) |
158 | | : mRect(aRect) |
159 | | , mRestriction(aRestriction) |
160 | | , mExtendMode(aExtendMode) |
161 | | , mIsRestricted(true) |
162 | | { } |
163 | | |
164 | | gfxRect mRect; |
165 | | gfxRect mRestriction; |
166 | | ExtendMode mExtendMode; |
167 | | bool mIsRestricted; |
168 | | }; |
169 | | |
170 | | } // namespace image |
171 | | } // namespace mozilla |
172 | | |
173 | | #endif // mozilla_image_ImageRegion_h |