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

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

Issue 921453002: Rename GrResourceCache2 to GrResourceCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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/GrClipMaskManager.h ('k') | src/gpu/GrGpu.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
11 #include "GrAARectRenderer.h" 11 #include "GrAARectRenderer.h"
12 #include "GrBufferAllocPool.h" 12 #include "GrBufferAllocPool.h"
13 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
14 #include "GrFontCache.h" 14 #include "GrFontCache.h"
15 #include "GrGpuResource.h" 15 #include "GrGpuResource.h"
16 #include "GrGpuResourceCacheAccess.h" 16 #include "GrGpuResourceCacheAccess.h"
17 #include "GrDistanceFieldTextContext.h" 17 #include "GrDistanceFieldTextContext.h"
18 #include "GrDrawTargetCaps.h" 18 #include "GrDrawTargetCaps.h"
19 #include "GrGpu.h" 19 #include "GrGpu.h"
20 #include "GrIndexBuffer.h" 20 #include "GrIndexBuffer.h"
21 #include "GrInOrderDrawBuffer.h" 21 #include "GrInOrderDrawBuffer.h"
22 #include "GrLayerCache.h" 22 #include "GrLayerCache.h"
23 #include "GrOvalRenderer.h" 23 #include "GrOvalRenderer.h"
24 #include "GrPathRenderer.h" 24 #include "GrPathRenderer.h"
25 #include "GrPathUtils.h" 25 #include "GrPathUtils.h"
26 #include "GrResourceCache2.h" 26 #include "GrResourceCache.h"
27 #include "GrSoftwarePathRenderer.h" 27 #include "GrSoftwarePathRenderer.h"
28 #include "GrStencilAndCoverTextContext.h" 28 #include "GrStencilAndCoverTextContext.h"
29 #include "GrStrokeInfo.h" 29 #include "GrStrokeInfo.h"
30 #include "GrSurfacePriv.h" 30 #include "GrSurfacePriv.h"
31 #include "GrTexturePriv.h" 31 #include "GrTexturePriv.h"
32 #include "GrTraceMarker.h" 32 #include "GrTraceMarker.h"
33 #include "GrTracing.h" 33 #include "GrTracing.h"
34 #include "SkDashPathPriv.h" 34 #include "SkDashPathPriv.h"
35 #include "SkConfig8888.h" 35 #include "SkConfig8888.h"
36 #include "SkGr.h" 36 #include "SkGr.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 context->unref(); 81 context->unref();
82 return NULL; 82 return NULL;
83 } 83 }
84 } 84 }
85 85
86 GrContext::GrContext(const Options& opts) : fOptions(opts) { 86 GrContext::GrContext(const Options& opts) : fOptions(opts) {
87 fGpu = NULL; 87 fGpu = NULL;
88 fClip = NULL; 88 fClip = NULL;
89 fPathRendererChain = NULL; 89 fPathRendererChain = NULL;
90 fSoftwarePathRenderer = NULL; 90 fSoftwarePathRenderer = NULL;
91 fResourceCache2 = NULL; 91 fResourceCache = NULL;
92 fFontCache = NULL; 92 fFontCache = NULL;
93 fDrawBuffer = NULL; 93 fDrawBuffer = NULL;
94 fDrawBufferVBAllocPool = NULL; 94 fDrawBufferVBAllocPool = NULL;
95 fDrawBufferIBAllocPool = NULL; 95 fDrawBufferIBAllocPool = NULL;
96 fFlushToReduceCacheSize = false; 96 fFlushToReduceCacheSize = false;
97 fAARectRenderer = NULL; 97 fAARectRenderer = NULL;
98 fOvalRenderer = NULL; 98 fOvalRenderer = NULL;
99 fMaxTextureSizeOverride = 1 << 20; 99 fMaxTextureSizeOverride = 1 << 20;
100 } 100 }
101 101
102 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 102 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
103 SkASSERT(NULL == fGpu); 103 SkASSERT(NULL == fGpu);
104 104
105 fGpu = GrGpu::Create(backend, backendContext, this); 105 fGpu = GrGpu::Create(backend, backendContext, this);
106 if (NULL == fGpu) { 106 if (NULL == fGpu) {
107 return false; 107 return false;
108 } 108 }
109 this->initCommon(); 109 this->initCommon();
110 return true; 110 return true;
111 } 111 }
112 112
113 void GrContext::initCommon() { 113 void GrContext::initCommon() {
114 fResourceCache2 = SkNEW(GrResourceCache2); 114 fResourceCache = SkNEW(GrResourceCache);
115 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); 115 fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
116 116
117 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); 117 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
118 118
119 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 119 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
120 120
121 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); 121 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
122 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); 122 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu));
123 123
124 fDidTestPMConversions = false; 124 fDidTestPMConversions = false;
125 125
126 this->setupDrawBuffer(); 126 this->setupDrawBuffer();
127 } 127 }
128 128
129 GrContext::~GrContext() { 129 GrContext::~GrContext() {
130 if (NULL == fGpu) { 130 if (NULL == fGpu) {
131 return; 131 return;
132 } 132 }
133 133
134 this->flush(); 134 this->flush();
135 135
136 for (int i = 0; i < fCleanUpData.count(); ++i) { 136 for (int i = 0; i < fCleanUpData.count(); ++i) {
137 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 137 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
138 } 138 }
139 139
140 SkDELETE(fResourceCache2); 140 SkDELETE(fResourceCache);
141 SkDELETE(fFontCache); 141 SkDELETE(fFontCache);
142 SkDELETE(fDrawBuffer); 142 SkDELETE(fDrawBuffer);
143 SkDELETE(fDrawBufferVBAllocPool); 143 SkDELETE(fDrawBufferVBAllocPool);
144 SkDELETE(fDrawBufferIBAllocPool); 144 SkDELETE(fDrawBufferIBAllocPool);
145 145
146 fAARectRenderer->unref(); 146 fAARectRenderer->unref();
147 fOvalRenderer->unref(); 147 fOvalRenderer->unref();
148 148
149 fGpu->unref(); 149 fGpu->unref();
150 SkSafeUnref(fPathRendererChain); 150 SkSafeUnref(fPathRendererChain);
151 SkSafeUnref(fSoftwarePathRenderer); 151 SkSafeUnref(fSoftwarePathRenderer);
152 } 152 }
153 153
154 void GrContext::abandonContext() { 154 void GrContext::abandonContext() {
155 // abandon first to so destructors 155 // abandon first to so destructors
156 // don't try to free the resources in the API. 156 // don't try to free the resources in the API.
157 fResourceCache2->abandonAll(); 157 fResourceCache->abandonAll();
158 158
159 fGpu->contextAbandoned(); 159 fGpu->contextAbandoned();
160 160
161 // a path renderer may be holding onto resources that 161 // a path renderer may be holding onto resources that
162 // are now unusable 162 // are now unusable
163 SkSafeSetNull(fPathRendererChain); 163 SkSafeSetNull(fPathRendererChain);
164 SkSafeSetNull(fSoftwarePathRenderer); 164 SkSafeSetNull(fSoftwarePathRenderer);
165 165
166 delete fDrawBuffer; 166 delete fDrawBuffer;
167 fDrawBuffer = NULL; 167 fDrawBuffer = NULL;
(...skipping 27 matching lines...) Expand all
195 195
196 fFontCache->freeAll(); 196 fFontCache->freeAll();
197 fLayerCache->freeAll(); 197 fLayerCache->freeAll();
198 // a path renderer may be holding onto resources 198 // a path renderer may be holding onto resources
199 SkSafeSetNull(fPathRendererChain); 199 SkSafeSetNull(fPathRendererChain);
200 SkSafeSetNull(fSoftwarePathRenderer); 200 SkSafeSetNull(fSoftwarePathRenderer);
201 } 201 }
202 202
203 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { 203 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
204 if (resourceCount) { 204 if (resourceCount) {
205 *resourceCount = fResourceCache2->getBudgetedResourceCount(); 205 *resourceCount = fResourceCache->getBudgetedResourceCount();
206 } 206 }
207 if (resourceBytes) { 207 if (resourceBytes) {
208 *resourceBytes = fResourceCache2->getBudgetedResourceBytes(); 208 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
209 } 209 }
210 } 210 }
211 211
212 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, 212 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
213 const SkDeviceProperties& 213 const SkDeviceProperties&
214 leakyProperties, 214 leakyProperties,
215 bool enableDistanceFieldFonts) { 215 bool enableDistanceFieldFonts) {
216 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() && 216 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() &&
217 renderTarget->isMultisampled()) { 217 renderTarget->isMultisampled()) {
218 return GrStencilAndCoverTextContext::Create(this, leakyProperties); 218 return GrStencilAndCoverTextContext::Create(this, leakyProperties);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 GrSurfaceDesc* wdesc = desc.writable(); 292 GrSurfaceDesc* wdesc = desc.writable();
293 wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth)); 293 wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth));
294 wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight)); 294 wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight));
295 } 295 }
296 296
297 do { 297 do {
298 GrScratchKey key; 298 GrScratchKey key;
299 GrTexturePriv::ComputeScratchKey(*desc, &key); 299 GrTexturePriv::ComputeScratchKey(*desc, &key);
300 uint32_t scratchFlags = 0; 300 uint32_t scratchFlags = 0;
301 if (kNoPendingIO_ScratchTextureFlag & flags) { 301 if (kNoPendingIO_ScratchTextureFlag & flags) {
302 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag ; 302 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
303 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { 303 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
304 // If it is not a render target then it will most likely be popu lated by 304 // If it is not a render target then it will most likely be popu lated by
305 // writePixels() which will trigger a flush if the texture has p ending IO. 305 // writePixels() which will trigger a flush if the texture has p ending IO.
306 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; 306 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
307 } 307 }
308 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource (key, scratchFlags); 308 GrGpuResource* resource = fResourceCache->findAndRefScratchResource( key, scratchFlags);
309 if (resource) { 309 if (resource) {
310 GrSurface* surface = static_cast<GrSurface*>(resource); 310 GrSurface* surface = static_cast<GrSurface*>(resource);
311 GrRenderTarget* rt = surface->asRenderTarget(); 311 GrRenderTarget* rt = surface->asRenderTarget();
312 if (rt && fGpu->caps()->discardRenderTargetSupport()) { 312 if (rt && fGpu->caps()->discardRenderTargetSupport()) {
313 rt->discard(); 313 rt->discard();
314 } 314 }
315 return surface->asTexture(); 315 return surface->asTexture();
316 } 316 }
317 317
318 if (kExact_ScratchTextureFlag & flags) { 318 if (kExact_ScratchTextureFlag & flags) {
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix); 1562 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix);
1563 } else { 1563 } else {
1564 return NULL; 1564 return NULL;
1565 } 1565 }
1566 } 1566 }
1567 1567
1568 ////////////////////////////////////////////////////////////////////////////// 1568 //////////////////////////////////////////////////////////////////////////////
1569 1569
1570 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const { 1570 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const {
1571 if (maxTextures) { 1571 if (maxTextures) {
1572 *maxTextures = fResourceCache2->getMaxResourceCount(); 1572 *maxTextures = fResourceCache->getMaxResourceCount();
1573 } 1573 }
1574 if (maxTextureBytes) { 1574 if (maxTextureBytes) {
1575 *maxTextureBytes = fResourceCache2->getMaxResourceBytes(); 1575 *maxTextureBytes = fResourceCache->getMaxResourceBytes();
1576 } 1576 }
1577 } 1577 }
1578 1578
1579 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { 1579 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
1580 fResourceCache2->setLimits(maxTextures, maxTextureBytes); 1580 fResourceCache->setLimits(maxTextures, maxTextureBytes);
1581 } 1581 }
1582 1582
1583 bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resou rce) { 1583 bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resou rce) {
1584 ASSERT_OWNED_RESOURCE(resource); 1584 ASSERT_OWNED_RESOURCE(resource);
1585 if (!resource || resource->wasDestroyed()) { 1585 if (!resource || resource->wasDestroyed()) {
1586 return false; 1586 return false;
1587 } 1587 }
1588 return resource->cacheAccess().setContentKey(key); 1588 return resource->cacheAccess().setContentKey(key);
1589 } 1589 }
1590 1590
1591 bool GrContext::isResourceInCache(const GrContentKey& key) const { 1591 bool GrContext::isResourceInCache(const GrContentKey& key) const {
1592 return fResourceCache2->hasContentKey(key); 1592 return fResourceCache->hasContentKey(key);
1593 } 1593 }
1594 1594
1595 GrGpuResource* GrContext::findAndRefCachedResource(const GrContentKey& key) { 1595 GrGpuResource* GrContext::findAndRefCachedResource(const GrContentKey& key) {
1596 return fResourceCache2->findAndRefContentResource(key); 1596 return fResourceCache->findAndRefContentResource(key);
1597 } 1597 }
1598 1598
1599 ////////////////////////////////////////////////////////////////////////////// 1599 //////////////////////////////////////////////////////////////////////////////
1600 1600
1601 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { 1601 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
1602 fGpu->addGpuTraceMarker(marker); 1602 fGpu->addGpuTraceMarker(marker);
1603 if (fDrawBuffer) { 1603 if (fDrawBuffer) {
1604 fDrawBuffer->addGpuTraceMarker(marker); 1604 fDrawBuffer->addGpuTraceMarker(marker);
1605 } 1605 }
1606 } 1606 }
1607 1607
1608 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1608 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1609 fGpu->removeGpuTraceMarker(marker); 1609 fGpu->removeGpuTraceMarker(marker);
1610 if (fDrawBuffer) { 1610 if (fDrawBuffer) {
1611 fDrawBuffer->removeGpuTraceMarker(marker); 1611 fDrawBuffer->removeGpuTraceMarker(marker);
1612 } 1612 }
1613 } 1613 }
1614 1614
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.h ('k') | src/gpu/GrGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698