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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 /** | 297 /** |
298 * Temporarily override the true max texture size. Note: an override | 298 * Temporarily override the true max texture size. Note: an override |
299 * larger then the true max texture size will have no effect. | 299 * larger then the true max texture size will have no effect. |
300 * This entry point is mainly meant for testing texture size dependent | 300 * This entry point is mainly meant for testing texture size dependent |
301 * features and is only available if defined outside of Skia (see | 301 * features and is only available if defined outside of Skia (see |
302 * bleed GM. | 302 * bleed GM. |
303 */ | 303 */ |
304 void setMaxTextureSizeOverride(int maxTextureSizeOverride); | 304 void setMaxTextureSizeOverride(int maxTextureSizeOverride); |
305 | 305 |
306 /////////////////////////////////////////////////////////////////////////// | |
307 // Render targets | |
308 | |
309 /** | |
310 * Sets the render target. | |
311 * @param target the render target to set. | |
312 */ | |
313 void setRenderTarget(GrRenderTarget* target) { | |
314 fRenderTarget.reset(SkSafeRef(target)); | |
315 } | |
316 | |
317 /** | |
318 * Gets the current render target. | |
319 * @return the currently bound render target. | |
320 */ | |
321 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get();
} | |
322 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } | |
323 | |
324 /** | 306 /** |
325 * Can the provided configuration act as a color render target? | 307 * Can the provided configuration act as a color render target? |
326 */ | 308 */ |
327 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; | 309 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; |
328 | 310 |
329 /** | 311 /** |
330 * Return the max width or height of a render target supported by the | 312 * Return the max width or height of a render target supported by the |
331 * current GPU. | 313 * current GPU. |
332 */ | 314 */ |
333 int getMaxRenderTargetSize() const; | 315 int getMaxRenderTargetSize() const; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 * @param color the color to clear to. | 383 * @param color the color to clear to. |
402 * @param canIgnoreRect allows partial clears to be converted to whole | 384 * @param canIgnoreRect allows partial clears to be converted to whole |
403 * clears on platforms for which that is cheap | 385 * clears on platforms for which that is cheap |
404 * @param target The render target to clear. | 386 * @param target The render target to clear. |
405 */ | 387 */ |
406 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderT
arget* target); | 388 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderT
arget* target); |
407 | 389 |
408 /** | 390 /** |
409 * Draw everywhere (respecting the clip) with the paint. | 391 * Draw everywhere (respecting the clip) with the paint. |
410 */ | 392 */ |
411 void drawPaint(const GrPaint&, const SkMatrix& viewMatrix); | 393 void drawPaint(GrRenderTarget*, const GrPaint&, const SkMatrix& viewMatrix); |
412 | 394 |
413 /** | 395 /** |
414 * Draw the rect using a paint. | 396 * Draw the rect using a paint. |
415 * @param paint describes how to color pixels. | 397 * @param paint describes how to color pixels. |
416 * @param viewMatrix transformation matrix | 398 * @param viewMatrix transformation matrix |
417 * @param strokeInfo the stroke information (width, join, cap), and. | 399 * @param strokeInfo the stroke information (width, join, cap), and. |
418 * the dash information (intervals, count, phase). | 400 * the dash information (intervals, count, phase). |
419 * If strokeInfo == NULL, then the rect is filled. | 401 * If strokeInfo == NULL, then the rect is filled. |
420 * Otherwise, if stroke width == 0, then the stroke | 402 * Otherwise, if stroke width == 0, then the stroke |
421 * is always a single pixel thick, else the rect is | 403 * is always a single pixel thick, else the rect is |
422 * mitered/beveled stroked based on stroke width. | 404 * mitered/beveled stroked based on stroke width. |
423 * The rects coords are used to access the paint (through texture matrix) | 405 * The rects coords are used to access the paint (through texture matrix) |
424 */ | 406 */ |
425 void drawRect(const GrPaint& paint, | 407 void drawRect(GrRenderTarget*, |
| 408 const GrPaint& paint, |
426 const SkMatrix& viewMatrix, | 409 const SkMatrix& viewMatrix, |
427 const SkRect&, | 410 const SkRect&, |
428 const GrStrokeInfo* strokeInfo = NULL); | 411 const GrStrokeInfo* strokeInfo = NULL); |
429 | 412 |
430 /** | 413 /** |
431 * Maps a rectangle of shader coordinates to a rectangle and draws that rect
angle | 414 * Maps a rectangle of shader coordinates to a rectangle and draws that rect
angle |
432 * | 415 * |
433 * @param paint describes how to color pixels. | 416 * @param paint describes how to color pixels. |
434 * @param viewMatrix transformation matrix which applies to rectToDraw | 417 * @param viewMatrix transformation matrix which applies to rectToDraw |
435 * @param rectToDraw the rectangle to draw | 418 * @param rectToDraw the rectangle to draw |
436 * @param localRect the rectangle of shader coordinates applied to rectT
oDraw | 419 * @param localRect the rectangle of shader coordinates applied to rectT
oDraw |
437 * @param localMatrix an optional matrix to transform the shader coordinat
es before applying | 420 * @param localMatrix an optional matrix to transform the shader coordinat
es before applying |
438 * to rectToDraw | 421 * to rectToDraw |
439 */ | 422 */ |
440 void drawNonAARectToRect(const GrPaint& paint, | 423 void drawNonAARectToRect(GrRenderTarget*, |
| 424 const GrPaint& paint, |
441 const SkMatrix& viewMatrix, | 425 const SkMatrix& viewMatrix, |
442 const SkRect& rectToDraw, | 426 const SkRect& rectToDraw, |
443 const SkRect& localRect, | 427 const SkRect& localRect, |
444 const SkMatrix* localMatrix = NULL); | 428 const SkMatrix* localMatrix = NULL); |
445 | 429 |
446 /** | 430 /** |
447 * Draws a non-AA rect with paint and a localMatrix | 431 * Draws a non-AA rect with paint and a localMatrix |
448 */ | 432 */ |
449 void drawNonAARectWithLocalMatrix(const GrPaint& paint, | 433 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt, |
| 434 const GrPaint& paint, |
450 const SkMatrix& viewMatrix, | 435 const SkMatrix& viewMatrix, |
451 const SkRect& rect, | 436 const SkRect& rect, |
452 const SkMatrix& localMatrix) { | 437 const SkMatrix& localMatrix) { |
453 this->drawNonAARectToRect(paint, viewMatrix, rect, rect, &localMatrix); | 438 this->drawNonAARectToRect(rt, paint, viewMatrix, rect, rect, &localMatri
x); |
454 } | 439 } |
455 | 440 |
456 /** | 441 /** |
457 * Draw a roundrect using a paint. | 442 * Draw a roundrect using a paint. |
458 * | 443 * |
459 * @param paint describes how to color pixels. | 444 * @param paint describes how to color pixels. |
460 * @param viewMatrix transformation matrix | 445 * @param viewMatrix transformation matrix |
461 * @param rrect the roundrect to draw | 446 * @param rrect the roundrect to draw |
462 * @param strokeInfo the stroke information (width, join, cap) and | 447 * @param strokeInfo the stroke information (width, join, cap) and |
463 * the dash information (intervals, count, phase). | 448 * the dash information (intervals, count, phase). |
464 */ | 449 */ |
465 void drawRRect(const GrPaint&, const SkMatrix& viewMatrix, const SkRRect& rr
ect, | 450 void drawRRect(GrRenderTarget*, |
| 451 const GrPaint&, |
| 452 const SkMatrix& viewMatrix, |
| 453 const SkRRect& rrect, |
466 const GrStrokeInfo&); | 454 const GrStrokeInfo&); |
467 | 455 |
468 /** | 456 /** |
469 * Shortcut for drawing an SkPath consisting of nested rrects using a paint
. | 457 * Shortcut for drawing an SkPath consisting of nested rrects using a paint
. |
470 * Does not support stroking. The result is undefined if outer does not con
tain | 458 * Does not support stroking. The result is undefined if outer does not con
tain |
471 * inner. | 459 * inner. |
472 * | 460 * |
473 * @param paint describes how to color pixels. | 461 * @param paint describes how to color pixels. |
474 * @param viewMatrix transformation matrix | 462 * @param viewMatrix transformation matrix |
475 * @param outer the outer roundrect | 463 * @param outer the outer roundrect |
476 * @param inner the inner roundrect | 464 * @param inner the inner roundrect |
477 */ | 465 */ |
478 void drawDRRect(const GrPaint&, const SkMatrix& viewMatrix, const SkRRect& o
uter, | 466 void drawDRRect(GrRenderTarget*, |
| 467 const GrPaint&, |
| 468 const SkMatrix& viewMatrix, |
| 469 const SkRRect& outer, |
479 const SkRRect& inner); | 470 const SkRRect& inner); |
480 | 471 |
481 | 472 |
482 /** | 473 /** |
483 * Draws a path. | 474 * Draws a path. |
484 * | 475 * |
485 * @param paint describes how to color pixels. | 476 * @param paint describes how to color pixels. |
486 * @param viewMatrix transformation matrix | 477 * @param viewMatrix transformation matrix |
487 * @param path the path to draw | 478 * @param path the path to draw |
488 * @param strokeInfo the stroke information (width, join, cap) and | 479 * @param strokeInfo the stroke information (width, join, cap) and |
489 * the dash information (intervals, count, phase). | 480 * the dash information (intervals, count, phase). |
490 */ | 481 */ |
491 void drawPath(const GrPaint&, const SkMatrix& viewMatrix, const SkPath&, con
st GrStrokeInfo&); | 482 void drawPath(GrRenderTarget*, |
| 483 const GrPaint&, |
| 484 const SkMatrix& viewMatrix, |
| 485 const SkPath&, |
| 486 const GrStrokeInfo&); |
492 | 487 |
493 /** | 488 /** |
494 * Draws vertices with a paint. | 489 * Draws vertices with a paint. |
495 * | 490 * |
496 * @param paint describes how to color pixels. | 491 * @param paint describes how to color pixels. |
497 * @param viewMatrix transformation matrix | 492 * @param viewMatrix transformation matrix |
498 * @param primitiveType primitives type to draw. | 493 * @param primitiveType primitives type to draw. |
499 * @param vertexCount number of vertices. | 494 * @param vertexCount number of vertices. |
500 * @param positions array of vertex positions, required. | 495 * @param positions array of vertex positions, required. |
501 * @param texCoords optional array of texture coordinates used | 496 * @param texCoords optional array of texture coordinates used |
502 * to access the paint. | 497 * to access the paint. |
503 * @param colors optional array of per-vertex colors, supercedes | 498 * @param colors optional array of per-vertex colors, supercedes |
504 * the paint's color field. | 499 * the paint's color field. |
505 * @param indices optional array of indices. If NULL vertices | 500 * @param indices optional array of indices. If NULL vertices |
506 * are drawn non-indexed. | 501 * are drawn non-indexed. |
507 * @param indexCount if indices is non-null then this is the | 502 * @param indexCount if indices is non-null then this is the |
508 * number of indices. | 503 * number of indices. |
509 */ | 504 */ |
510 void drawVertices(const GrPaint& paint, | 505 void drawVertices(GrRenderTarget*, |
| 506 const GrPaint& paint, |
511 const SkMatrix& viewMatrix, | 507 const SkMatrix& viewMatrix, |
512 GrPrimitiveType primitiveType, | 508 GrPrimitiveType primitiveType, |
513 int vertexCount, | 509 int vertexCount, |
514 const SkPoint positions[], | 510 const SkPoint positions[], |
515 const SkPoint texs[], | 511 const SkPoint texs[], |
516 const GrColor colors[], | 512 const GrColor colors[], |
517 const uint16_t indices[], | 513 const uint16_t indices[], |
518 int indexCount); | 514 int indexCount); |
519 | 515 |
520 /** | 516 /** |
521 * Draws an oval. | 517 * Draws an oval. |
522 * | 518 * |
523 * @param paint describes how to color pixels. | 519 * @param paint describes how to color pixels. |
524 * @param viewMatrix transformation matrix | 520 * @param viewMatrix transformation matrix |
525 * @param oval the bounding rect of the oval. | 521 * @param oval the bounding rect of the oval. |
526 * @param strokeInfo the stroke information (width, join, cap) and | 522 * @param strokeInfo the stroke information (width, join, cap) and |
527 * the dash information (intervals, count, phase). | 523 * the dash information (intervals, count, phase). |
528 */ | 524 */ |
529 void drawOval(const GrPaint& paint, | 525 void drawOval(GrRenderTarget*, |
| 526 const GrPaint& paint, |
530 const SkMatrix& viewMatrix, | 527 const SkMatrix& viewMatrix, |
531 const SkRect& oval, | 528 const SkRect& oval, |
532 const GrStrokeInfo& strokeInfo); | 529 const GrStrokeInfo& strokeInfo); |
533 | 530 |
534 /////////////////////////////////////////////////////////////////////////// | 531 /////////////////////////////////////////////////////////////////////////// |
535 // Misc. | 532 // Misc. |
536 | 533 |
537 /** | 534 /** |
538 * Flags that affect flush() behavior. | 535 * Flags that affect flush() behavior. |
539 */ | 536 */ |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 */ | 660 */ |
664 void discardRenderTarget(GrRenderTarget*); | 661 void discardRenderTarget(GrRenderTarget*); |
665 | 662 |
666 #ifdef SK_DEVELOPER | 663 #ifdef SK_DEVELOPER |
667 void dumpFontCache() const; | 664 void dumpFontCache() const; |
668 #endif | 665 #endif |
669 | 666 |
670 /////////////////////////////////////////////////////////////////////////// | 667 /////////////////////////////////////////////////////////////////////////// |
671 // Helpers | 668 // Helpers |
672 | 669 |
673 class AutoRenderTarget : public ::SkNoncopyable { | |
674 public: | |
675 AutoRenderTarget(GrContext* context, GrRenderTarget* target) { | |
676 fPrevTarget = context->getRenderTarget(); | |
677 SkSafeRef(fPrevTarget); | |
678 context->setRenderTarget(target); | |
679 fContext = context; | |
680 } | |
681 AutoRenderTarget(GrContext* context) { | |
682 fPrevTarget = context->getRenderTarget(); | |
683 SkSafeRef(fPrevTarget); | |
684 fContext = context; | |
685 } | |
686 ~AutoRenderTarget() { | |
687 if (fContext) { | |
688 fContext->setRenderTarget(fPrevTarget); | |
689 } | |
690 SkSafeUnref(fPrevTarget); | |
691 } | |
692 private: | |
693 GrContext* fContext; | |
694 GrRenderTarget* fPrevTarget; | |
695 }; | |
696 | |
697 class AutoClip : public ::SkNoncopyable { | 670 class AutoClip : public ::SkNoncopyable { |
698 public: | 671 public: |
699 // This enum exists to require a caller of the constructor to acknowledg
e that the clip will | 672 // This enum exists to require a caller of the constructor to acknowledg
e that the clip will |
700 // initially be wide open. It also could be extended if there are other
desirable initial | 673 // initially be wide open. It also could be extended if there are other
desirable initial |
701 // clip states. | 674 // clip states. |
702 enum InitialClip { | 675 enum InitialClip { |
703 kWideOpen_InitialClip, | 676 kWideOpen_InitialClip, |
704 }; | 677 }; |
705 | 678 |
706 AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState)) | 679 AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState)) |
(...skipping 22 matching lines...) Expand all Loading... |
729 private: | 702 private: |
730 GrContext* fContext; | 703 GrContext* fContext; |
731 const GrClipData* fOldClip; | 704 const GrClipData* fOldClip; |
732 | 705 |
733 SkClipStack fNewClipStack; | 706 SkClipStack fNewClipStack; |
734 GrClipData fNewClipData; | 707 GrClipData fNewClipData; |
735 }; | 708 }; |
736 | 709 |
737 class AutoWideOpenIdentityDraw { | 710 class AutoWideOpenIdentityDraw { |
738 public: | 711 public: |
739 AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt) | 712 AutoWideOpenIdentityDraw(GrContext* ctx) |
740 : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) | 713 : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) { |
741 , fAutoRT(ctx, rt) { | |
742 } | 714 } |
743 | 715 |
744 private: | 716 private: |
745 AutoClip fAutoClip; | 717 AutoClip fAutoClip; |
746 AutoRenderTarget fAutoRT; | |
747 }; | 718 }; |
748 | 719 |
749 /////////////////////////////////////////////////////////////////////////// | 720 /////////////////////////////////////////////////////////////////////////// |
750 // Functions intended for internal use only. | 721 // Functions intended for internal use only. |
751 GrGpu* getGpu() { return fGpu; } | 722 GrGpu* getGpu() { return fGpu; } |
752 const GrGpu* getGpu() const { return fGpu; } | 723 const GrGpu* getGpu() const { return fGpu; } |
753 GrFontCache* getFontCache() { return fFontCache; } | 724 GrFontCache* getFontCache() { return fFontCache; } |
754 GrLayerCache* getLayerCache() { return fLayerCache.get(); } | 725 GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
755 GrDrawTarget* getTextTarget(); | 726 GrDrawTarget* getTextTarget(); |
756 const GrIndexBuffer* getQuadIndexBuffer() const; | 727 const GrIndexBuffer* getQuadIndexBuffer() const; |
(...skipping 25 matching lines...) Expand all Loading... |
782 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ | 753 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
783 void dumpCacheStats(SkString*) const; | 754 void dumpCacheStats(SkString*) const; |
784 void printCacheStats() const; | 755 void printCacheStats() const; |
785 | 756 |
786 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ | 757 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
787 void dumpGpuStats(SkString*) const; | 758 void dumpGpuStats(SkString*) const; |
788 void printGpuStats() const; | 759 void printGpuStats() const; |
789 | 760 |
790 private: | 761 private: |
791 GrGpu* fGpu; | 762 GrGpu* fGpu; |
792 SkAutoTUnref<GrRenderTarget> fRenderTarget; | |
793 const GrClipData* fClip; // TODO: make this ref counted | 763 const GrClipData* fClip; // TODO: make this ref counted |
794 | 764 |
795 GrResourceCache* fResourceCache; | 765 GrResourceCache* fResourceCache; |
796 GrFontCache* fFontCache; | 766 GrFontCache* fFontCache; |
797 SkAutoTDelete<GrLayerCache> fLayerCache; | 767 SkAutoTDelete<GrLayerCache> fLayerCache; |
798 | 768 |
799 GrPathRendererChain* fPathRendererChain; | 769 GrPathRendererChain* fPathRendererChain; |
800 GrSoftwarePathRenderer* fSoftwarePathRenderer; | 770 GrSoftwarePathRenderer* fSoftwarePathRenderer; |
801 | 771 |
802 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; | 772 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
(...skipping 23 matching lines...) Expand all Loading... |
826 GrContext(const Options&); // init must be called after the constructor. | 796 GrContext(const Options&); // init must be called after the constructor. |
827 bool init(GrBackend, GrBackendContext); | 797 bool init(GrBackend, GrBackendContext); |
828 void initMockContext(); | 798 void initMockContext(); |
829 void initCommon(); | 799 void initCommon(); |
830 | 800 |
831 void setupDrawBuffer(); | 801 void setupDrawBuffer(); |
832 | 802 |
833 class AutoCheckFlush; | 803 class AutoCheckFlush; |
834 // Sets the paint and returns the target to draw into. This function is ove
rloaded to either | 804 // Sets the paint and returns the target to draw into. This function is ove
rloaded to either |
835 // take a GrDrawState, GrPaint, and AutoCheckFlush, or JUST an AutoCheckFlus
h | 805 // take a GrDrawState, GrPaint, and AutoCheckFlush, or JUST an AutoCheckFlus
h |
836 GrDrawTarget* prepareToDraw(GrPipelineBuilder*, const GrPaint* paint, const
AutoCheckFlush*); | 806 GrDrawTarget* prepareToDraw(GrPipelineBuilder*, GrRenderTarget* rt, const Gr
Paint* paint, |
| 807 const AutoCheckFlush*); |
837 | 808 |
838 void internalDrawPath(GrDrawTarget*, | 809 void internalDrawPath(GrDrawTarget*, |
839 GrPipelineBuilder*, | 810 GrPipelineBuilder*, |
840 const SkMatrix& viewMatrix, | 811 const SkMatrix& viewMatrix, |
841 GrColor, | 812 GrColor, |
842 bool useAA, | 813 bool useAA, |
843 const SkPath&, | 814 const SkPath&, |
844 const GrStrokeInfo&); | 815 const GrStrokeInfo&); |
845 | 816 |
846 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); | 817 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); |
847 | 818 |
848 /** | 819 /** |
849 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair | 820 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair |
850 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they | 821 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they |
851 * return NULL. | 822 * return NULL. |
852 */ | 823 */ |
853 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 824 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
854 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 825 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
855 | 826 |
856 /** | 827 /** |
857 * This callback allows the resource cache to callback into the GrContext | 828 * This callback allows the resource cache to callback into the GrContext |
858 * when the cache is still over budget after a purge. | 829 * when the cache is still over budget after a purge. |
859 */ | 830 */ |
860 static void OverBudgetCB(void* data); | 831 static void OverBudgetCB(void* data); |
861 | 832 |
862 typedef SkRefCnt INHERITED; | 833 typedef SkRefCnt INHERITED; |
863 }; | 834 }; |
864 | 835 |
865 #endif | 836 #endif |
OLD | NEW |