Chromium Code Reviews| 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" |
| 11 | 11 |
| 12 #include "effects/GrSingleTextureEffect.h" | 12 #include "effects/GrSingleTextureEffect.h" |
| 13 #include "effects/GrConfigConversionEffect.h" | 13 #include "effects/GrConfigConversionEffect.h" |
| 14 | 14 |
| 15 #include "GrAARectRenderer.h" | 15 #include "GrAARectRenderer.h" |
| 16 #include "GrBufferAllocPool.h" | 16 #include "GrBufferAllocPool.h" |
| 17 #include "GrGpu.h" | 17 #include "GrGpu.h" |
| 18 #include "GrDrawTargetCaps.h" | 18 #include "GrDrawTargetCaps.h" |
| 19 #include "GrIndexBuffer.h" | 19 #include "GrIndexBuffer.h" |
| 20 #include "GrInOrderDrawBuffer.h" | 20 #include "GrInOrderDrawBuffer.h" |
| 21 #include "GrOvalRenderer.h" | 21 #include "GrOvalRenderer.h" |
| 22 #include "GrPathRenderer.h" | 22 #include "GrPathRenderer.h" |
| 23 #include "GrPathUtils.h" | 23 #include "GrPathUtils.h" |
| 24 #include "GrResourceCache.h" | 24 #include "GrResourceCache.h" |
| 25 #include "GrSoftwarePathRenderer.h" | 25 #include "GrSoftwarePathRenderer.h" |
| 26 #include "GrStencilBuffer.h" | 26 #include "GrStencilBuffer.h" |
| 27 #include "GrTextStrike.h" | 27 #include "GrTextStrike.h" |
| 28 #include "GrTracing.h" | |
| 28 #include "SkRTConf.h" | 29 #include "SkRTConf.h" |
| 29 #include "SkRRect.h" | 30 #include "SkRRect.h" |
| 30 #include "SkStrokeRec.h" | 31 #include "SkStrokeRec.h" |
| 31 #include "SkTLazy.h" | 32 #include "SkTLazy.h" |
| 32 #include "SkTLS.h" | 33 #include "SkTLS.h" |
| 33 #include "SkTrace.h" | 34 #include "SkTrace.h" |
| 34 | 35 |
| 35 // It can be useful to set this to false to test whether a bug is caused by usin g the | 36 // It can be useful to set this to false to test whether a bug is caused by usin g the |
| 36 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make | 37 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make |
| 37 // debugging simpler. | 38 // debugging simpler. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 fTextureCache = NULL; | 95 fTextureCache = NULL; |
| 95 fFontCache = NULL; | 96 fFontCache = NULL; |
| 96 fDrawBuffer = NULL; | 97 fDrawBuffer = NULL; |
| 97 fDrawBufferVBAllocPool = NULL; | 98 fDrawBufferVBAllocPool = NULL; |
| 98 fDrawBufferIBAllocPool = NULL; | 99 fDrawBufferIBAllocPool = NULL; |
| 99 fFlushToReduceCacheSize = false; | 100 fFlushToReduceCacheSize = false; |
| 100 fAARectRenderer = NULL; | 101 fAARectRenderer = NULL; |
| 101 fOvalRenderer = NULL; | 102 fOvalRenderer = NULL; |
| 102 fViewMatrix.reset(); | 103 fViewMatrix.reset(); |
| 103 fMaxTextureSizeOverride = 1 << 20; | 104 fMaxTextureSizeOverride = 1 << 20; |
| 105 fGpuTracingEnabled = false; | |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 108 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
| 107 SkASSERT(NULL == fGpu); | 109 SkASSERT(NULL == fGpu); |
| 108 | 110 |
| 109 fGpu = GrGpu::Create(backend, backendContext, this); | 111 fGpu = GrGpu::Create(backend, backendContext, this); |
| 110 if (NULL == fGpu) { | 112 if (NULL == fGpu) { |
| 111 return false; | 113 return false; |
| 112 } | 114 } |
| 113 | 115 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 void GrContext::drawRect(const GrPaint& paint, | 769 void GrContext::drawRect(const GrPaint& paint, |
| 768 const SkRect& rect, | 770 const SkRect& rect, |
| 769 const SkStrokeRec* stroke, | 771 const SkStrokeRec* stroke, |
| 770 const SkMatrix* matrix) { | 772 const SkMatrix* matrix) { |
| 771 SK_TRACE_EVENT0("GrContext::drawRect"); | 773 SK_TRACE_EVENT0("GrContext::drawRect"); |
| 772 | 774 |
| 773 AutoRestoreEffects are; | 775 AutoRestoreEffects are; |
| 774 AutoCheckFlush acf(this); | 776 AutoCheckFlush acf(this); |
| 775 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 777 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 776 | 778 |
| 779 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); | |
| 780 | |
| 777 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); | 781 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); |
| 778 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); | 782 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); |
| 779 if (NULL != matrix) { | 783 if (NULL != matrix) { |
| 780 combinedMatrix.preConcat(*matrix); | 784 combinedMatrix.preConcat(*matrix); |
| 781 } | 785 } |
| 782 | 786 |
| 783 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking | 787 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking |
| 784 // cases where the RT is fully inside a stroke. | 788 // cases where the RT is fully inside a stroke. |
| 785 if (width < 0) { | 789 if (width < 0) { |
| 786 SkRect rtRect; | 790 SkRect rtRect; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 void GrContext::drawRectToRect(const GrPaint& paint, | 892 void GrContext::drawRectToRect(const GrPaint& paint, |
| 889 const SkRect& dstRect, | 893 const SkRect& dstRect, |
| 890 const SkRect& localRect, | 894 const SkRect& localRect, |
| 891 const SkMatrix* dstMatrix, | 895 const SkMatrix* dstMatrix, |
| 892 const SkMatrix* localMatrix) { | 896 const SkMatrix* localMatrix) { |
| 893 SK_TRACE_EVENT0("GrContext::drawRectToRect"); | 897 SK_TRACE_EVENT0("GrContext::drawRectToRect"); |
| 894 AutoRestoreEffects are; | 898 AutoRestoreEffects are; |
| 895 AutoCheckFlush acf(this); | 899 AutoCheckFlush acf(this); |
| 896 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 900 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 897 | 901 |
| 902 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); | |
| 903 | |
| 898 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 904 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
| 899 } | 905 } |
| 900 | 906 |
| 901 namespace { | 907 namespace { |
| 902 | 908 |
| 903 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 909 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| 904 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 910 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
| 905 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind ing }, | 911 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind ing }, |
| 906 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding } | 912 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding } |
| 907 }; | 913 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 const uint16_t indices[], | 951 const uint16_t indices[], |
| 946 int indexCount) { | 952 int indexCount) { |
| 947 SK_TRACE_EVENT0("GrContext::drawVertices"); | 953 SK_TRACE_EVENT0("GrContext::drawVertices"); |
| 948 | 954 |
| 949 AutoRestoreEffects are; | 955 AutoRestoreEffects are; |
| 950 AutoCheckFlush acf(this); | 956 AutoCheckFlush acf(this); |
| 951 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e | 957 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e |
| 952 | 958 |
| 953 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 959 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 954 | 960 |
| 961 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); | |
|
bsalomon
2014/03/20 16:32:53
Make sure you've groked the discussion on the othe
| |
| 962 | |
| 955 GrDrawState* drawState = target->drawState(); | 963 GrDrawState* drawState = target->drawState(); |
| 956 | 964 |
| 957 int colorOffset = -1, texOffset = -1; | 965 int colorOffset = -1, texOffset = -1; |
| 958 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); | 966 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); |
| 959 | 967 |
| 960 size_t vertexSize = drawState->getVertexSize(); | 968 size_t vertexSize = drawState->getVertexSize(); |
| 961 if (sizeof(GrPoint) != vertexSize) { | 969 if (sizeof(GrPoint) != vertexSize) { |
| 962 if (!geo.set(target, vertexCount, 0)) { | 970 if (!geo.set(target, vertexCount, 0)) { |
| 963 GrPrintf("Failed to get space for vertices!\n"); | 971 GrPrintf("Failed to get space for vertices!\n"); |
| 964 return; | 972 return; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 const SkRRect& rect, | 1006 const SkRRect& rect, |
| 999 const SkStrokeRec& stroke) { | 1007 const SkStrokeRec& stroke) { |
| 1000 if (rect.isEmpty()) { | 1008 if (rect.isEmpty()) { |
| 1001 return; | 1009 return; |
| 1002 } | 1010 } |
| 1003 | 1011 |
| 1004 AutoRestoreEffects are; | 1012 AutoRestoreEffects are; |
| 1005 AutoCheckFlush acf(this); | 1013 AutoCheckFlush acf(this); |
| 1006 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 1014 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 1007 | 1015 |
| 1016 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); | |
| 1017 | |
| 1008 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect, stroke)) { | 1018 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect, stroke)) { |
| 1009 SkPath path; | 1019 SkPath path; |
| 1010 path.addRRect(rect); | 1020 path.addRRect(rect); |
| 1011 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1021 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
| 1012 } | 1022 } |
| 1013 } | 1023 } |
| 1014 | 1024 |
| 1015 /////////////////////////////////////////////////////////////////////////////// | 1025 /////////////////////////////////////////////////////////////////////////////// |
| 1016 | 1026 |
| 1017 void GrContext::drawOval(const GrPaint& paint, | 1027 void GrContext::drawOval(const GrPaint& paint, |
| 1018 const SkRect& oval, | 1028 const SkRect& oval, |
| 1019 const SkStrokeRec& stroke) { | 1029 const SkStrokeRec& stroke) { |
| 1020 if (oval.isEmpty()) { | 1030 if (oval.isEmpty()) { |
| 1021 return; | 1031 return; |
| 1022 } | 1032 } |
| 1023 | 1033 |
| 1024 AutoRestoreEffects are; | 1034 AutoRestoreEffects are; |
| 1025 AutoCheckFlush acf(this); | 1035 AutoCheckFlush acf(this); |
| 1026 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 1036 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 1027 | 1037 |
| 1038 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); | |
| 1039 | |
| 1028 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke )) { | 1040 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke )) { |
| 1029 SkPath path; | 1041 SkPath path; |
| 1030 path.addOval(oval); | 1042 path.addOval(oval); |
| 1031 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1043 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
| 1032 } | 1044 } |
| 1033 } | 1045 } |
| 1034 | 1046 |
| 1035 // Can 'path' be drawn as a pair of filled nested rectangles? | 1047 // Can 'path' be drawn as a pair of filled nested rectangles? |
| 1036 static bool is_nested_rects(GrDrawTarget* target, | 1048 static bool is_nested_rects(GrDrawTarget* target, |
| 1037 const SkPath& path, | 1049 const SkPath& path, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. | 1111 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. |
| 1100 // Scratch textures can be recycled after they are returned to the texture | 1112 // Scratch textures can be recycled after they are returned to the texture |
| 1101 // cache. This presents a potential hazard for buffered drawing. However, | 1113 // cache. This presents a potential hazard for buffered drawing. However, |
| 1102 // the writePixels that uploads to the scratch will perform a flush so we're | 1114 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1103 // OK. | 1115 // OK. |
| 1104 AutoRestoreEffects are; | 1116 AutoRestoreEffects are; |
| 1105 AutoCheckFlush acf(this); | 1117 AutoCheckFlush acf(this); |
| 1106 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); | 1118 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); |
| 1107 GrDrawState* drawState = target->drawState(); | 1119 GrDrawState* drawState = target->drawState(); |
| 1108 | 1120 |
| 1121 GR_CREATE_TRACE_MARKER("GrContext::drawPath", target); | |
| 1122 | |
| 1109 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled(); | 1123 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled(); |
| 1110 | 1124 |
| 1111 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { | 1125 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { |
| 1112 // Concave AA paths are expensive - try to avoid them for special cases | 1126 // Concave AA paths are expensive - try to avoid them for special cases |
| 1113 bool useVertexCoverage; | 1127 bool useVertexCoverage; |
| 1114 SkRect rects[2]; | 1128 SkRect rects[2]; |
| 1115 | 1129 |
| 1116 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { | 1130 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { |
| 1117 SkMatrix origViewMatrix = drawState->getViewMatrix(); | 1131 SkMatrix origViewMatrix = drawState->getViewMatrix(); |
| 1118 GrDrawState::AutoViewMatrixRestore avmr; | 1132 GrDrawState::AutoViewMatrixRestore avmr; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1134 if (!isOval || path.isInverseFillType() | 1148 if (!isOval || path.isInverseFillType() |
| 1135 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect, stroke)) { | 1149 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect, stroke)) { |
| 1136 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1150 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
| 1137 } | 1151 } |
| 1138 } | 1152 } |
| 1139 | 1153 |
| 1140 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, | 1154 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, |
| 1141 const SkStrokeRec& origStroke) { | 1155 const SkStrokeRec& origStroke) { |
| 1142 SkASSERT(!path.isEmpty()); | 1156 SkASSERT(!path.isEmpty()); |
| 1143 | 1157 |
| 1158 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); | |
| 1159 | |
| 1160 | |
| 1144 // An Assumption here is that path renderer would use some form of tweaking | 1161 // An Assumption here is that path renderer would use some form of tweaking |
| 1145 // the src color (either the input alpha or in the frag shader) to implement | 1162 // the src color (either the input alpha or in the frag shader) to implement |
| 1146 // aa. If we have some future driver-mojo path AA that can do the right | 1163 // aa. If we have some future driver-mojo path AA that can do the right |
| 1147 // thing WRT to the blend then we'll need some query on the PR. | 1164 // thing WRT to the blend then we'll need some query on the PR. |
| 1148 bool useCoverageAA = useAA && | 1165 bool useCoverageAA = useAA && |
| 1149 !target->getDrawState().getRenderTarget()->isMultisampled() && | 1166 !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 1150 !target->shouldDisableCoverageAAForBlend(); | 1167 !target->shouldDisableCoverageAAForBlend(); |
| 1151 | 1168 |
| 1152 | 1169 |
| 1153 GrPathRendererChain::DrawType type = | 1170 GrPathRendererChain::DrawType type = |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1810 } | 1827 } |
| 1811 return path; | 1828 return path; |
| 1812 } | 1829 } |
| 1813 | 1830 |
| 1814 /////////////////////////////////////////////////////////////////////////////// | 1831 /////////////////////////////////////////////////////////////////////////////// |
| 1815 #if GR_CACHE_STATS | 1832 #if GR_CACHE_STATS |
| 1816 void GrContext::printCacheStats() const { | 1833 void GrContext::printCacheStats() const { |
| 1817 fTextureCache->printStats(); | 1834 fTextureCache->printStats(); |
| 1818 } | 1835 } |
| 1819 #endif | 1836 #endif |
| OLD | NEW |