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

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

Issue 716143004: Replace GrResourceCache with GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix asserts Created 6 years, 1 month 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/GrBufferAllocPool.cpp ('k') | src/gpu/GrGpuResource.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 "effects/GrConfigConversionEffect.h" 11 #include "effects/GrConfigConversionEffect.h"
12 #include "effects/GrDashingEffect.h" 12 #include "effects/GrDashingEffect.h"
13 #include "effects/GrSingleTextureEffect.h" 13 #include "effects/GrSingleTextureEffect.h"
14 14
15 #include "GrAARectRenderer.h" 15 #include "GrAARectRenderer.h"
16 #include "GrBufferAllocPool.h" 16 #include "GrBufferAllocPool.h"
17 #include "GrGpu.h" 17 #include "GrGpu.h"
18 #include "GrGpuResource.h" 18 #include "GrGpuResource.h"
19 #include "GrGpuResourceCacheAccess.h" 19 #include "GrGpuResourceCacheAccess.h"
20 #include "GrDistanceFieldTextContext.h" 20 #include "GrDistanceFieldTextContext.h"
21 #include "GrDrawTargetCaps.h" 21 #include "GrDrawTargetCaps.h"
22 #include "GrIndexBuffer.h" 22 #include "GrIndexBuffer.h"
23 #include "GrInOrderDrawBuffer.h" 23 #include "GrInOrderDrawBuffer.h"
24 #include "GrLayerCache.h" 24 #include "GrLayerCache.h"
25 #include "GrOvalRenderer.h" 25 #include "GrOvalRenderer.h"
26 #include "GrPathRenderer.h" 26 #include "GrPathRenderer.h"
27 #include "GrPathUtils.h" 27 #include "GrPathUtils.h"
28 #include "GrResourceCache.h"
29 #include "GrResourceCache2.h" 28 #include "GrResourceCache2.h"
30 #include "GrSoftwarePathRenderer.h" 29 #include "GrSoftwarePathRenderer.h"
31 #include "GrStencilBuffer.h" 30 #include "GrStencilBuffer.h"
32 #include "GrStencilAndCoverTextContext.h" 31 #include "GrStencilAndCoverTextContext.h"
33 #include "GrStrokeInfo.h" 32 #include "GrStrokeInfo.h"
34 #include "GrSurfacePriv.h" 33 #include "GrSurfacePriv.h"
35 #include "GrTextStrike.h" 34 #include "GrTextStrike.h"
36 #include "GrTexturePriv.h" 35 #include "GrTexturePriv.h"
37 #include "GrTraceMarker.h" 36 #include "GrTraceMarker.h"
38 #include "GrTracing.h" 37 #include "GrTracing.h"
39 #include "SkDashPathPriv.h" 38 #include "SkDashPathPriv.h"
40 #include "SkConfig8888.h" 39 #include "SkConfig8888.h"
41 #include "SkGr.h" 40 #include "SkGr.h"
42 #include "SkRRect.h" 41 #include "SkRRect.h"
43 #include "SkStrokeRec.h" 42 #include "SkStrokeRec.h"
44 #include "SkTLazy.h" 43 #include "SkTLazy.h"
45 #include "SkTLS.h" 44 #include "SkTLS.h"
46 #include "SkTraceEvent.h" 45 #include "SkTraceEvent.h"
47 46
48 #ifdef SK_DEBUG 47 #ifdef SK_DEBUG
49 // change this to a 1 to see notifications when partial coverage fails 48 // change this to a 1 to see notifications when partial coverage fails
50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 49 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
51 #else 50 #else
52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 51 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
53 #endif 52 #endif
54 53
55 static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_L IMIT;
56 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI T * 1024 * 1024;
57
58 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; 54 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
59 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; 55 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
60 56
61 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; 57 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
62 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; 58 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
63 59
64 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 60 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
65 61
66 // Glorified typedef to avoid including GrDrawState.h in GrContext.h 62 // Glorified typedef to avoid including GrDrawState.h in GrContext.h
67 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; 63 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {};
(...skipping 28 matching lines...) Expand all
96 return NULL; 92 return NULL;
97 } 93 }
98 } 94 }
99 95
100 GrContext::GrContext(const Options& opts) : fOptions(opts) { 96 GrContext::GrContext(const Options& opts) : fOptions(opts) {
101 fDrawState = NULL; 97 fDrawState = NULL;
102 fGpu = NULL; 98 fGpu = NULL;
103 fClip = NULL; 99 fClip = NULL;
104 fPathRendererChain = NULL; 100 fPathRendererChain = NULL;
105 fSoftwarePathRenderer = NULL; 101 fSoftwarePathRenderer = NULL;
106 fResourceCache = NULL;
107 fResourceCache2 = NULL; 102 fResourceCache2 = NULL;
108 fFontCache = NULL; 103 fFontCache = NULL;
109 fDrawBuffer = NULL; 104 fDrawBuffer = NULL;
110 fDrawBufferVBAllocPool = NULL; 105 fDrawBufferVBAllocPool = NULL;
111 fDrawBufferIBAllocPool = NULL; 106 fDrawBufferIBAllocPool = NULL;
112 fFlushToReduceCacheSize = false; 107 fFlushToReduceCacheSize = false;
113 fAARectRenderer = NULL; 108 fAARectRenderer = NULL;
114 fOvalRenderer = NULL; 109 fOvalRenderer = NULL;
115 fViewMatrix.reset(); 110 fViewMatrix.reset();
116 fMaxTextureSizeOverride = 1 << 20; 111 fMaxTextureSizeOverride = 1 << 20;
117 } 112 }
118 113
119 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 114 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
120 SkASSERT(NULL == fGpu); 115 SkASSERT(NULL == fGpu);
121 116
122 fGpu = GrGpu::Create(backend, backendContext, this); 117 fGpu = GrGpu::Create(backend, backendContext, this);
123 if (NULL == fGpu) { 118 if (NULL == fGpu) {
124 return false; 119 return false;
125 } 120 }
126 this->initCommon(); 121 this->initCommon();
127 return true; 122 return true;
128 } 123 }
129 124
130 void GrContext::initCommon() { 125 void GrContext::initCommon() {
131 fDrawState = SkNEW(GrDrawState); 126 fDrawState = SkNEW(GrDrawState);
132 127
133 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(),
134 MAX_RESOURCE_CACHE_COUNT,
135 MAX_RESOURCE_CACHE_BYTES));
136 fResourceCache->setOverbudgetCallback(OverbudgetCB, this);
137 fResourceCache2 = SkNEW(GrResourceCache2); 128 fResourceCache2 = SkNEW(GrResourceCache2);
129 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this);
138 130
139 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); 131 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
140 132
141 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 133 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
142 134
143 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); 135 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
144 fOvalRenderer = SkNEW(GrOvalRenderer); 136 fOvalRenderer = SkNEW(GrOvalRenderer);
145 137
146 fDidTestPMConversions = false; 138 fDidTestPMConversions = false;
147 139
148 this->setupDrawBuffer(); 140 this->setupDrawBuffer();
149 } 141 }
150 142
151 GrContext::~GrContext() { 143 GrContext::~GrContext() {
152 if (NULL == fGpu) { 144 if (NULL == fGpu) {
153 return; 145 return;
154 } 146 }
155 147
156 this->flush(); 148 this->flush();
157 149
158 for (int i = 0; i < fCleanUpData.count(); ++i) { 150 for (int i = 0; i < fCleanUpData.count(); ++i) {
159 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 151 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
160 } 152 }
161 153
162 SkDELETE(fResourceCache2); 154 SkDELETE(fResourceCache2);
163 fResourceCache2 = NULL;
164 SkDELETE(fResourceCache);
165 fResourceCache = NULL;
166 SkDELETE(fFontCache); 155 SkDELETE(fFontCache);
167 SkDELETE(fDrawBuffer); 156 SkDELETE(fDrawBuffer);
168 SkDELETE(fDrawBufferVBAllocPool); 157 SkDELETE(fDrawBufferVBAllocPool);
169 SkDELETE(fDrawBufferIBAllocPool); 158 SkDELETE(fDrawBufferIBAllocPool);
170 159
171 fAARectRenderer->unref(); 160 fAARectRenderer->unref();
172 fOvalRenderer->unref(); 161 fOvalRenderer->unref();
173 162
174 fGpu->unref(); 163 fGpu->unref();
175 SkSafeUnref(fPathRendererChain); 164 SkSafeUnref(fPathRendererChain);
(...skipping 18 matching lines...) Expand all
194 183
195 delete fDrawBufferVBAllocPool; 184 delete fDrawBufferVBAllocPool;
196 fDrawBufferVBAllocPool = NULL; 185 fDrawBufferVBAllocPool = NULL;
197 186
198 delete fDrawBufferIBAllocPool; 187 delete fDrawBufferIBAllocPool;
199 fDrawBufferIBAllocPool = NULL; 188 fDrawBufferIBAllocPool = NULL;
200 189
201 fAARectRenderer->reset(); 190 fAARectRenderer->reset();
202 fOvalRenderer->reset(); 191 fOvalRenderer->reset();
203 192
204 fResourceCache->purgeAllUnlocked();
205
206 fFontCache->freeAll(); 193 fFontCache->freeAll();
207 fLayerCache->freeAll(); 194 fLayerCache->freeAll();
208 } 195 }
209 196
210 void GrContext::resetContext(uint32_t state) { 197 void GrContext::resetContext(uint32_t state) {
211 fGpu->markContextDirty(state); 198 fGpu->markContextDirty(state);
212 } 199 }
213 200
214 void GrContext::freeGpuResources() { 201 void GrContext::freeGpuResources() {
215 this->flush(); 202 this->flush();
216 203
217 if (fDrawBuffer) { 204 if (fDrawBuffer) {
218 fDrawBuffer->purgeResources(); 205 fDrawBuffer->purgeResources();
219 } 206 }
220 207
221 fAARectRenderer->reset(); 208 fAARectRenderer->reset();
222 fOvalRenderer->reset(); 209 fOvalRenderer->reset();
223 210
224 fResourceCache->purgeAllUnlocked();
225 fFontCache->freeAll(); 211 fFontCache->freeAll();
226 fLayerCache->freeAll(); 212 fLayerCache->freeAll();
227 // a path renderer may be holding onto resources 213 // a path renderer may be holding onto resources
228 SkSafeSetNull(fPathRendererChain); 214 SkSafeSetNull(fPathRendererChain);
229 SkSafeSetNull(fSoftwarePathRenderer); 215 SkSafeSetNull(fSoftwarePathRenderer);
230 } 216 }
231 217
232 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { 218 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
233 if (resourceCount) { 219 if (resourceCount) {
234 *resourceCount = fResourceCache->getCachedResourceCount(); 220 *resourceCount = fResourceCache2->getResourceCount();
235 } 221 }
236 if (resourceBytes) { 222 if (resourceBytes) {
237 *resourceBytes = fResourceCache->getCachedResourceBytes(); 223 *resourceBytes = fResourceCache2->getResourceBytes();
238 } 224 }
239 } 225 }
240 226
241 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, 227 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
242 const SkDeviceProperties& 228 const SkDeviceProperties&
243 leakyProperties, 229 leakyProperties,
244 bool enableDistanceFieldFonts) { 230 bool enableDistanceFieldFonts) {
245 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() && 231 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() &&
246 renderTarget->isMultisampled()) { 232 renderTarget->isMultisampled()) {
247 return GrStencilAndCoverTextContext::Create(this, leakyProperties); 233 return GrStencilAndCoverTextContext::Create(this, leakyProperties);
248 } 234 }
(...skipping 17 matching lines...) Expand all
266 } 252 }
267 253
268 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, 254 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc,
269 const GrCacheID& cacheID, 255 const GrCacheID& cacheID,
270 const GrTextureParams* params) const { 256 const GrTextureParams* params) const {
271 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID); 257 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID);
272 return fResourceCache2->hasContentKey(resourceKey); 258 return fResourceCache2->hasContentKey(resourceKey);
273 } 259 }
274 260
275 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { 261 void GrContext::addStencilBuffer(GrStencilBuffer* sb) {
262 // TODO: Make GrStencilBuffers use the scratch mechanism rather than content keys.
276 ASSERT_OWNED_RESOURCE(sb); 263 ASSERT_OWNED_RESOURCE(sb);
277 264
278 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), 265 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(),
279 sb->height(), 266 sb->height(),
280 sb->numSamples()); 267 sb->numSamples());
281 fResourceCache->addResource(resourceKey, sb); 268 SkAssertResult(sb->cacheAccess().setContentKey(resourceKey));
282 } 269 }
283 270
284 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s ampleCnt) { 271 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s ampleCnt) {
285 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl eCnt); 272 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl eCnt);
286 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey); 273 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey);
287 return static_cast<GrStencilBuffer*>(resource); 274 return static_cast<GrStencilBuffer*>(resource);
288 } 275 }
289 276
290 static void stretch_image(void* dst, 277 static void stretch_image(void* dst,
291 int dstW, 278 int dstW,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); 400 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
414 401
415 texture = this->createResizedTexture(desc, cacheID, 402 texture = this->createResizedTexture(desc, cacheID,
416 srcData, rowBytes, 403 srcData, rowBytes,
417 GrTexturePriv::NeedsBilerp(resource Key)); 404 GrTexturePriv::NeedsBilerp(resource Key));
418 } else { 405 } else {
419 texture = fGpu->createTexture(desc, srcData, rowBytes); 406 texture = fGpu->createTexture(desc, srcData, rowBytes);
420 } 407 }
421 408
422 if (texture) { 409 if (texture) {
423 fResourceCache->addResource(resourceKey, texture); 410 if (texture->cacheAccess().setContentKey(resourceKey)) {
424 411 if (cacheKey) {
425 if (cacheKey) { 412 *cacheKey = resourceKey;
426 *cacheKey = resourceKey; 413 }
414 } else {
415 texture->unref();
416 texture = NULL;
427 } 417 }
428 } 418 }
429 419
430 return texture; 420 return texture;
431 } 421 }
432 422
433 GrTexture* GrContext::createNewScratchTexture(const GrSurfaceDesc& desc) {
434 GrTexture* texture = fGpu->createTexture(desc, NULL, 0);
435 if (!texture) {
436 return NULL;
437 }
438 fResourceCache->addResource(texture->cacheAccess().getScratchKey(), texture) ;
439 return texture;
440 }
441
442 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM atch match, 423 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM atch match,
443 bool calledDuringFlush) { 424 bool calledDuringFlush) {
444 // kNoStencil has no meaning if kRT isn't set. 425 // kNoStencil has no meaning if kRT isn't set.
445 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || 426 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) ||
446 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); 427 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag));
447 428
448 // Make sure caller has checked for renderability if kRT is set. 429 // Make sure caller has checked for renderability if kRT is set.
449 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || 430 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) ||
450 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); 431 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0));
451 432
(...skipping 14 matching lines...) Expand all
466 uint32_t scratchFlags = 0; 447 uint32_t scratchFlags = 0;
467 if (calledDuringFlush) { 448 if (calledDuringFlush) {
468 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag ; 449 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag ;
469 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { 450 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
470 // If it is not a render target then it will most likely be popu lated by 451 // If it is not a render target then it will most likely be popu lated by
471 // writePixels() which will trigger a flush if the texture has p ending IO. 452 // writePixels() which will trigger a flush if the texture has p ending IO.
472 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; 453 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag;
473 } 454 }
474 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource (key, scratchFlags); 455 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource (key, scratchFlags);
475 if (resource) { 456 if (resource) {
476 fResourceCache->makeResourceMRU(resource);
477 return static_cast<GrSurface*>(resource)->asTexture(); 457 return static_cast<GrSurface*>(resource)->asTexture();
478 } 458 }
479 459
480 if (kExact_ScratchTexMatch == match) { 460 if (kExact_ScratchTexMatch == match) {
481 break; 461 break;
482 } 462 }
483 // We had a cache miss and we are in approx mode, relax the fit of t he flags. 463 // We had a cache miss and we are in approx mode, relax the fit of t he flags.
484 464
485 // We no longer try to reuse textures that were previously used as r ender targets in 465 // We no longer try to reuse textures that were previously used as r ender targets in
486 // situations where no RT is needed; doing otherwise can confuse the video driver and 466 // situations where no RT is needed; doing otherwise can confuse the video driver and
487 // cause significant performance problems in some cases. 467 // cause significant performance problems in some cases.
488 if (desc->fFlags & kNoStencil_GrSurfaceFlag) { 468 if (desc->fFlags & kNoStencil_GrSurfaceFlag) {
489 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag; 469 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag;
490 } else { 470 } else {
491 break; 471 break;
492 } 472 }
493 473
494 } while (true); 474 } while (true);
495 475
496 desc.writable()->fFlags = origFlags; 476 desc.writable()->fFlags = origFlags;
497 } 477 }
498 478
499 GrTexture* texture = this->createNewScratchTexture(*desc); 479 GrTexture* texture = fGpu->createTexture(*desc, NULL, 0);
500 SkASSERT(NULL == texture || 480 SkASSERT(NULL == texture ||
501 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr atchKey(*desc)); 481 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr atchKey(*desc));
502 return texture; 482 return texture;
503 } 483 }
504 484
505 bool GrContext::OverbudgetCB(void* data) { 485 void GrContext::OverBudgetCB(void* data) {
506 SkASSERT(data); 486 SkASSERT(data);
507 487
508 GrContext* context = reinterpret_cast<GrContext*>(data); 488 GrContext* context = reinterpret_cast<GrContext*>(data);
509 489
510 // Flush the InOrderDrawBuffer to possibly free up some textures 490 // Flush the InOrderDrawBuffer to possibly free up some textures
511 context->fFlushToReduceCacheSize = true; 491 context->fFlushToReduceCacheSize = true;
512
513 return true;
514 } 492 }
515 493
516 494
517 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, 495 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn,
518 void* srcData, 496 void* srcData,
519 size_t rowBytes) { 497 size_t rowBytes) {
520 GrSurfaceDesc descCopy = descIn; 498 GrSurfaceDesc descCopy = descIn;
521 return fGpu->createTexture(descCopy, srcData, rowBytes); 499 return fGpu->createTexture(descCopy, srcData, rowBytes);
522 } 500 }
523 501
524 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const { 502 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const {
525 fResourceCache->getLimits(maxTextures, maxTextureBytes); 503 if (maxTextures) {
504 *maxTextures = fResourceCache2->getMaxResourceCount();
505 }
506 if (maxTextureBytes) {
507 *maxTextureBytes = fResourceCache2->getMaxResourceBytes();
508 }
526 } 509 }
527 510
528 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { 511 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
529 fResourceCache->setLimits(maxTextures, maxTextureBytes); 512 fResourceCache2->setLimits(maxTextures, maxTextureBytes);
530 } 513 }
531 514
532 int GrContext::getMaxTextureSize() const { 515 int GrContext::getMaxTextureSize() const {
533 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); 516 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride);
534 } 517 }
535 518
536 int GrContext::getMaxRenderTargetSize() const { 519 int GrContext::getMaxRenderTargetSize() const {
537 return fGpu->caps()->maxRenderTargetSize(); 520 return fGpu->caps()->maxRenderTargetSize();
538 } 521 }
539 522
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 void GrContext::flush(int flagsBitfield) { 1218 void GrContext::flush(int flagsBitfield) {
1236 if (NULL == fDrawBuffer) { 1219 if (NULL == fDrawBuffer) {
1237 return; 1220 return;
1238 } 1221 }
1239 1222
1240 if (kDiscard_FlushBit & flagsBitfield) { 1223 if (kDiscard_FlushBit & flagsBitfield) {
1241 fDrawBuffer->reset(); 1224 fDrawBuffer->reset();
1242 } else { 1225 } else {
1243 fDrawBuffer->flush(); 1226 fDrawBuffer->flush();
1244 } 1227 }
1245 fResourceCache->purgeAsNeeded();
1246 fFlushToReduceCacheSize = false; 1228 fFlushToReduceCacheSize = false;
1247 } 1229 }
1248 1230
1249 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, 1231 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
1250 const void* inPixels, size_t outRowBytes, void* outPix els) { 1232 const void* inPixels, size_t outRowBytes, void* outPix els) {
1251 SkSrcPixelInfo srcPI; 1233 SkSrcPixelInfo srcPI;
1252 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { 1234 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) {
1253 return false; 1235 return false;
1254 } 1236 }
1255 srcPI.fAlphaType = kUnpremul_SkAlphaType; 1237 srcPI.fAlphaType = kUnpremul_SkAlphaType;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 GrConfigConversionEffect::PMConversion upmToPM = 1721 GrConfigConversionEffect::PMConversion upmToPM =
1740 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); 1722 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
1741 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { 1723 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) {
1742 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix); 1724 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix);
1743 } else { 1725 } else {
1744 return NULL; 1726 return NULL;
1745 } 1727 }
1746 } 1728 }
1747 1729
1748 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour ce* resource) { 1730 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour ce* resource) {
1749 fResourceCache->addResource(resourceKey, resource); 1731 resource->cacheAccess().setContentKey(resourceKey);
1750 } 1732 }
1751 1733
1752 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource Key) { 1734 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource Key) {
1753 GrGpuResource* resource = fResourceCache2->findAndRefContentResource(resourc eKey); 1735 return fResourceCache2->findAndRefContentResource(resourceKey);
1754 if (resource) {
1755 fResourceCache->makeResourceMRU(resource);
1756 }
1757 return resource;
1758 } 1736 }
1759 1737
1760 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { 1738 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
1761 fGpu->addGpuTraceMarker(marker); 1739 fGpu->addGpuTraceMarker(marker);
1762 if (fDrawBuffer) { 1740 if (fDrawBuffer) {
1763 fDrawBuffer->addGpuTraceMarker(marker); 1741 fDrawBuffer->addGpuTraceMarker(marker);
1764 } 1742 }
1765 } 1743 }
1766 1744
1767 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1745 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1768 fGpu->removeGpuTraceMarker(marker); 1746 fGpu->removeGpuTraceMarker(marker);
1769 if (fDrawBuffer) { 1747 if (fDrawBuffer) {
1770 fDrawBuffer->removeGpuTraceMarker(marker); 1748 fDrawBuffer->removeGpuTraceMarker(marker);
1771 } 1749 }
1772 } 1750 }
1773 1751
1774 /////////////////////////////////////////////////////////////////////////////// 1752 ///////////////////////////////////////////////////////////////////////////////
1775 #if GR_CACHE_STATS 1753 #if GR_CACHE_STATS
1776 void GrContext::printCacheStats() const { 1754 void GrContext::printCacheStats() const {
1777 fResourceCache->printStats(); 1755 fResourceCache2->printStats();
1778 } 1756 }
1779 #endif 1757 #endif
1780 1758
1781 #if GR_GPU_STATS 1759 #if GR_GPU_STATS
1782 const GrContext::GPUStats* GrContext::gpuStats() const { 1760 const GrContext::GPUStats* GrContext::gpuStats() const {
1783 return fGpu->gpuStats(); 1761 return fGpu->gpuStats();
1784 } 1762 }
1785 #endif 1763 #endif
1786 1764
OLDNEW
« no previous file with comments | « src/gpu/GrBufferAllocPool.cpp ('k') | src/gpu/GrGpuResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698