| 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 "GrBatch.h" | 12 #include "GrBatch.h" |
| 13 #include "GrBatchFontCache.h" |
| 13 #include "GrBatchTarget.h" | 14 #include "GrBatchTarget.h" |
| 15 #include "GrBitmapTextContext.h" |
| 14 #include "GrBufferAllocPool.h" | 16 #include "GrBufferAllocPool.h" |
| 15 #include "GrDefaultGeoProcFactory.h" | 17 #include "GrDefaultGeoProcFactory.h" |
| 16 #include "GrFontCache.h" | 18 #include "GrFontCache.h" |
| 17 #include "GrGpuResource.h" | 19 #include "GrGpuResource.h" |
| 18 #include "GrGpuResourcePriv.h" | 20 #include "GrGpuResourcePriv.h" |
| 19 #include "GrDistanceFieldTextContext.h" | 21 #include "GrDistanceFieldTextContext.h" |
| 20 #include "GrDrawTargetCaps.h" | 22 #include "GrDrawTargetCaps.h" |
| 21 #include "GrGpu.h" | 23 #include "GrGpu.h" |
| 22 #include "GrIndexBuffer.h" | 24 #include "GrIndexBuffer.h" |
| 23 #include "GrInOrderDrawBuffer.h" | 25 #include "GrInOrderDrawBuffer.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 context->unref(); | 89 context->unref(); |
| 88 return NULL; | 90 return NULL; |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 GrContext::GrContext(const Options& opts) : fOptions(opts) { | 94 GrContext::GrContext(const Options& opts) : fOptions(opts) { |
| 93 fGpu = NULL; | 95 fGpu = NULL; |
| 94 fPathRendererChain = NULL; | 96 fPathRendererChain = NULL; |
| 95 fSoftwarePathRenderer = NULL; | 97 fSoftwarePathRenderer = NULL; |
| 96 fResourceCache = NULL; | 98 fResourceCache = NULL; |
| 99 fBatchFontCache = NULL; |
| 97 fFontCache = NULL; | 100 fFontCache = NULL; |
| 98 fDrawBuffer = NULL; | 101 fDrawBuffer = NULL; |
| 99 fDrawBufferVBAllocPool = NULL; | 102 fDrawBufferVBAllocPool = NULL; |
| 100 fDrawBufferIBAllocPool = NULL; | 103 fDrawBufferIBAllocPool = NULL; |
| 101 fFlushToReduceCacheSize = false; | 104 fFlushToReduceCacheSize = false; |
| 102 fAARectRenderer = NULL; | 105 fAARectRenderer = NULL; |
| 103 fOvalRenderer = NULL; | 106 fOvalRenderer = NULL; |
| 104 fMaxTextureSizeOverride = 1 << 20; | 107 fMaxTextureSizeOverride = 1 << 20; |
| 105 } | 108 } |
| 106 | 109 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 122 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 125 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 123 | 126 |
| 124 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 127 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
| 125 | 128 |
| 126 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); | 129 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
| 127 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); | 130 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); |
| 128 | 131 |
| 129 fDidTestPMConversions = false; | 132 fDidTestPMConversions = false; |
| 130 | 133 |
| 131 this->setupDrawBuffer(); | 134 this->setupDrawBuffer(); |
| 135 |
| 136 // GrBatchFontCache will eventually replace GrFontCache |
| 137 fBatchFontCache = SkNEW(GrBatchFontCache); |
| 138 fBatchFontCache->init(this); |
| 132 } | 139 } |
| 133 | 140 |
| 134 GrContext::~GrContext() { | 141 GrContext::~GrContext() { |
| 135 if (NULL == fGpu) { | 142 if (NULL == fGpu) { |
| 136 return; | 143 return; |
| 137 } | 144 } |
| 138 | 145 |
| 139 this->flush(); | 146 this->flush(); |
| 140 | 147 |
| 141 for (int i = 0; i < fCleanUpData.count(); ++i) { | 148 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 142 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 149 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 143 } | 150 } |
| 144 | 151 |
| 145 SkDELETE(fResourceCache); | 152 SkDELETE(fResourceCache); |
| 153 SkDELETE(fBatchFontCache); |
| 146 SkDELETE(fFontCache); | 154 SkDELETE(fFontCache); |
| 147 SkDELETE(fDrawBuffer); | 155 SkDELETE(fDrawBuffer); |
| 148 SkDELETE(fDrawBufferVBAllocPool); | 156 SkDELETE(fDrawBufferVBAllocPool); |
| 149 SkDELETE(fDrawBufferIBAllocPool); | 157 SkDELETE(fDrawBufferIBAllocPool); |
| 150 | 158 |
| 151 fAARectRenderer->unref(); | 159 fAARectRenderer->unref(); |
| 152 fOvalRenderer->unref(); | 160 fOvalRenderer->unref(); |
| 153 | 161 |
| 154 fGpu->unref(); | 162 fGpu->unref(); |
| 155 SkSafeUnref(fPathRendererChain); | 163 SkSafeUnref(fPathRendererChain); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 173 | 181 |
| 174 delete fDrawBufferVBAllocPool; | 182 delete fDrawBufferVBAllocPool; |
| 175 fDrawBufferVBAllocPool = NULL; | 183 fDrawBufferVBAllocPool = NULL; |
| 176 | 184 |
| 177 delete fDrawBufferIBAllocPool; | 185 delete fDrawBufferIBAllocPool; |
| 178 fDrawBufferIBAllocPool = NULL; | 186 fDrawBufferIBAllocPool = NULL; |
| 179 | 187 |
| 180 fAARectRenderer->reset(); | 188 fAARectRenderer->reset(); |
| 181 fOvalRenderer->reset(); | 189 fOvalRenderer->reset(); |
| 182 | 190 |
| 191 fBatchFontCache->freeAll(); |
| 183 fFontCache->freeAll(); | 192 fFontCache->freeAll(); |
| 184 fLayerCache->freeAll(); | 193 fLayerCache->freeAll(); |
| 185 } | 194 } |
| 186 | 195 |
| 187 void GrContext::resetContext(uint32_t state) { | 196 void GrContext::resetContext(uint32_t state) { |
| 188 fGpu->markContextDirty(state); | 197 fGpu->markContextDirty(state); |
| 189 } | 198 } |
| 190 | 199 |
| 191 void GrContext::freeGpuResources() { | 200 void GrContext::freeGpuResources() { |
| 192 this->flush(); | 201 this->flush(); |
| 193 | 202 |
| 194 if (fDrawBuffer) { | 203 if (fDrawBuffer) { |
| 195 fDrawBuffer->purgeResources(); | 204 fDrawBuffer->purgeResources(); |
| 196 } | 205 } |
| 197 | 206 |
| 198 fAARectRenderer->reset(); | 207 fAARectRenderer->reset(); |
| 199 fOvalRenderer->reset(); | 208 fOvalRenderer->reset(); |
| 200 | 209 |
| 210 fBatchFontCache->freeAll(); |
| 201 fFontCache->freeAll(); | 211 fFontCache->freeAll(); |
| 202 fLayerCache->freeAll(); | 212 fLayerCache->freeAll(); |
| 203 // a path renderer may be holding onto resources | 213 // a path renderer may be holding onto resources |
| 204 SkSafeSetNull(fPathRendererChain); | 214 SkSafeSetNull(fPathRendererChain); |
| 205 SkSafeSetNull(fSoftwarePathRenderer); | 215 SkSafeSetNull(fSoftwarePathRenderer); |
| 206 } | 216 } |
| 207 | 217 |
| 208 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 218 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
| 209 if (resourceCount) { | 219 if (resourceCount) { |
| 210 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 220 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 211 } | 221 } |
| 212 if (resourceBytes) { | 222 if (resourceBytes) { |
| 213 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 223 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 214 } | 224 } |
| 215 } | 225 } |
| 216 | 226 |
| 217 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, | 227 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
| 218 SkGpuDevice* gpuDevice, | 228 SkGpuDevice* gpuDevice, |
| 219 const SkDeviceProperties& | 229 const SkDeviceProperties& |
| 220 leakyProperties, | 230 leakyProperties, |
| 221 bool enableDistanceFieldFonts) { | 231 bool enableDistanceFieldFonts) { |
| 222 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled())
{ | 232 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled())
{ |
| 223 GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuff
er(); | 233 GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuff
er(); |
| 224 if (sb) { | 234 if (sb) { |
| 225 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr
operties); | 235 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr
operties); |
| 226 } | 236 } |
| 227 } | 237 } |
| 228 | 238 |
| 239 #ifdef USE_BITMAP_TEXTBLOBS |
| 240 return GrBitmapTextContextB::Create(this, gpuDevice, leakyProperties); |
| 241 #else |
| 229 return GrDistanceFieldTextContext::Create(this, gpuDevice, leakyProperties, | 242 return GrDistanceFieldTextContext::Create(this, gpuDevice, leakyProperties, |
| 230 enableDistanceFieldFonts); | 243 enableDistanceFieldFonts); |
| 244 #endif |
| 231 } | 245 } |
| 232 | 246 |
| 233 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
| 234 enum ScratchTextureFlags { | 248 enum ScratchTextureFlags { |
| 235 kExact_ScratchTextureFlag = 0x1, | 249 kExact_ScratchTextureFlag = 0x1, |
| 236 kNoPendingIO_ScratchTextureFlag = 0x2, | 250 kNoPendingIO_ScratchTextureFlag = 0x2, |
| 237 kNoCreate_ScratchTextureFlag = 0x4, | 251 kNoCreate_ScratchTextureFlag = 0x4, |
| 238 }; | 252 }; |
| 239 | 253 |
| 240 bool GrContext::isConfigTexturable(GrPixelConfig config) const { | 254 bool GrContext::isConfigTexturable(GrPixelConfig config) const { |
| (...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 } | 2013 } |
| 2000 } | 2014 } |
| 2001 | 2015 |
| 2002 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 2016 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 2003 fGpu->removeGpuTraceMarker(marker); | 2017 fGpu->removeGpuTraceMarker(marker); |
| 2004 if (fDrawBuffer) { | 2018 if (fDrawBuffer) { |
| 2005 fDrawBuffer->removeGpuTraceMarker(marker); | 2019 fDrawBuffer->removeGpuTraceMarker(marker); |
| 2006 } | 2020 } |
| 2007 } | 2021 } |
| 2008 | 2022 |
| OLD | NEW |