Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 * @param config the configuration of the render target. | 165 * @param config the configuration of the render target. |
| 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. |
|
reed1
2015/06/10 15:10:45
I presume there is no ownership change w/ this? i.
robertphillips
2015/06/10 15:17:44
Done - added some comments.
| |
| 177 * | 176 * |
| 177 * @param devProps the device properties (mainly defines text drawing) | |
| 178 * @param uesDFT should Distance Field Text be used? | |
| 179 * | |
| 178 * @return a draw context | 180 * @return a draw context |
| 179 */ | 181 */ |
| 180 GrDrawContext* drawContext() { | 182 GrDrawContext* drawContext(const SkDeviceProperties* devProps = NULL, bool u seDFT = false) { |
| 181 return fDrawingMgr.drawContext(); | 183 return fDrawingMgr.drawContext(devProps, useDFT); |
| 182 } | 184 } |
| 183 | 185 |
| 184 /////////////////////////////////////////////////////////////////////////// | 186 /////////////////////////////////////////////////////////////////////////// |
| 185 // Misc. | 187 // Misc. |
| 186 | 188 |
| 187 /** | 189 /** |
| 188 * Flags that affect flush() behavior. | 190 * Flags that affect flush() behavior. |
| 189 */ | 191 */ |
| 190 enum FlushBits { | 192 enum FlushBits { |
| 191 /** | 193 /** |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 void* fInfo; | 385 void* fInfo; |
| 384 }; | 386 }; |
| 385 | 387 |
| 386 SkTDArray<CleanUpData> fCleanUpData; | 388 SkTDArray<CleanUpData> fCleanUpData; |
| 387 | 389 |
| 388 const uint32_t fUniqueID; | 390 const uint32_t fUniqueID; |
| 389 | 391 |
| 390 GrContext(); // init must be called after the constructor. | 392 GrContext(); // init must be called after the constructor. |
| 391 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); | 393 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 392 | 394 |
| 393 // Currently the DrawingMgr just wraps the single GrDrawTarget in a single | 395 // Currently the DrawingMgr stores a separate GrDrawContext for each |
| 394 // GrDrawContext and hands it out. In the future this class will allocate | 396 // combination of text drawing options (pixel geometry x DFT use) |
| 395 // a new GrDrawContext for each GrRenderTarget/GrDrawTarget and manage | 397 // and hands the appropriate one back given the user's request. |
| 396 // the DAG. | 398 // All of the GrDrawContexts still land in the same GrDrawTarget! |
| 399 // | |
| 400 // In the future this class will allocate a new GrDrawContext for | |
| 401 // each GrRenderTarget/GrDrawTarget and manage the DAG. | |
| 397 class DrawingMgr { | 402 class DrawingMgr { |
| 398 public: | 403 public: |
| 399 DrawingMgr() | 404 DrawingMgr() : fDrawTarget(NULL) { |
| 400 : fDrawTarget(NULL) | 405 sk_bzero(fDrawContext, sizeof(fDrawContext)); |
| 401 , fDrawContext(NULL) { | |
| 402 } | 406 } |
| 403 | 407 |
| 404 ~DrawingMgr(); | 408 ~DrawingMgr(); |
| 405 | 409 |
| 406 void init(GrContext* context); | 410 void init(GrContext* context); |
| 407 | 411 |
| 408 void abandon(); | 412 void abandon(); |
| 409 bool abandoned() const { return NULL == fDrawTarget; } | 413 bool abandoned() const { return NULL == fDrawTarget; } |
| 410 | 414 |
| 411 void purgeResources(); | 415 void purgeResources(); |
| 412 void reset(); | 416 void reset(); |
| 413 void flush(); | 417 void flush(); |
| 414 | 418 |
| 415 // Callers should take a ref if they rely on the GrDrawContext sticking around. | 419 // Callers should take a ref if they rely on the GrDrawContext sticking around. |
| 416 // NULL will be returned if the context has been abandoned. | 420 // NULL will be returned if the context has been abandoned. |
| 417 GrDrawContext* drawContext(); | 421 GrDrawContext* drawContext(const SkDeviceProperties* devProps, bool useD FT); |
| 418 | 422 |
| 419 private: | 423 private: |
| 420 friend class GrContext; // for access to fDrawTarget for testing | 424 friend class GrContext; // for access to fDrawTarget for testing |
| 421 | 425 |
| 426 static const int kNumPixelGeometries = 5; // The different pixel geometr ies | |
| 427 static const int kNumDFTOptions = 2; // DFT or no DFT | |
| 428 | |
| 429 GrContext* fContext; | |
| 422 GrDrawTarget* fDrawTarget; | 430 GrDrawTarget* fDrawTarget; |
| 423 | 431 |
| 424 GrDrawContext* fDrawContext; | 432 GrDrawContext* fDrawContext[kNumPixelGeometries][kNumDFTOptions]; |
| 425 }; | 433 }; |
| 426 | 434 |
| 427 DrawingMgr fDrawingMgr; | 435 DrawingMgr fDrawingMgr; |
| 428 | 436 |
| 429 void initMockContext(); | 437 void initMockContext(); |
| 430 void initCommon(); | 438 void initCommon(); |
| 431 | 439 |
| 432 /** | 440 /** |
| 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 | 441 * 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 | 442 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they |
| 447 * return NULL. | 443 * return NULL. |
| 448 */ | 444 */ |
| 449 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 445 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
| 450 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 446 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
| 451 | 447 |
| 452 /** | 448 /** |
| 453 * This callback allows the resource cache to callback into the GrContext | 449 * This callback allows the resource cache to callback into the GrContext |
| 454 * when the cache is still over budget after a purge. | 450 * when the cache is still over budget after a purge. |
| 455 */ | 451 */ |
| 456 static void OverBudgetCB(void* data); | 452 static void OverBudgetCB(void* data); |
| 457 | 453 |
| 458 /** | 454 /** |
| 459 * A callback similar to the above for use by the TextBlobCache | 455 * 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. | 456 * TODO move textblob draw calls below context so we can use the call above. |
| 461 */ | 457 */ |
| 462 static void TextBlobCacheOverBudgetCB(void* data); | 458 static void TextBlobCacheOverBudgetCB(void* data); |
| 463 | 459 |
| 464 // TODO see note on createTextContext | |
| 465 friend class SkGpuDevice; | |
| 466 | |
| 467 typedef SkRefCnt INHERITED; | 460 typedef SkRefCnt INHERITED; |
| 468 }; | 461 }; |
| 469 | 462 |
| 470 #endif | 463 #endif |
| OLD | NEW |