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" |
11 #include "effects/GrSimpleTextureEffect.h" | 11 #include "effects/GrSimpleTextureEffect.h" |
12 | 12 |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrTextContext.h" | 14 #include "GrTextContext.h" |
15 | 15 |
16 #include "SkGrTexturePixelRef.h" | 16 #include "SkGrTexturePixelRef.h" |
17 | 17 |
18 #include "SkColorFilter.h" | 18 #include "SkColorFilter.h" |
19 #include "SkDeviceImageFilterProxy.h" | 19 #include "SkDeviceImageFilterProxy.h" |
20 #include "SkDrawProcs.h" | 20 #include "SkDrawProcs.h" |
21 #include "SkGlyphCache.h" | 21 #include "SkGlyphCache.h" |
22 #include "SkImageFilter.h" | 22 #include "SkImageFilter.h" |
23 #include "SkPathEffect.h" | 23 #include "SkPathEffect.h" |
24 #include "SkRRect.h" | 24 #include "SkRRect.h" |
25 #include "SkStroke.h" | 25 #include "SkStroke.h" |
26 #include "SkUtils.h" | 26 #include "SkUtils.h" |
27 #include "SkBlurMaskFilter.h" | |
27 | 28 |
28 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 | 29 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 |
29 | 30 |
30 #if 0 | 31 #if 0 |
31 extern bool (*gShouldDrawProc)(); | 32 extern bool (*gShouldDrawProc)(); |
32 #define CHECK_SHOULD_DRAW(draw, forceI) \ | 33 #define CHECK_SHOULD_DRAW(draw, forceI) \ |
33 do { \ | 34 do { \ |
34 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 35 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
35 this->prepareDraw(draw, forceI); \ | 36 this->prepareDraw(draw, forceI); \ |
36 } while (0) | 37 } while (0) |
37 #else | 38 #else |
38 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) | 39 #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI) |
39 #endif | 40 #endif |
40 | 41 |
41 // we use the same effect slot on GrPaint for bitmaps and shaders (since drawBit map, drawSprite, | 42 // we use the same effect slot on GrPaint for bitmaps and shaders (since drawBit map, drawSprite, |
42 // and drawDevice ignore SkShader) | 43 // and drawDevice ignore SkShader) |
43 enum { | 44 enum { |
44 kShaderEffectIdx = 0, | 45 kShaderEffectIdx = 0, |
45 kBitmapEffectIdx = 0, | 46 kBitmapEffectIdx = 0, |
46 kColorFilterEffectIdx = 1, | 47 kColorFilterEffectIdx = 1, |
47 kXfermodeEffectIdx = 2, | 48 kXfermodeEffectIdx = 2, |
48 }; | 49 }; |
49 | 50 |
50 #define MAX_BLUR_SIGMA 4.0f | |
51 // FIXME: This value comes from from SkBlurMaskFilter.cpp. | 51 // FIXME: This value comes from from SkBlurMaskFilter.cpp. |
52 // Should probably be put in a common header someplace. | 52 // Should probably be put in a common header someplace. |
53 #define MAX_BLUR_RADIUS SkIntToScalar(128) | 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 | 54 // This constant represents the screen alignment criterion in texels for |
63 // requiring texture domain clamping to prevent color bleeding when drawing | 55 // requiring texture domain clamping to prevent color bleeding when drawing |
64 // a sub region of a larger source image. | 56 // a sub region of a larger source image. |
65 #define COLOR_BLEED_TOLERANCE SkFloatToScalar(0.001f) | 57 #define COLOR_BLEED_TOLERANCE SkFloatToScalar(0.001f) |
66 | 58 |
67 #define DO_DEFERRED_CLEAR() \ | 59 #define DO_DEFERRED_CLEAR() \ |
68 do { \ | 60 do { \ |
69 if (fNeedClear) { \ | 61 if (fNeedClear) { \ |
70 this->clear(SK_ColorTRANSPARENT); \ | 62 this->clear(SK_ColorTRANSPARENT); \ |
71 } \ | 63 } \ |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 radius = SkMinScalar(radius, MAX_BLUR_RADIUS); | 793 radius = SkMinScalar(radius, MAX_BLUR_RADIUS); |
802 if (radius <= 0) { | 794 if (radius <= 0) { |
803 return false; | 795 return false; |
804 } | 796 } |
805 | 797 |
806 SkRect srcRect = devPath.getBounds(); | 798 SkRect srcRect = devPath.getBounds(); |
807 if (shouldDrawBlurWithCPU(srcRect, radius)) { | 799 if (shouldDrawBlurWithCPU(srcRect, radius)) { |
808 return false; | 800 return false; |
809 } | 801 } |
810 | 802 |
811 float sigma = SkScalarToFloat(radius) * BLUR_SIGMA_SCALE; | 803 float sigma = SkScalarToFloat(radius) * SkBlurMaskFilter::kBLUR_SIGMA_SCALE; |
bsalomon
2013/06/14 18:23:54
Could the radius returned in info already account
| |
812 float sigma3 = sigma * 3.0f; | 804 float sigma3 = sigma * 3.0f; |
813 | 805 |
814 SkRect clipRect; | 806 SkRect clipRect; |
815 clipRect.set(clip.getBounds()); | 807 clipRect.set(clip.getBounds()); |
816 | 808 |
817 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area. | 809 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area. |
818 srcRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); | 810 srcRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); |
819 clipRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); | 811 clipRect.inset(SkFloatToScalar(-sigma3), SkFloatToScalar(-sigma3)); |
820 srcRect.intersect(clipRect); | 812 srcRect.intersect(clipRect); |
821 SkRect finalRect = srcRect; | 813 SkRect finalRect = srcRect; |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1852 GrTexture* texture, | 1844 GrTexture* texture, |
1853 bool needClear) | 1845 bool needClear) |
1854 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { | 1846 : SkDevice(make_bitmap(context, texture->asRenderTarget())) { |
1855 | 1847 |
1856 GrAssert(texture && texture->asRenderTarget()); | 1848 GrAssert(texture && texture->asRenderTarget()); |
1857 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture | 1849 // 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. | 1850 // cache. We pass true for the third argument so that it will get unlocked. |
1859 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1851 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1860 fNeedClear = needClear; | 1852 fNeedClear = needClear; |
1861 } | 1853 } |
OLD | NEW |