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

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

Powered by Google App Engine
This is Rietveld 408576698