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 25 matching lines...) Expand all Loading... |
36 class GrResourceEntry; | 36 class GrResourceEntry; |
37 class GrResourceCache; | 37 class GrResourceCache; |
38 class GrResourceProvider; | 38 class GrResourceProvider; |
39 class GrTestTarget; | 39 class GrTestTarget; |
40 class GrTextBlobCache; | 40 class GrTextBlobCache; |
41 class GrTextContext; | 41 class GrTextContext; |
42 class GrTextureParams; | 42 class GrTextureParams; |
43 class GrVertexBuffer; | 43 class GrVertexBuffer; |
44 class GrStrokeInfo; | 44 class GrStrokeInfo; |
45 class GrSoftwarePathRenderer; | 45 class GrSoftwarePathRenderer; |
46 class SkGpuDevice; | |
47 | 46 |
48 class SK_API GrContext : public SkRefCnt { | 47 class SK_API GrContext : public SkRefCnt { |
49 public: | 48 public: |
50 SK_DECLARE_INST_COUNT(GrContext) | 49 SK_DECLARE_INST_COUNT(GrContext) |
51 | 50 |
52 /** | 51 /** |
53 * Creates a GrContext for a backend context. | 52 * Creates a GrContext for a backend context. |
54 */ | 53 */ |
55 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions
& options); | 54 static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions
& options); |
56 static GrContext* Create(GrBackend, GrBackendContext); | 55 static GrContext* Create(GrBackend, GrBackendContext); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 * @param dpi the display density in dots per inch. | 166 * @param dpi the display density in dots per inch. |
168 * | 167 * |
169 * @return sample count that should be perform well and have good enough | 168 * @return sample count that should be perform well and have good enough |
170 * rendering quality for the display. Alternatively returns 0 if | 169 * rendering quality for the display. Alternatively returns 0 if |
171 * MSAA is not supported or recommended to be used by default. | 170 * MSAA is not supported or recommended to be used by default. |
172 */ | 171 */ |
173 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; | 172 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
174 | 173 |
175 /** | 174 /** |
176 * Returns a helper object to orchestrate draws. | 175 * Returns a helper object to orchestrate draws. |
| 176 * Callers should take a ref if they rely on the GrDrawContext sticking arou
nd. |
| 177 * NULL will be returned if the context has been abandoned. |
| 178 * |
| 179 * @param devProps the device properties (mainly defines text drawing) |
| 180 * @param uesDFT should Distance Field Text be used? |
177 * | 181 * |
178 * @return a draw context | 182 * @return a draw context |
179 */ | 183 */ |
180 GrDrawContext* drawContext() { | 184 GrDrawContext* drawContext(const SkDeviceProperties* devProps = NULL, bool u
seDFT = false) { |
181 return fDrawingMgr.drawContext(); | 185 return fDrawingMgr.drawContext(devProps, useDFT); |
182 } | 186 } |
183 | 187 |
184 /////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////// |
185 // Misc. | 189 // Misc. |
186 | 190 |
187 /** | 191 /** |
188 * Flags that affect flush() behavior. | 192 * Flags that affect flush() behavior. |
189 */ | 193 */ |
190 enum FlushBits { | 194 enum FlushBits { |
191 /** | 195 /** |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 void* fInfo; | 387 void* fInfo; |
384 }; | 388 }; |
385 | 389 |
386 SkTDArray<CleanUpData> fCleanUpData; | 390 SkTDArray<CleanUpData> fCleanUpData; |
387 | 391 |
388 const uint32_t fUniqueID; | 392 const uint32_t fUniqueID; |
389 | 393 |
390 GrContext(); // init must be called after the constructor. | 394 GrContext(); // init must be called after the constructor. |
391 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); | 395 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
392 | 396 |
393 // Currently the DrawingMgr just wraps the single GrDrawTarget in a single | 397 // Currently the DrawingMgr stores a separate GrDrawContext for each |
394 // GrDrawContext and hands it out. In the future this class will allocate | 398 // combination of text drawing options (pixel geometry x DFT use) |
395 // a new GrDrawContext for each GrRenderTarget/GrDrawTarget and manage | 399 // and hands the appropriate one back given the user's request. |
396 // the DAG. | 400 // All of the GrDrawContexts still land in the same GrDrawTarget! |
| 401 // |
| 402 // In the future this class will allocate a new GrDrawContext for |
| 403 // each GrRenderTarget/GrDrawTarget and manage the DAG. |
397 class DrawingMgr { | 404 class DrawingMgr { |
398 public: | 405 public: |
399 DrawingMgr() | 406 DrawingMgr() : fDrawTarget(NULL) { |
400 : fDrawTarget(NULL) | 407 sk_bzero(fDrawContext, sizeof(fDrawContext)); |
401 , fDrawContext(NULL) { | |
402 } | 408 } |
403 | 409 |
404 ~DrawingMgr(); | 410 ~DrawingMgr(); |
405 | 411 |
406 void init(GrContext* context); | 412 void init(GrContext* context); |
407 | 413 |
408 void abandon(); | 414 void abandon(); |
409 bool abandoned() const { return NULL == fDrawTarget; } | 415 bool abandoned() const { return NULL == fDrawTarget; } |
410 | 416 |
411 void purgeResources(); | 417 void purgeResources(); |
412 void reset(); | 418 void reset(); |
413 void flush(); | 419 void flush(); |
414 | 420 |
415 // Callers should take a ref if they rely on the GrDrawContext sticking
around. | 421 // Callers should take a ref if they rely on the GrDrawContext sticking
around. |
416 // NULL will be returned if the context has been abandoned. | 422 // NULL will be returned if the context has been abandoned. |
417 GrDrawContext* drawContext(); | 423 GrDrawContext* drawContext(const SkDeviceProperties* devProps, bool useD
FT); |
418 | 424 |
419 private: | 425 private: |
| 426 void cleanup(); |
| 427 |
420 friend class GrContext; // for access to fDrawTarget for testing | 428 friend class GrContext; // for access to fDrawTarget for testing |
421 | 429 |
| 430 static const int kNumPixelGeometries = 5; // The different pixel geometr
ies |
| 431 static const int kNumDFTOptions = 2; // DFT or no DFT |
| 432 |
| 433 GrContext* fContext; |
422 GrDrawTarget* fDrawTarget; | 434 GrDrawTarget* fDrawTarget; |
423 | 435 |
424 GrDrawContext* fDrawContext; | 436 GrDrawContext* fDrawContext[kNumPixelGeometries][kNumDFTOptions]; |
425 }; | 437 }; |
426 | 438 |
427 DrawingMgr fDrawingMgr; | 439 DrawingMgr fDrawingMgr; |
428 | 440 |
429 void initMockContext(); | 441 void initMockContext(); |
430 void initCommon(); | 442 void initCommon(); |
431 | 443 |
432 /** | 444 /** |
433 * Creates a new text rendering context that is optimal for the | |
434 * render target and the context. Caller assumes the ownership | |
435 * of the returned object. The returned object must be deleted | |
436 * before the context is destroyed. | |
437 * TODO bury this behind context! | |
438 */ | |
439 GrTextContext* createTextContext(GrRenderTarget*, | |
440 const SkDeviceProperties&, | |
441 bool enableDistanceFieldFonts); | |
442 | |
443 | |
444 /** | |
445 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair | 445 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair |
446 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they | 446 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they |
447 * return NULL. | 447 * return NULL. |
448 */ | 448 */ |
449 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 449 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
450 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 450 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
451 | 451 |
452 /** | 452 /** |
453 * This callback allows the resource cache to callback into the GrContext | 453 * This callback allows the resource cache to callback into the GrContext |
454 * when the cache is still over budget after a purge. | 454 * when the cache is still over budget after a purge. |
455 */ | 455 */ |
456 static void OverBudgetCB(void* data); | 456 static void OverBudgetCB(void* data); |
457 | 457 |
458 /** | 458 /** |
459 * A callback similar to the above for use by the TextBlobCache | 459 * A callback similar to the above for use by the TextBlobCache |
460 * TODO move textblob draw calls below context so we can use the call above. | 460 * TODO move textblob draw calls below context so we can use the call above. |
461 */ | 461 */ |
462 static void TextBlobCacheOverBudgetCB(void* data); | 462 static void TextBlobCacheOverBudgetCB(void* data); |
463 | 463 |
464 // TODO see note on createTextContext | |
465 friend class SkGpuDevice; | |
466 | |
467 typedef SkRefCnt INHERITED; | 464 typedef SkRefCnt INHERITED; |
468 }; | 465 }; |
469 | 466 |
470 #endif | 467 #endif |
OLD | NEW |