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

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

Issue 1121463002: Move bounds to GrBatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 7 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 #include "GrContext.h" 9 #include "GrContext.h"
10 10
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 618
619 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 619 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
620 620
621 private: 621 private:
622 StrokeRectBatch(const Geometry& geometry) { 622 StrokeRectBatch(const Geometry& geometry) {
623 this->initClassID<StrokeRectBatch>(); 623 this->initClassID<StrokeRectBatch>();
624 624
625 fBatch.fHairline = geometry.fStrokeWidth == 0; 625 fBatch.fHairline = geometry.fStrokeWidth == 0;
626 626
627 fGeoData.push_back(geometry); 627 fGeoData.push_back(geometry);
628
629 // setup bounds
630 this->setBounds(geometry.fRect);
631 SkScalar rad = SkScalarHalf(geometry.fStrokeWidth);
632 this->getBounds()->outset(rad, rad);
633 geometry.fViewMatrix.mapRect(this->getBounds());
628 } 634 }
629 635
630 /* create a triangle strip that strokes the specified rect. There are 8 636 /* create a triangle strip that strokes the specified rect. There are 8
631 unique vertices, but we repeat the last 2 to close up. Alternatively we 637 unique vertices, but we repeat the last 2 to close up. Alternatively we
632 could use an indices array, and then only send 8 verts, but not sure that 638 could use an indices array, and then only send 8 verts, but not sure that
633 would be faster. 639 would be faster.
634 */ 640 */
635 void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar widt h) { 641 void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar widt h) {
636 const SkScalar rad = SkScalarHalf(width); 642 const SkScalar rad = SkScalarHalf(width);
637 // TODO we should be able to enable this assert, but we'd have to filter these draws 643 // TODO we should be able to enable this assert, but we'd have to filter these draws
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 774
769 if (width >= 0) { 775 if (width >= 0) {
770 StrokeRectBatch::Geometry geometry; 776 StrokeRectBatch::Geometry geometry;
771 geometry.fViewMatrix = viewMatrix; 777 geometry.fViewMatrix = viewMatrix;
772 geometry.fColor = color; 778 geometry.fColor = color;
773 geometry.fRect = rect; 779 geometry.fRect = rect;
774 geometry.fStrokeWidth = width; 780 geometry.fStrokeWidth = width;
775 781
776 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry)); 782 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry));
777 783
778 SkRect bounds = rect;
779 SkScalar rad = SkScalarHalf(width);
780 bounds.outset(rad, rad);
781 viewMatrix.mapRect(&bounds);
782 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of 784 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of
783 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA 785 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA
784 // is enabled because it can cause ugly artifacts. 786 // is enabled because it can cause ugly artifacts.
785 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag, 787 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag,
786 0 == width && !rt->isMultisampled()); 788 0 == width && !rt->isMultisampled());
787 target->drawBatch(&pipelineBuilder, batch, &bounds); 789 target->drawBatch(&pipelineBuilder, batch);
788 } else { 790 } else {
789 // filled BW rect 791 // filled BW rect
790 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); 792 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect);
791 } 793 }
792 } 794 }
793 795
794 void GrContext::drawNonAARectToRect(GrRenderTarget* rt, 796 void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
795 const GrClip& clip, 797 const GrClip& clip,
796 const GrPaint& paint, 798 const GrPaint& paint,
797 const SkMatrix& viewMatrix, 799 const SkMatrix& viewMatrix,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1017
1016 if (localCoords) { 1018 if (localCoords) {
1017 installedGeo.fLocalCoords.append(vertexCount, localCoords); 1019 installedGeo.fLocalCoords.append(vertexCount, localCoords);
1018 fBatch.fHasLocalCoords = true; 1020 fBatch.fHasLocalCoords = true;
1019 } else { 1021 } else {
1020 fBatch.fHasLocalCoords = false; 1022 fBatch.fHasLocalCoords = false;
1021 } 1023 }
1022 fBatch.fVertexCount = vertexCount; 1024 fBatch.fVertexCount = vertexCount;
1023 fBatch.fIndexCount = indexCount; 1025 fBatch.fIndexCount = indexCount;
1024 fBatch.fPrimitiveType = primitiveType; 1026 fBatch.fPrimitiveType = primitiveType;
1027
1028 // TODO figure out bounds
1029 this->setBoundsLargest();
1025 } 1030 }
1026 1031
1027 GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; } 1032 GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; }
1028 bool batchablePrimitiveType() const { 1033 bool batchablePrimitiveType() const {
1029 return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType || 1034 return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType ||
1030 kLines_GrPrimitiveType == fBatch.fPrimitiveType || 1035 kLines_GrPrimitiveType == fBatch.fPrimitiveType ||
1031 kPoints_GrPrimitiveType == fBatch.fPrimitiveType; 1036 kPoints_GrPrimitiveType == fBatch.fPrimitiveType;
1032 } 1037 }
1033 GrColor color() const { return fBatch.fColor; } 1038 GrColor color() const { return fBatch.fColor; }
1034 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 1039 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 if (!this->hasColors() && this->color() != that->color()) { 1074 if (!this->hasColors() && this->color() != that->color()) {
1070 return false; 1075 return false;
1071 } 1076 }
1072 1077
1073 if (this->color() != that->color()) { 1078 if (this->color() != that->color()) {
1074 fBatch.fColor = GrColor_ILLEGAL; 1079 fBatch.fColor = GrColor_ILLEGAL;
1075 } 1080 }
1076 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 1081 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ;
1077 fBatch.fVertexCount += that->vertexCount(); 1082 fBatch.fVertexCount += that->vertexCount();
1078 fBatch.fIndexCount += that->indexCount(); 1083 fBatch.fIndexCount += that->indexCount();
1084
1085 this->joinBounds(that->bounds());
1079 return true; 1086 return true;
1080 } 1087 }
1081 1088
1082 struct BatchTracker { 1089 struct BatchTracker {
1083 GrPrimitiveType fPrimitiveType; 1090 GrPrimitiveType fPrimitiveType;
1084 SkMatrix fViewMatrix; 1091 SkMatrix fViewMatrix;
1085 GrColor fColor; 1092 GrColor fColor;
1086 bool fUsesLocalCoords; 1093 bool fUsesLocalCoords;
1087 bool fColorIgnored; 1094 bool fColorIgnored;
1088 bool fCoverageIgnored; 1095 bool fCoverageIgnored;
(...skipping 30 matching lines...) Expand all
1119 1126
1120 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 1127 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
1121 1128
1122 DrawVerticesBatch::Geometry geometry; 1129 DrawVerticesBatch::Geometry geometry;
1123 geometry.fColor = paint.getColor(); 1130 geometry.fColor = paint.getColor();
1124 1131
1125 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix, 1132 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix,
1126 positions, vertexCount , indices, 1133 positions, vertexCount , indices,
1127 indexCount,colors, tex Coords)); 1134 indexCount,colors, tex Coords));
1128 1135
1129 // TODO figure out bounds 1136 target->drawBatch(&pipelineBuilder, batch);
1130 target->drawBatch(&pipelineBuilder, batch, NULL);
1131 } 1137 }
1132 1138
1133 /////////////////////////////////////////////////////////////////////////////// 1139 ///////////////////////////////////////////////////////////////////////////////
1134 1140
1135 void GrContext::drawRRect(GrRenderTarget*rt, 1141 void GrContext::drawRRect(GrRenderTarget*rt,
1136 const GrClip& clip, 1142 const GrClip& clip,
1137 const GrPaint& paint, 1143 const GrPaint& paint,
1138 const SkMatrix& viewMatrix, 1144 const SkMatrix& viewMatrix,
1139 const SkRRect& rrect, 1145 const SkRRect& rrect,
1140 const GrStrokeInfo& strokeInfo) { 1146 const GrStrokeInfo& strokeInfo) {
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 } 2014 }
2009 } 2015 }
2010 2016
2011 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 2017 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
2012 fGpu->removeGpuTraceMarker(marker); 2018 fGpu->removeGpuTraceMarker(marker);
2013 if (fDrawBuffer) { 2019 if (fDrawBuffer) {
2014 fDrawBuffer->removeGpuTraceMarker(marker); 2020 fDrawBuffer->removeGpuTraceMarker(marker);
2015 } 2021 }
2016 } 2022 }
2017 2023
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698