OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // we use the same effect slot on GrPaint for bitmaps and shaders (since drawBit
map, drawSprite, | 41 // we use the same effect slot on GrPaint for bitmaps and shaders (since drawBit
map, drawSprite, |
42 // and drawDevice ignore SkShader) | 42 // and drawDevice ignore SkShader) |
43 enum { | 43 enum { |
44 kShaderEffectIdx = 0, | 44 kShaderEffectIdx = 0, |
45 kBitmapEffectIdx = 0, | 45 kBitmapEffectIdx = 0, |
46 kColorFilterEffectIdx = 1, | 46 kColorFilterEffectIdx = 1, |
47 kXfermodeEffectIdx = 2, | 47 kXfermodeEffectIdx = 2, |
48 }; | 48 }; |
49 | 49 |
50 #define MAX_BLUR_SIGMA 4.0f | |
51 // FIXME: This value comes from from SkBlurMaskFilter.cpp. | |
52 // Should probably be put in a common header someplace. | |
53 #define MAX_BLUR_RADIUS SkIntToScalar(128) | |
54 // This constant approximates the scaling done in the software path's | |
55 // "high quality" mode, in SkBlurMask::Blur() (1 / sqrt(3)). | |
56 // IMHO, it actually should be 1: we blur "less" than we should do | |
57 // according to the CSS and canvas specs, simply because Safari does the same. | |
58 // Firefox used to do the same too, until 4.0 where they fixed it. So at some | |
59 // point we should probably get rid of these scaling constants and rebaseline | |
60 // all the blur tests. | |
61 #define BLUR_SIGMA_SCALE 0.6f | |
62 // This constant represents the screen alignment criterion in texels for | 50 // This constant represents the screen alignment criterion in texels for |
63 // requiring texture domain clamping to prevent color bleeding when drawing | 51 // requiring texture domain clamping to prevent color bleeding when drawing |
64 // a sub region of a larger source image. | 52 // a sub region of a larger source image. |
65 #define COLOR_BLEED_TOLERANCE SkFloatToScalar(0.001f) | 53 #define COLOR_BLEED_TOLERANCE SkFloatToScalar(0.001f) |
66 | 54 |
67 #define DO_DEFERRED_CLEAR() \ | 55 #define DO_DEFERRED_CLEAR() \ |
68 do { \ | 56 do { \ |
69 if (fNeedClear) { \ | 57 if (fNeedClear) { \ |
70 this->clear(SK_ColorTRANSPARENT); \ | 58 this->clear(SK_ColorTRANSPARENT); \ |
71 } \ | 59 } \ |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
rokeRec& stroke, | 779 bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
rokeRec& stroke, |
792 SkMaskFilter* filter, const SkRegion& clip, | 780 SkMaskFilter* filter, const SkRegion& clip, |
793 SkBounder* bounder, GrPaint* grp) { | 781 SkBounder* bounder, GrPaint* grp) { |
794 SkMaskFilter::BlurInfo info; | 782 SkMaskFilter::BlurInfo info; |
795 SkMaskFilter::BlurType blurType = filter->asABlur(&info); | 783 SkMaskFilter::BlurType blurType = filter->asABlur(&info); |
796 if (SkMaskFilter::kNone_BlurType == blurType) { | 784 if (SkMaskFilter::kNone_BlurType == blurType) { |
797 return false; | 785 return false; |
798 } | 786 } |
799 SkScalar radius = info.fIgnoreTransform ? info.fRadius | 787 SkScalar radius = info.fIgnoreTransform ? info.fRadius |
800 : context->getMatrix().mapRadius(inf
o.fRadius); | 788 : context->getMatrix().mapRadius(inf
o.fRadius); |
801 radius = SkMinScalar(radius, MAX_BLUR_RADIUS); | 789 radius = SkMinScalar(radius, info.fMaxRadius); |
802 if (radius <= 0) { | 790 if (radius <= 0) { |
803 return false; | 791 return false; |
804 } | 792 } |
805 | 793 |
806 SkRect srcRect = devPath.getBounds(); | 794 SkRect srcRect = devPath.getBounds(); |
807 if (shouldDrawBlurWithCPU(srcRect, radius)) { | 795 if (shouldDrawBlurWithCPU(srcRect, radius)) { |
808 return false; | 796 return false; |
809 } | 797 } |
810 | 798 |
811 float sigma = SkScalarToFloat(radius) * BLUR_SIGMA_SCALE; | 799 float sigma = SkScalarToFloat(radius) * info.fSigmaFraction; |
812 float sigma3 = sigma * 3.0f; | 800 float sigma3 = sigma * 3.0f; |
813 | 801 |
814 SkRect clipRect; | 802 SkRect clipRect; |
815 clipRect.set(clip.getBounds()); | 803 clipRect.set(clip.getBounds()); |
816 | 804 |
817 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area. | 805 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area. |
818 srcRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); | 806 srcRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); |
819 clipRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); | 807 clipRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); |
820 srcRect.intersect(clipRect); | 808 srcRect.intersect(clipRect); |
821 SkRect finalRect = srcRect; | 809 SkRect finalRect = srcRect; |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 GrTexture* texture, | 1840 GrTexture* texture, |
1853 bool needClear) | 1841 bool needClear) |
1854 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { | 1842 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { |
1855 | 1843 |
1856 GrAssert(texture && texture->asRenderTarget()); | 1844 GrAssert(texture && texture->asRenderTarget()); |
1857 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1845 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1858 // cache. We pass true for the third argument so that it will get unlocked. | 1846 // cache. We pass true for the third argument so that it will get unlocked. |
1859 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1847 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1860 fNeedClear = needClear; | 1848 fNeedClear = needClear; |
1861 } | 1849 } |
OLD | NEW |