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