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

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

Issue 683733005: GrContext no longer ever draws on Gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: one more cleanup Created 6 years, 1 month 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
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "GrContext.h" 9 #include "GrContext.h"
10 10
(...skipping 19 matching lines...) Expand all
30 #include "GrStencilAndCoverTextContext.h" 30 #include "GrStencilAndCoverTextContext.h"
31 #include "GrStrokeInfo.h" 31 #include "GrStrokeInfo.h"
32 #include "GrSurfacePriv.h" 32 #include "GrSurfacePriv.h"
33 #include "GrTextStrike.h" 33 #include "GrTextStrike.h"
34 #include "GrTexturePriv.h" 34 #include "GrTexturePriv.h"
35 #include "GrTraceMarker.h" 35 #include "GrTraceMarker.h"
36 #include "GrTracing.h" 36 #include "GrTracing.h"
37 #include "SkDashPathPriv.h" 37 #include "SkDashPathPriv.h"
38 #include "SkConfig8888.h" 38 #include "SkConfig8888.h"
39 #include "SkGr.h" 39 #include "SkGr.h"
40 #include "SkRTConf.h"
41 #include "SkRRect.h" 40 #include "SkRRect.h"
42 #include "SkStrokeRec.h" 41 #include "SkStrokeRec.h"
43 #include "SkTLazy.h" 42 #include "SkTLazy.h"
44 #include "SkTLS.h" 43 #include "SkTLS.h"
45 #include "SkTraceEvent.h" 44 #include "SkTraceEvent.h"
46 45
47 // It can be useful to set this to false to test whether a bug is caused by usin g the
48 // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffe r, or to make
49 // debugging simpler.
50 SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true,
51 "Defers rendering in GrContext via GrInOrderDrawBuffer.");
52
53 #define BUFFERED_DRAW (c_Defer ? kYes_BufferedDraw : kNo_BufferedDraw)
54
55 #ifdef SK_DEBUG 46 #ifdef SK_DEBUG
56 // change this to a 1 to see notifications when partial coverage fails 47 // change this to a 1 to see notifications when partial coverage fails
57 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 48 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
58 #else 49 #else
59 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
60 #endif 51 #endif
61 52
62 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L IMIT; 53 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L IMIT;
63 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI T * 1024 * 1024; 54 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI T * 1024 * 1024;
64 55
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(), 128 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(),
138 MAX_RESOURCE_CACHE_COUNT, 129 MAX_RESOURCE_CACHE_COUNT,
139 MAX_RESOURCE_CACHE_BYTES)); 130 MAX_RESOURCE_CACHE_BYTES));
140 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); 131 fResourceCache->setOverbudgetCallback(OverbudgetCB, this);
141 fResourceCache2 = SkNEW(GrResourceCache2); 132 fResourceCache2 = SkNEW(GrResourceCache2);
142 133
143 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); 134 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
144 135
145 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 136 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
146 137
147 fLastDrawWasBuffered = kNo_BufferedDraw;
148
149 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); 138 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
150 fOvalRenderer = SkNEW(GrOvalRenderer); 139 fOvalRenderer = SkNEW(GrOvalRenderer);
151 140
152 fDidTestPMConversions = false; 141 fDidTestPMConversions = false;
153 142
154 this->setupDrawBuffer(); 143 this->setupDrawBuffer();
155 144
156 return true; 145 return true;
157 } 146 }
158 147
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 GrSurfaceDesc rtDesc = desc; 338 GrSurfaceDesc rtDesc = desc;
350 rtDesc.fFlags = rtDesc.fFlags | 339 rtDesc.fFlags = rtDesc.fFlags |
351 kRenderTarget_GrSurfaceFlag | 340 kRenderTarget_GrSurfaceFlag |
352 kNoStencil_GrSurfaceFlag; 341 kNoStencil_GrSurfaceFlag;
353 rtDesc.fWidth = GrNextPow2(desc.fWidth); 342 rtDesc.fWidth = GrNextPow2(desc.fWidth);
354 rtDesc.fHeight = GrNextPow2(desc.fHeight); 343 rtDesc.fHeight = GrNextPow2(desc.fHeight);
355 344
356 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); 345 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0);
357 346
358 if (texture) { 347 if (texture) {
359 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); 348 bool mustFlush = false;
360 GrDrawState* drawState = fGpu->drawState(); 349 {
361 drawState->setRenderTarget(texture->asRenderTarget()); 350 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRIni t);
351 GrDrawState* drawState = fDrawBuffer->drawState();
352 drawState->setRenderTarget(texture->asRenderTarget());
362 353
363 // if filtering is not desired then we want to ensure all 354 // if filtering is not desired then we want to ensure all
364 // texels in the resampled image are copies of texels from 355 // texels in the resampled image are copies of texels from
365 // the original. 356 // the original.
366 GrTextureParams params(SkShader::kClamp_TileMode, filter ? GrTexturePara ms::kBilerp_FilterMode : 357 GrTextureParams params(SkShader::kClamp_TileMode,
367 GrTexturePara ms::kNone_FilterMode); 358 filter ? GrTextureParams::kBilerp_FilterMode :
368 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), param s); 359 GrTextureParams::kNone_FilterMode);
360 drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), p arams);
369 361
370 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttrib s), 362 drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAt tribs),
371 2 * sizeof(SkPoint)); 363 2 * sizeof(SkPoint));
372 364
373 GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); 365 GrDrawTarget::AutoReleaseGeometry arg(fDrawBuffer, 4, 0);
374 366
375 if (arg.succeeded()) { 367 if (arg.succeeded()) {
376 SkPoint* verts = (SkPoint*) arg.vertices(); 368 SkPoint* verts = (SkPoint*) arg.vertices();
377 verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); 369 verts[0].setIRectFan(0, 0, texture->width(), texture->height(),
378 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); 370 2 * sizeof(SkPoint));
379 fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); 371 verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint));
372 fDrawBuffer->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
373 mustFlush = true;
374 }
375 }
376
377 // The inorder draw buffer will buffer the draw, so we need to flush her e
378 if (mustFlush) {
bsalomon 2014/10/31 17:35:17 I don't think we need this flush
379 fDrawBuffer->flush();
380 } 380 }
381 } else { 381 } else {
382 // TODO: Our CPU stretch doesn't filter. But we create separate 382 // TODO: Our CPU stretch doesn't filter. But we create separate
383 // stretched textures when the texture params is either filtered or 383 // stretched textures when the texture params is either filtered or
384 // not. Either implement filtered stretch blit on CPU or just create 384 // not. Either implement filtered stretch blit on CPU or just create
385 // one when FBO case fails. 385 // one when FBO case fails.
386 386
387 rtDesc.fFlags = kNone_GrSurfaceFlags; 387 rtDesc.fFlags = kNone_GrSurfaceFlags;
388 // no longer need to clamp at min RT size. 388 // no longer need to clamp at min RT size.
389 rtDesc.fWidth = GrNextPow2(desc.fWidth); 389 rtDesc.fWidth = GrNextPow2(desc.fWidth);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 //////////////////////////////////////////////////////////////////////////////// 582 ////////////////////////////////////////////////////////////////////////////////
583 583
584 void GrContext::clear(const SkIRect* rect, 584 void GrContext::clear(const SkIRect* rect,
585 const GrColor color, 585 const GrColor color,
586 bool canIgnoreRect, 586 bool canIgnoreRect,
587 GrRenderTarget* renderTarget) { 587 GrRenderTarget* renderTarget) {
588 ASSERT_OWNED_RESOURCE(renderTarget); 588 ASSERT_OWNED_RESOURCE(renderTarget);
589 AutoRestoreEffects are; 589 AutoRestoreEffects are;
590 AutoCheckFlush acf(this); 590 AutoCheckFlush acf(this);
591 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); 591 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
592 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); 592 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf);
593 if (NULL == target) { 593 if (NULL == target) {
594 return; 594 return;
595 } 595 }
596 target->clear(rect, color, canIgnoreRect, renderTarget); 596 target->clear(rect, color, canIgnoreRect, renderTarget);
597 } 597 }
598 598
599 void GrContext::drawPaint(const GrPaint& origPaint) { 599 void GrContext::drawPaint(const GrPaint& origPaint) {
600 // set rect to be big enough to fill the space, but not super-huge, so we 600 // set rect to be big enough to fill the space, but not super-huge, so we
601 // don't overflow fixed-point implementations 601 // don't overflow fixed-point implementations
602 SkRect r; 602 SkRect r;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 const GrStrokeInfo* strokeInfo) { 715 const GrStrokeInfo* strokeInfo) {
716 if (strokeInfo && strokeInfo->isDashed()) { 716 if (strokeInfo && strokeInfo->isDashed()) {
717 SkPath path; 717 SkPath path;
718 path.addRect(rect); 718 path.addRect(rect);
719 this->drawPath(paint, path, *strokeInfo); 719 this->drawPath(paint, path, *strokeInfo);
720 return; 720 return;
721 } 721 }
722 722
723 AutoRestoreEffects are; 723 AutoRestoreEffects are;
724 AutoCheckFlush acf(this); 724 AutoCheckFlush acf(this);
725 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 725 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
726 if (NULL == target) { 726 if (NULL == target) {
727 return; 727 return;
728 } 728 }
729 729
730 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); 730 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target);
731 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); 731 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th();
732 SkMatrix matrix = target->drawState()->getViewMatrix(); 732 SkMatrix matrix = target->drawState()->getViewMatrix();
733 733
734 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking 734 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking
735 // cases where the RT is fully inside a stroke. 735 // cases where the RT is fully inside a stroke.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 target->drawSimpleRect(rect); 829 target->drawSimpleRect(rect);
830 } 830 }
831 } 831 }
832 832
833 void GrContext::drawRectToRect(const GrPaint& paint, 833 void GrContext::drawRectToRect(const GrPaint& paint,
834 const SkRect& dstRect, 834 const SkRect& dstRect,
835 const SkRect& localRect, 835 const SkRect& localRect,
836 const SkMatrix* localMatrix) { 836 const SkMatrix* localMatrix) {
837 AutoRestoreEffects are; 837 AutoRestoreEffects are;
838 AutoCheckFlush acf(this); 838 AutoCheckFlush acf(this);
839 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 839 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
840 if (NULL == target) { 840 if (NULL == target) {
841 return; 841 return;
842 } 842 }
843 843
844 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); 844 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
845 845
846 target->drawRect(dstRect, &localRect, localMatrix); 846 target->drawRect(dstRect, &localRect, localMatrix);
847 } 847 }
848 848
849 namespace { 849 namespace {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 int vertexCount, 895 int vertexCount,
896 const SkPoint positions[], 896 const SkPoint positions[],
897 const SkPoint texCoords[], 897 const SkPoint texCoords[],
898 const GrColor colors[], 898 const GrColor colors[],
899 const uint16_t indices[], 899 const uint16_t indices[],
900 int indexCount) { 900 int indexCount) {
901 AutoRestoreEffects are; 901 AutoRestoreEffects are;
902 AutoCheckFlush acf(this); 902 AutoCheckFlush acf(this);
903 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e 903 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
904 904
905 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 905 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
906 if (NULL == target) { 906 if (NULL == target) {
907 return; 907 return;
908 } 908 }
909 GrDrawState* drawState = target->drawState(); 909 GrDrawState* drawState = target->drawState();
910 910
911 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 911 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
912 912
913 int colorOffset = -1, texOffset = -1; 913 int colorOffset = -1, texOffset = -1;
914 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); 914 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset );
915 915
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 959
960 if (strokeInfo.isDashed()) { 960 if (strokeInfo.isDashed()) {
961 SkPath path; 961 SkPath path;
962 path.addRRect(rrect); 962 path.addRRect(rrect);
963 this->drawPath(paint, path, strokeInfo); 963 this->drawPath(paint, path, strokeInfo);
964 return; 964 return;
965 } 965 }
966 966
967 AutoRestoreEffects are; 967 AutoRestoreEffects are;
968 AutoCheckFlush acf(this); 968 AutoCheckFlush acf(this);
969 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 969 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
970 if (NULL == target) { 970 if (NULL == target) {
971 return; 971 return;
972 } 972 }
973 973
974 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); 974 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target);
975 975
976 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 976 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
977 977
978 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro keRec)) { 978 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro keRec)) {
979 SkPath path; 979 SkPath path;
980 path.addRRect(rrect); 980 path.addRRect(rrect);
981 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); 981 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo);
982 } 982 }
983 } 983 }
984 984
985 /////////////////////////////////////////////////////////////////////////////// 985 ///////////////////////////////////////////////////////////////////////////////
986 986
987 void GrContext::drawDRRect(const GrPaint& paint, 987 void GrContext::drawDRRect(const GrPaint& paint,
988 const SkRRect& outer, 988 const SkRRect& outer,
989 const SkRRect& inner) { 989 const SkRRect& inner) {
990 if (outer.isEmpty()) { 990 if (outer.isEmpty()) {
991 return; 991 return;
992 } 992 }
993 993
994 AutoRestoreEffects are; 994 AutoRestoreEffects are;
995 AutoCheckFlush acf(this); 995 AutoCheckFlush acf(this);
996 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 996 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
997 997
998 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); 998 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
999 999
1000 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn er)) { 1000 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn er)) {
1001 SkPath path; 1001 SkPath path;
1002 path.addRRect(inner); 1002 path.addRRect(inner);
1003 path.addRRect(outer); 1003 path.addRRect(outer);
1004 path.setFillType(SkPath::kEvenOdd_FillType); 1004 path.setFillType(SkPath::kEvenOdd_FillType);
1005 1005
1006 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); 1006 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
(...skipping 12 matching lines...) Expand all
1019 1019
1020 if (strokeInfo.isDashed()) { 1020 if (strokeInfo.isDashed()) {
1021 SkPath path; 1021 SkPath path;
1022 path.addOval(oval); 1022 path.addOval(oval);
1023 this->drawPath(paint, path, strokeInfo); 1023 this->drawPath(paint, path, strokeInfo);
1024 return; 1024 return;
1025 } 1025 }
1026 1026
1027 AutoRestoreEffects are; 1027 AutoRestoreEffects are;
1028 AutoCheckFlush acf(this); 1028 AutoCheckFlush acf(this);
1029 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 1029 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
1030 if (NULL == target) { 1030 if (NULL == target) {
1031 return; 1031 return;
1032 } 1032 }
1033 1033
1034 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); 1034 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target);
1035 1035
1036 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 1036 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
1037 1037
1038 1038
1039 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke Rec)) { 1039 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke Rec)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 this->drawPaint(paint); 1107 this->drawPaint(paint);
1108 } 1108 }
1109 return; 1109 return;
1110 } 1110 }
1111 1111
1112 if (strokeInfo.isDashed()) { 1112 if (strokeInfo.isDashed()) {
1113 SkPoint pts[2]; 1113 SkPoint pts[2];
1114 if (path.isLine(pts)) { 1114 if (path.isLine(pts)) {
1115 AutoRestoreEffects are; 1115 AutoRestoreEffects are;
1116 AutoCheckFlush acf(this); 1116 AutoCheckFlush acf(this);
1117 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &a re, &acf); 1117 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
1118 if (NULL == target) { 1118 if (NULL == target) {
1119 return; 1119 return;
1120 } 1120 }
1121 GrDrawState* drawState = target->drawState(); 1121 GrDrawState* drawState = target->drawState();
1122 1122
1123 SkMatrix origViewMatrix = drawState->getViewMatrix(); 1123 SkMatrix origViewMatrix = drawState->getViewMatrix();
1124 GrDrawState::AutoViewMatrixRestore avmr; 1124 GrDrawState::AutoViewMatrixRestore avmr;
1125 if (avmr.setIdentity(target->drawState())) { 1125 if (avmr.setIdentity(target->drawState())) {
1126 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu, target, 1126 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu, target,
1127 origViewMatrix)) { 1127 origViewMatrix)) {
(...skipping 16 matching lines...) Expand all
1144 return; 1144 return;
1145 } 1145 }
1146 1146
1147 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. 1147 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re.
1148 // Scratch textures can be recycled after they are returned to the texture 1148 // Scratch textures can be recycled after they are returned to the texture
1149 // cache. This presents a potential hazard for buffered drawing. However, 1149 // cache. This presents a potential hazard for buffered drawing. However,
1150 // the writePixels that uploads to the scratch will perform a flush so we're 1150 // the writePixels that uploads to the scratch will perform a flush so we're
1151 // OK. 1151 // OK.
1152 AutoRestoreEffects are; 1152 AutoRestoreEffects are;
1153 AutoCheckFlush acf(this); 1153 AutoCheckFlush acf(this);
1154 GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf ); 1154 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
1155 if (NULL == target) { 1155 if (NULL == target) {
1156 return; 1156 return;
1157 } 1157 }
1158 GrDrawState* drawState = target->drawState(); 1158 GrDrawState* drawState = target->drawState();
1159 1159
1160 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); 1160 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex());
1161 1161
1162 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 1162 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
1163 1163
1164 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled(); 1164 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 } 1367 }
1368 1368
1369 SkMatrix matrix; 1369 SkMatrix matrix;
1370 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); 1370 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
1371 1371
1372 // This function can be called in the midst of drawing another object (e.g., when uploading a 1372 // This function can be called in the midst of drawing another object (e.g., when uploading a
1373 // SW-rasterized clip while issuing a draw). So we push the current geometry state before 1373 // SW-rasterized clip while issuing a draw). So we push the current geometry state before
1374 // drawing a rect to the render target. 1374 // drawing a rect to the render target.
1375 // The bracket ensures we pop the stack if we wind up flushing below. 1375 // The bracket ensures we pop the stack if we wind up flushing below.
1376 { 1376 {
1377 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, kYes_BufferedDraw, NULL, NULL); 1377 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL);
1378 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k Reset_ASRInit, 1378 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k Reset_ASRInit,
1379 &matrix); 1379 &matrix);
1380 GrDrawState* drawState = drawTarget->drawState(); 1380 GrDrawState* drawState = drawTarget->drawState();
1381 drawState->addColorProcessor(fp); 1381 drawState->addColorProcessor(fp);
1382 drawState->setRenderTarget(renderTarget); 1382 drawState->setRenderTarget(renderTarget);
1383 drawState->disableState(GrDrawState::kClip_StateBit); 1383 drawState->disableState(GrDrawState::kClip_StateBit);
1384 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height))); 1384 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height)));
1385 } 1385 }
1386 1386
1387 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1387 if (kFlushWrites_PixelOp & pixelOpsFlags) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 if (!fp) { 1491 if (!fp) {
1492 fp.reset(GrConfigConversionEffect::Create( 1492 fp.reset(GrConfigConversionEffect::Create(
1493 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo nversion, 1493 src, swapRAndB, GrConfigConversionEffect::kNone_PMCo nversion,
1494 textureMatrix)); 1494 textureMatrix));
1495 } 1495 }
1496 swapRAndB = false; // we will handle the swap in the draw. 1496 swapRAndB = false; // we will handle the swap in the draw.
1497 1497
1498 // We protect the existing geometry here since it may not be 1498 // We protect the existing geometry here since it may not be
1499 // clear to the caller that a draw operation (i.e., drawSimpleRe ct) 1499 // clear to the caller that a draw operation (i.e., drawSimpleRe ct)
1500 // can be invoked in this method 1500 // can be invoked in this method
1501 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget: :kReset_ASRInit); 1501 {
1502 GrDrawState* drawState = fGpu->drawState(); 1502 GrDrawTarget::AutoGeometryAndStatePush agasp(fDrawBuffer,
1503 SkASSERT(fp); 1503 GrDrawTarget::k Reset_ASRInit);
1504 drawState->addColorProcessor(fp); 1504 GrDrawState* drawState = fDrawBuffer->drawState();
1505 SkASSERT(fp);
1506 drawState->addColorProcessor(fp);
1505 1507
1506 drawState->setRenderTarget(texture->asRenderTarget()); 1508 drawState->setRenderTarget(texture->asRenderTarget());
1507 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar (height)); 1509 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToSc alar(height));
1508 fGpu->drawSimpleRect(rect); 1510 fDrawBuffer->drawSimpleRect(rect);
1511 }
1512 fDrawBuffer->flush();
1509 // we want to read back from the scratch's origin 1513 // we want to read back from the scratch's origin
1510 left = 0; 1514 left = 0;
1511 top = 0; 1515 top = 0;
1512 target = texture->asRenderTarget(); 1516 target = texture->asRenderTarget();
1513 } 1517 }
1514 } 1518 }
1515 } 1519 }
1516 if (!fGpu->readPixels(target, 1520 if (!fGpu->readPixels(target,
bsalomon 2014/10/31 17:35:17 Instead of flushing above I think we should call t
1517 left, top, width, height, 1521 left, top, width, height,
1518 readConfig, buffer, rowBytes)) { 1522 readConfig, buffer, rowBytes)) {
1519 return false; 1523 return false;
1520 } 1524 }
1521 // Perform any conversions we weren't able to perform using a scratch textur e. 1525 // Perform any conversions we weren't able to perform using a scratch textur e.
1522 if (unpremul || swapRAndB) { 1526 if (unpremul || swapRAndB) {
1523 SkDstPixelInfo dstPI; 1527 SkDstPixelInfo dstPI;
1524 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { 1528 if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) {
1525 return false; 1529 return false;
1526 } 1530 }
(...skipping 22 matching lines...) Expand all
1549 if (fGpu) { 1553 if (fGpu) {
1550 fGpu->resolveRenderTarget(target); 1554 fGpu->resolveRenderTarget(target);
1551 } 1555 }
1552 } 1556 }
1553 1557
1554 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { 1558 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
1555 SkASSERT(renderTarget); 1559 SkASSERT(renderTarget);
1556 ASSERT_OWNED_RESOURCE(renderTarget); 1560 ASSERT_OWNED_RESOURCE(renderTarget);
1557 AutoRestoreEffects are; 1561 AutoRestoreEffects are;
1558 AutoCheckFlush acf(this); 1562 AutoCheckFlush acf(this);
1559 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); 1563 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf);
1560 if (NULL == target) { 1564 if (NULL == target) {
1561 return; 1565 return;
1562 } 1566 }
1563 target->discard(renderTarget); 1567 target->discard(renderTarget);
1564 } 1568 }
1565 1569
1566 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, 1570 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct,
1567 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { 1571 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) {
1568 if (NULL == src || NULL == dst) { 1572 if (NULL == src || NULL == dst) {
1569 return; 1573 return;
1570 } 1574 }
1571 ASSERT_OWNED_RESOURCE(src); 1575 ASSERT_OWNED_RESOURCE(src);
1572 ASSERT_OWNED_RESOURCE(dst); 1576 ASSERT_OWNED_RESOURCE(dst);
1573 1577
1574 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh 1578 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh
1575 // here. 1579 // here.
1576 1580
1577 GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); 1581 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL);
1578 if (NULL == target) { 1582 if (NULL == target) {
1579 return; 1583 return;
1580 } 1584 }
1581 target->copySurface(dst, src, srcRect, dstPoint); 1585 target->copySurface(dst, src, srcRect, dstPoint);
1582 1586
1583 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1587 if (kFlushWrites_PixelOp & pixelOpsFlags) {
1584 this->flush(); 1588 this->flush();
1585 } 1589 }
1586 } 1590 }
1587 1591
1588 void GrContext::flushSurfaceWrites(GrSurface* surface) { 1592 void GrContext::flushSurfaceWrites(GrSurface* surface) {
1589 if (surface->surfacePriv().hasPendingWrite()) { 1593 if (surface->surfacePriv().hasPendingWrite()) {
1590 this->flush(); 1594 this->flush();
1591 } 1595 }
1592 } 1596 }
1593 1597
1594 //////////////////////////////////////////////////////////////////////////////// 1598 ////////////////////////////////////////////////////////////////////////////////
1595 1599
1596 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, 1600 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint,
1597 BufferedDraw buffered,
1598 AutoRestoreEffects* are, 1601 AutoRestoreEffects* are,
1599 AutoCheckFlush* acf) { 1602 AutoCheckFlush* acf) {
1600 // All users of this draw state should be freeing up all effects when they'r e done. 1603 // All users of this draw state should be freeing up all effects when they'r e done.
1601 // Otherwise effects that own resources may keep those resources alive indef initely. 1604 // Otherwise effects that own resources may keep those resources alive indef initely.
1602 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() && 1605 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() &&
1603 !fDrawState->hasGeometryProcessor()); 1606 !fDrawState->hasGeometryProcessor());
1604 1607
1605 if (NULL == fGpu) { 1608 if (NULL == fGpu) {
1606 return NULL; 1609 return NULL;
1607 } 1610 }
1608 1611
1609 if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffere d) {
1610 fDrawBuffer->flush();
1611 fLastDrawWasBuffered = kNo_BufferedDraw;
1612 }
1613 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); 1612 ASSERT_OWNED_RESOURCE(fRenderTarget.get());
1614 if (paint) { 1613 if (paint) {
1615 SkASSERT(are); 1614 SkASSERT(are);
1616 SkASSERT(acf); 1615 SkASSERT(acf);
1617 are->set(fDrawState); 1616 are->set(fDrawState);
1618 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); 1617 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
1619 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK 1618 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK
1620 if ((paint->hasMask() || 0xff != paint->fCoverage) && 1619 if ((paint->hasMask() || 0xff != paint->fCoverage) &&
1621 !fDrawState->couldApplyCoverage(fGpu->caps())) { 1620 !fDrawState->couldApplyCoverage(fGpu->caps())) {
1622 GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); 1621 GrPrintf("Partial pixel coverage will be incorrectly blended.\n");
1623 } 1622 }
1624 #endif 1623 #endif
1625 // Clear any vertex attributes configured for the previous use of the 1624 // Clear any vertex attributes configured for the previous use of the
1626 // GrDrawState which can effect which blend optimizations are in effect. 1625 // GrDrawState which can effect which blend optimizations are in effect.
1627 fDrawState->setDefaultVertexAttribs(); 1626 fDrawState->setDefaultVertexAttribs();
1628 } else { 1627 } else {
1629 fDrawState->reset(fViewMatrix); 1628 fDrawState->reset(fViewMatrix);
1630 fDrawState->setRenderTarget(fRenderTarget.get()); 1629 fDrawState->setRenderTarget(fRenderTarget.get());
1631 } 1630 }
1632 GrDrawTarget* target;
1633 if (kYes_BufferedDraw == buffered) {
1634 fLastDrawWasBuffered = kYes_BufferedDraw;
1635 target = fDrawBuffer;
1636 } else {
1637 SkASSERT(kNo_BufferedDraw == buffered);
1638 fLastDrawWasBuffered = kNo_BufferedDraw;
1639 target = fGpu;
1640 }
1641 fDrawState->setState(GrDrawState::kClip_StateBit, fClip && 1631 fDrawState->setState(GrDrawState::kClip_StateBit, fClip &&
1642 !fClip->fClipStack->isWideO pen()); 1632 !fClip->fClipStack->isWideO pen());
1643 target->setClip(fClip); 1633 fDrawBuffer->setClip(fClip);
1644 SkASSERT(fDrawState == target->drawState()); 1634 SkASSERT(fDrawState == fDrawBuffer->drawState());
1645 return target; 1635 return fDrawBuffer;
1646 } 1636 }
1647 1637
1648 /* 1638 /*
1649 * This method finds a path renderer that can draw the specified path on 1639 * This method finds a path renderer that can draw the specified path on
1650 * the provided target. 1640 * the provided target.
1651 * Due to its expense, the software path renderer has split out so it can 1641 * Due to its expense, the software path renderer has split out so it can
1652 * can be individually allowed/disallowed via the "allowSW" boolean. 1642 * can be individually allowed/disallowed via the "allowSW" boolean.
1653 */ 1643 */
1654 GrPathRenderer* GrContext::getPathRenderer(const SkPath& path, 1644 GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
1655 const SkStrokeRec& stroke, 1645 const SkStrokeRec& stroke,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); 1705 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
1716 1706
1717 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, 1707 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
1718 fDrawBufferVBAllocPool, 1708 fDrawBufferVBAllocPool,
1719 fDrawBufferIBAllocPool)); 1709 fDrawBufferIBAllocPool));
1720 1710
1721 fDrawBuffer->setDrawState(fDrawState); 1711 fDrawBuffer->setDrawState(fDrawState);
1722 } 1712 }
1723 1713
1724 GrDrawTarget* GrContext::getTextTarget() { 1714 GrDrawTarget* GrContext::getTextTarget() {
1725 return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); 1715 return this->prepareToDraw(NULL, NULL, NULL);
1726 } 1716 }
1727 1717
1728 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { 1718 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
1729 return fGpu->getQuadIndexBuffer(); 1719 return fGpu->getQuadIndexBuffer();
1730 } 1720 }
1731 1721
1732 namespace { 1722 namespace {
1733 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { 1723 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
1734 GrConfigConversionEffect::PMConversion pmToUPM; 1724 GrConfigConversionEffect::PMConversion pmToUPM;
1735 GrConfigConversionEffect::PMConversion upmToPM; 1725 GrConfigConversionEffect::PMConversion upmToPM;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 fResourceCache->printStats(); 1791 fResourceCache->printStats();
1802 } 1792 }
1803 #endif 1793 #endif
1804 1794
1805 #if GR_GPU_STATS 1795 #if GR_GPU_STATS
1806 const GrContext::GPUStats* GrContext::gpuStats() const { 1796 const GrContext::GPUStats* GrContext::gpuStats() const {
1807 return fGpu->gpuStats(); 1797 return fGpu->gpuStats();
1808 } 1798 }
1809 #endif 1799 #endif
1810 1800
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698