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