OLD | NEW |
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 "GrGpuResourcePriv.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 "GrResourceCache.h" | 26 #include "GrResourceCache.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 !this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 242 !this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
243 return NULL; | 243 return NULL; |
244 } | 244 } |
245 if (!GrPixelConfigIsCompressed(desc.fConfig)) { | 245 if (!GrPixelConfigIsCompressed(desc.fConfig)) { |
246 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 246 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
247 kNoCreate_ScratchTextureFlag; | 247 kNoCreate_ScratchTextureFlag; |
248 if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags))
{ | 248 if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags))
{ |
249 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 249 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, |
250 srcData, rowBytes)) { | 250 srcData, rowBytes)) { |
251 if (!budgeted) { | 251 if (!budgeted) { |
252 texture->cacheAccess().makeUnbudgeted(); | 252 texture->resourcePriv().makeUnbudgeted(); |
253 } | 253 } |
254 return texture; | 254 return texture; |
255 } | 255 } |
256 texture->unref(); | 256 texture->unref(); |
257 } | 257 } |
258 } | 258 } |
259 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 259 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); |
260 } | 260 } |
261 | 261 |
262 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMat
ch match, | 262 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMat
ch match, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } else { | 328 } else { |
329 break; | 329 break; |
330 } | 330 } |
331 | 331 |
332 } while (true); | 332 } while (true); |
333 | 333 |
334 desc.writable()->fFlags = origFlags; | 334 desc.writable()->fFlags = origFlags; |
335 } | 335 } |
336 | 336 |
337 if (!(kNoCreate_ScratchTextureFlag & flags)) { | 337 if (!(kNoCreate_ScratchTextureFlag & flags)) { |
338 GrTexture* texture = fGpu->createTexture(*desc, true, NULL, 0); | 338 return fGpu->createTexture(*desc, true, NULL, 0); |
339 #ifdef SK_DEBUG | |
340 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarge
t_GrSurfaceFlag)) { | |
341 GrScratchKey key; | |
342 GrTexturePriv::ComputeScratchKey(*desc, &key); | |
343 SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() =
= key); | |
344 } | |
345 #endif | |
346 return texture; | |
347 } | 339 } |
348 | 340 |
349 return NULL; | 341 return NULL; |
350 } | 342 } |
351 | 343 |
352 void GrContext::OverBudgetCB(void* data) { | 344 void GrContext::OverBudgetCB(void* data) { |
353 SkASSERT(data); | 345 SkASSERT(data); |
354 | 346 |
355 GrContext* context = reinterpret_cast<GrContext*>(data); | 347 GrContext* context = reinterpret_cast<GrContext*>(data); |
356 | 348 |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 | 1570 |
1579 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 1571 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
1580 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 1572 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
1581 } | 1573 } |
1582 | 1574 |
1583 bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resou
rce) { | 1575 bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resou
rce) { |
1584 ASSERT_OWNED_RESOURCE(resource); | 1576 ASSERT_OWNED_RESOURCE(resource); |
1585 if (!resource || resource->wasDestroyed()) { | 1577 if (!resource || resource->wasDestroyed()) { |
1586 return false; | 1578 return false; |
1587 } | 1579 } |
1588 return resource->cacheAccess().setContentKey(key); | 1580 return resource->resourcePriv().setContentKey(key); |
1589 } | 1581 } |
1590 | 1582 |
1591 bool GrContext::isResourceInCache(const GrContentKey& key) const { | 1583 bool GrContext::isResourceInCache(const GrContentKey& key) const { |
1592 return fResourceCache->hasContentKey(key); | 1584 return fResourceCache->hasContentKey(key); |
1593 } | 1585 } |
1594 | 1586 |
1595 GrGpuResource* GrContext::findAndRefCachedResource(const GrContentKey& key) { | 1587 GrGpuResource* GrContext::findAndRefCachedResource(const GrContentKey& key) { |
1596 return fResourceCache->findAndRefContentResource(key); | 1588 return fResourceCache->findAndRefContentResource(key); |
1597 } | 1589 } |
1598 | 1590 |
1599 ////////////////////////////////////////////////////////////////////////////// | 1591 ////////////////////////////////////////////////////////////////////////////// |
1600 | 1592 |
1601 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1593 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1602 fGpu->addGpuTraceMarker(marker); | 1594 fGpu->addGpuTraceMarker(marker); |
1603 if (fDrawBuffer) { | 1595 if (fDrawBuffer) { |
1604 fDrawBuffer->addGpuTraceMarker(marker); | 1596 fDrawBuffer->addGpuTraceMarker(marker); |
1605 } | 1597 } |
1606 } | 1598 } |
1607 | 1599 |
1608 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1600 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
1609 fGpu->removeGpuTraceMarker(marker); | 1601 fGpu->removeGpuTraceMarker(marker); |
1610 if (fDrawBuffer) { | 1602 if (fDrawBuffer) { |
1611 fDrawBuffer->removeGpuTraceMarker(marker); | 1603 fDrawBuffer->removeGpuTraceMarker(marker); |
1612 } | 1604 } |
1613 } | 1605 } |
1614 | 1606 |
OLD | NEW |