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

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: tweak 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
« no previous file with comments | « src/gpu/GrBatch.h ('k') | src/gpu/GrDefaultPathRenderer.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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 523 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
524 524
525 private: 525 private:
526 StrokeRectBatch(const Geometry& geometry) { 526 StrokeRectBatch(const Geometry& geometry) {
527 this->initClassID<StrokeRectBatch>(); 527 this->initClassID<StrokeRectBatch>();
528 528
529 fBatch.fHairline = geometry.fStrokeWidth == 0; 529 fBatch.fHairline = geometry.fStrokeWidth == 0;
530 530
531 fGeoData.push_back(geometry); 531 fGeoData.push_back(geometry);
532
533 // setup bounds
534 fBounds = geometry.fRect;
535 SkScalar rad = SkScalarHalf(geometry.fStrokeWidth);
536 fBounds.outset(rad, rad);
537 geometry.fViewMatrix.mapRect(&fBounds);
532 } 538 }
533 539
534 /* create a triangle strip that strokes the specified rect. There are 8 540 /* create a triangle strip that strokes the specified rect. There are 8
535 unique vertices, but we repeat the last 2 to close up. Alternatively we 541 unique vertices, but we repeat the last 2 to close up. Alternatively we
536 could use an indices array, and then only send 8 verts, but not sure that 542 could use an indices array, and then only send 8 verts, but not sure that
537 would be faster. 543 would be faster.
538 */ 544 */
539 void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar widt h) { 545 void setStrokeRectStrip(SkPoint verts[10], const SkRect& rect, SkScalar widt h) {
540 const SkScalar rad = SkScalarHalf(width); 546 const SkScalar rad = SkScalarHalf(width);
541 // TODO we should be able to enable this assert, but we'd have to filter these draws 547 // 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
672 678
673 if (width >= 0) { 679 if (width >= 0) {
674 StrokeRectBatch::Geometry geometry; 680 StrokeRectBatch::Geometry geometry;
675 geometry.fViewMatrix = viewMatrix; 681 geometry.fViewMatrix = viewMatrix;
676 geometry.fColor = color; 682 geometry.fColor = color;
677 geometry.fRect = rect; 683 geometry.fRect = rect;
678 geometry.fStrokeWidth = width; 684 geometry.fStrokeWidth = width;
679 685
680 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry)); 686 SkAutoTUnref<GrBatch> batch(StrokeRectBatch::Create(geometry));
681 687
682 SkRect bounds = rect;
683 SkScalar rad = SkScalarHalf(width);
684 bounds.outset(rad, rad);
685 viewMatrix.mapRect(&bounds);
686 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of 688 // Depending on sub-pixel coordinates and the particular GPU, we may los e a corner of
687 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA 689 // hairline rects. We jam all the vertices to pixel centers to avoid thi s, but not when MSAA
688 // is enabled because it can cause ugly artifacts. 690 // is enabled because it can cause ugly artifacts.
689 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag, 691 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_ Flag,
690 0 == width && !rt->isMultisampled()); 692 0 == width && !rt->isMultisampled());
691 target->drawBatch(&pipelineBuilder, batch, &bounds); 693 target->drawBatch(&pipelineBuilder, batch);
692 } else { 694 } else {
693 // filled BW rect 695 // filled BW rect
694 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect); 696 target->drawSimpleRect(&pipelineBuilder, color, viewMatrix, rect);
695 } 697 }
696 } 698 }
697 699
698 void GrContext::drawNonAARectToRect(GrRenderTarget* rt, 700 void GrContext::drawNonAARectToRect(GrRenderTarget* rt,
699 const GrClip& clip, 701 const GrClip& clip,
700 const GrPaint& paint, 702 const GrPaint& paint,
701 const SkMatrix& viewMatrix, 703 const SkMatrix& viewMatrix,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 SkTDArray<SkPoint> fPositions; 753 SkTDArray<SkPoint> fPositions;
752 SkTDArray<uint16_t> fIndices; 754 SkTDArray<uint16_t> fIndices;
753 SkTDArray<GrColor> fColors; 755 SkTDArray<GrColor> fColors;
754 SkTDArray<SkPoint> fLocalCoords; 756 SkTDArray<SkPoint> fLocalCoords;
755 }; 757 };
756 758
757 static GrBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveTy pe, 759 static GrBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveTy pe,
758 const SkMatrix& viewMatrix, 760 const SkMatrix& viewMatrix,
759 const SkPoint* positions, int vertexCount, 761 const SkPoint* positions, int vertexCount,
760 const uint16_t* indices, int indexCount, 762 const uint16_t* indices, int indexCount,
761 const GrColor* colors, const SkPoint* localCoords) { 763 const GrColor* colors, const SkPoint* localCoords,
764 const SkRect& bounds) {
762 return SkNEW_ARGS(DrawVerticesBatch, (geometry, primitiveType, viewMatri x, positions, 765 return SkNEW_ARGS(DrawVerticesBatch, (geometry, primitiveType, viewMatri x, positions,
763 vertexCount, indices, indexCount, colors, 766 vertexCount, indices, indexCount, colors,
764 localCoords)); 767 localCoords, bounds));
765 } 768 }
766 769
767 const char* name() const override { return "DrawVerticesBatch"; } 770 const char* name() const override { return "DrawVerticesBatch"; }
768 771
769 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 772 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
770 // When this is called on a batch, there is only one geometry bundle 773 // When this is called on a batch, there is only one geometry bundle
771 if (this->hasColors()) { 774 if (this->hasColors()) {
772 out->setUnknownFourComponents(); 775 out->setUnknownFourComponents();
773 } else { 776 } else {
774 out->setKnownFourComponents(fGeoData[0].fColor); 777 out->setKnownFourComponents(fGeoData[0].fColor);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 batchTarget->draw(drawInfo); 891 batchTarget->draw(drawInfo);
889 } 892 }
890 893
891 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 894 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
892 895
893 private: 896 private:
894 DrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType, 897 DrawVerticesBatch(const Geometry& geometry, GrPrimitiveType primitiveType,
895 const SkMatrix& viewMatrix, 898 const SkMatrix& viewMatrix,
896 const SkPoint* positions, int vertexCount, 899 const SkPoint* positions, int vertexCount,
897 const uint16_t* indices, int indexCount, 900 const uint16_t* indices, int indexCount,
898 const GrColor* colors, const SkPoint* localCoords) { 901 const GrColor* colors, const SkPoint* localCoords, const S kRect& bounds) {
899 this->initClassID<DrawVerticesBatch>(); 902 this->initClassID<DrawVerticesBatch>();
900 SkASSERT(positions); 903 SkASSERT(positions);
901 904
902 fBatch.fViewMatrix = viewMatrix; 905 fBatch.fViewMatrix = viewMatrix;
903 Geometry& installedGeo = fGeoData.push_back(geometry); 906 Geometry& installedGeo = fGeoData.push_back(geometry);
904 907
905 installedGeo.fPositions.append(vertexCount, positions); 908 installedGeo.fPositions.append(vertexCount, positions);
906 if (indices) { 909 if (indices) {
907 installedGeo.fIndices.append(indexCount, indices); 910 installedGeo.fIndices.append(indexCount, indices);
908 fBatch.fHasIndices = true; 911 fBatch.fHasIndices = true;
(...skipping 10 matching lines...) Expand all
919 922
920 if (localCoords) { 923 if (localCoords) {
921 installedGeo.fLocalCoords.append(vertexCount, localCoords); 924 installedGeo.fLocalCoords.append(vertexCount, localCoords);
922 fBatch.fHasLocalCoords = true; 925 fBatch.fHasLocalCoords = true;
923 } else { 926 } else {
924 fBatch.fHasLocalCoords = false; 927 fBatch.fHasLocalCoords = false;
925 } 928 }
926 fBatch.fVertexCount = vertexCount; 929 fBatch.fVertexCount = vertexCount;
927 fBatch.fIndexCount = indexCount; 930 fBatch.fIndexCount = indexCount;
928 fBatch.fPrimitiveType = primitiveType; 931 fBatch.fPrimitiveType = primitiveType;
932
933 this->setBounds(bounds);
929 } 934 }
930 935
931 GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; } 936 GrPrimitiveType primitiveType() const { return fBatch.fPrimitiveType; }
932 bool batchablePrimitiveType() const { 937 bool batchablePrimitiveType() const {
933 return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType || 938 return kTriangles_GrPrimitiveType == fBatch.fPrimitiveType ||
934 kLines_GrPrimitiveType == fBatch.fPrimitiveType || 939 kLines_GrPrimitiveType == fBatch.fPrimitiveType ||
935 kPoints_GrPrimitiveType == fBatch.fPrimitiveType; 940 kPoints_GrPrimitiveType == fBatch.fPrimitiveType;
936 } 941 }
937 GrColor color() const { return fBatch.fColor; } 942 GrColor color() const { return fBatch.fColor; }
938 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 943 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 if (!this->hasColors() && this->color() != that->color()) { 978 if (!this->hasColors() && this->color() != that->color()) {
974 return false; 979 return false;
975 } 980 }
976 981
977 if (this->color() != that->color()) { 982 if (this->color() != that->color()) {
978 fBatch.fColor = GrColor_ILLEGAL; 983 fBatch.fColor = GrColor_ILLEGAL;
979 } 984 }
980 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 985 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ;
981 fBatch.fVertexCount += that->vertexCount(); 986 fBatch.fVertexCount += that->vertexCount();
982 fBatch.fIndexCount += that->indexCount(); 987 fBatch.fIndexCount += that->indexCount();
988
989 this->joinBounds(that->bounds());
983 return true; 990 return true;
984 } 991 }
985 992
986 struct BatchTracker { 993 struct BatchTracker {
987 GrPrimitiveType fPrimitiveType; 994 GrPrimitiveType fPrimitiveType;
988 SkMatrix fViewMatrix; 995 SkMatrix fViewMatrix;
989 GrColor fColor; 996 GrColor fColor;
990 bool fUsesLocalCoords; 997 bool fUsesLocalCoords;
991 bool fColorIgnored; 998 bool fColorIgnored;
992 bool fCoverageIgnored; 999 bool fCoverageIgnored;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 1032
1026 // TODO clients should give us bounds 1033 // TODO clients should give us bounds
1027 SkRect bounds; 1034 SkRect bounds;
1028 if (!bounds.setBoundsCheck(positions, vertexCount)) { 1035 if (!bounds.setBoundsCheck(positions, vertexCount)) {
1029 SkDebugf("drawVertices call empty bounds\n"); 1036 SkDebugf("drawVertices call empty bounds\n");
1030 return; 1037 return;
1031 } 1038 }
1032 1039
1033 DrawVerticesBatch::Geometry geometry; 1040 DrawVerticesBatch::Geometry geometry;
1034 geometry.fColor = paint.getColor(); 1041 geometry.fColor = paint.getColor();
1035
1036 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix, 1042 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix,
1037 positions, vertexCount , indices, 1043 positions, vertexCount , indices,
1038 indexCount,colors, tex Coords)); 1044 indexCount, colors, te xCoords,
1045 bounds));
1039 1046
1040 // TODO figure out bounds 1047 target->drawBatch(&pipelineBuilder, batch);
1041 target->drawBatch(&pipelineBuilder, batch, &bounds);
1042 } 1048 }
1043 1049
1044 /////////////////////////////////////////////////////////////////////////////// 1050 ///////////////////////////////////////////////////////////////////////////////
1045 1051
1046 void GrContext::drawRRect(GrRenderTarget*rt, 1052 void GrContext::drawRRect(GrRenderTarget*rt,
1047 const GrClip& clip, 1053 const GrClip& clip,
1048 const GrPaint& paint, 1054 const GrPaint& paint,
1049 const SkMatrix& viewMatrix, 1055 const SkMatrix& viewMatrix,
1050 const SkRRect& rrect, 1056 const SkRRect& rrect,
1051 const GrStrokeInfo& strokeInfo) { 1057 const GrStrokeInfo& strokeInfo) {
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 fDrawBuffer->addGpuTraceMarker(marker); 1909 fDrawBuffer->addGpuTraceMarker(marker);
1904 } 1910 }
1905 } 1911 }
1906 1912
1907 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1913 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1908 fGpu->removeGpuTraceMarker(marker); 1914 fGpu->removeGpuTraceMarker(marker);
1909 if (fDrawBuffer) { 1915 if (fDrawBuffer) {
1910 fDrawBuffer->removeGpuTraceMarker(marker); 1916 fDrawBuffer->removeGpuTraceMarker(marker);
1911 } 1917 }
1912 } 1918 }
OLDNEW
« no previous file with comments | « src/gpu/GrBatch.h ('k') | src/gpu/GrDefaultPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698