OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 bm.eraseColor(SK_ColorBLUE); | 1254 bm.eraseColor(SK_ColorBLUE); |
1255 SkPaint paint; | 1255 SkPaint paint; |
1256 paint.setColor(SK_ColorRED); | 1256 paint.setColor(SK_ColorRED); |
1257 paint.setImageFilter(unflattenedFilter); | 1257 paint.setImageFilter(unflattenedFilter); |
1258 | 1258 |
1259 SkCanvas canvas(bm); | 1259 SkCanvas canvas(bm); |
1260 canvas.drawRect(SkRect::MakeWH(10, 10), paint); | 1260 canvas.drawRect(SkRect::MakeWH(10, 10), paint); |
1261 REPORTER_ASSERT(reporter, *bm.getAddr32(0, 0) == SkPreMultiplyColor(SK_Color
GREEN)); | 1261 REPORTER_ASSERT(reporter, *bm.getAddr32(0, 0) == SkPreMultiplyColor(SK_Color
GREEN)); |
1262 } | 1262 } |
1263 | 1263 |
| 1264 static void test_large_blur_input(skiatest::Reporter* reporter, SkCanvas* canvas
) { |
| 1265 SkBitmap largeBmp; |
| 1266 int largeW = 5000; |
| 1267 int largeH = 5000; |
| 1268 #if SK_SUPPORT_GPU |
| 1269 // If we're GPU-backed make the bitmap too large to be converted into a text
ure. |
| 1270 if (GrContext* ctx = canvas->getGrContext()) { |
| 1271 largeW = ctx->caps()->maxTextureSize() + 1; |
| 1272 } |
| 1273 #endif |
| 1274 |
| 1275 largeBmp.allocN32Pixels(largeW, largeH); |
| 1276 if (!largeBmp.getPixels()) { |
| 1277 ERRORF(reporter, "Failed to allocate large bmp."); |
| 1278 return; |
| 1279 } |
| 1280 |
| 1281 SkAutoTUnref<SkImage> largeImage(SkImage::NewFromBitmap(largeBmp)); |
| 1282 if (!largeImage) { |
| 1283 ERRORF(reporter, "Failed to create large image."); |
| 1284 return; |
| 1285 } |
| 1286 |
| 1287 SkAutoTUnref<SkImageFilter> largeSource(SkImageSource::Create(largeImage)); |
| 1288 if (!largeSource) { |
| 1289 ERRORF(reporter, "Failed to create large SkImageSource."); |
| 1290 return; |
| 1291 } |
| 1292 |
| 1293 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, large
Source)); |
| 1294 if (!blur) { |
| 1295 ERRORF(reporter, "Failed to create SkBlurImageFilter."); |
| 1296 return; |
| 1297 } |
| 1298 |
| 1299 SkPaint paint; |
| 1300 paint.setImageFilter(blur); |
| 1301 |
| 1302 // This should not crash (http://crbug.com/570479). |
| 1303 canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); |
| 1304 } |
| 1305 |
| 1306 DEF_TEST(BlurLargeImage, reporter) { |
| 1307 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Pre
mul(100, 100))); |
| 1308 test_large_blur_input(reporter, surface->getCanvas()); |
| 1309 } |
| 1310 |
1264 #if SK_SUPPORT_GPU | 1311 #if SK_SUPPORT_GPU |
1265 | 1312 |
1266 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) { | 1313 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageFilterCropRect_Gpu, reporter, context) { |
1267 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1314 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1268 | 1315 |
1269 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1316 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1270 SkSurface::kNo_Budgeted
, | 1317 SkSurface::kNo_Budgeted
, |
1271 SkImageInfo::MakeN32Pre
mul(100, 100), | 1318 SkImageInfo::MakeN32Pre
mul(100, 100), |
1272 0, | 1319 0, |
1273 &props, | 1320 &props, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1358 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1312 SkSurface::kNo_Budgeted
, | 1359 SkSurface::kNo_Budgeted
, |
1313 SkImageInfo::MakeN32Pre
mul(1, 1), | 1360 SkImageInfo::MakeN32Pre
mul(1, 1), |
1314 0, | 1361 0, |
1315 &props, | 1362 &props, |
1316 SkGpuDevice::kUninit_In
itContents)); | 1363 SkGpuDevice::kUninit_In
itContents)); |
1317 SkImageFilter::DeviceProxy proxy(device); | 1364 SkImageFilter::DeviceProxy proxy(device); |
1318 | 1365 |
1319 test_negative_blur_sigma(&proxy, reporter); | 1366 test_negative_blur_sigma(&proxy, reporter); |
1320 } | 1367 } |
| 1368 |
| 1369 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
| 1370 SkAutoTUnref<SkSurface> surface( |
| 1371 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, |
| 1372 SkImageInfo::MakeN32Premul(100, 100))); |
| 1373 test_large_blur_input(reporter, surface->getCanvas()); |
| 1374 } |
1321 #endif | 1375 #endif |
OLD | NEW |