| 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 "GrGpuResourcePriv.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 "GrRenderTargetPriv.h" |
| 26 #include "GrResourceCache.h" | 27 #include "GrResourceCache.h" |
| 27 #include "GrSoftwarePathRenderer.h" | 28 #include "GrSoftwarePathRenderer.h" |
| 28 #include "GrStencilAndCoverTextContext.h" | 29 #include "GrStencilAndCoverTextContext.h" |
| 29 #include "GrStrokeInfo.h" | 30 #include "GrStrokeInfo.h" |
| 30 #include "GrSurfacePriv.h" | 31 #include "GrSurfacePriv.h" |
| 31 #include "GrTexturePriv.h" | 32 #include "GrTexturePriv.h" |
| 32 #include "GrTraceMarker.h" | 33 #include "GrTraceMarker.h" |
| 33 #include "GrTracing.h" | 34 #include "GrTracing.h" |
| 34 #include "SkDashPathPriv.h" | 35 #include "SkDashPathPriv.h" |
| 35 #include "SkConfig8888.h" | 36 #include "SkConfig8888.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 207 } |
| 207 if (resourceBytes) { | 208 if (resourceBytes) { |
| 208 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 209 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 | 212 |
| 212 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, | 213 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
| 213 const SkDeviceProperties& | 214 const SkDeviceProperties& |
| 214 leakyProperties, | 215 leakyProperties, |
| 215 bool enableDistanceFieldFonts) { | 216 bool enableDistanceFieldFonts) { |
| 216 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer()
&& | 217 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled())
{ |
| 217 renderTarget->isMultisampled())
{ | 218 GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuff
er(); |
| 218 return GrStencilAndCoverTextContext::Create(this, leakyProperties); | 219 if (sb) { |
| 220 return GrStencilAndCoverTextContext::Create(this, leakyProperties); |
| 221 } |
| 219 } | 222 } |
| 220 | 223 |
| 221 return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDista
nceFieldFonts); | 224 return GrDistanceFieldTextContext::Create(this, leakyProperties, enableDista
nceFieldFonts); |
| 222 } | 225 } |
| 223 | 226 |
| 224 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 225 enum ScratchTextureFlags { | 228 enum ScratchTextureFlags { |
| 226 kExact_ScratchTextureFlag = 0x1, | 229 kExact_ScratchTextureFlag = 0x1, |
| 227 kNoPendingIO_ScratchTextureFlag = 0x2, | 230 kNoPendingIO_ScratchTextureFlag = 0x2, |
| 228 kNoCreate_ScratchTextureFlag = 0x4, | 231 kNoCreate_ScratchTextureFlag = 0x4, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 274 } |
| 272 if (calledDuringFlush) { | 275 if (calledDuringFlush) { |
| 273 flags |= kNoPendingIO_ScratchTextureFlag; | 276 flags |= kNoPendingIO_ScratchTextureFlag; |
| 274 } | 277 } |
| 275 return this->internalRefScratchTexture(desc, flags); | 278 return this->internalRefScratchTexture(desc, flags); |
| 276 } | 279 } |
| 277 } | 280 } |
| 278 | 281 |
| 279 GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uin
t32_t flags) { | 282 GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uin
t32_t flags) { |
| 280 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); | 283 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); |
| 281 // kNoStencil has no meaning if kRT isn't set. | |
| 282 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || | |
| 283 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); | |
| 284 | 284 |
| 285 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); | 285 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); |
| 286 | 286 |
| 287 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr
SurfaceFlag)) { | 287 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr
SurfaceFlag)) { |
| 288 GrSurfaceFlags origFlags = desc->fFlags; | |
| 289 if (!(kExact_ScratchTextureFlag & flags)) { | 288 if (!(kExact_ScratchTextureFlag & flags)) { |
| 290 // bin by pow2 with a reasonable min | 289 // bin by pow2 with a reasonable min |
| 291 static const int MIN_SIZE = 16; | 290 static const int MIN_SIZE = 16; |
| 292 GrSurfaceDesc* wdesc = desc.writable(); | 291 GrSurfaceDesc* wdesc = desc.writable(); |
| 293 wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth)); | 292 wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth)); |
| 294 wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight)); | 293 wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight)); |
| 295 } | 294 } |
| 296 | 295 |
| 297 do { | 296 GrScratchKey key; |
| 298 GrScratchKey key; | 297 GrTexturePriv::ComputeScratchKey(*desc, &key); |
| 299 GrTexturePriv::ComputeScratchKey(*desc, &key); | 298 uint32_t scratchFlags = 0; |
| 300 uint32_t scratchFlags = 0; | 299 if (kNoPendingIO_ScratchTextureFlag & flags) { |
| 301 if (kNoPendingIO_ScratchTextureFlag & flags) { | 300 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
| 302 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 301 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 303 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { | 302 // If it is not a render target then it will most likely be populate
d by |
| 304 // If it is not a render target then it will most likely be popu
lated by | 303 // writePixels() which will trigger a flush if the texture has pendi
ng IO. |
| 305 // writePixels() which will trigger a flush if the texture has p
ending IO. | 304 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
| 306 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 305 } |
| 306 GrGpuResource* resource = fResourceCache->findAndRefScratchResource(key,
scratchFlags); |
| 307 if (resource) { |
| 308 GrSurface* surface = static_cast<GrSurface*>(resource); |
| 309 GrRenderTarget* rt = surface->asRenderTarget(); |
| 310 if (rt && fGpu->caps()->discardRenderTargetSupport()) { |
| 311 rt->discard(); |
| 307 } | 312 } |
| 308 GrGpuResource* resource = fResourceCache->findAndRefScratchResource(
key, scratchFlags); | 313 return surface->asTexture(); |
| 309 if (resource) { | 314 } |
| 310 GrSurface* surface = static_cast<GrSurface*>(resource); | |
| 311 GrRenderTarget* rt = surface->asRenderTarget(); | |
| 312 if (rt && fGpu->caps()->discardRenderTargetSupport()) { | |
| 313 rt->discard(); | |
| 314 } | |
| 315 return surface->asTexture(); | |
| 316 } | |
| 317 | |
| 318 if (kExact_ScratchTextureFlag & flags) { | |
| 319 break; | |
| 320 } | |
| 321 // We had a cache miss and we are in approx mode, relax the fit of t
he flags. | |
| 322 | |
| 323 // We no longer try to reuse textures that were previously used as r
ender targets in | |
| 324 // situations where no RT is needed; doing otherwise can confuse the
video driver and | |
| 325 // cause significant performance problems in some cases. | |
| 326 if (desc->fFlags & kNoStencil_GrSurfaceFlag) { | |
| 327 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl
ag; | |
| 328 } else { | |
| 329 break; | |
| 330 } | |
| 331 | |
| 332 } while (true); | |
| 333 | |
| 334 desc.writable()->fFlags = origFlags; | |
| 335 } | 315 } |
| 336 | 316 |
| 337 if (!(kNoCreate_ScratchTextureFlag & flags)) { | 317 if (!(kNoCreate_ScratchTextureFlag & flags)) { |
| 338 return fGpu->createTexture(*desc, true, NULL, 0); | 318 return fGpu->createTexture(*desc, true, NULL, 0); |
| 339 } | 319 } |
| 340 | 320 |
| 341 return NULL; | 321 return NULL; |
| 342 } | 322 } |
| 343 | 323 |
| 344 void GrContext::OverBudgetCB(void* data) { | 324 void GrContext::OverBudgetCB(void* data) { |
| (...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 } | 1587 } |
| 1608 } | 1588 } |
| 1609 | 1589 |
| 1610 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 1590 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1611 fGpu->removeGpuTraceMarker(marker); | 1591 fGpu->removeGpuTraceMarker(marker); |
| 1612 if (fDrawBuffer) { | 1592 if (fDrawBuffer) { |
| 1613 fDrawBuffer->removeGpuTraceMarker(marker); | 1593 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1614 } | 1594 } |
| 1615 } | 1595 } |
| 1616 | 1596 |
| OLD | NEW |