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

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

Issue 1131553002: Isolate GrBufferAllocPools inside GrBatchTarget (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: minor cleanup 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
11 #include "GrAARectRenderer.h" 11 #include "GrAARectRenderer.h"
12 #include "GrAtlasTextContext.h" 12 #include "GrAtlasTextContext.h"
13 #include "GrBatch.h" 13 #include "GrBatch.h"
14 #include "GrBatchFontCache.h" 14 #include "GrBatchFontCache.h"
15 #include "GrBatchTarget.h" 15 #include "GrBatchTarget.h"
16 #include "GrBufferAllocPool.h"
17 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
18 #include "GrGpuResource.h" 17 #include "GrGpuResource.h"
19 #include "GrGpuResourcePriv.h" 18 #include "GrGpuResourcePriv.h"
20 #include "GrDrawTargetCaps.h" 19 #include "GrDrawTargetCaps.h"
21 #include "GrGpu.h" 20 #include "GrGpu.h"
22 #include "GrIndexBuffer.h" 21 #include "GrIndexBuffer.h"
23 #include "GrInOrderDrawBuffer.h" 22 #include "GrInOrderDrawBuffer.h"
24 #include "GrLayerCache.h" 23 #include "GrLayerCache.h"
25 #include "GrOvalRenderer.h" 24 #include "GrOvalRenderer.h"
26 #include "GrPathRenderer.h" 25 #include "GrPathRenderer.h"
(...skipping 16 matching lines...) Expand all
43 #include "SkRRect.h" 42 #include "SkRRect.h"
44 #include "SkStrokeRec.h" 43 #include "SkStrokeRec.h"
45 #include "SkTLazy.h" 44 #include "SkTLazy.h"
46 #include "SkTLS.h" 45 #include "SkTLS.h"
47 #include "SkTraceEvent.h" 46 #include "SkTraceEvent.h"
48 47
49 #include "effects/GrConfigConversionEffect.h" 48 #include "effects/GrConfigConversionEffect.h"
50 #include "effects/GrDashingEffect.h" 49 #include "effects/GrDashingEffect.h"
51 #include "effects/GrSingleTextureEffect.h" 50 #include "effects/GrSingleTextureEffect.h"
52 51
53 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
54 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
55
56 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
57 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
58
59 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 52 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
60 #define RETURN_IF_ABANDONED if (!fDrawBuffer) { return; } 53 #define RETURN_IF_ABANDONED if (!fDrawBuffer) { return; }
61 #define RETURN_FALSE_IF_ABANDONED if (!fDrawBuffer) { return false; } 54 #define RETURN_FALSE_IF_ABANDONED if (!fDrawBuffer) { return false; }
62 #define RETURN_NULL_IF_ABANDONED if (!fDrawBuffer) { return NULL; } 55 #define RETURN_NULL_IF_ABANDONED if (!fDrawBuffer) { return NULL; }
63 56
64 class GrContext::AutoCheckFlush { 57 class GrContext::AutoCheckFlush {
65 public: 58 public:
66 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } 59 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
67 60
68 ~AutoCheckFlush() { 61 ~AutoCheckFlush() {
(...skipping 24 matching lines...) Expand all
93 } 86 }
94 87
95 GrContext::GrContext(const Options& opts) : fOptions(opts) { 88 GrContext::GrContext(const Options& opts) : fOptions(opts) {
96 fGpu = NULL; 89 fGpu = NULL;
97 fResourceCache = NULL; 90 fResourceCache = NULL;
98 fResourceProvider = NULL; 91 fResourceProvider = NULL;
99 fPathRendererChain = NULL; 92 fPathRendererChain = NULL;
100 fSoftwarePathRenderer = NULL; 93 fSoftwarePathRenderer = NULL;
101 fBatchFontCache = NULL; 94 fBatchFontCache = NULL;
102 fDrawBuffer = NULL; 95 fDrawBuffer = NULL;
103 fDrawBufferVBAllocPool = NULL;
104 fDrawBufferIBAllocPool = NULL;
105 fFlushToReduceCacheSize = false; 96 fFlushToReduceCacheSize = false;
106 fAARectRenderer = NULL; 97 fAARectRenderer = NULL;
107 fOvalRenderer = NULL; 98 fOvalRenderer = NULL;
108 fMaxTextureSizeOverride = 1 << 20; 99 fMaxTextureSizeOverride = 1 << 20;
109 } 100 }
110 101
111 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 102 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
112 SkASSERT(NULL == fGpu); 103 SkASSERT(NULL == fGpu);
113 104
114 fGpu = GrGpu::Create(backend, backendContext, this); 105 fGpu = GrGpu::Create(backend, backendContext, this);
115 if (NULL == fGpu) { 106 if (NULL == fGpu) {
116 return false; 107 return false;
117 } 108 }
118 this->initCommon(); 109 this->initCommon();
119 return true; 110 return true;
120 } 111 }
121 112
122 void GrContext::initCommon() { 113 void GrContext::initCommon() {
123 fResourceCache = SkNEW(GrResourceCache); 114 fResourceCache = SkNEW(GrResourceCache);
124 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); 115 fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
125 fResourceProvider = SkNEW_ARGS(GrResourceProvider, (fGpu, fResourceCache)); 116 fResourceProvider = SkNEW_ARGS(GrResourceProvider, (fGpu, fResourceCache));
126 117
127 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 118 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
128 119
129 fAARectRenderer = SkNEW(GrAARectRenderer); 120 fAARectRenderer = SkNEW(GrAARectRenderer);
130 fOvalRenderer = SkNEW(GrOvalRenderer); 121 fOvalRenderer = SkNEW(GrOvalRenderer);
131 122
132 fDidTestPMConversions = false; 123 fDidTestPMConversions = false;
133 124
134 this->setupDrawBuffer(); 125 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this));
135 126
136 // GrBatchFontCache will eventually replace GrFontCache 127 // GrBatchFontCache will eventually replace GrFontCache
137 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this)); 128 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this));
138 129
139 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB, this))); 130 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB, this)));
140 } 131 }
141 132
142 GrContext::~GrContext() { 133 GrContext::~GrContext() {
143 if (NULL == fGpu) { 134 if (NULL == fGpu) {
144 return; 135 return;
145 } 136 }
146 137
147 this->flush(); 138 this->flush();
148 139
149 for (int i = 0; i < fCleanUpData.count(); ++i) { 140 for (int i = 0; i < fCleanUpData.count(); ++i) {
150 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 141 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
151 } 142 }
152 143
153 SkDELETE(fResourceProvider); 144 SkDELETE(fResourceProvider);
154 SkDELETE(fResourceCache); 145 SkDELETE(fResourceCache);
155 SkDELETE(fBatchFontCache); 146 SkDELETE(fBatchFontCache);
156 SkDELETE(fDrawBuffer); 147 SkDELETE(fDrawBuffer);
157 SkDELETE(fDrawBufferVBAllocPool);
158 SkDELETE(fDrawBufferIBAllocPool);
159 148
160 fAARectRenderer->unref(); 149 fAARectRenderer->unref();
161 fOvalRenderer->unref(); 150 fOvalRenderer->unref();
162 151
163 fGpu->unref(); 152 fGpu->unref();
164 SkSafeUnref(fPathRendererChain); 153 SkSafeUnref(fPathRendererChain);
165 SkSafeUnref(fSoftwarePathRenderer); 154 SkSafeUnref(fSoftwarePathRenderer);
166 } 155 }
167 156
168 void GrContext::abandonContext() { 157 void GrContext::abandonContext() {
169 fResourceProvider->abandon(); 158 fResourceProvider->abandon();
170 // abandon first to so destructors 159 // abandon first to so destructors
171 // don't try to free the resources in the API. 160 // don't try to free the resources in the API.
172 fResourceCache->abandonAll(); 161 fResourceCache->abandonAll();
173 162
174 fGpu->contextAbandoned(); 163 fGpu->contextAbandoned();
175 164
176 // a path renderer may be holding onto resources that 165 // a path renderer may be holding onto resources that
177 // are now unusable 166 // are now unusable
178 SkSafeSetNull(fPathRendererChain); 167 SkSafeSetNull(fPathRendererChain);
179 SkSafeSetNull(fSoftwarePathRenderer); 168 SkSafeSetNull(fSoftwarePathRenderer);
180 169
181 delete fDrawBuffer; 170 SkDELETE(fDrawBuffer);
182 fDrawBuffer = NULL; 171 fDrawBuffer = NULL;
183 172
184 delete fDrawBufferVBAllocPool;
185 fDrawBufferVBAllocPool = NULL;
186
187 delete fDrawBufferIBAllocPool;
188 fDrawBufferIBAllocPool = NULL;
189
190 fBatchFontCache->freeAll(); 173 fBatchFontCache->freeAll();
191 fLayerCache->freeAll(); 174 fLayerCache->freeAll();
192 fTextBlobCache->freeAll(); 175 fTextBlobCache->freeAll();
193 } 176 }
194 177
195 void GrContext::resetContext(uint32_t state) { 178 void GrContext::resetContext(uint32_t state) {
196 fGpu->markContextDirty(state); 179 fGpu->markContextDirty(state);
197 } 180 }
198 181
199 void GrContext::freeGpuResources() { 182 void GrContext::freeGpuResources() {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 Geometry& args = fGeoData[0]; 450 Geometry& args = fGeoData[0];
468 451
469 int vertexCount = kVertsPerHairlineRect; 452 int vertexCount = kVertsPerHairlineRect;
470 if (args.fStrokeWidth > 0) { 453 if (args.fStrokeWidth > 0) {
471 vertexCount = kVertsPerStrokeRect; 454 vertexCount = kVertsPerStrokeRect;
472 } 455 }
473 456
474 const GrVertexBuffer* vertexBuffer; 457 const GrVertexBuffer* vertexBuffer;
475 int firstVertex; 458 int firstVertex;
476 459
477 void* verts = batchTarget->vertexPool()->makeSpace(vertexStride, 460 void* verts = batchTarget->makeVertSpace(vertexStride, vertexCount,
478 vertexCount, 461 &vertexBuffer, &firstVertex);
479 &vertexBuffer,
480 &firstVertex);
481 462
482 if (!verts) { 463 if (!verts) {
483 SkDebugf("Could not allocate vertices\n"); 464 SkDebugf("Could not allocate vertices\n");
484 return; 465 return;
485 } 466 }
486 467
487 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); 468 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts);
488 469
489 GrPrimitiveType primType; 470 GrPrimitiveType primType;
490 471
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 size_t vertexStride = gp->getVertexStride(); 786 size_t vertexStride = gp->getVertexStride();
806 787
807 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? siz eof(SkPoint) : 0) 788 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? siz eof(SkPoint) : 0)
808 + (this->hasColors() ? sizeof(G rColor) : 0)); 789 + (this->hasColors() ? sizeof(G rColor) : 0));
809 790
810 int instanceCount = fGeoData.count(); 791 int instanceCount = fGeoData.count();
811 792
812 const GrVertexBuffer* vertexBuffer; 793 const GrVertexBuffer* vertexBuffer;
813 int firstVertex; 794 int firstVertex;
814 795
815 void* verts = batchTarget->vertexPool()->makeSpace(vertexStride, 796 void* verts = batchTarget->makeVertSpace(vertexStride, this->vertexCount (),
816 this->vertexCount(), 797 &vertexBuffer, &firstVertex);
817 &vertexBuffer,
818 &firstVertex);
819 798
820 if (!verts) { 799 if (!verts) {
821 SkDebugf("Could not allocate vertices\n"); 800 SkDebugf("Could not allocate vertices\n");
822 return; 801 return;
823 } 802 }
824 803
825 const GrIndexBuffer* indexBuffer = NULL; 804 const GrIndexBuffer* indexBuffer = NULL;
826 int firstIndex = 0; 805 int firstIndex = 0;
827 806
828 void* indices = NULL; 807 uint16_t* indices = NULL;
829 if (this->hasIndices()) { 808 if (this->hasIndices()) {
830 indices = batchTarget->indexPool()->makeSpace(this->indexCount(), 809 indices = batchTarget->makeIndexSpace(this->indexCount(), &indexBuff er, &firstIndex);
831 &indexBuffer,
832 &firstIndex);
833 810
834 if (!indices) { 811 if (!indices) {
835 SkDebugf("Could not allocate indices\n"); 812 SkDebugf("Could not allocate indices\n");
836 return; 813 return;
837 } 814 }
838 } 815 }
839 816
840 int indexOffset = 0; 817 int indexOffset = 0;
841 int vertexOffset = 0; 818 int vertexOffset = 0;
842 for (int i = 0; i < instanceCount; i++) { 819 for (int i = 0; i < instanceCount; i++) {
843 const Geometry& args = fGeoData[i]; 820 const Geometry& args = fGeoData[i];
844 821
845 // TODO we can actually cache this interleaved and then just memcopy 822 // TODO we can actually cache this interleaved and then just memcopy
846 if (this->hasIndices()) { 823 if (this->hasIndices()) {
847 for (int j = 0; j < args.fIndices.count(); ++j, ++indexOffset) { 824 for (int j = 0; j < args.fIndices.count(); ++j, ++indexOffset) {
848 *((uint16_t*)indices + indexOffset) = args.fIndices[j] + ver texOffset; 825 *(indices + indexOffset) = args.fIndices[j] + vertexOffset;
849 } 826 }
850 } 827 }
851 828
852 for (int j = 0; j < args.fPositions.count(); ++j) { 829 for (int j = 0; j < args.fPositions.count(); ++j) {
853 *((SkPoint*)verts) = args.fPositions[j]; 830 *((SkPoint*)verts) = args.fPositions[j];
854 if (this->hasColors()) { 831 if (this->hasColors()) {
855 *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j] ; 832 *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j] ;
856 } 833 }
857 if (this->hasLocalCoords()) { 834 if (this->hasLocalCoords()) {
858 *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords [j]; 835 *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords [j];
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 if (dpi >= 250.0f) { 1774 if (dpi >= 250.0f) {
1798 chosenSampleCount = 4; 1775 chosenSampleCount = 4;
1799 } else { 1776 } else {
1800 chosenSampleCount = 16; 1777 chosenSampleCount = 16;
1801 } 1778 }
1802 } 1779 }
1803 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? 1780 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ?
1804 chosenSampleCount : 0; 1781 chosenSampleCount : 0;
1805 } 1782 }
1806 1783
1807 void GrContext::setupDrawBuffer() {
1808 SkASSERT(NULL == fDrawBuffer);
1809 SkASSERT(NULL == fDrawBufferVBAllocPool);
1810 SkASSERT(NULL == fDrawBufferIBAllocPool);
1811
1812 fDrawBufferVBAllocPool =
1813 SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu,
1814 DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
1815 DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS ));
1816 fDrawBufferIBAllocPool =
1817 SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu,
1818 DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
1819 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS) );
1820
1821 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (this,
1822 fDrawBufferVBAllocPool,
1823 fDrawBufferIBAllocPool));
1824 }
1825
1826 GrDrawTarget* GrContext::getTextTarget() { 1784 GrDrawTarget* GrContext::getTextTarget() {
1827 return this->prepareToDraw(); 1785 return this->prepareToDraw();
1828 } 1786 }
1829 1787
1830 namespace { 1788 namespace {
1831 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { 1789 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
1832 GrConfigConversionEffect::PMConversion pmToUPM; 1790 GrConfigConversionEffect::PMConversion pmToUPM;
1833 GrConfigConversionEffect::PMConversion upmToPM; 1791 GrConfigConversionEffect::PMConversion upmToPM;
1834 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm ToPM); 1792 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm ToPM);
1835 *pmToUPMValue = pmToUPM; 1793 *pmToUPMValue = pmToUPM;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 fDrawBuffer->addGpuTraceMarker(marker); 1850 fDrawBuffer->addGpuTraceMarker(marker);
1893 } 1851 }
1894 } 1852 }
1895 1853
1896 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1854 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1897 fGpu->removeGpuTraceMarker(marker); 1855 fGpu->removeGpuTraceMarker(marker);
1898 if (fDrawBuffer) { 1856 if (fDrawBuffer) {
1899 fDrawBuffer->removeGpuTraceMarker(marker); 1857 fDrawBuffer->removeGpuTraceMarker(marker);
1900 } 1858 }
1901 } 1859 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698