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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that | 355 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
356 * the client will resolve to a texture). | 356 * the client will resolve to a texture). |
357 * | 357 * |
358 * @param desc description of the object to create. | 358 * @param desc description of the object to create. |
359 * | 359 * |
360 * @return GrTexture object or NULL on failure. | 360 * @return GrTexture object or NULL on failure. |
361 */ | 361 */ |
362 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de
sc); | 362 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de
sc); |
363 | 363 |
364 /////////////////////////////////////////////////////////////////////////// | 364 /////////////////////////////////////////////////////////////////////////// |
365 // Clip state | |
366 /** | |
367 * Gets the current clip. | |
368 * @return the current clip. | |
369 */ | |
370 const GrClip* getClip() const { return fClip; } | |
371 | |
372 /** | |
373 * Sets the clip. | |
374 * @param clipData the clip to set. | |
375 */ | |
376 void setClip(const GrClip* clipData) { fClip = clipData; } | |
377 | |
378 /////////////////////////////////////////////////////////////////////////// | |
379 // Draws | 365 // Draws |
380 | 366 |
381 /** | 367 /** |
382 * Clear the entire or rect of the render target, ignoring any clips. | 368 * Clear the entire or rect of the render target, ignoring any clips. |
383 * @param rect the rect to clear or the whole thing if rect is NULL. | 369 * @param rect the rect to clear or the whole thing if rect is NULL. |
384 * @param color the color to clear to. | 370 * @param color the color to clear to. |
385 * @param canIgnoreRect allows partial clears to be converted to whole | 371 * @param canIgnoreRect allows partial clears to be converted to whole |
386 * clears on platforms for which that is cheap | 372 * clears on platforms for which that is cheap |
387 * @param target The render target to clear. | 373 * @param target The render target to clear. |
388 */ | 374 */ |
389 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderT
arget* target); | 375 void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderT
arget* target); |
390 | 376 |
391 /** | 377 /** |
392 * Draw everywhere (respecting the clip) with the paint. | 378 * Draw everywhere (respecting the clip) with the paint. |
393 */ | 379 */ |
394 void drawPaint(GrRenderTarget*, const GrPaint&, const SkMatrix& viewMatrix); | 380 void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatri
x& viewMatrix); |
395 | 381 |
396 /** | 382 /** |
397 * Draw the rect using a paint. | 383 * Draw the rect using a paint. |
398 * @param paint describes how to color pixels. | 384 * @param paint describes how to color pixels. |
399 * @param viewMatrix transformation matrix | 385 * @param viewMatrix transformation matrix |
400 * @param strokeInfo the stroke information (width, join, cap), and. | 386 * @param strokeInfo the stroke information (width, join, cap), and. |
401 * the dash information (intervals, count, phase). | 387 * the dash information (intervals, count, phase). |
402 * If strokeInfo == NULL, then the rect is filled. | 388 * If strokeInfo == NULL, then the rect is filled. |
403 * Otherwise, if stroke width == 0, then the stroke | 389 * Otherwise, if stroke width == 0, then the stroke |
404 * is always a single pixel thick, else the rect is | 390 * is always a single pixel thick, else the rect is |
405 * mitered/beveled stroked based on stroke width. | 391 * mitered/beveled stroked based on stroke width. |
406 * The rects coords are used to access the paint (through texture matrix) | 392 * The rects coords are used to access the paint (through texture matrix) |
407 */ | 393 */ |
408 void drawRect(GrRenderTarget*, | 394 void drawRect(GrRenderTarget*, |
| 395 const GrClip&, |
409 const GrPaint& paint, | 396 const GrPaint& paint, |
410 const SkMatrix& viewMatrix, | 397 const SkMatrix& viewMatrix, |
411 const SkRect&, | 398 const SkRect&, |
412 const GrStrokeInfo* strokeInfo = NULL); | 399 const GrStrokeInfo* strokeInfo = NULL); |
413 | 400 |
414 /** | 401 /** |
415 * Maps a rectangle of shader coordinates to a rectangle and draws that rect
angle | 402 * Maps a rectangle of shader coordinates to a rectangle and draws that rect
angle |
416 * | 403 * |
417 * @param paint describes how to color pixels. | 404 * @param paint describes how to color pixels. |
418 * @param viewMatrix transformation matrix which applies to rectToDraw | 405 * @param viewMatrix transformation matrix which applies to rectToDraw |
419 * @param rectToDraw the rectangle to draw | 406 * @param rectToDraw the rectangle to draw |
420 * @param localRect the rectangle of shader coordinates applied to rectT
oDraw | 407 * @param localRect the rectangle of shader coordinates applied to rectT
oDraw |
421 * @param localMatrix an optional matrix to transform the shader coordinat
es before applying | 408 * @param localMatrix an optional matrix to transform the shader coordinat
es before applying |
422 * to rectToDraw | 409 * to rectToDraw |
423 */ | 410 */ |
424 void drawNonAARectToRect(GrRenderTarget*, | 411 void drawNonAARectToRect(GrRenderTarget*, |
| 412 const GrClip&, |
425 const GrPaint& paint, | 413 const GrPaint& paint, |
426 const SkMatrix& viewMatrix, | 414 const SkMatrix& viewMatrix, |
427 const SkRect& rectToDraw, | 415 const SkRect& rectToDraw, |
428 const SkRect& localRect, | 416 const SkRect& localRect, |
429 const SkMatrix* localMatrix = NULL); | 417 const SkMatrix* localMatrix = NULL); |
430 | 418 |
431 /** | 419 /** |
432 * Draws a non-AA rect with paint and a localMatrix | 420 * Draws a non-AA rect with paint and a localMatrix |
433 */ | 421 */ |
434 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt, | 422 void drawNonAARectWithLocalMatrix(GrRenderTarget* rt, |
| 423 const GrClip& clip, |
435 const GrPaint& paint, | 424 const GrPaint& paint, |
436 const SkMatrix& viewMatrix, | 425 const SkMatrix& viewMatrix, |
437 const SkRect& rect, | 426 const SkRect& rect, |
438 const SkMatrix& localMatrix) { | 427 const SkMatrix& localMatrix) { |
439 this->drawNonAARectToRect(rt, paint, viewMatrix, rect, rect, &localMatri
x); | 428 this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &loca
lMatrix); |
440 } | 429 } |
441 | 430 |
442 /** | 431 /** |
443 * Draw a roundrect using a paint. | 432 * Draw a roundrect using a paint. |
444 * | 433 * |
445 * @param paint describes how to color pixels. | 434 * @param paint describes how to color pixels. |
446 * @param viewMatrix transformation matrix | 435 * @param viewMatrix transformation matrix |
447 * @param rrect the roundrect to draw | 436 * @param rrect the roundrect to draw |
448 * @param strokeInfo the stroke information (width, join, cap) and | 437 * @param strokeInfo the stroke information (width, join, cap) and |
449 * the dash information (intervals, count, phase). | 438 * the dash information (intervals, count, phase). |
450 */ | 439 */ |
451 void drawRRect(GrRenderTarget*, | 440 void drawRRect(GrRenderTarget*, |
| 441 const GrClip&, |
452 const GrPaint&, | 442 const GrPaint&, |
453 const SkMatrix& viewMatrix, | 443 const SkMatrix& viewMatrix, |
454 const SkRRect& rrect, | 444 const SkRRect& rrect, |
455 const GrStrokeInfo&); | 445 const GrStrokeInfo&); |
456 | 446 |
457 /** | 447 /** |
458 * Shortcut for drawing an SkPath consisting of nested rrects using a paint
. | 448 * Shortcut for drawing an SkPath consisting of nested rrects using a paint
. |
459 * Does not support stroking. The result is undefined if outer does not con
tain | 449 * Does not support stroking. The result is undefined if outer does not con
tain |
460 * inner. | 450 * inner. |
461 * | 451 * |
462 * @param paint describes how to color pixels. | 452 * @param paint describes how to color pixels. |
463 * @param viewMatrix transformation matrix | 453 * @param viewMatrix transformation matrix |
464 * @param outer the outer roundrect | 454 * @param outer the outer roundrect |
465 * @param inner the inner roundrect | 455 * @param inner the inner roundrect |
466 */ | 456 */ |
467 void drawDRRect(GrRenderTarget*, | 457 void drawDRRect(GrRenderTarget*, |
| 458 const GrClip&, |
468 const GrPaint&, | 459 const GrPaint&, |
469 const SkMatrix& viewMatrix, | 460 const SkMatrix& viewMatrix, |
470 const SkRRect& outer, | 461 const SkRRect& outer, |
471 const SkRRect& inner); | 462 const SkRRect& inner); |
472 | 463 |
473 | 464 |
474 /** | 465 /** |
475 * Draws a path. | 466 * Draws a path. |
476 * | 467 * |
477 * @param paint describes how to color pixels. | 468 * @param paint describes how to color pixels. |
478 * @param viewMatrix transformation matrix | 469 * @param viewMatrix transformation matrix |
479 * @param path the path to draw | 470 * @param path the path to draw |
480 * @param strokeInfo the stroke information (width, join, cap) and | 471 * @param strokeInfo the stroke information (width, join, cap) and |
481 * the dash information (intervals, count, phase). | 472 * the dash information (intervals, count, phase). |
482 */ | 473 */ |
483 void drawPath(GrRenderTarget*, | 474 void drawPath(GrRenderTarget*, |
| 475 const GrClip&, |
484 const GrPaint&, | 476 const GrPaint&, |
485 const SkMatrix& viewMatrix, | 477 const SkMatrix& viewMatrix, |
486 const SkPath&, | 478 const SkPath&, |
487 const GrStrokeInfo&); | 479 const GrStrokeInfo&); |
488 | 480 |
489 /** | 481 /** |
490 * Draws vertices with a paint. | 482 * Draws vertices with a paint. |
491 * | 483 * |
492 * @param paint describes how to color pixels. | 484 * @param paint describes how to color pixels. |
493 * @param viewMatrix transformation matrix | 485 * @param viewMatrix transformation matrix |
494 * @param primitiveType primitives type to draw. | 486 * @param primitiveType primitives type to draw. |
495 * @param vertexCount number of vertices. | 487 * @param vertexCount number of vertices. |
496 * @param positions array of vertex positions, required. | 488 * @param positions array of vertex positions, required. |
497 * @param texCoords optional array of texture coordinates used | 489 * @param texCoords optional array of texture coordinates used |
498 * to access the paint. | 490 * to access the paint. |
499 * @param colors optional array of per-vertex colors, supercedes | 491 * @param colors optional array of per-vertex colors, supercedes |
500 * the paint's color field. | 492 * the paint's color field. |
501 * @param indices optional array of indices. If NULL vertices | 493 * @param indices optional array of indices. If NULL vertices |
502 * are drawn non-indexed. | 494 * are drawn non-indexed. |
503 * @param indexCount if indices is non-null then this is the | 495 * @param indexCount if indices is non-null then this is the |
504 * number of indices. | 496 * number of indices. |
505 */ | 497 */ |
506 void drawVertices(GrRenderTarget*, | 498 void drawVertices(GrRenderTarget*, |
| 499 const GrClip&, |
507 const GrPaint& paint, | 500 const GrPaint& paint, |
508 const SkMatrix& viewMatrix, | 501 const SkMatrix& viewMatrix, |
509 GrPrimitiveType primitiveType, | 502 GrPrimitiveType primitiveType, |
510 int vertexCount, | 503 int vertexCount, |
511 const SkPoint positions[], | 504 const SkPoint positions[], |
512 const SkPoint texs[], | 505 const SkPoint texs[], |
513 const GrColor colors[], | 506 const GrColor colors[], |
514 const uint16_t indices[], | 507 const uint16_t indices[], |
515 int indexCount); | 508 int indexCount); |
516 | 509 |
517 /** | 510 /** |
518 * Draws an oval. | 511 * Draws an oval. |
519 * | 512 * |
520 * @param paint describes how to color pixels. | 513 * @param paint describes how to color pixels. |
521 * @param viewMatrix transformation matrix | 514 * @param viewMatrix transformation matrix |
522 * @param oval the bounding rect of the oval. | 515 * @param oval the bounding rect of the oval. |
523 * @param strokeInfo the stroke information (width, join, cap) and | 516 * @param strokeInfo the stroke information (width, join, cap) and |
524 * the dash information (intervals, count, phase). | 517 * the dash information (intervals, count, phase). |
525 */ | 518 */ |
526 void drawOval(GrRenderTarget*, | 519 void drawOval(GrRenderTarget*, |
| 520 const GrClip&, |
527 const GrPaint& paint, | 521 const GrPaint& paint, |
528 const SkMatrix& viewMatrix, | 522 const SkMatrix& viewMatrix, |
529 const SkRect& oval, | 523 const SkRect& oval, |
530 const GrStrokeInfo& strokeInfo); | 524 const GrStrokeInfo& strokeInfo); |
531 | 525 |
532 /////////////////////////////////////////////////////////////////////////// | 526 /////////////////////////////////////////////////////////////////////////// |
533 // Misc. | 527 // Misc. |
534 | 528 |
535 /** | 529 /** |
536 * Flags that affect flush() behavior. | 530 * Flags that affect flush() behavior. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 * Provides a perfomance hint that the render target's contents are allowed | 653 * Provides a perfomance hint that the render target's contents are allowed |
660 * to become undefined. | 654 * to become undefined. |
661 */ | 655 */ |
662 void discardRenderTarget(GrRenderTarget*); | 656 void discardRenderTarget(GrRenderTarget*); |
663 | 657 |
664 #ifdef SK_DEVELOPER | 658 #ifdef SK_DEVELOPER |
665 void dumpFontCache() const; | 659 void dumpFontCache() const; |
666 #endif | 660 #endif |
667 | 661 |
668 /////////////////////////////////////////////////////////////////////////// | 662 /////////////////////////////////////////////////////////////////////////// |
669 // Helpers | |
670 | |
671 class AutoClip : public ::SkNoncopyable { | |
672 public: | |
673 // This enum exists to require a caller of the constructor to acknowledg
e that the clip will | |
674 // initially be wide open. It also could be extended if there are other
desirable initial | |
675 // clip states. | |
676 enum InitialClip { | |
677 kWideOpen_InitialClip, | |
678 }; | |
679 | |
680 AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState)) | |
681 : fContext(context) { | |
682 SkASSERT(kWideOpen_InitialClip == initialState); | |
683 fNewClipData.setClipStack(&fNewClipStack); | |
684 | |
685 fOldClip = context->getClip(); | |
686 context->setClip(&fNewClipData); | |
687 } | |
688 | |
689 AutoClip(GrContext* context, const SkRect& newClipRect) | |
690 : fContext(context) | |
691 , fNewClipStack(newClipRect) { | |
692 fNewClipData.setClipStack(&fNewClipStack); | |
693 | |
694 fOldClip = fContext->getClip(); | |
695 fContext->setClip(&fNewClipData); | |
696 } | |
697 | |
698 ~AutoClip() { | |
699 if (fContext) { | |
700 fContext->setClip(fOldClip); | |
701 } | |
702 } | |
703 private: | |
704 GrContext* fContext; | |
705 const GrClip* fOldClip; | |
706 | |
707 SkClipStack fNewClipStack; | |
708 GrClip fNewClipData; | |
709 }; | |
710 | |
711 class AutoWideOpenIdentityDraw { | |
712 public: | |
713 AutoWideOpenIdentityDraw(GrContext* ctx) | |
714 : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) { | |
715 } | |
716 | |
717 private: | |
718 AutoClip fAutoClip; | |
719 }; | |
720 | |
721 /////////////////////////////////////////////////////////////////////////// | |
722 // Functions intended for internal use only. | 663 // Functions intended for internal use only. |
723 GrGpu* getGpu() { return fGpu; } | 664 GrGpu* getGpu() { return fGpu; } |
724 const GrGpu* getGpu() const { return fGpu; } | 665 const GrGpu* getGpu() const { return fGpu; } |
725 GrFontCache* getFontCache() { return fFontCache; } | 666 GrFontCache* getFontCache() { return fFontCache; } |
726 GrLayerCache* getLayerCache() { return fLayerCache.get(); } | 667 GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
727 GrDrawTarget* getTextTarget(); | 668 GrDrawTarget* getTextTarget(); |
728 const GrIndexBuffer* getQuadIndexBuffer() const; | 669 const GrIndexBuffer* getQuadIndexBuffer() const; |
729 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } | 670 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } |
730 GrResourceCache* getResourceCache() { return fResourceCache; } | 671 GrResourceCache* getResourceCache() { return fResourceCache; } |
731 | 672 |
(...skipping 22 matching lines...) Expand all Loading... |
754 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ | 695 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
755 void dumpCacheStats(SkString*) const; | 696 void dumpCacheStats(SkString*) const; |
756 void printCacheStats() const; | 697 void printCacheStats() const; |
757 | 698 |
758 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ | 699 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
759 void dumpGpuStats(SkString*) const; | 700 void dumpGpuStats(SkString*) const; |
760 void printGpuStats() const; | 701 void printGpuStats() const; |
761 | 702 |
762 private: | 703 private: |
763 GrGpu* fGpu; | 704 GrGpu* fGpu; |
764 const GrClip* fClip; | |
765 | 705 |
766 GrResourceCache* fResourceCache; | 706 GrResourceCache* fResourceCache; |
767 GrFontCache* fFontCache; | 707 GrFontCache* fFontCache; |
768 SkAutoTDelete<GrLayerCache> fLayerCache; | 708 SkAutoTDelete<GrLayerCache> fLayerCache; |
769 | 709 |
770 GrPathRendererChain* fPathRendererChain; | 710 GrPathRendererChain* fPathRendererChain; |
771 GrSoftwarePathRenderer* fSoftwarePathRenderer; | 711 GrSoftwarePathRenderer* fSoftwarePathRenderer; |
772 | 712 |
773 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; | 713 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
774 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; | 714 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
(...skipping 20 matching lines...) Expand all Loading... |
795 const Options fOptions; | 735 const Options fOptions; |
796 | 736 |
797 GrContext(const Options&); // init must be called after the constructor. | 737 GrContext(const Options&); // init must be called after the constructor. |
798 bool init(GrBackend, GrBackendContext); | 738 bool init(GrBackend, GrBackendContext); |
799 void initMockContext(); | 739 void initMockContext(); |
800 void initCommon(); | 740 void initCommon(); |
801 | 741 |
802 void setupDrawBuffer(); | 742 void setupDrawBuffer(); |
803 | 743 |
804 class AutoCheckFlush; | 744 class AutoCheckFlush; |
805 // Sets the paint and returns the target to draw into. This function is ove
rloaded to either | 745 // Sets the paint and returns the target to draw into. |
806 // take a GrDrawState, GrPaint, and AutoCheckFlush, or JUST an AutoCheckFlus
h | 746 GrDrawTarget* prepareToDraw(GrPipelineBuilder*, |
807 GrDrawTarget* prepareToDraw(GrPipelineBuilder*, GrRenderTarget* rt, const Gr
Paint* paint, | 747 GrRenderTarget* rt, |
| 748 const GrClip&, |
| 749 const GrPaint* paint, |
808 const AutoCheckFlush*); | 750 const AutoCheckFlush*); |
809 | 751 |
| 752 // A simpler version of the above which just returns the draw target. Clip
is *NOT* set |
| 753 GrDrawTarget* prepareToDraw(); |
| 754 |
810 void internalDrawPath(GrDrawTarget*, | 755 void internalDrawPath(GrDrawTarget*, |
811 GrPipelineBuilder*, | 756 GrPipelineBuilder*, |
812 const SkMatrix& viewMatrix, | 757 const SkMatrix& viewMatrix, |
813 GrColor, | 758 GrColor, |
814 bool useAA, | 759 bool useAA, |
815 const SkPath&, | 760 const SkPath&, |
816 const GrStrokeInfo&); | 761 const GrStrokeInfo&); |
817 | 762 |
818 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); | 763 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); |
819 | 764 |
820 /** | 765 /** |
821 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair | 766 * These functions create premul <-> unpremul effects if it is possible to g
enerate a pair |
822 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they | 767 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O
therwise, they |
823 * return NULL. | 768 * return NULL. |
824 */ | 769 */ |
825 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 770 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
826 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); | 771 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c
onst SkMatrix&); |
827 | 772 |
828 /** | 773 /** |
829 * This callback allows the resource cache to callback into the GrContext | 774 * This callback allows the resource cache to callback into the GrContext |
830 * when the cache is still over budget after a purge. | 775 * when the cache is still over budget after a purge. |
831 */ | 776 */ |
832 static void OverBudgetCB(void* data); | 777 static void OverBudgetCB(void* data); |
833 | 778 |
834 typedef SkRefCnt INHERITED; | 779 typedef SkRefCnt INHERITED; |
835 }; | 780 }; |
836 | 781 |
837 #endif | 782 #endif |
OLD | NEW |