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 "SkTraceEvent.h" | 34 #include "SkTraceEvent.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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 765 } |
764 | 766 |
765 void GrContext::drawRect(const GrPaint& paint, | 767 void GrContext::drawRect(const GrPaint& paint, |
766 const SkRect& rect, | 768 const SkRect& rect, |
767 const SkStrokeRec* stroke, | 769 const SkStrokeRec* stroke, |
768 const SkMatrix* matrix) { | 770 const SkMatrix* matrix) { |
769 AutoRestoreEffects are; | 771 AutoRestoreEffects are; |
770 AutoCheckFlush acf(this); | 772 AutoCheckFlush acf(this); |
771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 773 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
772 | 774 |
| 775 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
| 776 |
773 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); | 777 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); |
774 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); | 778 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); |
775 if (NULL != matrix) { | 779 if (NULL != matrix) { |
776 combinedMatrix.preConcat(*matrix); | 780 combinedMatrix.preConcat(*matrix); |
777 } | 781 } |
778 | 782 |
779 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 783 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
780 // cases where the RT is fully inside a stroke. | 784 // cases where the RT is fully inside a stroke. |
781 if (width < 0) { | 785 if (width < 0) { |
782 SkRect rtRect; | 786 SkRect rtRect; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 | 887 |
884 void GrContext::drawRectToRect(const GrPaint& paint, | 888 void GrContext::drawRectToRect(const GrPaint& paint, |
885 const SkRect& dstRect, | 889 const SkRect& dstRect, |
886 const SkRect& localRect, | 890 const SkRect& localRect, |
887 const SkMatrix* dstMatrix, | 891 const SkMatrix* dstMatrix, |
888 const SkMatrix* localMatrix) { | 892 const SkMatrix* localMatrix) { |
889 AutoRestoreEffects are; | 893 AutoRestoreEffects are; |
890 AutoCheckFlush acf(this); | 894 AutoCheckFlush acf(this); |
891 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 895 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
892 | 896 |
| 897 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 898 |
893 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); | 899 target->drawRect(dstRect, dstMatrix, &localRect, localMatrix); |
894 } | 900 } |
895 | 901 |
896 namespace { | 902 namespace { |
897 | 903 |
898 extern const GrVertexAttrib gPosUVColorAttribs[] = { | 904 extern const GrVertexAttrib gPosUVColorAttribs[] = { |
899 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, | 905 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
900 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind
ing }, | 906 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBind
ing }, |
901 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding
} | 907 {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding
} |
902 }; | 908 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 const GrPoint texCoords[], | 944 const GrPoint texCoords[], |
939 const GrColor colors[], | 945 const GrColor colors[], |
940 const uint16_t indices[], | 946 const uint16_t indices[], |
941 int indexCount) { | 947 int indexCount) { |
942 AutoRestoreEffects are; | 948 AutoRestoreEffects are; |
943 AutoCheckFlush acf(this); | 949 AutoCheckFlush acf(this); |
944 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e | 950 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop
e |
945 | 951 |
946 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 952 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
947 | 953 |
| 954 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 955 |
948 GrDrawState* drawState = target->drawState(); | 956 GrDrawState* drawState = target->drawState(); |
949 | 957 |
950 int colorOffset = -1, texOffset = -1; | 958 int colorOffset = -1, texOffset = -1; |
951 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); | 959 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset
); |
952 | 960 |
953 size_t vertexSize = drawState->getVertexSize(); | 961 size_t vertexSize = drawState->getVertexSize(); |
954 if (sizeof(GrPoint) != vertexSize) { | 962 if (sizeof(GrPoint) != vertexSize) { |
955 if (!geo.set(target, vertexCount, 0)) { | 963 if (!geo.set(target, vertexCount, 0)) { |
956 GrPrintf("Failed to get space for vertices!\n"); | 964 GrPrintf("Failed to get space for vertices!\n"); |
957 return; | 965 return; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 const SkRRect& rect, | 999 const SkRRect& rect, |
992 const SkStrokeRec& stroke) { | 1000 const SkStrokeRec& stroke) { |
993 if (rect.isEmpty()) { | 1001 if (rect.isEmpty()) { |
994 return; | 1002 return; |
995 } | 1003 } |
996 | 1004 |
997 AutoRestoreEffects are; | 1005 AutoRestoreEffects are; |
998 AutoCheckFlush acf(this); | 1006 AutoCheckFlush acf(this); |
999 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 1007 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
1000 | 1008 |
| 1009 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
| 1010 |
1001 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect,
stroke)) { | 1011 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect,
stroke)) { |
1002 SkPath path; | 1012 SkPath path; |
1003 path.addRRect(rect); | 1013 path.addRRect(rect); |
1004 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1014 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
1005 } | 1015 } |
1006 } | 1016 } |
1007 | 1017 |
1008 /////////////////////////////////////////////////////////////////////////////// | 1018 /////////////////////////////////////////////////////////////////////////////// |
1009 | 1019 |
1010 void GrContext::drawOval(const GrPaint& paint, | 1020 void GrContext::drawOval(const GrPaint& paint, |
1011 const SkRect& oval, | 1021 const SkRect& oval, |
1012 const SkStrokeRec& stroke) { | 1022 const SkStrokeRec& stroke) { |
1013 if (oval.isEmpty()) { | 1023 if (oval.isEmpty()) { |
1014 return; | 1024 return; |
1015 } | 1025 } |
1016 | 1026 |
1017 AutoRestoreEffects are; | 1027 AutoRestoreEffects are; |
1018 AutoCheckFlush acf(this); | 1028 AutoCheckFlush acf(this); |
1019 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 1029 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
1020 | 1030 |
| 1031 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
| 1032 |
1021 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke
)) { | 1033 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke
)) { |
1022 SkPath path; | 1034 SkPath path; |
1023 path.addOval(oval); | 1035 path.addOval(oval); |
1024 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1036 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
1025 } | 1037 } |
1026 } | 1038 } |
1027 | 1039 |
1028 // Can 'path' be drawn as a pair of filled nested rectangles? | 1040 // Can 'path' be drawn as a pair of filled nested rectangles? |
1029 static bool is_nested_rects(GrDrawTarget* target, | 1041 static bool is_nested_rects(GrDrawTarget* target, |
1030 const SkPath& path, | 1042 const SkPath& path, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 1104 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
1093 // Scratch textures can be recycled after they are returned to the texture | 1105 // Scratch textures can be recycled after they are returned to the texture |
1094 // cache. This presents a potential hazard for buffered drawing. However, | 1106 // cache. This presents a potential hazard for buffered drawing. However, |
1095 // the writePixels that uploads to the scratch will perform a flush so we're | 1107 // the writePixels that uploads to the scratch will perform a flush so we're |
1096 // OK. | 1108 // OK. |
1097 AutoRestoreEffects are; | 1109 AutoRestoreEffects are; |
1098 AutoCheckFlush acf(this); | 1110 AutoCheckFlush acf(this); |
1099 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); | 1111 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf
); |
1100 GrDrawState* drawState = target->drawState(); | 1112 GrDrawState* drawState = target->drawState(); |
1101 | 1113 |
| 1114 GR_CREATE_TRACE_MARKER("GrContext::drawPath", target); |
| 1115 |
1102 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i
sMultisampled(); | 1116 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i
sMultisampled(); |
1103 | 1117 |
1104 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { | 1118 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { |
1105 // Concave AA paths are expensive - try to avoid them for special cases | 1119 // Concave AA paths are expensive - try to avoid them for special cases |
1106 bool useVertexCoverage; | 1120 bool useVertexCoverage; |
1107 SkRect rects[2]; | 1121 SkRect rects[2]; |
1108 | 1122 |
1109 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { | 1123 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { |
1110 SkMatrix origViewMatrix = drawState->getViewMatrix(); | 1124 SkMatrix origViewMatrix = drawState->getViewMatrix(); |
1111 GrDrawState::AutoViewMatrixRestore avmr; | 1125 GrDrawState::AutoViewMatrixRestore avmr; |
(...skipping 15 matching lines...) Expand all Loading... |
1127 if (!isOval || path.isInverseFillType() | 1141 if (!isOval || path.isInverseFillType() |
1128 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect,
stroke)) { | 1142 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect,
stroke)) { |
1129 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); | 1143 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); |
1130 } | 1144 } |
1131 } | 1145 } |
1132 | 1146 |
1133 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
path, | 1147 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath&
path, |
1134 const SkStrokeRec& origStroke) { | 1148 const SkStrokeRec& origStroke) { |
1135 SkASSERT(!path.isEmpty()); | 1149 SkASSERT(!path.isEmpty()); |
1136 | 1150 |
| 1151 GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
| 1152 |
| 1153 |
1137 // An Assumption here is that path renderer would use some form of tweaking | 1154 // An Assumption here is that path renderer would use some form of tweaking |
1138 // the src color (either the input alpha or in the frag shader) to implement | 1155 // the src color (either the input alpha or in the frag shader) to implement |
1139 // aa. If we have some future driver-mojo path AA that can do the right | 1156 // aa. If we have some future driver-mojo path AA that can do the right |
1140 // thing WRT to the blend then we'll need some query on the PR. | 1157 // thing WRT to the blend then we'll need some query on the PR. |
1141 bool useCoverageAA = useAA && | 1158 bool useCoverageAA = useAA && |
1142 !target->getDrawState().getRenderTarget()->isMultisampled() && | 1159 !target->getDrawState().getRenderTarget()->isMultisampled() && |
1143 !target->shouldDisableCoverageAAForBlend(); | 1160 !target->shouldDisableCoverageAAForBlend(); |
1144 | 1161 |
1145 | 1162 |
1146 GrPathRendererChain::DrawType type = | 1163 GrPathRendererChain::DrawType type = |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 } | 1816 } |
1800 return path; | 1817 return path; |
1801 } | 1818 } |
1802 | 1819 |
1803 /////////////////////////////////////////////////////////////////////////////// | 1820 /////////////////////////////////////////////////////////////////////////////// |
1804 #if GR_CACHE_STATS | 1821 #if GR_CACHE_STATS |
1805 void GrContext::printCacheStats() const { | 1822 void GrContext::printCacheStats() const { |
1806 fTextureCache->printStats(); | 1823 fTextureCache->printStats(); |
1807 } | 1824 } |
1808 #endif | 1825 #endif |
OLD | NEW |