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

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

Issue 715333003: Revert of Replace GrResourceCache with GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/GrAADistanceFieldPathRenderer.h ('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"
28 #include "GrResourceCache2.h" 29 #include "GrResourceCache2.h"
29 #include "GrSoftwarePathRenderer.h" 30 #include "GrSoftwarePathRenderer.h"
30 #include "GrStencilBuffer.h" 31 #include "GrStencilBuffer.h"
31 #include "GrStencilAndCoverTextContext.h" 32 #include "GrStencilAndCoverTextContext.h"
32 #include "GrStrokeInfo.h" 33 #include "GrStrokeInfo.h"
33 #include "GrSurfacePriv.h" 34 #include "GrSurfacePriv.h"
34 #include "GrTextStrike.h" 35 #include "GrTextStrike.h"
35 #include "GrTexturePriv.h" 36 #include "GrTexturePriv.h"
36 #include "GrTraceMarker.h" 37 #include "GrTraceMarker.h"
37 #include "GrTracing.h" 38 #include "GrTracing.h"
38 #include "SkDashPathPriv.h" 39 #include "SkDashPathPriv.h"
39 #include "SkConfig8888.h" 40 #include "SkConfig8888.h"
40 #include "SkGr.h" 41 #include "SkGr.h"
41 #include "SkRRect.h" 42 #include "SkRRect.h"
42 #include "SkStrokeRec.h" 43 #include "SkStrokeRec.h"
43 #include "SkTLazy.h" 44 #include "SkTLazy.h"
44 #include "SkTLS.h" 45 #include "SkTLS.h"
45 #include "SkTraceEvent.h" 46 #include "SkTraceEvent.h"
46 47
47 #ifdef SK_DEBUG 48 #ifdef SK_DEBUG
48 // change this to a 1 to see notifications when partial coverage fails 49 // change this to a 1 to see notifications when partial coverage fails
49 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 50 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
50 #else 51 #else
51 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0
52 #endif 53 #endif
53 54
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
54 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; 58 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
55 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; 59 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
56 60
57 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; 61 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
58 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; 62 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
59 63
60 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 64 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
61 65
62 // Glorified typedef to avoid including GrDrawState.h in GrContext.h 66 // Glorified typedef to avoid including GrDrawState.h in GrContext.h
63 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; 67 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {};
64 68
69 class GrContext::AutoCheckFlush {
70 public:
71 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); }
72
73 ~AutoCheckFlush() {
74 if (fContext->fFlushToReduceCacheSize) {
75 fContext->flush();
76 }
77 }
78
79 private:
80 GrContext* fContext;
81 };
82
65 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, 83 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
66 const Options* opts) { 84 const Options* opts) {
67 GrContext* context; 85 GrContext* context;
68 if (NULL == opts) { 86 if (NULL == opts) {
69 context = SkNEW_ARGS(GrContext, (Options())); 87 context = SkNEW_ARGS(GrContext, (Options()));
70 } else { 88 } else {
71 context = SkNEW_ARGS(GrContext, (*opts)); 89 context = SkNEW_ARGS(GrContext, (*opts));
72 } 90 }
73 91
74 if (context->init(backend, backendContext)) { 92 if (context->init(backend, backendContext)) {
75 return context; 93 return context;
76 } else { 94 } else {
77 context->unref(); 95 context->unref();
78 return NULL; 96 return NULL;
79 } 97 }
80 } 98 }
81 99
82 GrContext::GrContext(const Options& opts) : fOptions(opts) { 100 GrContext::GrContext(const Options& opts) : fOptions(opts) {
83 fDrawState = NULL; 101 fDrawState = NULL;
84 fGpu = NULL; 102 fGpu = NULL;
85 fClip = NULL; 103 fClip = NULL;
86 fPathRendererChain = NULL; 104 fPathRendererChain = NULL;
87 fSoftwarePathRenderer = NULL; 105 fSoftwarePathRenderer = NULL;
106 fResourceCache = NULL;
88 fResourceCache2 = NULL; 107 fResourceCache2 = NULL;
89 fFontCache = NULL; 108 fFontCache = NULL;
90 fDrawBuffer = NULL; 109 fDrawBuffer = NULL;
91 fDrawBufferVBAllocPool = NULL; 110 fDrawBufferVBAllocPool = NULL;
92 fDrawBufferIBAllocPool = NULL; 111 fDrawBufferIBAllocPool = NULL;
112 fFlushToReduceCacheSize = false;
93 fAARectRenderer = NULL; 113 fAARectRenderer = NULL;
94 fOvalRenderer = NULL; 114 fOvalRenderer = NULL;
95 fViewMatrix.reset(); 115 fViewMatrix.reset();
96 fMaxTextureSizeOverride = 1 << 20; 116 fMaxTextureSizeOverride = 1 << 20;
97 } 117 }
98 118
99 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 119 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
100 SkASSERT(NULL == fGpu); 120 SkASSERT(NULL == fGpu);
101 121
102 fGpu = GrGpu::Create(backend, backendContext, this); 122 fGpu = GrGpu::Create(backend, backendContext, this);
103 if (NULL == fGpu) { 123 if (NULL == fGpu) {
104 return false; 124 return false;
105 } 125 }
106 this->initCommon(); 126 this->initCommon();
107 return true; 127 return true;
108 } 128 }
109 129
110 void GrContext::initCommon() { 130 void GrContext::initCommon() {
111 fDrawState = SkNEW(GrDrawState); 131 fDrawState = SkNEW(GrDrawState);
112 132
133 fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(),
134 MAX_RESOURCE_CACHE_COUNT,
135 MAX_RESOURCE_CACHE_BYTES));
136 fResourceCache->setOverbudgetCallback(OverbudgetCB, this);
113 fResourceCache2 = SkNEW(GrResourceCache2); 137 fResourceCache2 = SkNEW(GrResourceCache2);
114 fResourceCache2->setOverBudgetCallback(OverBudgetCB, this);
115 138
116 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); 139 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
117 140
118 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 141 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
119 142
120 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); 143 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
121 fOvalRenderer = SkNEW(GrOvalRenderer); 144 fOvalRenderer = SkNEW(GrOvalRenderer);
122 145
123 fDidTestPMConversions = false; 146 fDidTestPMConversions = false;
124 147
125 this->setupDrawBuffer(); 148 this->setupDrawBuffer();
126 } 149 }
127 150
128 GrContext::~GrContext() { 151 GrContext::~GrContext() {
129 if (NULL == fGpu) { 152 if (NULL == fGpu) {
130 return; 153 return;
131 } 154 }
132 155
133 this->flush(); 156 this->flush();
134 157
135 for (int i = 0; i < fCleanUpData.count(); ++i) { 158 for (int i = 0; i < fCleanUpData.count(); ++i) {
136 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 159 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
137 } 160 }
138 161
139 SkDELETE(fResourceCache2); 162 SkDELETE(fResourceCache2);
163 fResourceCache2 = NULL;
164 SkDELETE(fResourceCache);
165 fResourceCache = NULL;
140 SkDELETE(fFontCache); 166 SkDELETE(fFontCache);
141 SkDELETE(fDrawBuffer); 167 SkDELETE(fDrawBuffer);
142 SkDELETE(fDrawBufferVBAllocPool); 168 SkDELETE(fDrawBufferVBAllocPool);
143 SkDELETE(fDrawBufferIBAllocPool); 169 SkDELETE(fDrawBufferIBAllocPool);
144 170
145 fAARectRenderer->unref(); 171 fAARectRenderer->unref();
146 fOvalRenderer->unref(); 172 fOvalRenderer->unref();
147 173
148 fGpu->unref(); 174 fGpu->unref();
149 SkSafeUnref(fPathRendererChain); 175 SkSafeUnref(fPathRendererChain);
(...skipping 18 matching lines...) Expand all
168 194
169 delete fDrawBufferVBAllocPool; 195 delete fDrawBufferVBAllocPool;
170 fDrawBufferVBAllocPool = NULL; 196 fDrawBufferVBAllocPool = NULL;
171 197
172 delete fDrawBufferIBAllocPool; 198 delete fDrawBufferIBAllocPool;
173 fDrawBufferIBAllocPool = NULL; 199 fDrawBufferIBAllocPool = NULL;
174 200
175 fAARectRenderer->reset(); 201 fAARectRenderer->reset();
176 fOvalRenderer->reset(); 202 fOvalRenderer->reset();
177 203
204 fResourceCache->purgeAllUnlocked();
205
178 fFontCache->freeAll(); 206 fFontCache->freeAll();
179 fLayerCache->freeAll(); 207 fLayerCache->freeAll();
180 } 208 }
181 209
182 void GrContext::resetContext(uint32_t state) { 210 void GrContext::resetContext(uint32_t state) {
183 fGpu->markContextDirty(state); 211 fGpu->markContextDirty(state);
184 } 212 }
185 213
186 void GrContext::freeGpuResources() { 214 void GrContext::freeGpuResources() {
187 this->flush(); 215 this->flush();
188 216
189 if (fDrawBuffer) { 217 if (fDrawBuffer) {
190 fDrawBuffer->purgeResources(); 218 fDrawBuffer->purgeResources();
191 } 219 }
192 220
193 fAARectRenderer->reset(); 221 fAARectRenderer->reset();
194 fOvalRenderer->reset(); 222 fOvalRenderer->reset();
195 223
224 fResourceCache->purgeAllUnlocked();
196 fFontCache->freeAll(); 225 fFontCache->freeAll();
197 fLayerCache->freeAll(); 226 fLayerCache->freeAll();
198 // a path renderer may be holding onto resources 227 // a path renderer may be holding onto resources
199 SkSafeSetNull(fPathRendererChain); 228 SkSafeSetNull(fPathRendererChain);
200 SkSafeSetNull(fSoftwarePathRenderer); 229 SkSafeSetNull(fSoftwarePathRenderer);
201 } 230 }
202 231
203 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { 232 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
204 if (resourceCount) { 233 if (resourceCount) {
205 *resourceCount = fResourceCache2->getResourceCount(); 234 *resourceCount = fResourceCache->getCachedResourceCount();
206 } 235 }
207 if (resourceBytes) { 236 if (resourceBytes) {
208 *resourceBytes = fResourceCache2->getResourceBytes(); 237 *resourceBytes = fResourceCache->getCachedResourceBytes();
209 } 238 }
210 } 239 }
211 240
212 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, 241 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
213 const SkDeviceProperties& 242 const SkDeviceProperties&
214 leakyProperties, 243 leakyProperties,
215 bool enableDistanceFieldFonts) { 244 bool enableDistanceFieldFonts) {
216 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() && 245 if (fGpu->caps()->pathRenderingSupport() && renderTarget->getStencilBuffer() &&
217 renderTarget->isMultisampled()) { 246 renderTarget->isMultisampled()) {
218 return GrStencilAndCoverTextContext::Create(this, leakyProperties); 247 return GrStencilAndCoverTextContext::Create(this, leakyProperties);
219 } 248 }
(...skipping 17 matching lines...) Expand all
237 } 266 }
238 267
239 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, 268 bool GrContext::isTextureInCache(const GrSurfaceDesc& desc,
240 const GrCacheID& cacheID, 269 const GrCacheID& cacheID,
241 const GrTextureParams* params) const { 270 const GrTextureParams* params) const {
242 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID); 271 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID);
243 return fResourceCache2->hasContentKey(resourceKey); 272 return fResourceCache2->hasContentKey(resourceKey);
244 } 273 }
245 274
246 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { 275 void GrContext::addStencilBuffer(GrStencilBuffer* sb) {
247 // TODO: Make GrStencilBuffers use the scratch mechanism rather than content keys.
248 ASSERT_OWNED_RESOURCE(sb); 276 ASSERT_OWNED_RESOURCE(sb);
249 277
250 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), 278 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(),
251 sb->height(), 279 sb->height(),
252 sb->numSamples()); 280 sb->numSamples());
253 SkAssertResult(sb->cacheAccess().setContentKey(resourceKey)); 281 fResourceCache->addResource(resourceKey, sb);
254 } 282 }
255 283
256 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s ampleCnt) { 284 GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int s ampleCnt) {
257 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl eCnt); 285 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, height, sampl eCnt);
258 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey); 286 GrGpuResource* resource = this->findAndRefCachedResource(resourceKey);
259 return static_cast<GrStencilBuffer*>(resource); 287 return static_cast<GrStencilBuffer*>(resource);
260 } 288 }
261 289
262 static void stretch_image(void* dst, 290 static void stretch_image(void* dst,
263 int dstW, 291 int dstW,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); 413 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
386 414
387 texture = this->createResizedTexture(desc, cacheID, 415 texture = this->createResizedTexture(desc, cacheID,
388 srcData, rowBytes, 416 srcData, rowBytes,
389 GrTexturePriv::NeedsBilerp(resource Key)); 417 GrTexturePriv::NeedsBilerp(resource Key));
390 } else { 418 } else {
391 texture = fGpu->createTexture(desc, srcData, rowBytes); 419 texture = fGpu->createTexture(desc, srcData, rowBytes);
392 } 420 }
393 421
394 if (texture) { 422 if (texture) {
395 if (texture->cacheAccess().setContentKey(resourceKey)) { 423 fResourceCache->addResource(resourceKey, texture);
396 if (cacheKey) { 424
397 *cacheKey = resourceKey; 425 if (cacheKey) {
398 } 426 *cacheKey = resourceKey;
399 } else {
400 texture->unref();
401 texture = NULL;
402 } 427 }
403 } 428 }
404 429
405 return texture; 430 return texture;
406 } 431 }
407 432
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
408 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM atch match, 442 GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM atch match,
409 bool calledDuringFlush) { 443 bool calledDuringFlush) {
410 // kNoStencil has no meaning if kRT isn't set. 444 // kNoStencil has no meaning if kRT isn't set.
411 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || 445 SkASSERT((inDesc.fFlags & kRenderTarget_GrSurfaceFlag) ||
412 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag)); 446 !(inDesc.fFlags & kNoStencil_GrSurfaceFlag));
413 447
414 // Make sure caller has checked for renderability if kRT is set. 448 // Make sure caller has checked for renderability if kRT is set.
415 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) || 449 SkASSERT(!(inDesc.fFlags & kRenderTarget_GrSurfaceFlag) ||
416 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0)); 450 this->isConfigRenderable(inDesc.fConfig, inDesc.fSampleCnt > 0));
417 451
(...skipping 14 matching lines...) Expand all
432 uint32_t scratchFlags = 0; 466 uint32_t scratchFlags = 0;
433 if (calledDuringFlush) { 467 if (calledDuringFlush) {
434 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag ; 468 scratchFlags = GrResourceCache2::kRequireNoPendingIO_ScratchFlag ;
435 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { 469 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
436 // If it is not a render target then it will most likely be popu lated by 470 // If it is not a render target then it will most likely be popu lated by
437 // writePixels() which will trigger a flush if the texture has p ending IO. 471 // writePixels() which will trigger a flush if the texture has p ending IO.
438 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag; 472 scratchFlags = GrResourceCache2::kPreferNoPendingIO_ScratchFlag;
439 } 473 }
440 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource (key, scratchFlags); 474 GrGpuResource* resource = fResourceCache2->findAndRefScratchResource (key, scratchFlags);
441 if (resource) { 475 if (resource) {
476 fResourceCache->makeResourceMRU(resource);
442 return static_cast<GrSurface*>(resource)->asTexture(); 477 return static_cast<GrSurface*>(resource)->asTexture();
443 } 478 }
444 479
445 if (kExact_ScratchTexMatch == match) { 480 if (kExact_ScratchTexMatch == match) {
446 break; 481 break;
447 } 482 }
448 // We had a cache miss and we are in approx mode, relax the fit of t he flags. 483 // We had a cache miss and we are in approx mode, relax the fit of t he flags.
449 484
450 // We no longer try to reuse textures that were previously used as r ender targets in 485 // We no longer try to reuse textures that were previously used as r ender targets in
451 // situations where no RT is needed; doing otherwise can confuse the video driver and 486 // situations where no RT is needed; doing otherwise can confuse the video driver and
452 // cause significant performance problems in some cases. 487 // cause significant performance problems in some cases.
453 if (desc->fFlags & kNoStencil_GrSurfaceFlag) { 488 if (desc->fFlags & kNoStencil_GrSurfaceFlag) {
454 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag; 489 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag;
455 } else { 490 } else {
456 break; 491 break;
457 } 492 }
458 493
459 } while (true); 494 } while (true);
460 495
461 desc.writable()->fFlags = origFlags; 496 desc.writable()->fFlags = origFlags;
462 } 497 }
463 498
464 GrTexture* texture = fGpu->createTexture(*desc, NULL, 0); 499 GrTexture* texture = this->createNewScratchTexture(*desc);
465 SkASSERT(NULL == texture || 500 SkASSERT(NULL == texture ||
466 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr atchKey(*desc)); 501 texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScr atchKey(*desc));
467 return texture; 502 return texture;
468 } 503 }
469 504
470 void GrContext::OverBudgetCB(void* data) { 505 bool GrContext::OverbudgetCB(void* data) {
506 SkASSERT(data);
507
508 GrContext* context = reinterpret_cast<GrContext*>(data);
509
471 // Flush the InOrderDrawBuffer to possibly free up some textures 510 // Flush the InOrderDrawBuffer to possibly free up some textures
472 SkASSERT(data); 511 context->fFlushToReduceCacheSize = true;
473 GrContext* context = reinterpret_cast<GrContext*>(data); 512
474 context->flush(); 513 return true;
475 } 514 }
476 515
477 516
478 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, 517 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn,
479 void* srcData, 518 void* srcData,
480 size_t rowBytes) { 519 size_t rowBytes) {
481 GrSurfaceDesc descCopy = descIn; 520 GrSurfaceDesc descCopy = descIn;
482 return fGpu->createTexture(descCopy, srcData, rowBytes); 521 return fGpu->createTexture(descCopy, srcData, rowBytes);
483 } 522 }
484 523
485 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const { 524 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const {
486 if (maxTextures) { 525 fResourceCache->getLimits(maxTextures, maxTextureBytes);
487 *maxTextures = fResourceCache2->getMaxResourceCount();
488 }
489 if (maxTextureBytes) {
490 *maxTextureBytes = fResourceCache2->getMaxResourceBytes();
491 }
492 } 526 }
493 527
494 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { 528 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
495 fResourceCache2->setLimits(maxTextures, maxTextureBytes); 529 fResourceCache->setLimits(maxTextures, maxTextureBytes);
496 } 530 }
497 531
498 int GrContext::getMaxTextureSize() const { 532 int GrContext::getMaxTextureSize() const {
499 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); 533 return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride);
500 } 534 }
501 535
502 int GrContext::getMaxRenderTargetSize() const { 536 int GrContext::getMaxRenderTargetSize() const {
503 return fGpu->caps()->maxRenderTargetSize(); 537 return fGpu->caps()->maxRenderTargetSize();
504 } 538 }
505 539
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 //////////////////////////////////////////////////////////////////////////////// 575 ////////////////////////////////////////////////////////////////////////////////
542 576
543 void GrContext::clear(const SkIRect* rect, 577 void GrContext::clear(const SkIRect* rect,
544 const GrColor color, 578 const GrColor color,
545 bool canIgnoreRect, 579 bool canIgnoreRect,
546 GrRenderTarget* renderTarget) { 580 GrRenderTarget* renderTarget) {
547 ASSERT_OWNED_RESOURCE(renderTarget); 581 ASSERT_OWNED_RESOURCE(renderTarget);
548 SkASSERT(renderTarget); 582 SkASSERT(renderTarget);
549 583
550 AutoRestoreEffects are; 584 AutoRestoreEffects are;
585 AutoCheckFlush acf(this);
551 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); 586 GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
552 GrDrawTarget* target = this->prepareToDraw(NULL, &are); 587 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf);
553 if (NULL == target) { 588 if (NULL == target) {
554 return; 589 return;
555 } 590 }
556 target->clear(rect, color, canIgnoreRect, renderTarget); 591 target->clear(rect, color, canIgnoreRect, renderTarget);
557 } 592 }
558 593
559 void GrContext::drawPaint(const GrPaint& origPaint) { 594 void GrContext::drawPaint(const GrPaint& origPaint) {
560 // set rect to be big enough to fill the space, but not super-huge, so we 595 // set rect to be big enough to fill the space, but not super-huge, so we
561 // don't overflow fixed-point implementations 596 // don't overflow fixed-point implementations
562 SkRect r; 597 SkRect r;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 const SkRect& rect, 709 const SkRect& rect,
675 const GrStrokeInfo* strokeInfo) { 710 const GrStrokeInfo* strokeInfo) {
676 if (strokeInfo && strokeInfo->isDashed()) { 711 if (strokeInfo && strokeInfo->isDashed()) {
677 SkPath path; 712 SkPath path;
678 path.addRect(rect); 713 path.addRect(rect);
679 this->drawPath(paint, path, *strokeInfo); 714 this->drawPath(paint, path, *strokeInfo);
680 return; 715 return;
681 } 716 }
682 717
683 AutoRestoreEffects are; 718 AutoRestoreEffects are;
684 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 719 AutoCheckFlush acf(this);
720 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
685 if (NULL == target) { 721 if (NULL == target) {
686 return; 722 return;
687 } 723 }
688 724
689 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); 725 GR_CREATE_TRACE_MARKER("GrContext::drawRect", target);
690 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th(); 726 SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWid th();
691 SkMatrix matrix = target->drawState()->getViewMatrix(); 727 SkMatrix matrix = target->drawState()->getViewMatrix();
692 728
693 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking 729 // Check if this is a full RT draw and can be replaced with a clear. We don' t bother checking
694 // cases where the RT is fully inside a stroke. 730 // cases where the RT is fully inside a stroke.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // filled BW rect 820 // filled BW rect
785 target->drawSimpleRect(rect); 821 target->drawSimpleRect(rect);
786 } 822 }
787 } 823 }
788 824
789 void GrContext::drawRectToRect(const GrPaint& paint, 825 void GrContext::drawRectToRect(const GrPaint& paint,
790 const SkRect& dstRect, 826 const SkRect& dstRect,
791 const SkRect& localRect, 827 const SkRect& localRect,
792 const SkMatrix* localMatrix) { 828 const SkMatrix* localMatrix) {
793 AutoRestoreEffects are; 829 AutoRestoreEffects are;
794 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 830 AutoCheckFlush acf(this);
831 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
795 if (NULL == target) { 832 if (NULL == target) {
796 return; 833 return;
797 } 834 }
798 835
799 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); 836 GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
800 837
801 target->drawRect(dstRect, &localRect, localMatrix); 838 target->drawRect(dstRect, &localRect, localMatrix);
802 } 839 }
803 840
804 namespace { 841 namespace {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 884
848 void GrContext::drawVertices(const GrPaint& paint, 885 void GrContext::drawVertices(const GrPaint& paint,
849 GrPrimitiveType primitiveType, 886 GrPrimitiveType primitiveType,
850 int vertexCount, 887 int vertexCount,
851 const SkPoint positions[], 888 const SkPoint positions[],
852 const SkPoint texCoords[], 889 const SkPoint texCoords[],
853 const GrColor colors[], 890 const GrColor colors[],
854 const uint16_t indices[], 891 const uint16_t indices[],
855 int indexCount) { 892 int indexCount) {
856 AutoRestoreEffects are; 893 AutoRestoreEffects are;
857 GrDrawTarget::AutoReleaseGeometry geo; 894 AutoCheckFlush acf(this);
895 GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scop e
858 896
859 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 897 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
860 if (NULL == target) { 898 if (NULL == target) {
861 return; 899 return;
862 } 900 }
863 GrDrawState* drawState = target->drawState(); 901 GrDrawState* drawState = target->drawState();
864 902
865 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); 903 GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target);
866 904
867 int colorOffset = -1, texOffset = -1; 905 int colorOffset = -1, texOffset = -1;
868 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset ); 906 set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset );
869 907
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 } 947 }
910 948
911 if (strokeInfo.isDashed()) { 949 if (strokeInfo.isDashed()) {
912 SkPath path; 950 SkPath path;
913 path.addRRect(rrect); 951 path.addRRect(rrect);
914 this->drawPath(paint, path, strokeInfo); 952 this->drawPath(paint, path, strokeInfo);
915 return; 953 return;
916 } 954 }
917 955
918 AutoRestoreEffects are; 956 AutoRestoreEffects are;
919 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 957 AutoCheckFlush acf(this);
958 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
920 if (NULL == target) { 959 if (NULL == target) {
921 return; 960 return;
922 } 961 }
923 962
924 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); 963 GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target);
925 964
926 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 965 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
927 966
928 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro keRec)) { 967 if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, stro keRec)) {
929 SkPath path; 968 SkPath path;
930 path.addRRect(rrect); 969 path.addRRect(rrect);
931 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); 970 this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo);
932 } 971 }
933 } 972 }
934 973
935 /////////////////////////////////////////////////////////////////////////////// 974 ///////////////////////////////////////////////////////////////////////////////
936 975
937 void GrContext::drawDRRect(const GrPaint& paint, 976 void GrContext::drawDRRect(const GrPaint& paint,
938 const SkRRect& outer, 977 const SkRRect& outer,
939 const SkRRect& inner) { 978 const SkRRect& inner) {
940 if (outer.isEmpty()) { 979 if (outer.isEmpty()) {
941 return; 980 return;
942 } 981 }
943 982
944 AutoRestoreEffects are; 983 AutoRestoreEffects are;
945 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 984 AutoCheckFlush acf(this);
985 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
946 986
947 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); 987 GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
948 988
949 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn er)) { 989 if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inn er)) {
950 SkPath path; 990 SkPath path;
951 path.addRRect(inner); 991 path.addRRect(inner);
952 path.addRRect(outer); 992 path.addRRect(outer);
953 path.setFillType(SkPath::kEvenOdd_FillType); 993 path.setFillType(SkPath::kEvenOdd_FillType);
954 994
955 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); 995 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
(...skipping 11 matching lines...) Expand all
967 } 1007 }
968 1008
969 if (strokeInfo.isDashed()) { 1009 if (strokeInfo.isDashed()) {
970 SkPath path; 1010 SkPath path;
971 path.addOval(oval); 1011 path.addOval(oval);
972 this->drawPath(paint, path, strokeInfo); 1012 this->drawPath(paint, path, strokeInfo);
973 return; 1013 return;
974 } 1014 }
975 1015
976 AutoRestoreEffects are; 1016 AutoRestoreEffects are;
977 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 1017 AutoCheckFlush acf(this);
1018 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
978 if (NULL == target) { 1019 if (NULL == target) {
979 return; 1020 return;
980 } 1021 }
981 1022
982 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); 1023 GR_CREATE_TRACE_MARKER("GrContext::drawOval", target);
983 1024
984 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 1025 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
985 1026
986 1027
987 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke Rec)) { 1028 if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, stroke Rec)) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 if (path.isInverseFillType()) { 1095 if (path.isInverseFillType()) {
1055 this->drawPaint(paint); 1096 this->drawPaint(paint);
1056 } 1097 }
1057 return; 1098 return;
1058 } 1099 }
1059 1100
1060 if (strokeInfo.isDashed()) { 1101 if (strokeInfo.isDashed()) {
1061 SkPoint pts[2]; 1102 SkPoint pts[2];
1062 if (path.isLine(pts)) { 1103 if (path.isLine(pts)) {
1063 AutoRestoreEffects are; 1104 AutoRestoreEffects are;
1064 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 1105 AutoCheckFlush acf(this);
1106 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
1065 if (NULL == target) { 1107 if (NULL == target) {
1066 return; 1108 return;
1067 } 1109 }
1068 GrDrawState* drawState = target->drawState(); 1110 GrDrawState* drawState = target->drawState();
1069 1111
1070 SkMatrix origViewMatrix = drawState->getViewMatrix(); 1112 SkMatrix origViewMatrix = drawState->getViewMatrix();
1071 GrDrawState::AutoViewMatrixRestore avmr; 1113 GrDrawState::AutoViewMatrixRestore avmr;
1072 if (avmr.setIdentity(target->drawState())) { 1114 if (avmr.setIdentity(target->drawState())) {
1073 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu, target, 1115 if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu, target,
1074 origViewMatrix)) { 1116 origViewMatrix)) {
(...skipping 15 matching lines...) Expand all
1090 this->drawPath(paint, path, newStrokeInfo); 1132 this->drawPath(paint, path, newStrokeInfo);
1091 return; 1133 return;
1092 } 1134 }
1093 1135
1094 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. 1136 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re.
1095 // Scratch textures can be recycled after they are returned to the texture 1137 // Scratch textures can be recycled after they are returned to the texture
1096 // cache. This presents a potential hazard for buffered drawing. However, 1138 // cache. This presents a potential hazard for buffered drawing. However,
1097 // the writePixels that uploads to the scratch will perform a flush so we're 1139 // the writePixels that uploads to the scratch will perform a flush so we're
1098 // OK. 1140 // OK.
1099 AutoRestoreEffects are; 1141 AutoRestoreEffects are;
1100 GrDrawTarget* target = this->prepareToDraw(&paint, &are); 1142 AutoCheckFlush acf(this);
1143 GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf);
1101 if (NULL == target) { 1144 if (NULL == target) {
1102 return; 1145 return;
1103 } 1146 }
1104 GrDrawState* drawState = target->drawState(); 1147 GrDrawState* drawState = target->drawState();
1105 1148
1106 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex()); 1149 GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isC onvex());
1107 1150
1108 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); 1151 const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
1109 1152
1110 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled(); 1153 bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->i sMultisampled();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 void GrContext::flush(int flagsBitfield) { 1235 void GrContext::flush(int flagsBitfield) {
1193 if (NULL == fDrawBuffer) { 1236 if (NULL == fDrawBuffer) {
1194 return; 1237 return;
1195 } 1238 }
1196 1239
1197 if (kDiscard_FlushBit & flagsBitfield) { 1240 if (kDiscard_FlushBit & flagsBitfield) {
1198 fDrawBuffer->reset(); 1241 fDrawBuffer->reset();
1199 } else { 1242 } else {
1200 fDrawBuffer->flush(); 1243 fDrawBuffer->flush();
1201 } 1244 }
1245 fResourceCache->purgeAsNeeded();
1246 fFlushToReduceCacheSize = false;
1202 } 1247 }
1203 1248
1204 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, 1249 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
1205 const void* inPixels, size_t outRowBytes, void* outPix els) { 1250 const void* inPixels, size_t outRowBytes, void* outPix els) {
1206 SkSrcPixelInfo srcPI; 1251 SkSrcPixelInfo srcPI;
1207 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { 1252 if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) {
1208 return false; 1253 return false;
1209 } 1254 }
1210 srcPI.fAlphaType = kUnpremul_SkAlphaType; 1255 srcPI.fAlphaType = kUnpremul_SkAlphaType;
1211 srcPI.fPixels = inPixels; 1256 srcPI.fPixels = inPixels;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1356 }
1312 1357
1313 SkMatrix matrix; 1358 SkMatrix matrix;
1314 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); 1359 matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
1315 1360
1316 // This function can be called in the midst of drawing another object (e.g., when uploading a 1361 // This function can be called in the midst of drawing another object (e.g., when uploading a
1317 // SW-rasterized clip while issuing a draw). So we push the current geometry state before 1362 // SW-rasterized clip while issuing a draw). So we push the current geometry state before
1318 // drawing a rect to the render target. 1363 // drawing a rect to the render target.
1319 // The bracket ensures we pop the stack if we wind up flushing below. 1364 // The bracket ensures we pop the stack if we wind up flushing below.
1320 { 1365 {
1321 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL); 1366 GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL);
1322 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k Reset_ASRInit, 1367 GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::k Reset_ASRInit,
1323 &matrix); 1368 &matrix);
1324 GrDrawState* drawState = drawTarget->drawState(); 1369 GrDrawState* drawState = drawTarget->drawState();
1325 drawState->addColorProcessor(fp); 1370 drawState->addColorProcessor(fp);
1326 drawState->setRenderTarget(renderTarget); 1371 drawState->setRenderTarget(renderTarget);
1327 drawState->disableState(GrDrawState::kClip_StateBit); 1372 drawState->disableState(GrDrawState::kClip_StateBit);
1328 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height))); 1373 drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToS calar(height)));
1329 } 1374 }
1330 1375
1331 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1376 if (kFlushWrites_PixelOp & pixelOpsFlags) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 GrRenderTarget* rt = surface->asRenderTarget(); 1536 GrRenderTarget* rt = surface->asRenderTarget();
1492 if (fGpu && rt) { 1537 if (fGpu && rt) {
1493 fGpu->resolveRenderTarget(rt); 1538 fGpu->resolveRenderTarget(rt);
1494 } 1539 }
1495 } 1540 }
1496 1541
1497 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { 1542 void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
1498 SkASSERT(renderTarget); 1543 SkASSERT(renderTarget);
1499 ASSERT_OWNED_RESOURCE(renderTarget); 1544 ASSERT_OWNED_RESOURCE(renderTarget);
1500 AutoRestoreEffects are; 1545 AutoRestoreEffects are;
1501 GrDrawTarget* target = this->prepareToDraw(NULL, &are); 1546 AutoCheckFlush acf(this);
1547 GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf);
1502 if (NULL == target) { 1548 if (NULL == target) {
1503 return; 1549 return;
1504 } 1550 }
1505 target->discard(renderTarget); 1551 target->discard(renderTarget);
1506 } 1552 }
1507 1553
1508 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct, 1554 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe ct,
1509 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { 1555 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) {
1510 if (NULL == src || NULL == dst) { 1556 if (NULL == src || NULL == dst) {
1511 return; 1557 return;
1512 } 1558 }
1513 ASSERT_OWNED_RESOURCE(src); 1559 ASSERT_OWNED_RESOURCE(src);
1514 ASSERT_OWNED_RESOURCE(dst); 1560 ASSERT_OWNED_RESOURCE(dst);
1515 1561
1516 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh 1562 // Since we're going to the draw target and not GPU, no need to check kNoFlu sh
1517 // here. 1563 // here.
1518 1564
1519 GrDrawTarget* target = this->prepareToDraw(NULL, NULL); 1565 GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL);
1520 if (NULL == target) { 1566 if (NULL == target) {
1521 return; 1567 return;
1522 } 1568 }
1523 target->copySurface(dst, src, srcRect, dstPoint); 1569 target->copySurface(dst, src, srcRect, dstPoint);
1524 1570
1525 if (kFlushWrites_PixelOp & pixelOpsFlags) { 1571 if (kFlushWrites_PixelOp & pixelOpsFlags) {
1526 this->flush(); 1572 this->flush();
1527 } 1573 }
1528 } 1574 }
1529 1575
1530 void GrContext::flushSurfaceWrites(GrSurface* surface) { 1576 void GrContext::flushSurfaceWrites(GrSurface* surface) {
1531 if (surface->surfacePriv().hasPendingWrite()) { 1577 if (surface->surfacePriv().hasPendingWrite()) {
1532 this->flush(); 1578 this->flush();
1533 } 1579 }
1534 } 1580 }
1535 1581
1536 //////////////////////////////////////////////////////////////////////////////// 1582 ////////////////////////////////////////////////////////////////////////////////
1537 1583
1538 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, AutoRestoreEffects* are) { 1584 GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint,
1585 AutoRestoreEffects* are,
1586 AutoCheckFlush* acf) {
1539 // All users of this draw state should be freeing up all effects when they'r e done. 1587 // All users of this draw state should be freeing up all effects when they'r e done.
1540 // Otherwise effects that own resources may keep those resources alive indef initely. 1588 // Otherwise effects that own resources may keep those resources alive indef initely.
1541 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() && 1589 SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageSt ages() &&
1542 !fDrawState->hasGeometryProcessor()); 1590 !fDrawState->hasGeometryProcessor());
1543 1591
1544 if (NULL == fGpu) { 1592 if (NULL == fGpu) {
1545 return NULL; 1593 return NULL;
1546 } 1594 }
1547 1595
1548 ASSERT_OWNED_RESOURCE(fRenderTarget.get()); 1596 ASSERT_OWNED_RESOURCE(fRenderTarget.get());
1549 if (paint) { 1597 if (paint) {
1550 SkASSERT(are); 1598 SkASSERT(are);
1599 SkASSERT(acf);
1551 are->set(fDrawState); 1600 are->set(fDrawState);
1552 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); 1601 fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
1553 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK 1602 #if GR_DEBUG_PARTIAL_COVERAGE_CHECK
1554 if ((paint->hasMask() || 0xff != paint->fCoverage) && 1603 if ((paint->hasMask() || 0xff != paint->fCoverage) &&
1555 !fDrawState->couldApplyCoverage(fGpu->caps())) { 1604 !fDrawState->couldApplyCoverage(fGpu->caps())) {
1556 SkDebugf("Partial pixel coverage will be incorrectly blended.\n"); 1605 SkDebugf("Partial pixel coverage will be incorrectly blended.\n");
1557 } 1606 }
1558 #endif 1607 #endif
1559 // Clear any vertex attributes configured for the previous use of the 1608 // Clear any vertex attributes configured for the previous use of the
1560 // GrDrawState which can effect which blend optimizations are in effect. 1609 // GrDrawState which can effect which blend optimizations are in effect.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); 1689 DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
1641 1690
1642 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, 1691 fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
1643 fDrawBufferVBAllocPool, 1692 fDrawBufferVBAllocPool,
1644 fDrawBufferIBAllocPool)); 1693 fDrawBufferIBAllocPool));
1645 1694
1646 fDrawBuffer->setDrawState(fDrawState); 1695 fDrawBuffer->setDrawState(fDrawState);
1647 } 1696 }
1648 1697
1649 GrDrawTarget* GrContext::getTextTarget() { 1698 GrDrawTarget* GrContext::getTextTarget() {
1650 return this->prepareToDraw(NULL, NULL); 1699 return this->prepareToDraw(NULL, NULL, NULL);
1651 } 1700 }
1652 1701
1653 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { 1702 const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
1654 return fGpu->getQuadIndexBuffer(); 1703 return fGpu->getQuadIndexBuffer();
1655 } 1704 }
1656 1705
1657 namespace { 1706 namespace {
1658 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { 1707 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
1659 GrConfigConversionEffect::PMConversion pmToUPM; 1708 GrConfigConversionEffect::PMConversion pmToUPM;
1660 GrConfigConversionEffect::PMConversion upmToPM; 1709 GrConfigConversionEffect::PMConversion upmToPM;
(...skipping 29 matching lines...) Expand all
1690 GrConfigConversionEffect::PMConversion upmToPM = 1739 GrConfigConversionEffect::PMConversion upmToPM =
1691 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); 1740 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
1692 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { 1741 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) {
1693 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix); 1742 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat rix);
1694 } else { 1743 } else {
1695 return NULL; 1744 return NULL;
1696 } 1745 }
1697 } 1746 }
1698 1747
1699 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour ce* resource) { 1748 void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResour ce* resource) {
1700 resource->cacheAccess().setContentKey(resourceKey); 1749 fResourceCache->addResource(resourceKey, resource);
1701 } 1750 }
1702 1751
1703 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource Key) { 1752 GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resource Key) {
1704 return fResourceCache2->findAndRefContentResource(resourceKey); 1753 GrGpuResource* resource = fResourceCache2->findAndRefContentResource(resourc eKey);
1754 if (resource) {
1755 fResourceCache->makeResourceMRU(resource);
1756 }
1757 return resource;
1705 } 1758 }
1706 1759
1707 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { 1760 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
1708 fGpu->addGpuTraceMarker(marker); 1761 fGpu->addGpuTraceMarker(marker);
1709 if (fDrawBuffer) { 1762 if (fDrawBuffer) {
1710 fDrawBuffer->addGpuTraceMarker(marker); 1763 fDrawBuffer->addGpuTraceMarker(marker);
1711 } 1764 }
1712 } 1765 }
1713 1766
1714 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 1767 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
1715 fGpu->removeGpuTraceMarker(marker); 1768 fGpu->removeGpuTraceMarker(marker);
1716 if (fDrawBuffer) { 1769 if (fDrawBuffer) {
1717 fDrawBuffer->removeGpuTraceMarker(marker); 1770 fDrawBuffer->removeGpuTraceMarker(marker);
1718 } 1771 }
1719 } 1772 }
1720 1773
1721 /////////////////////////////////////////////////////////////////////////////// 1774 ///////////////////////////////////////////////////////////////////////////////
1722 #if GR_CACHE_STATS 1775 #if GR_CACHE_STATS
1723 void GrContext::printCacheStats() const { 1776 void GrContext::printCacheStats() const {
1724 fResourceCache2->printStats(); 1777 fResourceCache->printStats();
1725 } 1778 }
1726 #endif 1779 #endif
1727 1780
1728 #if GR_GPU_STATS 1781 #if GR_GPU_STATS
1729 const GrContext::GPUStats* GrContext::gpuStats() const { 1782 const GrContext::GPUStats* GrContext::gpuStats() const {
1730 return fGpu->gpuStats(); 1783 return fGpu->gpuStats();
1731 } 1784 }
1732 #endif 1785 #endif
1733 1786
OLDNEW
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | src/gpu/GrGpuResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698