Chromium Code Reviews| 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/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
| 11 #include "effects/GrTextureDomain.h" | 11 #include "effects/GrTextureDomain.h" |
| 12 #include "effects/GrSimpleTextureEffect.h" | 12 #include "effects/GrSimpleTextureEffect.h" |
| 13 | 13 |
| 14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrBitmapTextContext.h" | 15 #include "GrBitmapTextContext.h" |
| 16 #if SK_DISTANCEFIELD_FONTS | 16 #if SK_DISTANCEFIELD_FONTS |
| 17 #include "GrDistanceFieldTextContext.h" | 17 #include "GrDistanceFieldTextContext.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 #include "SkGrTexturePixelRef.h" | 20 #include "SkGrTexturePixelRef.h" |
| 21 | 21 |
| 22 #include "SkColorFilter.h" | 22 #include "SkColorFilter.h" |
| 23 #include "SkDeviceImageFilterProxy.h" | 23 #include "SkDeviceImageFilterProxy.h" |
| 24 #include "SkDrawProcs.h" | 24 #include "SkDrawProcs.h" |
| 25 #include "SkGlyphCache.h" | 25 #include "SkGlyphCache.h" |
| 26 #include "SkImageFilter.h" | 26 #include "SkImageFilter.h" |
| 27 #include "SkPathEffect.h" | 27 #include "SkPathEffect.h" |
| 28 #include "SkRRect.h" | 28 #include "SkRRect.h" |
| 29 #include "SkStroke.h" | 29 #include "SkStroke.h" |
| 30 #include "SkTLazy.h" | |
| 30 #include "SkUtils.h" | 31 #include "SkUtils.h" |
| 31 #include "SkErrorInternals.h" | 32 #include "SkErrorInternals.h" |
| 32 | 33 |
| 33 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 | 34 #define CACHE_COMPATIBLE_DEVICE_TEXTURES 1 |
| 34 | 35 |
| 35 #if 0 | 36 #if 0 |
| 36 extern bool (*gShouldDrawProc)(); | 37 extern bool (*gShouldDrawProc)(); |
| 37 #define CHECK_SHOULD_DRAW(draw, forceI) \ | 38 #define CHECK_SHOULD_DRAW(draw, forceI) \ |
| 38 do { \ | 39 do { \ |
| 39 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 40 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 | 857 |
| 857 SkBitmap result; | 858 SkBitmap result; |
| 858 result.setConfig(info); | 859 result.setConfig(info); |
| 859 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 860 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 860 return result; | 861 return result; |
| 861 } | 862 } |
| 862 | 863 |
| 863 }; | 864 }; |
| 864 | 865 |
| 865 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 866 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 866 const SkPaint& paint, const SkMatrix* prePathMatrix, | 867 const SkPaint& paint, const SkMatrix* prePathMatrix, |
|
bsalomon
2013/12/18 15:20:04
Not recommending for this change, but maybe we cou
Kimmo Kinnunen
2013/12/19 06:30:01
Yeah, in theory that'd be useful for couple of com
| |
| 867 bool pathIsMutable) { | 868 bool pathIsMutable) { |
| 868 CHECK_FOR_ANNOTATION(paint); | 869 CHECK_FOR_ANNOTATION(paint); |
| 869 CHECK_SHOULD_DRAW(draw, false); | 870 CHECK_SHOULD_DRAW(draw, false); |
| 870 | 871 |
| 871 GrPaint grPaint; | 872 GrPaint grPaint; |
| 872 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 873 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
| 873 return; | 874 return; |
| 874 } | 875 } |
| 875 | 876 |
| 876 // If we have a prematrix, apply it to the path, optimizing for the case | 877 // If we have a prematrix, apply it to the path, optimizing for the case |
| 877 // where the original path can in fact be modified in place (even though | 878 // where the original path can in fact be modified in place (even though |
| 878 // its parameter type is const). | 879 // its parameter type is const). |
| 879 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 880 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
| 880 SkPath tmpPath, effectPath; | 881 SkTLazy<SkPath> tmpPath; |
| 882 SkTLazy<SkPath> effectPath; | |
| 881 | 883 |
| 882 if (prePathMatrix) { | 884 if (prePathMatrix) { |
| 883 SkPath* result = pathPtr; | 885 SkPath* result = pathPtr; |
| 884 | 886 |
| 885 if (!pathIsMutable) { | 887 if (!pathIsMutable) { |
| 886 result = &tmpPath; | 888 result = tmpPath.init(); |
| 887 pathIsMutable = true; | 889 pathIsMutable = true; |
| 888 } | 890 } |
| 889 // should I push prePathMatrix on our MV stack temporarily, instead | 891 // should I push prePathMatrix on our MV stack temporarily, instead |
| 890 // of applying it here? See SkDraw.cpp | 892 // of applying it here? See SkDraw.cpp |
| 891 pathPtr->transform(*prePathMatrix, result); | 893 pathPtr->transform(*prePathMatrix, result); |
| 892 pathPtr = result; | 894 pathPtr = result; |
| 893 } | 895 } |
| 894 // at this point we're done with prePathMatrix | 896 // at this point we're done with prePathMatrix |
| 895 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) | 897 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 896 | 898 |
| 897 SkStrokeRec stroke(paint); | 899 SkStrokeRec stroke(paint); |
| 898 SkPathEffect* pathEffect = paint.getPathEffect(); | 900 SkPathEffect* pathEffect = paint.getPathEffect(); |
| 899 const SkRect* cullRect = NULL; // TODO: what is our bounds? | 901 const SkRect* cullRect = NULL; // TODO: what is our bounds? |
| 900 if (pathEffect && pathEffect->filterPath(&effectPath, *pathPtr, &stroke, | 902 if (pathEffect && pathEffect->filterPath(effectPath.init(), *pathPtr, &strok e, |
| 901 cullRect)) { | 903 cullRect)) { |
| 902 pathPtr = &effectPath; | 904 pathPtr = effectPath.get(); |
| 905 pathIsMutable = true; | |
| 903 } | 906 } |
| 904 | 907 |
| 905 if (paint.getMaskFilter()) { | 908 if (paint.getMaskFilter()) { |
| 906 if (!stroke.isHairlineStyle()) { | 909 if (!stroke.isHairlineStyle()) { |
| 907 if (stroke.applyToPath(&tmpPath, *pathPtr)) { | 910 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); |
| 908 pathPtr = &tmpPath; | 911 if (stroke.applyToPath(strokedPath, *pathPtr)) { |
| 912 pathPtr = strokedPath; | |
| 909 pathIsMutable = true; | 913 pathIsMutable = true; |
| 910 stroke.setFillStyle(); | 914 stroke.setFillStyle(); |
| 911 } | 915 } |
| 912 } | 916 } |
| 913 | 917 |
| 914 // avoid possibly allocating a new path in transform if we can | 918 // avoid possibly allocating a new path in transform if we can |
| 915 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; | 919 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); |
| 916 | 920 |
| 917 // transform the path into device space | 921 // transform the path into device space |
| 918 pathPtr->transform(fContext->getMatrix(), devPathPtr); | 922 pathPtr->transform(fContext->getMatrix(), devPathPtr); |
| 919 | 923 |
| 920 SkRect maskRect; | 924 SkRect maskRect; |
| 921 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), | 925 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), |
| 922 draw.fClip->getBounds(), | 926 draw.fClip->getBounds(), |
| 923 fContext->getMatrix(), | 927 fContext->getMatrix(), |
| 924 &maskRect)) { | 928 &maskRect)) { |
| 925 SkIRect finalIRect; | 929 SkIRect finalIRect; |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1914 GrTexture* texture, | 1918 GrTexture* texture, |
| 1915 bool needClear) | 1919 bool needClear) |
| 1916 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1920 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| 1917 | 1921 |
| 1918 SkASSERT(texture && texture->asRenderTarget()); | 1922 SkASSERT(texture && texture->asRenderTarget()); |
| 1919 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture | 1923 // This constructor is called from onCreateCompatibleDevice. It has locked t he RT in the texture |
| 1920 // cache. We pass true for the third argument so that it will get unlocked. | 1924 // cache. We pass true for the third argument so that it will get unlocked. |
| 1921 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1925 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
| 1922 fNeedClear = needClear; | 1926 fNeedClear = needClear; |
| 1923 } | 1927 } |
| OLD | NEW |