OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrContext_DEFINED | 8 #ifndef GrContext_DEFINED |
9 #define GrContext_DEFINED | 9 #define GrContext_DEFINED |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 sk_sp<SkColorSpace> colorSpace, | 207 sk_sp<SkColorSpace> colorSpace, |
208 int sampleCnt = 0, | 208 int sampleCnt = 0, |
209 GrSurfaceOrigin origin = kDefau
lt_GrSurfaceOrigin, | 209 GrSurfaceOrigin origin = kDefau
lt_GrSurfaceOrigin, |
210 const SkSurfaceProps* surfacePr
ops = nullptr, | 210 const SkSurfaceProps* surfacePr
ops = nullptr, |
211 SkBudgeted budgeted = SkBudgete
d::kYes); | 211 SkBudgeted budgeted = SkBudgete
d::kYes); |
212 | 212 |
213 /////////////////////////////////////////////////////////////////////////// | 213 /////////////////////////////////////////////////////////////////////////// |
214 // Misc. | 214 // Misc. |
215 | 215 |
216 /** | 216 /** |
| 217 * Flags that affect flush() behavior. |
| 218 */ |
| 219 enum FlushBits { |
| 220 /** |
| 221 * A client may reach a point where it has partially rendered a frame |
| 222 * through a GrContext that it knows the user will never see. This flag |
| 223 * causes the flush to skip submission of deferred content to the 3D API |
| 224 * during the flush. |
| 225 */ |
| 226 kDiscard_FlushBit = 0x2, |
| 227 }; |
| 228 |
| 229 /** |
217 * Call to ensure all drawing to the context has been issued to the | 230 * Call to ensure all drawing to the context has been issued to the |
218 * underlying 3D API. | 231 * underlying 3D API. |
| 232 * @param flagsBitfield flags that control the flushing behavior. See |
| 233 * FlushBits. |
219 */ | 234 */ |
220 void flush(); | 235 void flush(int flagsBitfield = 0); |
| 236 |
| 237 void flushIfNecessary() { |
| 238 if (fFlushToReduceCacheSize || this->caps()->immediateFlush()) { |
| 239 this->flush(); |
| 240 } |
| 241 } |
221 | 242 |
222 /** | 243 /** |
223 * These flags can be used with the read/write pixels functions below. | 244 * These flags can be used with the read/write pixels functions below. |
224 */ | 245 */ |
225 enum PixelOpsFlags { | 246 enum PixelOpsFlags { |
226 /** The GrContext will not be flushed before the surface read or write.
This means that | 247 /** The GrContext will not be flushed before the surface read or write.
This means that |
227 the read or write may occur before previous draws have executed. */ | 248 the read or write may occur before previous draws have executed. */ |
228 kDontFlush_PixelOpsFlag = 0x1, | 249 kDontFlush_PixelOpsFlag = 0x1, |
229 /** Any surface writes should be flushed to the backend 3D API after the
surface operation | 250 /** Any surface writes should be flushed to the backend 3D API after the
surface operation |
230 is complete */ | 251 is complete */ |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 union { | 402 union { |
382 GrResourceProvider* fResourceProvider; | 403 GrResourceProvider* fResourceProvider; |
383 GrTextureProvider* fTextureProvider; | 404 GrTextureProvider* fTextureProvider; |
384 }; | 405 }; |
385 | 406 |
386 SkAutoTUnref<GrContextThreadSafeProxy> fThreadSafeProxy; | 407 SkAutoTUnref<GrContextThreadSafeProxy> fThreadSafeProxy; |
387 | 408 |
388 GrBatchFontCache* fBatchFontCache; | 409 GrBatchFontCache* fBatchFontCache; |
389 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; | 410 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; |
390 | 411 |
| 412 // Set by OverbudgetCB() to request that GrContext flush before exiting a dr
aw. |
| 413 bool fFlushToReduceCacheSize; |
391 bool fDidTestPMConversions; | 414 bool fDidTestPMConversions; |
392 int fPMToUPMConversion; | 415 int fPMToUPMConversion; |
393 int fUPMToPMConversion; | 416 int fUPMToPMConversion; |
394 // The sw backend may call GrContext::readSurfacePixels on multiple threads | 417 // The sw backend may call GrContext::readSurfacePixels on multiple threads |
395 // We may transfer the responsibilty for using a mutex to the sw backend | 418 // We may transfer the responsibilty for using a mutex to the sw backend |
396 // when there are fewer code paths that lead to a readSurfacePixels call | 419 // when there are fewer code paths that lead to a readSurfacePixels call |
397 // from the sw backend. readSurfacePixels is reentrant in one case - when pe
rforming | 420 // from the sw backend. readSurfacePixels is reentrant in one case - when pe
rforming |
398 // the PM conversions test. To handle this we do the PM conversions test out
side | 421 // the PM conversions test. To handle this we do the PM conversions test out
side |
399 // of fReadPixelsMutex and use a separate mutex to guard it. When it re-ente
rs | 422 // of fReadPixelsMutex and use a separate mutex to guard it. When it re-ente
rs |
400 // readSurfacePixels it will grab fReadPixelsMutex and release it before the
outer | 423 // readSurfacePixels it will grab fReadPixelsMutex and release it before the
outer |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 const SkMatrix&) const; | 465 const SkMatrix&) const; |
443 /** Called before either of the above two functions to determine the appropr
iate fragment | 466 /** Called before either of the above two functions to determine the appropr
iate fragment |
444 processors for conversions. This must be called by readSurfacePixels bef
ore a mutex is | 467 processors for conversions. This must be called by readSurfacePixels bef
ore a mutex is |
445 taken, since testingvPM conversions itself will call readSurfacePixels *
/ | 468 taken, since testingvPM conversions itself will call readSurfacePixels *
/ |
446 void testPMConversionsIfNecessary(uint32_t flags); | 469 void testPMConversionsIfNecessary(uint32_t flags); |
447 /** Returns true if we've already determined that createPMtoUPMEffect and cr
eateUPMToPMEffect | 470 /** Returns true if we've already determined that createPMtoUPMEffect and cr
eateUPMToPMEffect |
448 will fail. In such cases fall back to SW conversion. */ | 471 will fail. In such cases fall back to SW conversion. */ |
449 bool didFailPMUPMConversionTest() const; | 472 bool didFailPMUPMConversionTest() const; |
450 | 473 |
451 /** | 474 /** |
| 475 * This callback allows the resource cache to callback into the GrContext |
| 476 * when the cache is still over budget after a purge. |
| 477 */ |
| 478 static void OverBudgetCB(void* data); |
| 479 |
| 480 /** |
452 * A callback similar to the above for use by the TextBlobCache | 481 * A callback similar to the above for use by the TextBlobCache |
453 * TODO move textblob draw calls below context so we can use the call above. | 482 * TODO move textblob draw calls below context so we can use the call above. |
454 */ | 483 */ |
455 static void TextBlobCacheOverBudgetCB(void* data); | 484 static void TextBlobCacheOverBudgetCB(void* data); |
456 | 485 |
457 typedef SkRefCnt INHERITED; | 486 typedef SkRefCnt INHERITED; |
458 }; | 487 }; |
459 | 488 |
460 /** | 489 /** |
461 * Can be used to perform actions related to the generating GrContext in a threa
d safe manner. The | 490 * Can be used to perform actions related to the generating GrContext in a threa
d safe manner. The |
462 * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrCo
ntext. | 491 * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrCo
ntext. |
463 */ | 492 */ |
464 class GrContextThreadSafeProxy : public SkRefCnt { | 493 class GrContextThreadSafeProxy : public SkRefCnt { |
465 private: | 494 private: |
466 GrContextThreadSafeProxy(const GrCaps* caps, uint32_t uniqueID) | 495 GrContextThreadSafeProxy(const GrCaps* caps, uint32_t uniqueID) |
467 : fCaps(SkRef(caps)) | 496 : fCaps(SkRef(caps)) |
468 , fContextUniqueID(uniqueID) {} | 497 , fContextUniqueID(uniqueID) {} |
469 | 498 |
470 SkAutoTUnref<const GrCaps> fCaps; | 499 SkAutoTUnref<const GrCaps> fCaps; |
471 uint32_t fContextUniqueID; | 500 uint32_t fContextUniqueID; |
472 | 501 |
473 friend class GrContext; | 502 friend class GrContext; |
474 friend class SkImage; | 503 friend class SkImage; |
475 | 504 |
476 typedef SkRefCnt INHERITED; | 505 typedef SkRefCnt INHERITED; |
477 }; | 506 }; |
478 | 507 |
479 #endif | 508 #endif |
OLD | NEW |