OLD | NEW |
1 /* libs/graphics/sgl/SkDraw.cpp | 1 /* libs/graphics/sgl/SkDraw.cpp |
2 ** | 2 ** |
3 ** Copyright 2006, The Android Open Source Project | 3 ** Copyright 2006, The Android Open Source Project |
4 ** | 4 ** |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
6 ** you may not use this file except in compliance with the License. | 6 ** you may not use this file except in compliance with the License. |
7 ** You may obtain a copy of the License at | 7 ** You may obtain a copy of the License at |
8 ** | 8 ** |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
10 ** | 10 ** |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 // set the mask's bounds to the transformed bitmap-bounds, | 904 // set the mask's bounds to the transformed bitmap-bounds, |
905 // clipped to the actual device | 905 // clipped to the actual device |
906 { | 906 { |
907 SkIRect devBounds; | 907 SkIRect devBounds; |
908 devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); | 908 devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); |
909 // need intersect(l, t, r, b) on irect | 909 // need intersect(l, t, r, b) on irect |
910 if (!mask.fBounds.intersect(devBounds)) { | 910 if (!mask.fBounds.intersect(devBounds)) { |
911 return; | 911 return; |
912 } | 912 } |
913 } | 913 } |
| 914 |
914 mask.fFormat = SkMask::kA8_Format; | 915 mask.fFormat = SkMask::kA8_Format; |
915 mask.fRowBytes = SkAlign4(mask.fBounds.width()); | 916 mask.fRowBytes = SkAlign4(mask.fBounds.width()); |
| 917 size_t size = mask.computeImageSize(); |
| 918 if (0 == size) { |
| 919 // the mask is too big to allocated, draw nothing |
| 920 return; |
| 921 } |
916 | 922 |
917 // allocate (and clear) our temp buffer to hold the transformed bitmap | 923 // allocate (and clear) our temp buffer to hold the transformed bitmap |
918 size_t size = mask.computeImageSize(); | |
919 SkAutoMalloc storage(size); | 924 SkAutoMalloc storage(size); |
920 mask.fImage = (uint8_t*)storage.get(); | 925 mask.fImage = (uint8_t*)storage.get(); |
921 memset(mask.fImage, 0, size); | 926 memset(mask.fImage, 0, size); |
922 | 927 |
923 // now draw our bitmap(src) into mask(dst), transformed by the matrix | 928 // now draw our bitmap(src) into mask(dst), transformed by the matrix |
924 { | 929 { |
925 SkBitmap device; | 930 SkBitmap device; |
926 device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), | 931 device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), |
927 mask.fBounds.height(), mask.fRowBytes); | 932 mask.fBounds.height(), mask.fRowBytes); |
928 device.setPixels(mask.fImage); | 933 device.setPixels(mask.fImage); |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2329 SkMaskFilter* filter, const SkMatrix* filterMatrix, | 2334 SkMaskFilter* filter, const SkMatrix* filterMatrix, |
2330 SkMask* mask, SkMask::CreateMode mode) { | 2335 SkMask* mask, SkMask::CreateMode mode) { |
2331 if (SkMask::kJustRenderImage_CreateMode != mode) { | 2336 if (SkMask::kJustRenderImage_CreateMode != mode) { |
2332 if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fB
ounds)) | 2337 if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fB
ounds)) |
2333 return false; | 2338 return false; |
2334 } | 2339 } |
2335 | 2340 |
2336 if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { | 2341 if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { |
2337 mask->fFormat = SkMask::kA8_Format; | 2342 mask->fFormat = SkMask::kA8_Format; |
2338 mask->fRowBytes = mask->fBounds.width(); | 2343 mask->fRowBytes = mask->fBounds.width(); |
2339 mask->fImage = SkMask::AllocImage(mask->computeImageSize()); | 2344 size_t size = mask->computeImageSize(); |
| 2345 if (0 == size) { |
| 2346 // we're too big to allocate the mask, abort |
| 2347 return false; |
| 2348 } |
| 2349 mask->fImage = SkMask::AllocImage(size); |
2340 memset(mask->fImage, 0, mask->computeImageSize()); | 2350 memset(mask->fImage, 0, mask->computeImageSize()); |
2341 } | 2351 } |
2342 | 2352 |
2343 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2353 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2344 draw_into_mask(*mask, devPath); | 2354 draw_into_mask(*mask, devPath); |
2345 } | 2355 } |
2346 | 2356 |
2347 return true; | 2357 return true; |
2348 } | 2358 } |
OLD | NEW |