OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 const GrProcessor& proc) { | 743 const GrProcessor& proc) { |
744 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); | 744 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); |
745 SkRect rect = rbe.getRect(); | 745 SkRect rect = rbe.getRect(); |
746 | 746 |
747 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); | 747 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); |
748 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); | 748 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); |
749 } | 749 } |
750 | 750 |
751 bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, | 751 bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, |
752 GrTexture **blurProfileTexture)
{ | 752 GrTexture **blurProfileTexture)
{ |
753 GrTextureParams params; | |
754 GrSurfaceDesc texDesc; | 753 GrSurfaceDesc texDesc; |
755 | 754 |
756 unsigned int profileSize = SkScalarCeilToInt(6*sigma); | 755 unsigned int profileSize = SkScalarCeilToInt(6*sigma); |
757 | 756 |
758 texDesc.fWidth = profileSize; | 757 texDesc.fWidth = profileSize; |
759 texDesc.fHeight = 1; | 758 texDesc.fHeight = 1; |
760 texDesc.fConfig = kAlpha_8_GrPixelConfig; | 759 texDesc.fConfig = kAlpha_8_GrPixelConfig; |
761 | 760 |
762 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); | 761 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
763 GrContentKey key; | 762 GrContentKey key; |
764 GrContentKey::Builder builder(&key, kDomain, 1); | 763 GrContentKey::Builder builder(&key, kDomain, 1); |
765 builder[0] = profileSize; | 764 builder[0] = profileSize; |
766 builder.finish(); | 765 builder.finish(); |
767 | 766 |
768 uint8_t *profile = NULL; | 767 uint8_t *profile = NULL; |
769 SkAutoTDeleteArray<uint8_t> ada(NULL); | 768 SkAutoTDeleteArray<uint8_t> ada(NULL); |
770 | 769 |
771 *blurProfileTexture = context->findAndRefTexture(texDesc, key, ¶ms); | 770 *blurProfileTexture = context->findAndRefCachedTexture(key); |
772 | 771 |
773 if (NULL == *blurProfileTexture) { | 772 if (NULL == *blurProfileTexture) { |
774 | 773 |
775 SkBlurMask::ComputeBlurProfile(sigma, &profile); | 774 SkBlurMask::ComputeBlurProfile(sigma, &profile); |
776 ada.reset(profile); | 775 ada.reset(profile); |
777 | 776 |
778 *blurProfileTexture = context->createTexture(¶ms, texDesc, key, prof
ile, 0); | 777 *blurProfileTexture = context->createTexture(texDesc, profile, 0); |
779 | 778 |
780 if (NULL == *blurProfileTexture) { | 779 if (NULL == *blurProfileTexture) { |
781 return false; | 780 return false; |
782 } | 781 } |
| 782 SkAssertResult(context->addResourceToCache(key, *blurProfileTexture)); |
783 } | 783 } |
784 | 784 |
785 return true; | 785 return true; |
786 } | 786 } |
787 | 787 |
788 GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, | 788 GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, |
789 GrTexture *blur_profile) | 789 GrTexture *blur_profile) |
790 : fRect(rect), | 790 : fRect(rect), |
791 fSigma(sigma), | 791 fSigma(sigma), |
792 fBlurProfileAccess(blur_profile) { | 792 fBlurProfileAccess(blur_profile) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 return NULL; | 918 return NULL; |
919 } | 919 } |
920 | 920 |
921 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); | 921 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
922 GrContentKey key; | 922 GrContentKey key; |
923 GrContentKey::Builder builder(&key, kDomain, 2); | 923 GrContentKey::Builder builder(&key, kDomain, 2); |
924 builder[0] = blurRadius; | 924 builder[0] = blurRadius; |
925 builder[1] = cornerRadius; | 925 builder[1] = cornerRadius; |
926 builder.finish(); | 926 builder.finish(); |
927 | 927 |
928 GrTextureParams params; | 928 GrTexture *blurNinePatchTexture = context->findAndRefCachedTexture(key); |
929 params.setFilterMode(GrTextureParams::kBilerp_FilterMode); | |
930 | |
931 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; | |
932 unsigned int texSide = smallRectSide + 2*blurRadius; | |
933 GrSurfaceDesc texDesc; | |
934 texDesc.fWidth = texSide; | |
935 texDesc.fHeight = texSide; | |
936 texDesc.fConfig = kAlpha_8_GrPixelConfig; | |
937 | |
938 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, key, &
params); | |
939 | 929 |
940 if (NULL == blurNinePatchTexture) { | 930 if (NULL == blurNinePatchTexture) { |
941 SkMask mask; | 931 SkMask mask; |
942 | 932 |
| 933 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; |
| 934 |
943 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); | 935 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); |
944 mask.fFormat = SkMask::kA8_Format; | 936 mask.fFormat = SkMask::kA8_Format; |
945 mask.fRowBytes = mask.fBounds.width(); | 937 mask.fRowBytes = mask.fBounds.width(); |
946 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); | 938 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); |
947 SkAutoMaskFreeImage amfi(mask.fImage); | 939 SkAutoMaskFreeImage amfi(mask.fImage); |
948 | 940 |
949 memset(mask.fImage, 0, mask.computeTotalImageSize()); | 941 memset(mask.fImage, 0, mask.computeTotalImageSize()); |
950 | 942 |
951 SkRect smallRect; | 943 SkRect smallRect; |
952 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid
e)); | 944 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid
e)); |
953 | 945 |
954 SkRRect smallRRect; | 946 SkRRect smallRRect; |
955 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal
ar(cornerRadius)); | 947 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal
ar(cornerRadius)); |
956 | 948 |
957 SkPath path; | 949 SkPath path; |
958 path.addRRect( smallRRect ); | 950 path.addRRect( smallRRect ); |
959 | 951 |
960 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust
RenderImage_CreateMode, SkPaint::kFill_Style); | 952 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, |
| 953 SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_S
tyle); |
961 | 954 |
962 SkMask blurred_mask; | 955 SkMask blurred_mask; |
963 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi
gh_SkBlurQuality, NULL, true ); | 956 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi
gh_SkBlurQuality, |
| 957 NULL, true ); |
964 | 958 |
965 blurNinePatchTexture = context->createTexture(¶ms, texDesc, key, blu
rred_mask.fImage, 0); | 959 unsigned int texSide = smallRectSide + 2*blurRadius; |
| 960 GrSurfaceDesc texDesc; |
| 961 texDesc.fWidth = texSide; |
| 962 texDesc.fHeight = texSide; |
| 963 texDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 964 |
| 965 blurNinePatchTexture = context->createTexture(texDesc, blurred_mask.fIma
ge, 0); |
| 966 SkAssertResult(context->addResourceToCache(key, blurNinePatchTexture)); |
| 967 |
966 SkMask::FreeImage(blurred_mask.fImage); | 968 SkMask::FreeImage(blurred_mask.fImage); |
967 } | 969 } |
968 | 970 |
969 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); | 971 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); |
970 if (NULL == blurNinePatchTexture) { | 972 if (NULL == blurNinePatchTexture) { |
971 return NULL; | 973 return NULL; |
972 } | 974 } |
973 | 975 |
974 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); | 976 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); |
975 } | 977 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 } else { | 1267 } else { |
1266 str->append("None"); | 1268 str->append("None"); |
1267 } | 1269 } |
1268 str->append("))"); | 1270 str->append("))"); |
1269 } | 1271 } |
1270 #endif | 1272 #endif |
1271 | 1273 |
1272 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1274 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1273 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1275 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1274 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1276 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |