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

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

Issue 1274013003: Move GrDrawAtlasBatch to separate file (Closed) Base URL: https://skia.googlesource.com/skia.git@drawAtlas-08-06
Patch Set: Move to batches dir Created 5 years, 4 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 | « gyp/gpu.gypi ('k') | src/gpu/batches/GrDrawAtlasBatch.h » ('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 2015 Google Inc. 3 * Copyright 2015 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 "GrAARectRenderer.h" 9 #include "GrAARectRenderer.h"
10 #include "GrAtlasTextContext.h" 10 #include "GrAtlasTextContext.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
14 #include "GrDrawContext.h" 14 #include "GrDrawContext.h"
15 #include "GrOvalRenderer.h" 15 #include "GrOvalRenderer.h"
16 #include "GrPathRenderer.h" 16 #include "GrPathRenderer.h"
17 #include "GrRenderTarget.h" 17 #include "GrRenderTarget.h"
18 #include "GrRenderTargetPriv.h" 18 #include "GrRenderTargetPriv.h"
19 #include "GrStencilAndCoverTextContext.h" 19 #include "GrStencilAndCoverTextContext.h"
20 20
21 #include "batches/GrBatch.h" 21 #include "batches/GrBatch.h"
22 #include "batches/GrDrawAtlasBatch.h"
22 #include "batches/GrStrokeRectBatch.h" 23 #include "batches/GrStrokeRectBatch.h"
23 24
24 #include "SkGr.h" 25 #include "SkGr.h"
25 #include "SkRSXform.h" 26 #include "SkRSXform.h"
26 27
27 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) 28 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext)
28 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } 29 #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; }
29 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } 30 #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; }
30 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } 31 #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; }
31 32
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix, 689 SkAutoTUnref<GrBatch> batch(DrawVerticesBatch::Create(geometry, primitiveTyp e, viewMatrix,
689 positions, vertexCount , indices, 690 positions, vertexCount , indices,
690 indexCount, colors, te xCoords, 691 indexCount, colors, te xCoords,
691 bounds)); 692 bounds));
692 693
693 fDrawTarget->drawBatch(pipelineBuilder, batch); 694 fDrawTarget->drawBatch(pipelineBuilder, batch);
694 } 695 }
695 696
696 /////////////////////////////////////////////////////////////////////////////// 697 ///////////////////////////////////////////////////////////////////////////////
697 698
698 class DrawAtlasBatch : public GrBatch {
699 public:
700 struct Geometry {
701 GrColor fColor;
702 SkTDArray<SkPoint> fPositions;
703 SkTDArray<GrColor> fColors;
704 SkTDArray<SkPoint> fLocalCoords;
705 };
706
707 static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
708 const SkPoint* positions, int vertexCount,
709 const GrColor* colors, const SkPoint* localCoords,
710 const SkRect& bounds) {
711 return SkNEW_ARGS(DrawAtlasBatch, (geometry, viewMatrix, positions,
712 vertexCount, colors, localCoords, bou nds));
713 }
714
715 const char* name() const override { return "DrawAtlasBatch"; }
716
717 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
718 // When this is called on a batch, there is only one geometry bundle
719 if (this->hasColors()) {
720 out->setUnknownFourComponents();
721 } else {
722 out->setKnownFourComponents(fGeoData[0].fColor);
723 }
724 }
725
726 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
727 out->setKnownSingleComponent(0xff);
728 }
729
730 void initBatchTracker(const GrPipelineInfo& init) override {
731 // Handle any color overrides
732 if (!init.readsColor()) {
733 fGeoData[0].fColor = GrColor_ILLEGAL;
734 }
735 init.getOverrideColorIfSet(&fGeoData[0].fColor);
736
737 // setup batch properties
738 fColorIgnored = !init.readsColor();
739 fColor = fGeoData[0].fColor;
740 SkASSERT(init.readsLocalCoords());
741 fCoverageIgnored = !init.readsCoverage();
742 }
743
744 void generateGeometry(GrBatchTarget* batchTarget) override {
745 int colorOffset = -1, texOffset = -1;
746 // Setup geometry processor
747 SkAutoTUnref<const GrGeometryProcessor> gp(
748 set_vertex_attributes(true, this->hasColors(), & colorOffset,
749 &texOffset, this->color(), this->viewMatrix(),
750 this->coverageIgnored()));
751
752 batchTarget->initDraw(gp, this->pipeline());
753
754 int instanceCount = fGeoData.count();
755 size_t vertexStride = gp->getVertexStride();
756 SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint)
757 + (this->hasColors() ? sizeof(GrColor) : 0));
758
759 QuadHelper helper;
760 int numQuads = this->vertexCount()/4;
761 void* verts = helper.init(batchTarget, vertexStride, numQuads);
762 if (!verts) {
763 SkDebugf("Could not allocate vertices\n");
764 return;
765 }
766
767 int vertexOffset = 0;
768 for (int i = 0; i < instanceCount; i++) {
769 const Geometry& args = fGeoData[i];
770
771 for (int j = 0; j < args.fPositions.count(); ++j) {
772 *((SkPoint*)verts) = args.fPositions[j];
773 if (this->hasColors()) {
774 *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j] ;
775 }
776 *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords[j];
777 verts = (void*)((intptr_t)verts + vertexStride);
778 vertexOffset++;
779 }
780 }
781 helper.issueDraw(batchTarget);
782 }
783
784 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
785
786 private:
787 DrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix,
788 const SkPoint* positions, int vertexCount,
789 const GrColor* colors, const SkPoint* localCoords, const SkRe ct& bounds) {
790 this->initClassID<DrawVerticesBatch>();
791 SkASSERT(positions);
792 SkASSERT(localCoords);
793
794 fViewMatrix = viewMatrix;
795 Geometry& installedGeo = fGeoData.push_back(geometry);
796
797 installedGeo.fPositions.append(vertexCount, positions);
798
799 if (colors) {
800 installedGeo.fColors.append(vertexCount, colors);
801 fHasColors = true;
802 } else {
803 fHasColors = false;
804 }
805
806 installedGeo.fLocalCoords.append(vertexCount, localCoords);
807 fVertexCount = vertexCount;
808
809 this->setBounds(bounds);
810 }
811
812 GrColor color() const { return fColor; }
813 bool colorIgnored() const { return fColorIgnored; }
814 const SkMatrix& viewMatrix() const { return fViewMatrix; }
815 bool hasColors() const { return fHasColors; }
816 int vertexCount() const { return fVertexCount; }
817 bool coverageIgnored() const { return fCoverageIgnored; }
818
819 bool onCombineIfPossible(GrBatch* t) override {
820 if (!this->pipeline()->isEqual(*t->pipeline())) {
821 return false;
822 }
823
824 DrawAtlasBatch* that = t->cast<DrawAtlasBatch>();
825
826 // We currently use a uniform viewmatrix for this batch
827 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
828 return false;
829 }
830
831 if (this->hasColors() != that->hasColors()) {
832 return false;
833 }
834
835 if (!this->hasColors() && this->color() != that->color()) {
836 return false;
837 }
838
839 if (this->color() != that->color()) {
840 fColor = GrColor_ILLEGAL;
841 }
842 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ;
843 fVertexCount += that->vertexCount();
844
845 this->joinBounds(that->bounds());
846 return true;
847 }
848
849 SkSTArray<1, Geometry, true> fGeoData;
850
851 SkMatrix fViewMatrix;
852 GrColor fColor;
853 int fVertexCount;
854 bool fColorIgnored;
855 bool fCoverageIgnored;
856 bool fHasColors;
857 };
858
859 void GrDrawContext::drawAtlas(GrRenderTarget* rt, 699 void GrDrawContext::drawAtlas(GrRenderTarget* rt,
860 const GrClip& clip, 700 const GrClip& clip,
861 const GrPaint& paint, 701 const GrPaint& paint,
862 const SkMatrix& viewMatrix, 702 const SkMatrix& viewMatrix,
863 int spriteCount, 703 int spriteCount,
864 const SkRSXform xform[], 704 const SkRSXform xform[],
865 const SkRect texRect[], 705 const SkRect texRect[],
866 const SkColor colors[]) { 706 const SkColor colors[]) {
867 RETURN_IF_ABANDONED 707 RETURN_IF_ABANDONED
868 AutoCheckFlush acf(fContext); 708 AutoCheckFlush acf(fContext);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 758
919 vertCols[0] = vertCols[1] = vertCols[2] = vertCols[3] = grColor; 759 vertCols[0] = vertCols[1] = vertCols[2] = vertCols[3] = grColor;
920 vertCols += 4; 760 vertCols += 4;
921 } 761 }
922 } 762 }
923 763
924 verts = vertStorage.get(); 764 verts = vertStorage.get();
925 texs = verts + vertCount; 765 texs = verts + vertCount;
926 vertCols = colorStorage.get(); 766 vertCols = colorStorage.get();
927 767
928 DrawAtlasBatch::Geometry geometry; 768 GrDrawAtlasBatch::Geometry geometry;
929 geometry.fColor = paint.getColor(); 769 geometry.fColor = paint.getColor();
930 SkAutoTUnref<GrBatch> batch(DrawAtlasBatch::Create(geometry, viewMatrix, ver ts, vertCount, 770 SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, v erts, vertCount,
931 vertCols, texs, bounds)); 771 vertCols, texs, bounds) );
932 772
933 fDrawTarget->drawBatch(pipelineBuilder, batch); 773 fDrawTarget->drawBatch(pipelineBuilder, batch);
934 } 774 }
935 775
936 /////////////////////////////////////////////////////////////////////////////// 776 ///////////////////////////////////////////////////////////////////////////////
937 777
938 void GrDrawContext::drawRRect(GrRenderTarget*rt, 778 void GrDrawContext::drawRRect(GrRenderTarget*rt,
939 const GrClip& clip, 779 const GrClip& clip,
940 const GrPaint& paint, 780 const GrPaint& paint,
941 const SkMatrix& viewMatrix, 781 const SkMatrix& viewMatrix,
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 return DrawVerticesBatch::Create(geometry, type, viewMatrix, 1219 return DrawVerticesBatch::Create(geometry, type, viewMatrix,
1380 positions.begin(), vertexCount, 1220 positions.begin(), vertexCount,
1381 indices.begin(), hasIndices ? vertexCount : 0, 1221 indices.begin(), hasIndices ? vertexCount : 0,
1382 colors.begin(), 1222 colors.begin(),
1383 texCoords.begin(), 1223 texCoords.begin(),
1384 bounds); 1224 bounds);
1385 } 1225 }
1386 1226
1387 #endif 1227 #endif
1388 1228
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/batches/GrDrawAtlasBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698