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) | |
bsalomon
2015/06/11 01:47:57
devprops doesn't already have a DF flag? I guess I
robertphillips
2015/06/16 16:52:37
I think that would be reasonable.
| |
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: |
420 friend class GrContext; // for access to fDrawTarget for testing | 426 friend class GrContext; // for access to fDrawTarget for testing |
421 | 427 |
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; | |
422 GrDrawTarget* fDrawTarget; | 432 GrDrawTarget* fDrawTarget; |
423 | 433 |
424 GrDrawContext* fDrawContext; | 434 GrDrawContext* fDrawContext[kNumPixelGeometries][kNumDFTOptions]; |
425 }; | 435 }; |
426 | 436 |
427 DrawingMgr fDrawingMgr; | 437 DrawingMgr fDrawingMgr; |
428 | 438 |
429 void initMockContext(); | 439 void initMockContext(); |
430 void initCommon(); | 440 void initCommon(); |
431 | 441 |
432 /** | 442 /** |
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 | 443 * 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 | 444 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they |
447 * return NULL. | 445 * return NULL. |
448 */ | 446 */ |
449 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 447 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
450 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 448 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
451 | 449 |
452 /** | 450 /** |
453 * This callback allows the resource cache to callback into the GrContext | 451 * This callback allows the resource cache to callback into the GrContext |
454 * when the cache is still over budget after a purge. | 452 * when the cache is still over budget after a purge. |
455 */ | 453 */ |
456 static void OverBudgetCB(void* data); | 454 static void OverBudgetCB(void* data); |
457 | 455 |
458 /** | 456 /** |
459 * A callback similar to the above for use by the TextBlobCache | 457 * 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. | 458 * TODO move textblob draw calls below context so we can use the call above. |
461 */ | 459 */ |
462 static void TextBlobCacheOverBudgetCB(void* data); | 460 static void TextBlobCacheOverBudgetCB(void* data); |
463 | 461 |
464 // TODO see note on createTextContext | |
465 friend class SkGpuDevice; | |
466 | |
467 typedef SkRefCnt INHERITED; | 462 typedef SkRefCnt INHERITED; |
468 }; | 463 }; |
469 | 464 |
470 #endif | 465 #endif |
OLD | NEW |