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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; | 753 GrTextureParams params; |
754 GrSurfaceDesc texDesc; | 754 GrSurfaceDesc texDesc; |
755 | 755 |
756 unsigned int profile_size = SkScalarCeilToInt(6*sigma); | 756 unsigned int profileSize = SkScalarCeilToInt(6*sigma); |
757 | 757 |
758 texDesc.fWidth = profile_size; | 758 texDesc.fWidth = profileSize; |
759 texDesc.fHeight = 1; | 759 texDesc.fHeight = 1; |
760 texDesc.fConfig = kAlpha_8_GrPixelConfig; | 760 texDesc.fConfig = kAlpha_8_GrPixelConfig; |
761 | 761 |
762 static const GrCacheID::Domain gBlurProfileDomain = GrCacheID::GenerateDomai
n(); | 762 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
763 GrCacheID::Key key; | 763 GrContentKey key; |
764 memset(&key, 0, sizeof(key)); | 764 GrContentKey::Builder builder(&key, kDomain, 1); |
765 key.fData32[0] = profile_size; | 765 builder[0] = profileSize; |
766 key.fData32[1] = 1; | 766 builder.finish(); |
767 GrCacheID blurProfileKey(gBlurProfileDomain, key); | |
768 | 767 |
769 uint8_t *profile = NULL; | 768 uint8_t *profile = NULL; |
770 SkAutoTDeleteArray<uint8_t> ada(NULL); | 769 SkAutoTDeleteArray<uint8_t> ada(NULL); |
771 | 770 |
772 *blurProfileTexture = context->findAndRefTexture(texDesc, blurProfileKey, &p
arams); | 771 *blurProfileTexture = context->findAndRefTexture(texDesc, key, ¶ms); |
773 | 772 |
774 if (NULL == *blurProfileTexture) { | 773 if (NULL == *blurProfileTexture) { |
775 | 774 |
776 SkBlurMask::ComputeBlurProfile(sigma, &profile); | 775 SkBlurMask::ComputeBlurProfile(sigma, &profile); |
777 ada.reset(profile); | 776 ada.reset(profile); |
778 | 777 |
779 *blurProfileTexture = context->createTexture(¶ms, texDesc, blurProfi
leKey, | 778 *blurProfileTexture = context->createTexture(¶ms, texDesc, key, prof
ile, 0); |
780 profile, 0); | |
781 | 779 |
782 if (NULL == *blurProfileTexture) { | 780 if (NULL == *blurProfileTexture) { |
783 return false; | 781 return false; |
784 } | 782 } |
785 } | 783 } |
786 | 784 |
787 return true; | 785 return true; |
788 } | 786 } |
789 | 787 |
790 GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, | 788 GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 // sufficiently small relative to both the size of the corner radius and the | 911 // sufficiently small relative to both the size of the corner radius and the |
914 // width (and height) of the rrect. | 912 // width (and height) of the rrect. |
915 | 913 |
916 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f); | 914 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f); |
917 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x()); | 915 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x()); |
918 if (cornerRadius + blurRadius > rrect.width()/2 || | 916 if (cornerRadius + blurRadius > rrect.width()/2 || |
919 cornerRadius + blurRadius > rrect.height()/2) { | 917 cornerRadius + blurRadius > rrect.height()/2) { |
920 return NULL; | 918 return NULL; |
921 } | 919 } |
922 | 920 |
923 static const GrCacheID::Domain gRRectBlurDomain = GrCacheID::GenerateDomain(
); | 921 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
924 GrCacheID::Key key; | 922 GrContentKey key; |
925 memset(&key, 0, sizeof(key)); | 923 GrContentKey::Builder builder(&key, kDomain, 2); |
926 key.fData32[0] = blurRadius; | 924 builder[0] = blurRadius; |
927 key.fData32[1] = cornerRadius; | 925 builder[1] = cornerRadius; |
928 GrCacheID blurRRectNinePatchID(gRRectBlurDomain, key); | 926 builder.finish(); |
929 | 927 |
930 GrTextureParams params; | 928 GrTextureParams params; |
931 params.setFilterMode(GrTextureParams::kBilerp_FilterMode); | 929 params.setFilterMode(GrTextureParams::kBilerp_FilterMode); |
932 | 930 |
933 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; | 931 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; |
934 unsigned int texSide = smallRectSide + 2*blurRadius; | 932 unsigned int texSide = smallRectSide + 2*blurRadius; |
935 GrSurfaceDesc texDesc; | 933 GrSurfaceDesc texDesc; |
936 texDesc.fWidth = texSide; | 934 texDesc.fWidth = texSide; |
937 texDesc.fHeight = texSide; | 935 texDesc.fHeight = texSide; |
938 texDesc.fConfig = kAlpha_8_GrPixelConfig; | 936 texDesc.fConfig = kAlpha_8_GrPixelConfig; |
939 | 937 |
940 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, blurRR
ectNinePatchID, ¶ms); | 938 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, key, &
params); |
941 | 939 |
942 if (NULL == blurNinePatchTexture) { | 940 if (NULL == blurNinePatchTexture) { |
943 SkMask mask; | 941 SkMask mask; |
944 | 942 |
945 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); | 943 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); |
946 mask.fFormat = SkMask::kA8_Format; | 944 mask.fFormat = SkMask::kA8_Format; |
947 mask.fRowBytes = mask.fBounds.width(); | 945 mask.fRowBytes = mask.fBounds.width(); |
948 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); | 946 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); |
949 SkAutoMaskFreeImage amfi(mask.fImage); | 947 SkAutoMaskFreeImage amfi(mask.fImage); |
950 | 948 |
951 memset(mask.fImage, 0, mask.computeTotalImageSize()); | 949 memset(mask.fImage, 0, mask.computeTotalImageSize()); |
952 | 950 |
953 SkRect smallRect; | 951 SkRect smallRect; |
954 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid
e)); | 952 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid
e)); |
955 | 953 |
956 SkRRect smallRRect; | 954 SkRRect smallRRect; |
957 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal
ar(cornerRadius)); | 955 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal
ar(cornerRadius)); |
958 | 956 |
959 SkPath path; | 957 SkPath path; |
960 path.addRRect( smallRRect ); | 958 path.addRRect( smallRRect ); |
961 | 959 |
962 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust
RenderImage_CreateMode, SkPaint::kFill_Style); | 960 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust
RenderImage_CreateMode, SkPaint::kFill_Style); |
963 | 961 |
964 SkMask blurred_mask; | 962 SkMask blurred_mask; |
965 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi
gh_SkBlurQuality, NULL, true ); | 963 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi
gh_SkBlurQuality, NULL, true ); |
966 | 964 |
967 blurNinePatchTexture = context->createTexture(¶ms, texDesc, blurRRec
tNinePatchID, blurred_mask.fImage, 0); | 965 blurNinePatchTexture = context->createTexture(¶ms, texDesc, key, blu
rred_mask.fImage, 0); |
968 SkMask::FreeImage(blurred_mask.fImage); | 966 SkMask::FreeImage(blurred_mask.fImage); |
969 } | 967 } |
970 | 968 |
971 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); | 969 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); |
972 if (NULL == blurNinePatchTexture) { | 970 if (NULL == blurNinePatchTexture) { |
973 return NULL; | 971 return NULL; |
974 } | 972 } |
975 | 973 |
976 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); | 974 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); |
977 } | 975 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 } else { | 1265 } else { |
1268 str->append("None"); | 1266 str->append("None"); |
1269 } | 1267 } |
1270 str->append("))"); | 1268 str->append("))"); |
1271 } | 1269 } |
1272 #endif | 1270 #endif |
1273 | 1271 |
1274 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1272 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1275 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1273 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1276 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1274 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |