Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1222)

Side by Side Diff: src/effects/SkBlurMaskFilter.cpp

Issue 882223003: Move npot resizing out of GrContext and simplify GrContext texture functions. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: minor Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, &params); 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(&params, 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
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;
929 params.setFilterMode(GrTextureParams::kBilerp_FilterMode);
930
931 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; 928 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1;
932 unsigned int texSide = smallRectSide + 2*blurRadius; 929 unsigned int texSide = smallRectSide + 2*blurRadius;
robertphillips 2015/01/30 14:47:21 I guess we could move the creation of 'texDesc' do
bsalomon 2015/01/30 15:37:39 Done.
933 GrSurfaceDesc texDesc; 930 GrSurfaceDesc texDesc;
934 texDesc.fWidth = texSide; 931 texDesc.fWidth = texSide;
935 texDesc.fHeight = texSide; 932 texDesc.fHeight = texSide;
936 texDesc.fConfig = kAlpha_8_GrPixelConfig; 933 texDesc.fConfig = kAlpha_8_GrPixelConfig;
937 934
938 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, key, & params); 935 GrTexture *blurNinePatchTexture = context->findAndRefCachedTexture(key);
939 936
940 if (NULL == blurNinePatchTexture) { 937 if (NULL == blurNinePatchTexture) {
941 SkMask mask; 938 SkMask mask;
942 939
943 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); 940 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide);
944 mask.fFormat = SkMask::kA8_Format; 941 mask.fFormat = SkMask::kA8_Format;
945 mask.fRowBytes = mask.fBounds.width(); 942 mask.fRowBytes = mask.fBounds.width();
946 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); 943 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize());
947 SkAutoMaskFreeImage amfi(mask.fImage); 944 SkAutoMaskFreeImage amfi(mask.fImage);
948 945
949 memset(mask.fImage, 0, mask.computeTotalImageSize()); 946 memset(mask.fImage, 0, mask.computeTotalImageSize());
950 947
951 SkRect smallRect; 948 SkRect smallRect;
952 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid e)); 949 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSid e));
953 950
954 SkRRect smallRRect; 951 SkRRect smallRRect;
955 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal ar(cornerRadius)); 952 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScal ar(cornerRadius));
956 953
957 SkPath path; 954 SkPath path;
958 path.addRRect( smallRRect ); 955 path.addRRect( smallRRect );
959 956
robertphillips 2015/01/30 14:47:21 2 overlength lines
bsalomon 2015/01/30 15:37:39 Done.
960 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust RenderImage_CreateMode, SkPaint::kFill_Style); 957 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust RenderImage_CreateMode, SkPaint::kFill_Style);
961 958
962 SkMask blurred_mask; 959 SkMask blurred_mask;
963 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi gh_SkBlurQuality, NULL, true ); 960 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi gh_SkBlurQuality, NULL, true );
964 961
965 blurNinePatchTexture = context->createTexture(&params, texDesc, key, blu rred_mask.fImage, 0); 962 blurNinePatchTexture = context->createTexture(texDesc, blurred_mask.fIma ge, 0);
963 SkAssertResult(context->addResourceToCache(key, blurNinePatchTexture));
964
966 SkMask::FreeImage(blurred_mask.fImage); 965 SkMask::FreeImage(blurred_mask.fImage);
967 } 966 }
968 967
969 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); 968 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture);
970 if (NULL == blurNinePatchTexture) { 969 if (NULL == blurNinePatchTexture) {
971 return NULL; 970 return NULL;
972 } 971 }
973 972
974 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); 973 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture));
975 } 974 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 } else { 1264 } else {
1266 str->append("None"); 1265 str->append("None");
1267 } 1266 }
1268 str->append("))"); 1267 str->append("))");
1269 } 1268 }
1270 #endif 1269 #endif
1271 1270
1272 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1271 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1273 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1272 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1274 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1273 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698