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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 SkSafeRef(fPrevTarget); | 738 SkSafeRef(fPrevTarget); |
739 context->setRenderTarget(target); | 739 context->setRenderTarget(target); |
740 fContext = context; | 740 fContext = context; |
741 } | 741 } |
742 AutoRenderTarget(GrContext* context) { | 742 AutoRenderTarget(GrContext* context) { |
743 fPrevTarget = context->getRenderTarget(); | 743 fPrevTarget = context->getRenderTarget(); |
744 SkSafeRef(fPrevTarget); | 744 SkSafeRef(fPrevTarget); |
745 fContext = context; | 745 fContext = context; |
746 } | 746 } |
747 ~AutoRenderTarget() { | 747 ~AutoRenderTarget() { |
748 if (NULL != fContext) { | 748 if (fContext) { |
749 fContext->setRenderTarget(fPrevTarget); | 749 fContext->setRenderTarget(fPrevTarget); |
750 } | 750 } |
751 SkSafeUnref(fPrevTarget); | 751 SkSafeUnref(fPrevTarget); |
752 } | 752 } |
753 private: | 753 private: |
754 GrContext* fContext; | 754 GrContext* fContext; |
755 GrRenderTarget* fPrevTarget; | 755 GrRenderTarget* fPrevTarget; |
756 }; | 756 }; |
757 | 757 |
758 /** | 758 /** |
(...skipping 13 matching lines...) Expand all Loading... |
772 class AutoMatrix : public ::SkNoncopyable { | 772 class AutoMatrix : public ::SkNoncopyable { |
773 public: | 773 public: |
774 AutoMatrix() : fContext(NULL) {} | 774 AutoMatrix() : fContext(NULL) {} |
775 | 775 |
776 ~AutoMatrix() { this->restore(); } | 776 ~AutoMatrix() { this->restore(); } |
777 | 777 |
778 /** | 778 /** |
779 * Initializes by pre-concat'ing the context's current matrix with the p
reConcat param. | 779 * Initializes by pre-concat'ing the context's current matrix with the p
reConcat param. |
780 */ | 780 */ |
781 void setPreConcat(GrContext* context, const SkMatrix& preConcat, GrPaint
* paint = NULL) { | 781 void setPreConcat(GrContext* context, const SkMatrix& preConcat, GrPaint
* paint = NULL) { |
782 SkASSERT(NULL != context); | 782 SkASSERT(context); |
783 | 783 |
784 this->restore(); | 784 this->restore(); |
785 | 785 |
786 fContext = context; | 786 fContext = context; |
787 fMatrix = context->getMatrix(); | 787 fMatrix = context->getMatrix(); |
788 this->preConcat(preConcat, paint); | 788 this->preConcat(preConcat, paint); |
789 } | 789 } |
790 | 790 |
791 /** | 791 /** |
792 * Sets the context's matrix to identity. Returns false if the inverse m
atrix is required to | 792 * Sets the context's matrix to identity. Returns false if the inverse m
atrix is required to |
793 * update a paint but the matrix cannot be inverted. | 793 * update a paint but the matrix cannot be inverted. |
794 */ | 794 */ |
795 bool setIdentity(GrContext* context, GrPaint* paint = NULL) { | 795 bool setIdentity(GrContext* context, GrPaint* paint = NULL) { |
796 SkASSERT(NULL != context); | 796 SkASSERT(context); |
797 | 797 |
798 this->restore(); | 798 this->restore(); |
799 | 799 |
800 if (NULL != paint) { | 800 if (paint) { |
801 if (!paint->localCoordChangeInverse(context->getMatrix())) { | 801 if (!paint->localCoordChangeInverse(context->getMatrix())) { |
802 return false; | 802 return false; |
803 } | 803 } |
804 } | 804 } |
805 fMatrix = context->getMatrix(); | 805 fMatrix = context->getMatrix(); |
806 fContext = context; | 806 fContext = context; |
807 context->setIdentityMatrix(); | 807 context->setIdentityMatrix(); |
808 return true; | 808 return true; |
809 } | 809 } |
810 | 810 |
811 /** | 811 /** |
812 * Replaces the context's matrix with a new matrix. Returns false if the
inverse matrix is | 812 * Replaces the context's matrix with a new matrix. Returns false if the
inverse matrix is |
813 * required to update a paint but the matrix cannot be inverted. | 813 * required to update a paint but the matrix cannot be inverted. |
814 */ | 814 */ |
815 bool set(GrContext* context, const SkMatrix& newMatrix, GrPaint* paint =
NULL) { | 815 bool set(GrContext* context, const SkMatrix& newMatrix, GrPaint* paint =
NULL) { |
816 if (NULL != paint) { | 816 if (paint) { |
817 if (!this->setIdentity(context, paint)) { | 817 if (!this->setIdentity(context, paint)) { |
818 return false; | 818 return false; |
819 } | 819 } |
820 this->preConcat(newMatrix, paint); | 820 this->preConcat(newMatrix, paint); |
821 } else { | 821 } else { |
822 this->restore(); | 822 this->restore(); |
823 fContext = context; | 823 fContext = context; |
824 fMatrix = context->getMatrix(); | 824 fMatrix = context->getMatrix(); |
825 context->setMatrix(newMatrix); | 825 context->setMatrix(newMatrix); |
826 } | 826 } |
827 return true; | 827 return true; |
828 } | 828 } |
829 | 829 |
830 /** | 830 /** |
831 * If this has been initialized then the context's matrix will be furthe
r updated by | 831 * If this has been initialized then the context's matrix will be furthe
r updated by |
832 * pre-concat'ing the preConcat param. The matrix that will be restored
remains unchanged. | 832 * pre-concat'ing the preConcat param. The matrix that will be restored
remains unchanged. |
833 * The paint is assumed to be relative to the context's matrix at the ti
me this call is | 833 * The paint is assumed to be relative to the context's matrix at the ti
me this call is |
834 * made, not the matrix at the time AutoMatrix was first initialized. In
other words, this | 834 * made, not the matrix at the time AutoMatrix was first initialized. In
other words, this |
835 * performs an incremental update of the paint. | 835 * performs an incremental update of the paint. |
836 */ | 836 */ |
837 void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) { | 837 void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) { |
838 if (NULL != paint) { | 838 if (paint) { |
839 paint->localCoordChange(preConcat); | 839 paint->localCoordChange(preConcat); |
840 } | 840 } |
841 fContext->concatMatrix(preConcat); | 841 fContext->concatMatrix(preConcat); |
842 } | 842 } |
843 | 843 |
844 /** | 844 /** |
845 * Returns false if never initialized or the inverse matrix was required
to update a paint | 845 * Returns false if never initialized or the inverse matrix was required
to update a paint |
846 * but the matrix could not be inverted. | 846 * but the matrix could not be inverted. |
847 */ | 847 */ |
848 bool succeeded() const { return NULL != fContext; } | 848 bool succeeded() const { return SkToBool(fContext); } |
849 | 849 |
850 /** | 850 /** |
851 * If this has been initialized then the context's original matrix is re
stored. | 851 * If this has been initialized then the context's original matrix is re
stored. |
852 */ | 852 */ |
853 void restore() { | 853 void restore() { |
854 if (NULL != fContext) { | 854 if (fContext) { |
855 fContext->setMatrix(fMatrix); | 855 fContext->setMatrix(fMatrix); |
856 fContext = NULL; | 856 fContext = NULL; |
857 } | 857 } |
858 } | 858 } |
859 | 859 |
860 private: | 860 private: |
861 GrContext* fContext; | 861 GrContext* fContext; |
862 SkMatrix fMatrix; | 862 SkMatrix fMatrix; |
863 }; | 863 }; |
864 | 864 |
(...skipping 18 matching lines...) Expand all Loading... |
883 AutoClip(GrContext* context, const SkRect& newClipRect) | 883 AutoClip(GrContext* context, const SkRect& newClipRect) |
884 : fContext(context) | 884 : fContext(context) |
885 , fNewClipStack(newClipRect) { | 885 , fNewClipStack(newClipRect) { |
886 fNewClipData.fClipStack = &fNewClipStack; | 886 fNewClipData.fClipStack = &fNewClipStack; |
887 | 887 |
888 fOldClip = fContext->getClip(); | 888 fOldClip = fContext->getClip(); |
889 fContext->setClip(&fNewClipData); | 889 fContext->setClip(&fNewClipData); |
890 } | 890 } |
891 | 891 |
892 ~AutoClip() { | 892 ~AutoClip() { |
893 if (NULL != fContext) { | 893 if (fContext) { |
894 fContext->setClip(fOldClip); | 894 fContext->setClip(fOldClip); |
895 } | 895 } |
896 } | 896 } |
897 private: | 897 private: |
898 GrContext* fContext; | 898 GrContext* fContext; |
899 const GrClipData* fOldClip; | 899 const GrClipData* fOldClip; |
900 | 900 |
901 SkClipStack fNewClipStack; | 901 SkClipStack fNewClipStack; |
902 GrClipData fNewClipData; | 902 GrClipData fNewClipData; |
903 }; | 903 }; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 : fContext(NULL) | 1084 : fContext(NULL) |
1085 , fTexture(NULL) { | 1085 , fTexture(NULL) { |
1086 this->set(context, desc, match); | 1086 this->set(context, desc, match); |
1087 } | 1087 } |
1088 | 1088 |
1089 ~GrAutoScratchTexture() { | 1089 ~GrAutoScratchTexture() { |
1090 this->reset(); | 1090 this->reset(); |
1091 } | 1091 } |
1092 | 1092 |
1093 void reset() { | 1093 void reset() { |
1094 if (NULL != fContext && NULL != fTexture) { | 1094 if (fContext && fTexture) { |
1095 fContext->unlockScratchTexture(fTexture); | 1095 fContext->unlockScratchTexture(fTexture); |
1096 fTexture->unref(); | 1096 fTexture->unref(); |
1097 fTexture = NULL; | 1097 fTexture = NULL; |
1098 } | 1098 } |
1099 } | 1099 } |
1100 | 1100 |
1101 /* | 1101 /* |
1102 * When detaching a texture we do not unlock it in the texture cache but | 1102 * When detaching a texture we do not unlock it in the texture cache but |
1103 * we do set the returnToCache flag. In this way the texture remains | 1103 * we do set the returnToCache flag. In this way the texture remains |
1104 * "locked" in the texture cache until it is freed and recycled in | 1104 * "locked" in the texture cache until it is freed and recycled in |
(...skipping 12 matching lines...) Expand all Loading... |
1117 GrTexture* texture = fTexture; | 1117 GrTexture* texture = fTexture; |
1118 fTexture = NULL; | 1118 fTexture = NULL; |
1119 | 1119 |
1120 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, wh
ich we give up now. | 1120 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, wh
ich we give up now. |
1121 // The cache also has a ref which we are lending to the caller of detach
(). When the caller | 1121 // The cache also has a ref which we are lending to the caller of detach
(). When the caller |
1122 // lets go of the ref and the ref count goes to 0 internal_dispose will
see this flag is | 1122 // lets go of the ref and the ref count goes to 0 internal_dispose will
see this flag is |
1123 // set and re-ref the texture, thereby restoring the cache's ref. | 1123 // set and re-ref the texture, thereby restoring the cache's ref. |
1124 SkASSERT(!texture->unique()); | 1124 SkASSERT(!texture->unique()); |
1125 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_
FlagBit); | 1125 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_
FlagBit); |
1126 texture->unref(); | 1126 texture->unref(); |
1127 SkASSERT(NULL != texture->getCacheEntry()); | 1127 SkASSERT(texture->getCacheEntry()); |
1128 | 1128 |
1129 return texture; | 1129 return texture; |
1130 } | 1130 } |
1131 | 1131 |
1132 GrTexture* set(GrContext* context, | 1132 GrTexture* set(GrContext* context, |
1133 const GrTextureDesc& desc, | 1133 const GrTextureDesc& desc, |
1134 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch
TexMatch) { | 1134 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch
TexMatch) { |
1135 this->reset(); | 1135 this->reset(); |
1136 | 1136 |
1137 fContext = context; | 1137 fContext = context; |
1138 if (NULL != fContext) { | 1138 if (fContext) { |
1139 fTexture = fContext->lockAndRefScratchTexture(desc, match); | 1139 fTexture = fContext->lockAndRefScratchTexture(desc, match); |
1140 if (NULL == fTexture) { | 1140 if (NULL == fTexture) { |
1141 fContext = NULL; | 1141 fContext = NULL; |
1142 } | 1142 } |
1143 return fTexture; | 1143 return fTexture; |
1144 } else { | 1144 } else { |
1145 return NULL; | 1145 return NULL; |
1146 } | 1146 } |
1147 } | 1147 } |
1148 | 1148 |
1149 GrTexture* texture() { return fTexture; } | 1149 GrTexture* texture() { return fTexture; } |
1150 | 1150 |
1151 private: | 1151 private: |
1152 GrContext* fContext; | 1152 GrContext* fContext; |
1153 GrTexture* fTexture; | 1153 GrTexture* fTexture; |
1154 }; | 1154 }; |
1155 | 1155 |
1156 #endif | 1156 #endif |
OLD | NEW |