Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 184443003: Add Gpu Tracing to Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Partial version Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 fTextureCache = NULL; 94 fTextureCache = NULL;
95 fFontCache = NULL; 95 fFontCache = NULL;
96 fDrawBuffer = NULL; 96 fDrawBuffer = NULL;
97 fDrawBufferVBAllocPool = NULL; 97 fDrawBufferVBAllocPool = NULL;
98 fDrawBufferIBAllocPool = NULL; 98 fDrawBufferIBAllocPool = NULL;
99 fFlushToReduceCacheSize = false; 99 fFlushToReduceCacheSize = false;
100 fAARectRenderer = NULL; 100 fAARectRenderer = NULL;
101 fOvalRenderer = NULL; 101 fOvalRenderer = NULL;
102 fViewMatrix.reset(); 102 fViewMatrix.reset();
103 fMaxTextureSizeOverride = 1 << 20; 103 fMaxTextureSizeOverride = 1 << 20;
104 fGpuTracingEnabled = true;
bsalomon 2014/03/17 17:50:38 Let's start with false.
egdaniel 2014/03/17 19:49:12 That's the plan. Just set that way right now for e
104 } 105 }
105 106
106 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 107 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
107 SkASSERT(NULL == fGpu); 108 SkASSERT(NULL == fGpu);
108 109
109 fGpu = GrGpu::Create(backend, backendContext, this); 110 fGpu = GrGpu::Create(backend, backendContext, this);
110 if (NULL == fGpu) { 111 if (NULL == fGpu) {
111 return false; 112 return false;
112 } 113 }
113 114
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 void GrContext::drawRect(const GrPaint& paint, 764 void GrContext::drawRect(const GrPaint& paint,
764 const SkRect& rect, 765 const SkRect& rect,
765 const SkStrokeRec* stroke, 766 const SkStrokeRec* stroke,
766 const SkMatrix* matrix) { 767 const SkMatrix* matrix) {
767 SK_TRACE_EVENT0("GrContext::drawRect"); 768 SK_TRACE_EVENT0("GrContext::drawRect");
768 769
769 AutoRestoreEffects are; 770 AutoRestoreEffects are;
770 AutoCheckFlush acf(this); 771 AutoCheckFlush acf(this);
771 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 772 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf );
772 773
774 GR_CREATE_GPU_TRACE_MARKER("Test_marker_DRAW_RECT", target);
775
773 SkScalar width = stroke == NULL ? -1 : stroke->getWidth(); 776 SkScalar width = stroke == NULL ? -1 : stroke->getWidth();
774 SkMatrix combinedMatrix = target->drawState()->getViewMatrix(); 777 SkMatrix combinedMatrix = target->drawState()->getViewMatrix();
775 if (NULL != matrix) { 778 if (NULL != matrix) {
776 combinedMatrix.preConcat(*matrix); 779 combinedMatrix.preConcat(*matrix);
777 } 780 }
778 781
779 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking 782 // 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. 783 // cases where the RT is fully inside a stroke.
781 if (width < 0) { 784 if (width < 0) {
782 SkRect rtRect; 785 SkRect rtRect;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 const uint16_t indices[], 944 const uint16_t indices[],
942 int indexCount) { 945 int indexCount) {
943 SK_TRACE_EVENT0("GrContext::drawVertices"); 946 SK_TRACE_EVENT0("GrContext::drawVertices");
944 947
945 AutoRestoreEffects are; 948 AutoRestoreEffects are;
946 AutoCheckFlush acf(this); 949 AutoCheckFlush acf(this);
947 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 950 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
948 951
949 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 952 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf );
950 953
954 GR_CREATE_GPU_TRACE_MARKER("Test_marker_DRAW_VERTICES", target);
955
951 GrDrawState* drawState = target->drawState(); 956 GrDrawState* drawState = target->drawState();
952 957
953 int colorOffset = -1, texOffset = -1; 958 int colorOffset = -1, texOffset = -1;
954 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); 959 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset );
955 960
956 size_t vertexSize = drawState->getVertexSize(); 961 size_t vertexSize = drawState->getVertexSize();
957 if (sizeof(GrPoint) != vertexSize) { 962 if (sizeof(GrPoint) != vertexSize) {
958 if (!geo.set(target, vertexCount, 0)) { 963 if (!geo.set(target, vertexCount, 0)) {
959 GrPrintf("Failed to get space for vertices!\n"); 964 GrPrintf("Failed to get space for vertices!\n");
960 return; 965 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 const SkRRect& rect, 999 const SkRRect& rect,
995 const SkStrokeRec& stroke) { 1000 const SkStrokeRec& stroke) {
996 if (rect.isEmpty()) { 1001 if (rect.isEmpty()) {
997 return; 1002 return;
998 } 1003 }
999 1004
1000 AutoRestoreEffects are; 1005 AutoRestoreEffects are;
1001 AutoCheckFlush acf(this); 1006 AutoCheckFlush acf(this);
1002 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 1007 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf );
1003 1008
1009 GR_CREATE_GPU_TRACE_MARKER("Test_marker_DRAW_ROUND_REC", target);
bsalomon 2014/03/17 17:50:38 .._RECT (T)
1010
1004 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect, stroke)) { 1011 if (!fOvalRenderer->drawSimpleRRect(target, this, paint.isAntiAlias(), rect, stroke)) {
1005 SkPath path; 1012 SkPath path;
1006 path.addRRect(rect); 1013 path.addRRect(rect);
1007 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); 1014 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke);
1008 } 1015 }
1009 } 1016 }
1010 1017
1011 /////////////////////////////////////////////////////////////////////////////// 1018 ///////////////////////////////////////////////////////////////////////////////
1012 1019
1013 void GrContext::drawOval(const GrPaint& paint, 1020 void GrContext::drawOval(const GrPaint& paint,
1014 const SkRect& oval, 1021 const SkRect& oval,
1015 const SkStrokeRec& stroke) { 1022 const SkStrokeRec& stroke) {
1016 if (oval.isEmpty()) { 1023 if (oval.isEmpty()) {
1017 return; 1024 return;
1018 } 1025 }
1019 1026
1020 AutoRestoreEffects are; 1027 AutoRestoreEffects are;
1021 AutoCheckFlush acf(this); 1028 AutoCheckFlush acf(this);
1022 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 1029 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf );
1023 1030
1031 GR_CREATE_GPU_TRACE_MARKER("Test_marker_DRAW_OVAL", target);
1032
1024 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke )) { 1033 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke )) {
1025 SkPath path; 1034 SkPath path;
1026 path.addOval(oval); 1035 path.addOval(oval);
1027 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); 1036 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke);
1028 } 1037 }
1029 } 1038 }
1030 1039
1031 // Can 'path' be drawn as a pair of filled nested rectangles? 1040 // Can 'path' be drawn as a pair of filled nested rectangles?
1032 static bool is_nested_rects(GrDrawTarget* target, 1041 static bool is_nested_rects(GrDrawTarget* target,
1033 const SkPath& path, 1042 const SkPath& path,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 this->drawPaint(paint); 1099 this->drawPaint(paint);
1091 } 1100 }
1092 return; 1101 return;
1093 } 1102 }
1094 1103
1095 // 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.
1096 // 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
1097 // cache. This presents a potential hazard for buffered drawing. However, 1106 // cache. This presents a potential hazard for buffered drawing. However,
1098 // 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
1099 // OK. 1108 // OK.
1109
1100 AutoRestoreEffects are; 1110 AutoRestoreEffects are;
1101 AutoCheckFlush acf(this); 1111 AutoCheckFlush acf(this);
1102 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 1112 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf );
1103 GrDrawState* drawState = target->drawState(); 1113 GrDrawState* drawState = target->drawState();
1104 1114
1115 GR_CREATE_GPU_TRACE_MARKER("Test_marker_DRAW_PATH", target);
1116
1105 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled(); 1117 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled();
1106 1118
1107 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) { 1119 if (useCoverageAA && stroke.getWidth() < 0 && !path.isConvex()) {
1108 // Concave AA paths are expensive - try to avoid them for special cases 1120 // Concave AA paths are expensive - try to avoid them for special cases
1109 bool useVertexCoverage; 1121 bool useVertexCoverage;
1110 SkRect rects[2]; 1122 SkRect rects[2];
1111 1123
1112 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) { 1124 if (is_nested_rects(target, path, stroke, rects, &useVertexCoverage)) {
1113 SkMatrix origViewMatrix = drawState->getViewMatrix(); 1125 SkMatrix origViewMatrix = drawState->getViewMatrix();
1114 GrDrawState::AutoViewMatrixRestore avmr; 1126 GrDrawState::AutoViewMatrixRestore avmr;
(...skipping 15 matching lines...) Expand all
1130 if (!isOval || path.isInverseFillType() 1142 if (!isOval || path.isInverseFillType()
1131 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect, stroke)) { 1143 || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect, stroke)) {
1132 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke); 1144 this->internalDrawPath(target, paint.isAntiAlias(), path, stroke);
1133 } 1145 }
1134 } 1146 }
1135 1147
1136 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, 1148 void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
1137 const SkStrokeRec& origStroke) { 1149 const SkStrokeRec& origStroke) {
1138 SkASSERT(!path.isEmpty()); 1150 SkASSERT(!path.isEmpty());
1139 1151
1152 GR_CREATE_GPU_TRACE_MARKER("Test_marker_INTERNAL_DRAW_PATH", target);
1153
1154
1140 // An Assumption here is that path renderer would use some form of tweaking 1155 // An Assumption here is that path renderer would use some form of tweaking
1141 // the src color (either the input alpha or in the frag shader) to implement 1156 // the src color (either the input alpha or in the frag shader) to implement
1142 // aa. If we have some future driver-mojo path AA that can do the right 1157 // aa. If we have some future driver-mojo path AA that can do the right
1143 // thing WRT to the blend then we'll need some query on the PR. 1158 // thing WRT to the blend then we'll need some query on the PR.
1144 bool useCoverageAA = useAA && 1159 bool useCoverageAA = useAA &&
1145 !target->getDrawState().getRenderTarget()->isMultisampled() && 1160 !target->getDrawState().getRenderTarget()->isMultisampled() &&
1146 !target->shouldDisableCoverageAAForBlend(); 1161 !target->shouldDisableCoverageAAForBlend();
1147 1162
1148 1163
1149 GrPathRendererChain::DrawType type = 1164 GrPathRendererChain::DrawType type =
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 } 1239 }
1225 1240
1226 bool GrContext::readTexturePixels(GrTexture* texture, 1241 bool GrContext::readTexturePixels(GrTexture* texture,
1227 int left, int top, int width, int height, 1242 int left, int top, int width, int height,
1228 GrPixelConfig config, void* buffer, size_t row Bytes, 1243 GrPixelConfig config, void* buffer, size_t row Bytes,
1229 uint32_t flags) { 1244 uint32_t flags) {
1230 SK_TRACE_EVENT0("GrContext::readTexturePixels"); 1245 SK_TRACE_EVENT0("GrContext::readTexturePixels");
1231 ASSERT_OWNED_RESOURCE(texture); 1246 ASSERT_OWNED_RESOURCE(texture);
1232 1247
1233 GrRenderTarget* target = texture->asRenderTarget(); 1248 GrRenderTarget* target = texture->asRenderTarget();
1249
1234 if (NULL != target) { 1250 if (NULL != target) {
1235 return this->readRenderTargetPixels(target, 1251 return this->readRenderTargetPixels(target,
1236 left, top, width, height, 1252 left, top, width, height,
1237 config, buffer, rowBytes, 1253 config, buffer, rowBytes,
1238 flags); 1254 flags);
1239 } else { 1255 } else {
1240 // TODO: make this more efficient for cases where we're reading the enti re 1256 // TODO: make this more efficient for cases where we're reading the enti re
1241 // texture, i.e., use GetTexImage() instead 1257 // texture, i.e., use GetTexImage() instead
1242 1258
1243 // create scratch rendertarget and read from that 1259 // create scratch rendertarget and read from that
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 } 1822 }
1807 return path; 1823 return path;
1808 } 1824 }
1809 1825
1810 /////////////////////////////////////////////////////////////////////////////// 1826 ///////////////////////////////////////////////////////////////////////////////
1811 #if GR_CACHE_STATS 1827 #if GR_CACHE_STATS
1812 void GrContext::printCacheStats() const { 1828 void GrContext::printCacheStats() const {
1813 fTextureCache->printStats(); 1829 fTextureCache->printStats();
1814 } 1830 }
1815 #endif 1831 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698