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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 * | 163 * |
164 * @param config the configuration of the render target. | 164 * @param config the configuration of the render target. |
165 * @param dpi the display density in dots per inch. | 165 * @param dpi the display density in dots per inch. |
166 * | 166 * |
167 * @return sample count that should be perform well and have good enough | 167 * @return sample count that should be perform well and have good enough |
168 * rendering quality for the display. Alternatively returns 0 if | 168 * rendering quality for the display. Alternatively returns 0 if |
169 * MSAA is not supported or recommended to be used by default. | 169 * MSAA is not supported or recommended to be used by default. |
170 */ | 170 */ |
171 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; | 171 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
172 | 172 |
173 /** | |
174 * Returns a helper object to orchestrate draws. | |
175 * Callers should take a ref if they rely on the GrDrawContext sticking arou nd. | |
176 * NULL will be returned if the context has been abandoned. | |
177 * | |
178 * @param rt the render target receiving the draws | |
179 * @param surfaceProps the surface properties (mainly defines text drawing) | |
180 * | |
181 * @return a draw context | |
182 */ | |
183 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surface Props = NULL) { | |
184 return fDrawingMgr.drawContext(rt, surfaceProps); | |
185 } | |
186 | |
187 GrTextContext* textContext(const SkSurfaceProps& surfaceProps, GrRenderTarge t* rt) { | |
188 return fDrawingMgr.textContext(surfaceProps, rt); | |
189 } | |
190 | |
191 // The caller automatically gets a ref on the returned drawTarget. It must | |
192 // be balanced by an unref call. | |
193 GrDrawTarget* newDrawTarget(GrRenderTarget* rt) { | |
194 return fDrawingMgr.newDrawTarget(rt); | |
195 } | |
196 | |
197 /////////////////////////////////////////////////////////////////////////// | 173 /////////////////////////////////////////////////////////////////////////// |
198 // Misc. | 174 // Misc. |
199 | 175 |
200 /** | 176 /** |
201 * Flags that affect flush() behavior. | 177 * Flags that affect flush() behavior. |
202 */ | 178 */ |
203 enum FlushBits { | 179 enum FlushBits { |
204 /** | 180 /** |
205 * A client may reach a point where it has partially rendered a frame | 181 * A client may reach a point where it has partially rendered a frame |
206 * through a GrContext that it knows the user will never see. This flag | 182 * through a GrContext that it knows the user will never see. This flag |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 this is for testing only */ | 342 this is for testing only */ |
367 void setTextBlobCacheLimit_ForTesting(size_t bytes); | 343 void setTextBlobCacheLimit_ForTesting(size_t bytes); |
368 | 344 |
369 /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointe r below should be | 345 /** Specify the sizes of the GrAtlasTextContext atlases. The configs pointe r below should be |
370 to an array of 3 entries */ | 346 to an array of 3 entries */ |
371 void setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs); | 347 void setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs); |
372 | 348 |
373 /** Enumerates all cached GPU resources and dumps their memory to traceMemor yDump. */ | 349 /** Enumerates all cached GPU resources and dumps their memory to traceMemor yDump. */ |
374 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; | 350 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
375 | 351 |
352 // Currently the DrawingMgr creates a separate GrTextContext for each | |
353 // combination of text drawing options (pixel geometry x DFT use) | |
354 // and hands the appropriate one back given the DrawContext's request. | |
355 // | |
356 // It allocates a new GrDrawContext for each GrRenderTarget | |
357 // but all of them still land in the same GrDrawTarget! | |
358 // | |
359 // In the future this class will allocate a new GrDrawContext for | |
360 // each GrRenderTarget/GrDrawTarget and manage the DAG. | |
361 class DrawingMgr { | |
bsalomon
2015/10/16 17:54:53
Don't we want this to be private?
| |
362 public: | |
363 bool abandoned() const { return fAbandoned; } | |
364 | |
365 | |
366 /** | |
367 * Returns a helper object to orchestrate draws. | |
368 * Callers assume the creation ref of the drawContext | |
369 * NULL will be returned if the context has been abandoned. | |
370 * | |
371 * @param rt the render target receiving the draws | |
372 * @param surfaceProps the surface properties (mainly defines text draw ing) | |
373 * | |
374 * @return a draw context | |
375 */ | |
376 GrDrawContext* drawContext(GrRenderTarget* rt, | |
377 const SkSurfaceProps* surfaceProps = nullptr) const; | |
378 | |
379 GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt); | |
380 | |
381 // The caller automatically gets a ref on the returned drawTarget. It mu st | |
382 // be balanced by an unref call. | |
383 GrDrawTarget* newDrawTarget(GrRenderTarget* rt); | |
384 | |
385 GrContext* getContext() { return fContext; } | |
386 | |
387 private: | |
388 DrawingMgr() | |
389 : fContext(nullptr) | |
390 , fAbandoned(false) | |
391 , fNVPRTextContext(nullptr) { | |
392 sk_bzero(fTextContexts, sizeof(fTextContexts)); | |
393 } | |
394 | |
395 ~DrawingMgr(); | |
396 | |
397 void init(GrContext* context); | |
398 | |
399 void abandon(); | |
400 void cleanup(); | |
401 void reset(); | |
402 void flush(); | |
403 | |
404 friend class GrContext; // for access to: ctor, init, abandon, reset & flush | |
405 | |
406 static const int kNumPixelGeometries = 5; // The different pixel geometr ies | |
407 static const int kNumDFTOptions = 2; // DFT or no DFT | |
408 | |
409 GrContext* fContext; | |
410 | |
411 bool fAbandoned; | |
412 SkTDArray<GrDrawTarget*> fDrawTargets; | |
413 | |
414 GrTextContext* fNVPRTextContext; | |
415 GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; | |
416 }; | |
417 | |
418 // This returns a const DrawingMgr which only confers the ability to call | |
419 // drawContext and abandoned | |
420 const DrawingMgr& drawingMgr() { return fDrawingMgr; } | |
421 | |
376 private: | 422 private: |
377 GrGpu* fGpu; | 423 GrGpu* fGpu; |
378 const GrCaps* fCaps; | 424 const GrCaps* fCaps; |
379 GrResourceCache* fResourceCache; | 425 GrResourceCache* fResourceCache; |
380 // this union exists because the inheritance of GrTextureProvider->GrResourc eProvider | 426 // this union exists because the inheritance of GrTextureProvider->GrResourc eProvider |
381 // is in a private header. | 427 // is in a private header. |
382 union { | 428 union { |
383 GrResourceProvider* fResourceProvider; | 429 GrResourceProvider* fResourceProvider; |
384 GrTextureProvider* fTextureProvider; | 430 GrTextureProvider* fTextureProvider; |
385 }; | 431 }; |
(...skipping 28 matching lines...) Expand all Loading... | |
414 void* fInfo; | 460 void* fInfo; |
415 }; | 461 }; |
416 | 462 |
417 SkTDArray<CleanUpData> fCleanUpData; | 463 SkTDArray<CleanUpData> fCleanUpData; |
418 | 464 |
419 const uint32_t fUniqueID; | 465 const uint32_t fUniqueID; |
420 | 466 |
421 GrContext(); // init must be called after the constructor. | 467 GrContext(); // init must be called after the constructor. |
422 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); | 468 bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
423 | 469 |
424 // Currently the DrawingMgr creates a separate GrTextContext for each | |
425 // combination of text drawing options (pixel geometry x DFT use) | |
426 // and hands the appropriate one back given the DrawContext's request. | |
427 // | |
428 // It allocates a new GrDrawContext for each GrRenderTarget | |
429 // but all of them still land in the same GrDrawTarget! | |
430 // | |
431 // In the future this class will allocate a new GrDrawContext for | |
432 // each GrRenderTarget/GrDrawTarget and manage the DAG. | |
433 class DrawingMgr { | |
434 public: | |
435 DrawingMgr() | |
436 : fContext(nullptr) | |
437 , fAbandoned(false) | |
438 , fNVPRTextContext(nullptr) { | |
439 sk_bzero(fTextContexts, sizeof(fTextContexts)); | |
440 } | |
441 | |
442 ~DrawingMgr(); | |
443 | |
444 void init(GrContext* context); | |
445 | |
446 void abandon(); | |
447 bool abandoned() const { return fAbandoned; } | |
448 | |
449 void reset(); | |
450 void flush(); | |
451 | |
452 // Callers assume the creation ref of the drawContext! | |
453 // NULL will be returned if the context has been abandoned. | |
454 GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* sur faceProps); | |
455 | |
456 GrTextContext* textContext(const SkSurfaceProps& props, GrRenderTarget* rt); | |
457 | |
458 GrDrawTarget* newDrawTarget(GrRenderTarget* rt); | |
459 | |
460 private: | |
461 void cleanup(); | |
462 | |
463 friend class GrContext; // for access to fDrawTarget for testing | |
464 | |
465 static const int kNumPixelGeometries = 5; // The different pixel geometr ies | |
466 static const int kNumDFTOptions = 2; // DFT or no DFT | |
467 | |
468 GrContext* fContext; | |
469 | |
470 bool fAbandoned; | |
471 SkTDArray<GrDrawTarget*> fDrawTargets; | |
472 | |
473 GrTextContext* fNVPRTextContext; | |
474 GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; | |
475 }; | |
476 | |
477 DrawingMgr fDrawingMgr; | 470 DrawingMgr fDrawingMgr; |
478 | 471 |
479 void initMockContext(); | 472 void initMockContext(); |
480 void initCommon(); | 473 void initCommon(); |
481 | 474 |
482 /** | 475 /** |
483 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair | 476 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair |
484 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they | 477 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they |
485 * return NULL. | 478 * return NULL. |
486 */ | 479 */ |
(...skipping 18 matching lines...) Expand all Loading... | |
505 /** | 498 /** |
506 * A callback similar to the above for use by the TextBlobCache | 499 * A callback similar to the above for use by the TextBlobCache |
507 * TODO move textblob draw calls below context so we can use the call above. | 500 * TODO move textblob draw calls below context so we can use the call above. |
508 */ | 501 */ |
509 static void TextBlobCacheOverBudgetCB(void* data); | 502 static void TextBlobCacheOverBudgetCB(void* data); |
510 | 503 |
511 typedef SkRefCnt INHERITED; | 504 typedef SkRefCnt INHERITED; |
512 }; | 505 }; |
513 | 506 |
514 #endif | 507 #endif |
OLD | NEW |