| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 | 973 |
| 974 /////////////////////////////////////////////////////////////////////////////// | 974 /////////////////////////////////////////////////////////////////////////////// |
| 975 | 975 |
| 976 void GrContext::drawRRect(const GrPaint& paint, | 976 void GrContext::drawRRect(const GrPaint& paint, |
| 977 const SkRRect& rect, | 977 const SkRRect& rect, |
| 978 const SkStrokeRec& stroke) { | 978 const SkStrokeRec& stroke) { |
| 979 | 979 |
| 980 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 980 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 981 GrDrawState::AutoStageDisable atr(fDrawState); | 981 GrDrawState::AutoStageDisable atr(fDrawState); |
| 982 | 982 |
| 983 if (!fOvalRenderer->drawSimpleRRect(target, this, paint, rect, stroke)) { | 983 bool prAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled(
); |
| 984 |
| 985 if (!fOvalRenderer->drawSimpleRRect(target, this, prAA, rect, stroke)) { |
| 984 SkPath path; | 986 SkPath path; |
| 985 path.addRRect(rect); | 987 path.addRRect(rect); |
| 986 this->internalDrawPath(target, paint, path, stroke); | 988 this->internalDrawPath(target, prAA, path, stroke); |
| 987 } | 989 } |
| 988 } | 990 } |
| 989 | 991 |
| 990 /////////////////////////////////////////////////////////////////////////////// | 992 /////////////////////////////////////////////////////////////////////////////// |
| 991 | 993 |
| 992 void GrContext::drawOval(const GrPaint& paint, | 994 void GrContext::drawOval(const GrPaint& paint, |
| 993 const GrRect& oval, | 995 const GrRect& oval, |
| 994 const SkStrokeRec& stroke) { | 996 const SkStrokeRec& stroke) { |
| 995 | 997 |
| 996 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 998 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 997 GrDrawState::AutoStageDisable atr(fDrawState); | 999 GrDrawState::AutoStageDisable atr(fDrawState); |
| 998 | 1000 |
| 999 if (!fOvalRenderer->drawOval(target, this, paint, oval, stroke)) { | 1001 bool useAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled
(); |
| 1002 |
| 1003 if (!fOvalRenderer->drawOval(target, this, useAA, oval, stroke)) { |
| 1000 SkPath path; | 1004 SkPath path; |
| 1001 path.addOval(oval); | 1005 path.addOval(oval); |
| 1002 this->internalDrawPath(target, paint, path, stroke); | 1006 this->internalDrawPath(target, useAA, path, stroke); |
| 1003 } | 1007 } |
| 1004 } | 1008 } |
| 1005 | 1009 |
| 1006 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrok
eRec& stroke) { | 1010 void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrok
eRec& stroke) { |
| 1007 | 1011 |
| 1008 if (path.isEmpty()) { | 1012 if (path.isEmpty()) { |
| 1009 if (path.isInverseFillType()) { | 1013 if (path.isInverseFillType()) { |
| 1010 this->drawPaint(paint); | 1014 this->drawPaint(paint); |
| 1011 } | 1015 } |
| 1012 return; | 1016 return; |
| 1013 } | 1017 } |
| 1014 | 1018 |
| 1015 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 1019 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 1016 // Scratch textures can be recycled after they are returned to the texture | 1020 // Scratch textures can be recycled after they are returned to the texture |
| 1017 // cache. This presents a potential hazard for buffered drawing. However, | 1021 // cache. This presents a potential hazard for buffered drawing. However, |
| 1018 // the writePixels that uploads to the scratch will perform a flush so we're | 1022 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1019 // OK. | 1023 // OK. |
| 1020 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); | 1024 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW); |
| 1021 GrDrawState::AutoStageDisable atr(fDrawState); | 1025 GrDrawState::AutoStageDisable atr(fDrawState); |
| 1022 | 1026 |
| 1023 SkRect ovalRect; | 1027 SkRect ovalRect; |
| 1024 bool isOval = path.isOval(&ovalRect); | 1028 bool isOval = path.isOval(&ovalRect); |
| 1029 bool useAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled
(); |
| 1025 | 1030 |
| 1026 if (!isOval || path.isInverseFillType() | 1031 if (!isOval || path.isInverseFillType() |
| 1027 || !fOvalRenderer->drawOval(target, this, paint, ovalRect, stroke)) { | 1032 || !fOvalRenderer->drawOval(target, this, useAA, ovalRect, stroke)) { |
| 1028 this->internalDrawPath(target, paint, path, stroke); | 1033 this->internalDrawPath(target, useAA, path, stroke); |
| 1029 } | 1034 } |
| 1030 } | 1035 } |
| 1031 | 1036 |
| 1032 void GrContext::internalDrawPath(GrDrawTarget* target, const GrPaint& paint, con
st SkPath& path, | 1037 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
path, |
| 1033 const SkStrokeRec& stroke) { | 1038 const SkStrokeRec& stroke) { |
| 1034 | 1039 |
| 1035 bool prAA = paint.isAntiAlias() && !this->getRenderTarget()->isMultisampled(
); | |
| 1036 | |
| 1037 // An Assumption here is that path renderer would use some form of tweaking | 1040 // An Assumption here is that path renderer would use some form of tweaking |
| 1038 // the src color (either the input alpha or in the frag shader) to implement | 1041 // the src color (either the input alpha or in the frag shader) to implement |
| 1039 // aa. If we have some future driver-mojo path AA that can do the right | 1042 // aa. If we have some future driver-mojo path AA that can do the right |
| 1040 // thing WRT to the blend then we'll need some query on the PR. | 1043 // thing WRT to the blend then we'll need some query on the PR. |
| 1041 if (disable_coverage_aa_for_blend(target)) { | 1044 if (disable_coverage_aa_for_blend(target)) { |
| 1042 #if GR_DEBUG | 1045 #if GR_DEBUG |
| 1043 //GrPrintf("Turning off AA to correctly apply blend.\n"); | 1046 //GrPrintf("Turning off AA to correctly apply blend.\n"); |
| 1044 #endif | 1047 #endif |
| 1045 prAA = false; | 1048 useAA = false; |
| 1046 } | 1049 } |
| 1047 | 1050 |
| 1048 GrPathRendererChain::DrawType type = prAA ? GrPathRendererChain::kColorAntiA
lias_DrawType : | 1051 GrPathRendererChain::DrawType type = useAA ? GrPathRendererChain::kColorAnti
Alias_DrawType : |
| 1049 GrPathRendererChain::kColor_Draw
Type; | 1052 GrPathRendererChain::kColor_Dra
wType; |
| 1050 | 1053 |
| 1051 const SkPath* pathPtr = &path; | 1054 const SkPath* pathPtr = &path; |
| 1052 SkPath tmpPath; | 1055 SkPath tmpPath; |
| 1053 SkStrokeRec strokeRec(stroke); | 1056 SkStrokeRec strokeRec(stroke); |
| 1054 | 1057 |
| 1055 // Try a 1st time without stroking the path and without allowing the SW rend
erer | 1058 // Try a 1st time without stroking the path and without allowing the SW rend
erer |
| 1056 GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, fals
e, type); | 1059 GrPathRenderer* pr = this->getPathRenderer(*pathPtr, strokeRec, target, fals
e, type); |
| 1057 | 1060 |
| 1058 if (NULL == pr) { | 1061 if (NULL == pr) { |
| 1059 if (!strokeRec.isHairlineStyle()) { | 1062 if (!strokeRec.isHairlineStyle()) { |
| 1060 // It didn't work the 1st time, so try again with the stroked path | 1063 // It didn't work the 1st time, so try again with the stroked path |
| 1061 if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { | 1064 if (strokeRec.applyToPath(&tmpPath, *pathPtr)) { |
| 1062 pathPtr = &tmpPath; | 1065 pathPtr = &tmpPath; |
| 1063 strokeRec.setFillStyle(); | 1066 strokeRec.setFillStyle(); |
| 1064 } | 1067 } |
| 1065 } | 1068 } |
| 1066 // This time, allow SW renderer | 1069 // This time, allow SW renderer |
| 1067 pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type); | 1070 pr = this->getPathRenderer(*pathPtr, strokeRec, target, true, type); |
| 1068 } | 1071 } |
| 1069 | 1072 |
| 1070 if (NULL == pr) { | 1073 if (NULL == pr) { |
| 1071 #if GR_DEBUG | 1074 #if GR_DEBUG |
| 1072 GrPrintf("Unable to find path renderer compatible with path.\n"); | 1075 GrPrintf("Unable to find path renderer compatible with path.\n"); |
| 1073 #endif | 1076 #endif |
| 1074 return; | 1077 return; |
| 1075 } | 1078 } |
| 1076 | 1079 |
| 1077 pr->drawPath(*pathPtr, strokeRec, target, prAA); | 1080 pr->drawPath(*pathPtr, strokeRec, target, useAA); |
| 1078 } | 1081 } |
| 1079 | 1082 |
| 1080 //////////////////////////////////////////////////////////////////////////////// | 1083 //////////////////////////////////////////////////////////////////////////////// |
| 1081 | 1084 |
| 1082 void GrContext::flush(int flagsBitfield) { | 1085 void GrContext::flush(int flagsBitfield) { |
| 1083 if (kDiscard_FlushBit & flagsBitfield) { | 1086 if (kDiscard_FlushBit & flagsBitfield) { |
| 1084 fDrawBuffer->reset(); | 1087 fDrawBuffer->reset(); |
| 1085 } else { | 1088 } else { |
| 1086 this->flushDrawBuffer(); | 1089 this->flushDrawBuffer(); |
| 1087 } | 1090 } |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 return srcTexture; | 1807 return srcTexture; |
| 1805 } | 1808 } |
| 1806 } | 1809 } |
| 1807 | 1810 |
| 1808 /////////////////////////////////////////////////////////////////////////////// | 1811 /////////////////////////////////////////////////////////////////////////////// |
| 1809 #if GR_CACHE_STATS | 1812 #if GR_CACHE_STATS |
| 1810 void GrContext::printCacheStats() const { | 1813 void GrContext::printCacheStats() const { |
| 1811 fTextureCache->printStats(); | 1814 fTextureCache->printStats(); |
| 1812 } | 1815 } |
| 1813 #endif | 1816 #endif |
| OLD | NEW |