OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDraw.h" | 8 #include "SkDraw.h" |
9 #include "SkBlitter.h" | 9 #include "SkBlitter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 #include "SkBlitter.h" | 2174 #include "SkBlitter.h" |
2175 | 2175 |
2176 static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, | 2176 static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, |
2177 const SkMaskFilter* filter, const SkMatrix* filterMat
rix, | 2177 const SkMaskFilter* filter, const SkMatrix* filterMat
rix, |
2178 SkIRect* bounds) { | 2178 SkIRect* bounds) { |
2179 if (devPath.isEmpty()) { | 2179 if (devPath.isEmpty()) { |
2180 return false; | 2180 return false; |
2181 } | 2181 } |
2182 | 2182 |
2183 // init our bounds from the path | 2183 // init our bounds from the path |
2184 { | 2184 *bounds = devPath.getBounds().makeOutset(SK_ScalarHalf, SK_ScalarHalf).round
Out(); |
2185 SkRect pathBounds = devPath.getBounds(); | |
2186 pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); | |
2187 pathBounds.roundOut(bounds); | |
2188 } | |
2189 | 2185 |
2190 SkIPoint margin = SkIPoint::Make(0, 0); | 2186 SkIPoint margin = SkIPoint::Make(0, 0); |
2191 if (filter) { | 2187 if (filter) { |
2192 SkASSERT(filterMatrix); | 2188 SkASSERT(filterMatrix); |
2193 | 2189 |
2194 SkMask srcM, dstM; | 2190 SkMask srcM, dstM; |
2195 | 2191 |
2196 srcM.fBounds = *bounds; | 2192 srcM.fBounds = *bounds; |
2197 srcM.fFormat = SkMask::kA8_Format; | 2193 srcM.fFormat = SkMask::kA8_Format; |
2198 srcM.fImage = NULL; | 2194 srcM.fImage = NULL; |
2199 if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { | 2195 if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { |
2200 return false; | 2196 return false; |
2201 } | 2197 } |
2202 } | 2198 } |
2203 | 2199 |
2204 // (possibly) trim the bounds to reflect the clip | 2200 // (possibly) trim the bounds to reflect the clip |
2205 // (plus whatever slop the filter needs) | 2201 // (plus whatever slop the filter needs) |
2206 if (clipBounds) { | 2202 if (clipBounds) { |
2207 SkIRect tmp = *clipBounds; | |
2208 // Ugh. Guard against gigantic margins from wacky filters. Without this | 2203 // Ugh. Guard against gigantic margins from wacky filters. Without this |
2209 // check we can request arbitrary amounts of slop beyond our visible | 2204 // check we can request arbitrary amounts of slop beyond our visible |
2210 // clip, and bring down the renderer (at least on finite RAM machines | 2205 // clip, and bring down the renderer (at least on finite RAM machines |
2211 // like handsets, etc.). Need to balance this invented value between | 2206 // like handsets, etc.). Need to balance this invented value between |
2212 // quality of large filters like blurs, and the corresponding memory | 2207 // quality of large filters like blurs, and the corresponding memory |
2213 // requests. | 2208 // requests. |
2214 static const int MAX_MARGIN = 128; | 2209 static const int MAX_MARGIN = 128; |
2215 tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), | 2210 if (!bounds->intersect(clipBounds->makeOutset(SkMin32(margin.fX, MAX_MAR
GIN), |
2216 -SkMin32(margin.fY, MAX_MARGIN)); | 2211 SkMin32(margin.fY, MAX_MAR
GIN)))) { |
2217 if (!bounds->intersect(tmp)) { | |
2218 return false; | 2212 return false; |
2219 } | 2213 } |
2220 } | 2214 } |
2221 | 2215 |
2222 return true; | 2216 return true; |
2223 } | 2217 } |
2224 | 2218 |
2225 static void draw_into_mask(const SkMask& mask, const SkPath& devPath, | 2219 static void draw_into_mask(const SkMask& mask, const SkPath& devPath, |
2226 SkPaint::Style style) { | 2220 SkPaint::Style style) { |
2227 SkBitmap bm; | 2221 SkBitmap bm; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2266 mask->fImage = SkMask::AllocImage(size); | 2260 mask->fImage = SkMask::AllocImage(size); |
2267 memset(mask->fImage, 0, mask->computeImageSize()); | 2261 memset(mask->fImage, 0, mask->computeImageSize()); |
2268 } | 2262 } |
2269 | 2263 |
2270 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2264 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2271 draw_into_mask(*mask, devPath, style); | 2265 draw_into_mask(*mask, devPath, style); |
2272 } | 2266 } |
2273 | 2267 |
2274 return true; | 2268 return true; |
2275 } | 2269 } |
OLD | NEW |