OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
115 | 115 |
116 static bool gPrintStartupSpew; | 116 static bool gPrintStartupSpew; |
117 | 117 |
118 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) | 118 GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
119 : GrGpu(context) | 119 : GrGpu(context) |
120 , fGLContext(ctx) { | 120 , fGLContext(ctx) { |
121 | 121 |
122 GrAssert(ctx.isInitialized()); | 122 SkASSERT(ctx.isInitialized()); |
123 | 123 |
124 fCaps.reset(SkRef(ctx.info().caps())); | 124 fCaps.reset(SkRef(ctx.info().caps())); |
125 | 125 |
126 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); | 126 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); |
127 | 127 |
128 fillInConfigRenderableTable(); | 128 fillInConfigRenderableTable(); |
129 | 129 |
130 | 130 |
131 GrGLClearErr(fGLContext.interface()); | 131 GrGLClearErr(fGLContext.interface()); |
132 | 132 |
(...skipping 10 matching lines...) Expand all Loading... |
143 GrPrintf("------ RENDERER %s\n", renderer); | 143 GrPrintf("------ RENDERER %s\n", renderer); |
144 GrPrintf("------ VERSION %s\n", version); | 144 GrPrintf("------ VERSION %s\n", version); |
145 GrPrintf("------ EXTENSIONS\n"); | 145 GrPrintf("------ EXTENSIONS\n"); |
146 ctx.info().extensions().print(); | 146 ctx.info().extensions().print(); |
147 GrPrintf("\n"); | 147 GrPrintf("\n"); |
148 ctx.info().caps()->print(); | 148 ctx.info().caps()->print(); |
149 } | 149 } |
150 | 150 |
151 fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext())); | 151 fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext())); |
152 | 152 |
153 GrAssert(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr
ibCnt); | 153 SkASSERT(this->glCaps().maxVertexAttributes() >= GrDrawState::kMaxVertexAttr
ibCnt); |
154 | 154 |
155 fLastSuccessfulStencilFmtIdx = 0; | 155 fLastSuccessfulStencilFmtIdx = 0; |
156 fHWProgramID = 0; | 156 fHWProgramID = 0; |
157 } | 157 } |
158 | 158 |
159 GrGpuGL::~GrGpuGL() { | 159 GrGpuGL::~GrGpuGL() { |
160 if (0 != fHWProgramID) { | 160 if (0 != fHWProgramID) { |
161 // detach the current program so there is no confusion on OpenGL's part | 161 // detach the current program so there is no confusion on OpenGL's part |
162 // that we want it to be deleted | 162 // that we want it to be deleted |
163 GrAssert(fHWProgramID == fCurrentProgram->programID()); | 163 SkASSERT(fHWProgramID == fCurrentProgram->programID()); |
164 GL_CALL(UseProgram(0)); | 164 GL_CALL(UseProgram(0)); |
165 } | 165 } |
166 | 166 |
167 delete fProgramCache; | 167 delete fProgramCache; |
168 | 168 |
169 // This must be called by before the GrDrawTarget destructor | 169 // This must be called by before the GrDrawTarget destructor |
170 this->releaseGeometry(); | 170 this->releaseGeometry(); |
171 // This subclass must do this before the base class destructor runs | 171 // This subclass must do this before the base class destructor runs |
172 // since we will unref the GrGLInterface. | 172 // since we will unref the GrGLInterface. |
173 this->releaseResources(); | 173 this->releaseResources(); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } | 575 } |
576 | 576 |
577 } | 577 } |
578 | 578 |
579 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, | 579 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
580 bool isNewTexture, | 580 bool isNewTexture, |
581 int left, int top, int width, int height, | 581 int left, int top, int width, int height, |
582 GrPixelConfig dataConfig, | 582 GrPixelConfig dataConfig, |
583 const void* data, | 583 const void* data, |
584 size_t rowBytes) { | 584 size_t rowBytes) { |
585 GrAssert(NULL != data || isNewTexture); | 585 SkASSERT(NULL != data || isNewTexture); |
586 | 586 |
587 size_t bpp = GrBytesPerPixel(dataConfig); | 587 size_t bpp = GrBytesPerPixel(dataConfig); |
588 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, | 588 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
589 &width, &height, &data, &rowBytes)) { | 589 &width, &height, &data, &rowBytes)) { |
590 return false; | 590 return false; |
591 } | 591 } |
592 size_t trimRowBytes = width * bpp; | 592 size_t trimRowBytes = width * bpp; |
593 | 593 |
594 // in case we need a temporary, trimmed copy of the src pixels | 594 // in case we need a temporary, trimmed copy of the src pixels |
595 SkAutoSMalloc<128 * 128> tempStorage; | 595 SkAutoSMalloc<128 * 128> tempStorage; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 top = desc.fHeight - (top + height); | 729 top = desc.fHeight - (top + height); |
730 } | 730 } |
731 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 731 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
732 0, // level | 732 0, // level |
733 left, top, | 733 left, top, |
734 width, height, | 734 width, height, |
735 externalFormat, externalType, data)); | 735 externalFormat, externalType, data)); |
736 } | 736 } |
737 | 737 |
738 if (restoreGLRowLength) { | 738 if (restoreGLRowLength) { |
739 GrAssert(this->glCaps().unpackRowLengthSupport()); | 739 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
740 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 740 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
741 } | 741 } |
742 if (glFlipY) { | 742 if (glFlipY) { |
743 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 743 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
744 } | 744 } |
745 return succeeded; | 745 return succeeded; |
746 } | 746 } |
747 | 747 |
748 namespace { | 748 namespace { |
749 bool renderbuffer_storage_msaa(GrGLContext& ctx, | 749 bool renderbuffer_storage_msaa(GrGLContext& ctx, |
750 int sampleCount, | 750 int sampleCount, |
751 GrGLenum format, | 751 GrGLenum format, |
752 int width, int height) { | 752 int width, int height) { |
753 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); | 753 CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
754 GrAssert(GrGLCaps::kNone_MSFBOType != ctx.info().caps()->msFBOType()); | 754 SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.info().caps()->msFBOType()); |
755 bool created = false; | 755 bool created = false; |
756 if (GrGLCaps::kNVDesktop_CoverageAAType == | 756 if (GrGLCaps::kNVDesktop_CoverageAAType == |
757 ctx.info().caps()->coverageAAType()) { | 757 ctx.info().caps()->coverageAAType()) { |
758 const GrGLCaps::MSAACoverageMode& mode = | 758 const GrGLCaps::MSAACoverageMode& mode = |
759 ctx.info().caps()->getMSAACoverageMode(sampleCount); | 759 ctx.info().caps()->getMSAACoverageMode(sampleCount); |
760 GL_ALLOC_CALL(ctx.interface(), | 760 GL_ALLOC_CALL(ctx.interface(), |
761 RenderbufferStorageMultisampleCoverage(GR_GL_RENDERBUFFER, | 761 RenderbufferStorageMultisampleCoverage(GR_GL_RENDERBUFFER, |
762 mode.fCoverageSampleCnt, | 762 mode.fCoverageSampleCnt, |
763 mode.fColorSampleCnt, | 763 mode.fColorSampleCnt, |
764 format, | 764 format, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 NULL)) { | 816 NULL)) { |
817 goto FAILED; | 817 goto FAILED; |
818 } | 818 } |
819 } else { | 819 } else { |
820 desc->fRTFBOID = desc->fTexFBOID; | 820 desc->fRTFBOID = desc->fTexFBOID; |
821 } | 821 } |
822 | 822 |
823 // below here we may bind the FBO | 823 // below here we may bind the FBO |
824 fHWBoundRenderTarget = NULL; | 824 fHWBoundRenderTarget = NULL; |
825 if (desc->fRTFBOID != desc->fTexFBOID) { | 825 if (desc->fRTFBOID != desc->fTexFBOID) { |
826 GrAssert(desc->fSampleCnt > 0); | 826 SkASSERT(desc->fSampleCnt > 0); |
827 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, | 827 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, |
828 desc->fMSColorRenderbufferID)); | 828 desc->fMSColorRenderbufferID)); |
829 if (!renderbuffer_storage_msaa(fGLContext, | 829 if (!renderbuffer_storage_msaa(fGLContext, |
830 desc->fSampleCnt, | 830 desc->fSampleCnt, |
831 msColorFormat, | 831 msColorFormat, |
832 width, height)) { | 832 width, height)) { |
833 goto FAILED; | 833 goto FAILED; |
834 } | 834 } |
835 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); | 835 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
836 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 836 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); | 878 GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID)); |
879 } | 879 } |
880 if (desc->fTexFBOID) { | 880 if (desc->fTexFBOID) { |
881 GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); | 881 GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID)); |
882 } | 882 } |
883 return false; | 883 return false; |
884 } | 884 } |
885 | 885 |
886 // good to set a break-point here to know when createTexture fails | 886 // good to set a break-point here to know when createTexture fails |
887 static GrTexture* return_null_texture() { | 887 static GrTexture* return_null_texture() { |
888 // GrAssert(!"null texture"); | 888 // SkASSERT(!"null texture"); |
889 return NULL; | 889 return NULL; |
890 } | 890 } |
891 | 891 |
892 #if 0 && GR_DEBUG | 892 #if 0 && GR_DEBUG |
893 static size_t as_size_t(int x) { | 893 static size_t as_size_t(int x) { |
894 return x; | 894 return x; |
895 } | 895 } |
896 #endif | 896 #endif |
897 | 897 |
898 GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, | 898 GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, |
899 const void* srcData, | 899 const void* srcData, |
900 size_t rowBytes) { | 900 size_t rowBytes) { |
901 | 901 |
902 GrGLTexture::Desc glTexDesc; | 902 GrGLTexture::Desc glTexDesc; |
903 GrGLRenderTarget::Desc glRTDesc; | 903 GrGLRenderTarget::Desc glRTDesc; |
904 | 904 |
905 // Attempt to catch un- or wrongly initialized sample counts; | 905 // Attempt to catch un- or wrongly initialized sample counts; |
906 GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | 906 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
907 // We fail if the MSAA was requested and is not available. | 907 // We fail if the MSAA was requested and is not available. |
908 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { | 908 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { |
909 //GrPrintf("MSAA RT requested but not supported on this platform."); | 909 //GrPrintf("MSAA RT requested but not supported on this platform."); |
910 return return_null_texture(); | 910 return return_null_texture(); |
911 } | 911 } |
912 // If the sample count exceeds the max then we clamp it. | 912 // If the sample count exceeds the max then we clamp it. |
913 glTexDesc.fSampleCnt = GrMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 913 glTexDesc.fSampleCnt = GrMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
914 | 914 |
915 glTexDesc.fFlags = desc.fFlags; | 915 glTexDesc.fFlags = desc.fFlags; |
916 glTexDesc.fWidth = desc.fWidth; | 916 glTexDesc.fWidth = desc.fWidth; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 } | 1017 } |
1018 | 1018 |
1019 namespace { | 1019 namespace { |
1020 | 1020 |
1021 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; | 1021 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
1022 | 1022 |
1023 void inline get_stencil_rb_sizes(const GrGLInterface* gl, | 1023 void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
1024 GrGLStencilBuffer::Format* format) { | 1024 GrGLStencilBuffer::Format* format) { |
1025 | 1025 |
1026 // we shouldn't ever know one size and not the other | 1026 // we shouldn't ever know one size and not the other |
1027 GrAssert((kUnknownBitCount == format->fStencilBits) == | 1027 SkASSERT((kUnknownBitCount == format->fStencilBits) == |
1028 (kUnknownBitCount == format->fTotalBits)); | 1028 (kUnknownBitCount == format->fTotalBits)); |
1029 if (kUnknownBitCount == format->fStencilBits) { | 1029 if (kUnknownBitCount == format->fStencilBits) { |
1030 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, | 1030 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
1031 GR_GL_RENDERBUFFER_STENCIL_SIZE, | 1031 GR_GL_RENDERBUFFER_STENCIL_SIZE, |
1032 (GrGLint*)&format->fStencilBits); | 1032 (GrGLint*)&format->fStencilBits); |
1033 if (format->fPacked) { | 1033 if (format->fPacked) { |
1034 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, | 1034 GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
1035 GR_GL_RENDERBUFFER_DEPTH_SIZE, | 1035 GR_GL_RENDERBUFFER_DEPTH_SIZE, |
1036 (GrGLint*)&format->fTotalBits); | 1036 (GrGLint*)&format->fTotalBits); |
1037 format->fTotalBits += format->fStencilBits; | 1037 format->fTotalBits += format->fStencilBits; |
1038 } else { | 1038 } else { |
1039 format->fTotalBits = format->fStencilBits; | 1039 format->fTotalBits = format->fStencilBits; |
1040 } | 1040 } |
1041 } | 1041 } |
1042 } | 1042 } |
1043 } | 1043 } |
1044 | 1044 |
1045 bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, | 1045 bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, |
1046 int width, int height) { | 1046 int width, int height) { |
1047 | 1047 |
1048 // All internally created RTs are also textures. We don't create | 1048 // All internally created RTs are also textures. We don't create |
1049 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. | 1049 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. |
1050 GrAssert(rt->asTexture()); | 1050 SkASSERT(rt->asTexture()); |
1051 GrAssert(width >= rt->width()); | 1051 SkASSERT(width >= rt->width()); |
1052 GrAssert(height >= rt->height()); | 1052 SkASSERT(height >= rt->height()); |
1053 | 1053 |
1054 int samples = rt->numSamples(); | 1054 int samples = rt->numSamples(); |
1055 GrGLuint sbID; | 1055 GrGLuint sbID; |
1056 GL_CALL(GenRenderbuffers(1, &sbID)); | 1056 GL_CALL(GenRenderbuffers(1, &sbID)); |
1057 if (!sbID) { | 1057 if (!sbID) { |
1058 return false; | 1058 return false; |
1059 } | 1059 } |
1060 | 1060 |
1061 int stencilFmtCnt = this->glCaps().stencilFormats().count(); | 1061 int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
1062 for (int i = 0; i < stencilFmtCnt; ++i) { | 1062 for (int i = 0; i < stencilFmtCnt; ++i) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 if (NULL != rt->getStencilBuffer()) { | 1115 if (NULL != rt->getStencilBuffer()) { |
1116 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1116 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1117 GR_GL_STENCIL_ATTACHMENT, | 1117 GR_GL_STENCIL_ATTACHMENT, |
1118 GR_GL_RENDERBUFFER, 0)); | 1118 GR_GL_RENDERBUFFER, 0)); |
1119 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1119 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
1120 GR_GL_DEPTH_ATTACHMENT, | 1120 GR_GL_DEPTH_ATTACHMENT, |
1121 GR_GL_RENDERBUFFER, 0)); | 1121 GR_GL_RENDERBUFFER, 0)); |
1122 #if GR_DEBUG | 1122 #if GR_DEBUG |
1123 GrGLenum status; | 1123 GrGLenum status; |
1124 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1124 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1125 GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status); | 1125 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
1126 #endif | 1126 #endif |
1127 } | 1127 } |
1128 return true; | 1128 return true; |
1129 } else { | 1129 } else { |
1130 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); | 1130 GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb); |
1131 GrGLuint rb = glsb->renderbufferID(); | 1131 GrGLuint rb = glsb->renderbufferID(); |
1132 | 1132 |
1133 fHWBoundRenderTarget = NULL; | 1133 fHWBoundRenderTarget = NULL; |
1134 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); | 1134 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
1135 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 1135 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 return NULL; | 1230 return NULL; |
1231 } | 1231 } |
1232 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); | 1232 GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc
)); |
1233 return indexBuffer; | 1233 return indexBuffer; |
1234 } | 1234 } |
1235 return NULL; | 1235 return NULL; |
1236 } | 1236 } |
1237 } | 1237 } |
1238 | 1238 |
1239 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { | 1239 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) { |
1240 GrAssert(this->caps()->pathStencilingSupport()); | 1240 SkASSERT(this->caps()->pathStencilingSupport()); |
1241 return SkNEW_ARGS(GrGLPath, (this, inPath)); | 1241 return SkNEW_ARGS(GrGLPath, (this, inPath)); |
1242 } | 1242 } |
1243 | 1243 |
1244 void GrGpuGL::flushScissor() { | 1244 void GrGpuGL::flushScissor() { |
1245 const GrDrawState& drawState = this->getDrawState(); | 1245 const GrDrawState& drawState = this->getDrawState(); |
1246 const GrGLRenderTarget* rt = | 1246 const GrGLRenderTarget* rt = |
1247 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); | 1247 static_cast<const GrGLRenderTarget*>(drawState.getRenderTarget()); |
1248 | 1248 |
1249 GrAssert(NULL != rt); | 1249 SkASSERT(NULL != rt); |
1250 const GrGLIRect& vp = rt->getViewport(); | 1250 const GrGLIRect& vp = rt->getViewport(); |
1251 | 1251 |
1252 if (fScissorState.fEnabled) { | 1252 if (fScissorState.fEnabled) { |
1253 GrGLIRect scissor; | 1253 GrGLIRect scissor; |
1254 scissor.setRelativeTo(vp, | 1254 scissor.setRelativeTo(vp, |
1255 fScissorState.fRect.fLeft, | 1255 fScissorState.fRect.fLeft, |
1256 fScissorState.fRect.fTop, | 1256 fScissorState.fRect.fTop, |
1257 fScissorState.fRect.width(), | 1257 fScissorState.fRect.width(), |
1258 fScissorState.fRect.height(), | 1258 fScissorState.fRect.height(), |
1259 rt->origin()); | 1259 rt->origin()); |
(...skipping 15 matching lines...) Expand all Loading... |
1275 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); | 1275 GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
1276 fHWScissorSettings.fEnabled = kNo_TriState; | 1276 fHWScissorSettings.fEnabled = kNo_TriState; |
1277 return; | 1277 return; |
1278 } | 1278 } |
1279 } | 1279 } |
1280 | 1280 |
1281 void GrGpuGL::onClear(const SkIRect* rect, GrColor color) { | 1281 void GrGpuGL::onClear(const SkIRect* rect, GrColor color) { |
1282 const GrDrawState& drawState = this->getDrawState(); | 1282 const GrDrawState& drawState = this->getDrawState(); |
1283 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1283 const GrRenderTarget* rt = drawState.getRenderTarget(); |
1284 // parent class should never let us get here with no RT | 1284 // parent class should never let us get here with no RT |
1285 GrAssert(NULL != rt); | 1285 SkASSERT(NULL != rt); |
1286 | 1286 |
1287 SkIRect clippedRect; | 1287 SkIRect clippedRect; |
1288 if (NULL != rect) { | 1288 if (NULL != rect) { |
1289 // flushScissor expects rect to be clipped to the target. | 1289 // flushScissor expects rect to be clipped to the target. |
1290 clippedRect = *rect; | 1290 clippedRect = *rect; |
1291 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); | 1291 SkIRect rtRect = SkIRect::MakeWH(rt->width(), rt->height()); |
1292 if (clippedRect.intersect(rtRect)) { | 1292 if (clippedRect.intersect(rtRect)) { |
1293 rect = &clippedRect; | 1293 rect = &clippedRect; |
1294 } else { | 1294 } else { |
1295 return; | 1295 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 | 1330 |
1331 GL_CALL(StencilMask(0xffffffff)); | 1331 GL_CALL(StencilMask(0xffffffff)); |
1332 GL_CALL(ClearStencil(0)); | 1332 GL_CALL(ClearStencil(0)); |
1333 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | 1333 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
1334 fHWStencilSettings.invalidate(); | 1334 fHWStencilSettings.invalidate(); |
1335 } | 1335 } |
1336 | 1336 |
1337 void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) { | 1337 void GrGpuGL::clearStencilClip(const SkIRect& rect, bool insideClip) { |
1338 const GrDrawState& drawState = this->getDrawState(); | 1338 const GrDrawState& drawState = this->getDrawState(); |
1339 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1339 const GrRenderTarget* rt = drawState.getRenderTarget(); |
1340 GrAssert(NULL != rt); | 1340 SkASSERT(NULL != rt); |
1341 | 1341 |
1342 // this should only be called internally when we know we have a | 1342 // this should only be called internally when we know we have a |
1343 // stencil buffer. | 1343 // stencil buffer. |
1344 GrAssert(NULL != rt->getStencilBuffer()); | 1344 SkASSERT(NULL != rt->getStencilBuffer()); |
1345 GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); | 1345 GrGLint stencilBitCount = rt->getStencilBuffer()->bits(); |
1346 #if 0 | 1346 #if 0 |
1347 GrAssert(stencilBitCount > 0); | 1347 SkASSERT(stencilBitCount > 0); |
1348 GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); | 1348 GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
1349 #else | 1349 #else |
1350 // we could just clear the clip bit but when we go through | 1350 // we could just clear the clip bit but when we go through |
1351 // ANGLE a partial stencil mask will cause clears to be | 1351 // ANGLE a partial stencil mask will cause clears to be |
1352 // turned into draws. Our contract on GrDrawTarget says that | 1352 // turned into draws. Our contract on GrDrawTarget says that |
1353 // changing the clip between stencil passes may or may not | 1353 // changing the clip between stencil passes may or may not |
1354 // zero the client's clip bits. So we just clear the whole thing. | 1354 // zero the client's clip bits. So we just clear the whole thing. |
1355 static const GrGLint clipStencilMask = ~0; | 1355 static const GrGLint clipStencilMask = ~0; |
1356 #endif | 1356 #endif |
1357 GrGLint value; | 1357 GrGLint value; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 rowBytes = tightRowBytes; | 1459 rowBytes = tightRowBytes; |
1460 } | 1460 } |
1461 size_t readDstRowBytes = tightRowBytes; | 1461 size_t readDstRowBytes = tightRowBytes; |
1462 void* readDst = buffer; | 1462 void* readDst = buffer; |
1463 | 1463 |
1464 // determine if GL can read using the passed rowBytes or if we need | 1464 // determine if GL can read using the passed rowBytes or if we need |
1465 // a scratch buffer. | 1465 // a scratch buffer. |
1466 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; | 1466 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
1467 if (rowBytes != tightRowBytes) { | 1467 if (rowBytes != tightRowBytes) { |
1468 if (this->glCaps().packRowLengthSupport()) { | 1468 if (this->glCaps().packRowLengthSupport()) { |
1469 GrAssert(!(rowBytes % sizeof(GrColor))); | 1469 SkASSERT(!(rowBytes % sizeof(GrColor))); |
1470 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowBytes / sizeof(GrColor
))); | 1470 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowBytes / sizeof(GrColor
))); |
1471 readDstRowBytes = rowBytes; | 1471 readDstRowBytes = rowBytes; |
1472 } else { | 1472 } else { |
1473 scratch.reset(tightRowBytes * height); | 1473 scratch.reset(tightRowBytes * height); |
1474 readDst = scratch.get(); | 1474 readDst = scratch.get(); |
1475 } | 1475 } |
1476 } | 1476 } |
1477 if (flipY && this->glCaps().packFlipYSupport()) { | 1477 if (flipY && this->glCaps().packFlipYSupport()) { |
1478 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); | 1478 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
1479 } | 1479 } |
1480 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, | 1480 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
1481 readRect.fWidth, readRect.fHeight, | 1481 readRect.fWidth, readRect.fHeight, |
1482 format, type, readDst)); | 1482 format, type, readDst)); |
1483 if (readDstRowBytes != tightRowBytes) { | 1483 if (readDstRowBytes != tightRowBytes) { |
1484 GrAssert(this->glCaps().packRowLengthSupport()); | 1484 SkASSERT(this->glCaps().packRowLengthSupport()); |
1485 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 1485 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
1486 } | 1486 } |
1487 if (flipY && this->glCaps().packFlipYSupport()) { | 1487 if (flipY && this->glCaps().packFlipYSupport()) { |
1488 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); | 1488 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
1489 flipY = false; | 1489 flipY = false; |
1490 } | 1490 } |
1491 | 1491 |
1492 // now reverse the order of the rows, since GL's are bottom-to-top, but our | 1492 // now reverse the order of the rows, since GL's are bottom-to-top, but our |
1493 // API presents top-to-bottom. We must preserve the padding contents. Note | 1493 // API presents top-to-bottom. We must preserve the padding contents. Note |
1494 // that the above readPixels did not overwrite the padding. | 1494 // that the above readPixels did not overwrite the padding. |
1495 if (readDst == buffer) { | 1495 if (readDst == buffer) { |
1496 GrAssert(rowBytes == readDstRowBytes); | 1496 SkASSERT(rowBytes == readDstRowBytes); |
1497 if (flipY) { | 1497 if (flipY) { |
1498 scratch.reset(tightRowBytes); | 1498 scratch.reset(tightRowBytes); |
1499 void* tmpRow = scratch.get(); | 1499 void* tmpRow = scratch.get(); |
1500 // flip y in-place by rows | 1500 // flip y in-place by rows |
1501 const int halfY = height >> 1; | 1501 const int halfY = height >> 1; |
1502 char* top = reinterpret_cast<char*>(buffer); | 1502 char* top = reinterpret_cast<char*>(buffer); |
1503 char* bottom = top + (height - 1) * rowBytes; | 1503 char* bottom = top + (height - 1) * rowBytes; |
1504 for (int y = 0; y < halfY; y++) { | 1504 for (int y = 0; y < halfY; y++) { |
1505 memcpy(tmpRow, top, tightRowBytes); | 1505 memcpy(tmpRow, top, tightRowBytes); |
1506 memcpy(top, bottom, tightRowBytes); | 1506 memcpy(top, bottom, tightRowBytes); |
1507 memcpy(bottom, tmpRow, tightRowBytes); | 1507 memcpy(bottom, tmpRow, tightRowBytes); |
1508 top += rowBytes; | 1508 top += rowBytes; |
1509 bottom -= rowBytes; | 1509 bottom -= rowBytes; |
1510 } | 1510 } |
1511 } | 1511 } |
1512 } else { | 1512 } else { |
1513 GrAssert(readDst != buffer); GrAssert(rowBytes != tightRowBytes); | 1513 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes); |
1514 // copy from readDst to buffer while flipping y | 1514 // copy from readDst to buffer while flipping y |
1515 // const int halfY = height >> 1; | 1515 // const int halfY = height >> 1; |
1516 const char* src = reinterpret_cast<const char*>(readDst); | 1516 const char* src = reinterpret_cast<const char*>(readDst); |
1517 char* dst = reinterpret_cast<char*>(buffer); | 1517 char* dst = reinterpret_cast<char*>(buffer); |
1518 if (flipY) { | 1518 if (flipY) { |
1519 dst += (height-1) * rowBytes; | 1519 dst += (height-1) * rowBytes; |
1520 } | 1520 } |
1521 for (int y = 0; y < height; y++) { | 1521 for (int y = 0; y < height; y++) { |
1522 memcpy(dst, src, tightRowBytes); | 1522 memcpy(dst, src, tightRowBytes); |
1523 src += readDstRowBytes; | 1523 src += readDstRowBytes; |
1524 if (!flipY) { | 1524 if (!flipY) { |
1525 dst += rowBytes; | 1525 dst += rowBytes; |
1526 } else { | 1526 } else { |
1527 dst -= rowBytes; | 1527 dst -= rowBytes; |
1528 } | 1528 } |
1529 } | 1529 } |
1530 } | 1530 } |
1531 return true; | 1531 return true; |
1532 } | 1532 } |
1533 | 1533 |
1534 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { | 1534 void GrGpuGL::flushRenderTarget(const SkIRect* bound) { |
1535 | 1535 |
1536 GrGLRenderTarget* rt = | 1536 GrGLRenderTarget* rt = |
1537 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); | 1537 static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget()); |
1538 GrAssert(NULL != rt); | 1538 SkASSERT(NULL != rt); |
1539 | 1539 |
1540 if (fHWBoundRenderTarget != rt) { | 1540 if (fHWBoundRenderTarget != rt) { |
1541 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); | 1541 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID())); |
1542 #if GR_DEBUG | 1542 #if GR_DEBUG |
1543 GrGLenum status; | 1543 GrGLenum status; |
1544 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 1544 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
1545 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 1545 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
1546 GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n",
status); | 1546 GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n",
status); |
1547 } | 1547 } |
1548 #endif | 1548 #endif |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); | 1591 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
1592 } | 1592 } |
1593 } | 1593 } |
1594 #endif | 1594 #endif |
1595 #endif | 1595 #endif |
1596 | 1596 |
1597 void GrGpuGL::onGpuDraw(const DrawInfo& info) { | 1597 void GrGpuGL::onGpuDraw(const DrawInfo& info) { |
1598 size_t indexOffsetInBytes; | 1598 size_t indexOffsetInBytes; |
1599 this->setupGeometry(info, &indexOffsetInBytes); | 1599 this->setupGeometry(info, &indexOffsetInBytes); |
1600 | 1600 |
1601 GrAssert((size_t)info.primitiveType() < GR_ARRAY_COUNT(gPrimitiveType2GLMode
)); | 1601 SkASSERT((size_t)info.primitiveType() < GR_ARRAY_COUNT(gPrimitiveType2GLMode
)); |
1602 | 1602 |
1603 if (info.isIndexed()) { | 1603 if (info.isIndexed()) { |
1604 GrGLvoid* indices = | 1604 GrGLvoid* indices = |
1605 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
info.startIndex()); | 1605 reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
info.startIndex()); |
1606 // info.startVertex() was accounted for by setupGeometry. | 1606 // info.startVertex() was accounted for by setupGeometry. |
1607 GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], | 1607 GL_CALL(DrawElements(gPrimitiveType2GLMode[info.primitiveType()], |
1608 info.indexCount(), | 1608 info.indexCount(), |
1609 GR_GL_UNSIGNED_SHORT, | 1609 GR_GL_UNSIGNED_SHORT, |
1610 indices)); | 1610 indices)); |
1611 } else { | 1611 } else { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 return; | 1658 return; |
1659 case SkPath::kWinding_FillType: | 1659 case SkPath::kWinding_FillType: |
1660 *settings = winding_nv_path_stencil_settings(); | 1660 *settings = winding_nv_path_stencil_settings(); |
1661 return; | 1661 return; |
1662 default: | 1662 default: |
1663 GrCrash("Unexpected path fill."); | 1663 GrCrash("Unexpected path fill."); |
1664 } | 1664 } |
1665 } | 1665 } |
1666 | 1666 |
1667 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { | 1667 void GrGpuGL::onGpuStencilPath(const GrPath* path, SkPath::FillType fill) { |
1668 GrAssert(this->caps()->pathStencilingSupport()); | 1668 SkASSERT(this->caps()->pathStencilingSupport()); |
1669 | 1669 |
1670 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); | 1670 GrGLuint id = static_cast<const GrGLPath*>(path)->pathID(); |
1671 GrDrawState* drawState = this->drawState(); | 1671 GrDrawState* drawState = this->drawState(); |
1672 GrAssert(NULL != drawState->getRenderTarget()); | 1672 SkASSERT(NULL != drawState->getRenderTarget()); |
1673 if (NULL == drawState->getRenderTarget()->getStencilBuffer()) { | 1673 if (NULL == drawState->getRenderTarget()->getStencilBuffer()) { |
1674 return; | 1674 return; |
1675 } | 1675 } |
1676 | 1676 |
1677 // Decide how to manipulate the stencil buffer based on the fill rule. | 1677 // Decide how to manipulate the stencil buffer based on the fill rule. |
1678 // Also, assert that the stencil settings we set in setStencilPathSettings | 1678 // Also, assert that the stencil settings we set in setStencilPathSettings |
1679 // are present. | 1679 // are present. |
1680 GrAssert(!fStencilSettings.isTwoSided()); | 1680 SkASSERT(!fStencilSettings.isTwoSided()); |
1681 GrGLenum fillMode; | 1681 GrGLenum fillMode; |
1682 switch (fill) { | 1682 switch (fill) { |
1683 case SkPath::kWinding_FillType: | 1683 case SkPath::kWinding_FillType: |
1684 fillMode = GR_GL_COUNT_UP; | 1684 fillMode = GR_GL_COUNT_UP; |
1685 GrAssert(kIncClamp_StencilOp == | 1685 SkASSERT(kIncClamp_StencilOp == |
1686 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1686 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
1687 GrAssert(kIncClamp_StencilOp == | 1687 SkASSERT(kIncClamp_StencilOp == |
1688 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); | 1688 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
1689 break; | 1689 break; |
1690 case SkPath::kEvenOdd_FillType: | 1690 case SkPath::kEvenOdd_FillType: |
1691 fillMode = GR_GL_INVERT; | 1691 fillMode = GR_GL_INVERT; |
1692 GrAssert(kInvert_StencilOp == | 1692 SkASSERT(kInvert_StencilOp == |
1693 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); | 1693 fStencilSettings.passOp(GrStencilSettings::kFront_Face)); |
1694 GrAssert(kInvert_StencilOp == | 1694 SkASSERT(kInvert_StencilOp == |
1695 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); | 1695 fStencilSettings.failOp(GrStencilSettings::kFront_Face)); |
1696 break; | 1696 break; |
1697 default: | 1697 default: |
1698 // Only the above two fill rules are allowed. | 1698 // Only the above two fill rules are allowed. |
1699 GrCrash("Unexpected path fill."); | 1699 GrCrash("Unexpected path fill."); |
1700 return; // suppress unused var warning. | 1700 return; // suppress unused var warning. |
1701 } | 1701 } |
1702 GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Fac
e); | 1702 GrGLint writeMask = fStencilSettings.writeMask(GrStencilSettings::kFront_Fac
e); |
1703 GL_CALL(StencilFillPath(id, fillMode, writeMask)); | 1703 GL_CALL(StencilFillPath(id, fillMode, writeMask)); |
1704 } | 1704 } |
1705 | 1705 |
1706 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { | 1706 void GrGpuGL::onResolveRenderTarget(GrRenderTarget* target) { |
1707 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); | 1707 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
1708 if (rt->needsResolve()) { | 1708 if (rt->needsResolve()) { |
1709 // Some extensions automatically resolves the texture when it is read. | 1709 // Some extensions automatically resolves the texture when it is read. |
1710 if (this->glCaps().usesMSAARenderBuffers()) { | 1710 if (this->glCaps().usesMSAARenderBuffers()) { |
1711 GrAssert(rt->textureFBOID() != rt->renderFBOID()); | 1711 SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
1712 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); | 1712 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
1713 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; | 1713 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()))
; |
1714 // make sure we go through flushRenderTarget() since we've modified | 1714 // make sure we go through flushRenderTarget() since we've modified |
1715 // the bound DRAW FBO ID. | 1715 // the bound DRAW FBO ID. |
1716 fHWBoundRenderTarget = NULL; | 1716 fHWBoundRenderTarget = NULL; |
1717 const GrGLIRect& vp = rt->getViewport(); | 1717 const GrGLIRect& vp = rt->getViewport(); |
1718 const SkIRect dirtyRect = rt->getResolveRect(); | 1718 const SkIRect dirtyRect = rt->getResolveRect(); |
1719 GrGLIRect r; | 1719 GrGLIRect r; |
1720 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, | 1720 r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
1721 dirtyRect.width(), dirtyRect.height(), target->origi
n()); | 1721 dirtyRect.width(), dirtyRect.height(), target->origi
n()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 }; | 1761 }; |
1762 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kBasicStencilFuncCount); | 1762 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kBasicStencilFuncCount); |
1763 GR_STATIC_ASSERT(0 == kAlways_StencilFunc); | 1763 GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
1764 GR_STATIC_ASSERT(1 == kNever_StencilFunc); | 1764 GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
1765 GR_STATIC_ASSERT(2 == kGreater_StencilFunc); | 1765 GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
1766 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); | 1766 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
1767 GR_STATIC_ASSERT(4 == kLess_StencilFunc); | 1767 GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
1768 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); | 1768 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
1769 GR_STATIC_ASSERT(6 == kEqual_StencilFunc); | 1769 GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
1770 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); | 1770 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
1771 GrAssert((unsigned) basicFunc < kBasicStencilFuncCount); | 1771 SkASSERT((unsigned) basicFunc < kBasicStencilFuncCount); |
1772 | 1772 |
1773 return gTable[basicFunc]; | 1773 return gTable[basicFunc]; |
1774 } | 1774 } |
1775 | 1775 |
1776 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { | 1776 GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
1777 static const GrGLenum gTable[] = { | 1777 static const GrGLenum gTable[] = { |
1778 GR_GL_KEEP, // kKeep_StencilOp | 1778 GR_GL_KEEP, // kKeep_StencilOp |
1779 GR_GL_REPLACE, // kReplace_StencilOp | 1779 GR_GL_REPLACE, // kReplace_StencilOp |
1780 GR_GL_INCR_WRAP, // kIncWrap_StencilOp | 1780 GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
1781 GR_GL_INCR, // kIncClamp_StencilOp | 1781 GR_GL_INCR, // kIncClamp_StencilOp |
1782 GR_GL_DECR_WRAP, // kDecWrap_StencilOp | 1782 GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
1783 GR_GL_DECR, // kDecClamp_StencilOp | 1783 GR_GL_DECR, // kDecClamp_StencilOp |
1784 GR_GL_ZERO, // kZero_StencilOp | 1784 GR_GL_ZERO, // kZero_StencilOp |
1785 GR_GL_INVERT, // kInvert_StencilOp | 1785 GR_GL_INVERT, // kInvert_StencilOp |
1786 }; | 1786 }; |
1787 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kStencilOpCount); | 1787 GR_STATIC_ASSERT(GR_ARRAY_COUNT(gTable) == kStencilOpCount); |
1788 GR_STATIC_ASSERT(0 == kKeep_StencilOp); | 1788 GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
1789 GR_STATIC_ASSERT(1 == kReplace_StencilOp); | 1789 GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
1790 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); | 1790 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
1791 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); | 1791 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
1792 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); | 1792 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
1793 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); | 1793 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
1794 GR_STATIC_ASSERT(6 == kZero_StencilOp); | 1794 GR_STATIC_ASSERT(6 == kZero_StencilOp); |
1795 GR_STATIC_ASSERT(7 == kInvert_StencilOp); | 1795 GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
1796 GrAssert((unsigned) op < kStencilOpCount); | 1796 SkASSERT((unsigned) op < kStencilOpCount); |
1797 return gTable[op]; | 1797 return gTable[op]; |
1798 } | 1798 } |
1799 | 1799 |
1800 void set_gl_stencil(const GrGLInterface* gl, | 1800 void set_gl_stencil(const GrGLInterface* gl, |
1801 const GrStencilSettings& settings, | 1801 const GrStencilSettings& settings, |
1802 GrGLenum glFace, | 1802 GrGLenum glFace, |
1803 GrStencilSettings::Face grFace) { | 1803 GrStencilSettings::Face grFace) { |
1804 GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); | 1804 GrGLenum glFunc = gr_to_gl_stencil_func(settings.func(grFace)); |
1805 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); | 1805 GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); |
1806 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); | 1806 GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); |
(...skipping 11 matching lines...) Expand all Loading... |
1818 } else { | 1818 } else { |
1819 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); | 1819 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
1820 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); | 1820 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
1821 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); | 1821 GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); |
1822 } | 1822 } |
1823 } | 1823 } |
1824 } | 1824 } |
1825 | 1825 |
1826 void GrGpuGL::flushStencil(DrawType type) { | 1826 void GrGpuGL::flushStencil(DrawType type) { |
1827 if (kStencilPath_DrawType == type) { | 1827 if (kStencilPath_DrawType == type) { |
1828 GrAssert(!fStencilSettings.isTwoSided()); | 1828 SkASSERT(!fStencilSettings.isTwoSided()); |
1829 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call | 1829 // Just the func, ref, and mask is set here. The op and write mask are p
arams to the call |
1830 // that draws the path to the SB (glStencilFillPath) | 1830 // that draws the path to the SB (glStencilFillPath) |
1831 GrGLenum func = | 1831 GrGLenum func = |
1832 gr_to_gl_stencil_func(fStencilSettings.func(GrStencilSettings::kFron
t_Face)); | 1832 gr_to_gl_stencil_func(fStencilSettings.func(GrStencilSettings::kFron
t_Face)); |
1833 GL_CALL(PathStencilFunc(func, | 1833 GL_CALL(PathStencilFunc(func, |
1834 fStencilSettings.funcRef(GrStencilSettings::kFro
nt_Face), | 1834 fStencilSettings.funcRef(GrStencilSettings::kFro
nt_Face), |
1835 fStencilSettings.funcMask(GrStencilSettings::kFr
ont_Face))); | 1835 fStencilSettings.funcMask(GrStencilSettings::kFr
ont_Face))); |
1836 } else if (fHWStencilSettings != fStencilSettings) { | 1836 } else if (fHWStencilSettings != fStencilSettings) { |
1837 if (fStencilSettings.isDisabled()) { | 1837 if (fStencilSettings.isDisabled()) { |
1838 if (kNo_TriState != fHWStencilTestEnabled) { | 1838 if (kNo_TriState != fHWStencilTestEnabled) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | 1992 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
1993 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); | 1993 GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
1994 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); | 1994 GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
1995 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); | 1995 GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
1996 return gWrapModes[tm]; | 1996 return gWrapModes[tm]; |
1997 } | 1997 } |
1998 | 1998 |
1999 } | 1999 } |
2000 | 2000 |
2001 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { | 2001 void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { |
2002 GrAssert(NULL != texture); | 2002 SkASSERT(NULL != texture); |
2003 | 2003 |
2004 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing | 2004 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing |
2005 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this | 2005 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this |
2006 // out of the "last != next" check. | 2006 // out of the "last != next" check. |
2007 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); | 2007 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderT
arget()); |
2008 if (NULL != texRT) { | 2008 if (NULL != texRT) { |
2009 this->onResolveRenderTarget(texRT); | 2009 this->onResolveRenderTarget(texRT); |
2010 } | 2010 } |
2011 | 2011 |
2012 if (fHWBoundTextures[unitIdx] != texture) { | 2012 if (fHWBoundTextures[unitIdx] != texture) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 GL_CALL(Disable(GR_GL_CULL_FACE)); | 2125 GL_CALL(Disable(GR_GL_CULL_FACE)); |
2126 break; | 2126 break; |
2127 default: | 2127 default: |
2128 GrCrash("Unknown draw face."); | 2128 GrCrash("Unknown draw face."); |
2129 } | 2129 } |
2130 fHWDrawFace = drawState.getDrawFace(); | 2130 fHWDrawFace = drawState.getDrawFace(); |
2131 } | 2131 } |
2132 } | 2132 } |
2133 | 2133 |
2134 void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { | 2134 void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) { |
2135 GrAssert(NULL != renderTarget); | 2135 SkASSERT(NULL != renderTarget); |
2136 if (fHWBoundRenderTarget == renderTarget) { | 2136 if (fHWBoundRenderTarget == renderTarget) { |
2137 fHWBoundRenderTarget = NULL; | 2137 fHWBoundRenderTarget = NULL; |
2138 } | 2138 } |
2139 } | 2139 } |
2140 | 2140 |
2141 void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { | 2141 void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) { |
2142 for (int s = 0; s < fHWBoundTextures.count(); ++s) { | 2142 for (int s = 0; s < fHWBoundTextures.count(); ++s) { |
2143 if (fHWBoundTextures[s] == texture) { | 2143 if (fHWBoundTextures[s] == texture) { |
2144 // deleting bound texture does implied bind to 0 | 2144 // deleting bound texture does implied bind to 0 |
2145 fHWBoundTextures[s] = NULL; | 2145 fHWBoundTextures[s] = NULL; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 *externalType = GR_GL_UNSIGNED_BYTE; | 2252 *externalType = GR_GL_UNSIGNED_BYTE; |
2253 } | 2253 } |
2254 break; | 2254 break; |
2255 default: | 2255 default: |
2256 return false; | 2256 return false; |
2257 } | 2257 } |
2258 return true; | 2258 return true; |
2259 } | 2259 } |
2260 | 2260 |
2261 void GrGpuGL::setTextureUnit(int unit) { | 2261 void GrGpuGL::setTextureUnit(int unit) { |
2262 GrAssert(unit >= 0 && unit < fHWBoundTextures.count()); | 2262 SkASSERT(unit >= 0 && unit < fHWBoundTextures.count()); |
2263 if (unit != fHWActiveTextureUnitIdx) { | 2263 if (unit != fHWActiveTextureUnitIdx) { |
2264 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); | 2264 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
2265 fHWActiveTextureUnitIdx = unit; | 2265 fHWActiveTextureUnitIdx = unit; |
2266 } | 2266 } |
2267 } | 2267 } |
2268 | 2268 |
2269 void GrGpuGL::setScratchTextureUnit() { | 2269 void GrGpuGL::setScratchTextureUnit() { |
2270 // Bind the last texture unit since it is the least likely to be used by GrG
LProgram. | 2270 // Bind the last texture unit since it is the least likely to be used by GrG
LProgram. |
2271 int lastUnitIdx = fHWBoundTextures.count() - 1; | 2271 int lastUnitIdx = fHWBoundTextures.count() - 1; |
2272 if (lastUnitIdx != fHWActiveTextureUnitIdx) { | 2272 if (lastUnitIdx != fHWActiveTextureUnitIdx) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 | 2332 |
2333 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2333 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is |
2334 // relative to is output. | 2334 // relative to is output. |
2335 inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl, | 2335 inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl, |
2336 GrSurface* surface, | 2336 GrSurface* surface, |
2337 GrGLenum fboTarget, | 2337 GrGLenum fboTarget, |
2338 GrGLIRect* viewport) { | 2338 GrGLIRect* viewport) { |
2339 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); | 2339 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); |
2340 GrGLuint tempFBOID; | 2340 GrGLuint tempFBOID; |
2341 if (NULL == rt) { | 2341 if (NULL == rt) { |
2342 GrAssert(NULL != surface->asTexture()); | 2342 SkASSERT(NULL != surface->asTexture()); |
2343 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); | 2343 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); |
2344 GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID)); | 2344 GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID)); |
2345 GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID)); | 2345 GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID)); |
2346 GR_GL_CALL(gl, FramebufferTexture2D(fboTarget, | 2346 GR_GL_CALL(gl, FramebufferTexture2D(fboTarget, |
2347 GR_GL_COLOR_ATTACHMENT0, | 2347 GR_GL_COLOR_ATTACHMENT0, |
2348 GR_GL_TEXTURE_2D, | 2348 GR_GL_TEXTURE_2D, |
2349 texID, | 2349 texID, |
2350 0)); | 2350 0)); |
2351 viewport->fLeft = 0; | 2351 viewport->fLeft = 0; |
2352 viewport->fBottom = 0; | 2352 viewport->fBottom = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 const SkIPoint& dstPoint) { | 2394 const SkIPoint& dstPoint) { |
2395 bool inheritedCouldCopy = INHERITED::onCanCopySurface(dst, src, srcRect, dst
Point); | 2395 bool inheritedCouldCopy = INHERITED::onCanCopySurface(dst, src, srcRect, dst
Point); |
2396 bool copied = false; | 2396 bool copied = false; |
2397 bool wouldNeedTempFBO = false; | 2397 bool wouldNeedTempFBO = false; |
2398 if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) && | 2398 if (can_copy_texsubimage(dst, src, this, &wouldNeedTempFBO) && |
2399 (!wouldNeedTempFBO || !inheritedCouldCopy)) { | 2399 (!wouldNeedTempFBO || !inheritedCouldCopy)) { |
2400 GrGLuint srcFBO; | 2400 GrGLuint srcFBO; |
2401 GrGLIRect srcVP; | 2401 GrGLIRect srcVP; |
2402 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER
, &srcVP); | 2402 srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER
, &srcVP); |
2403 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); | 2403 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
2404 GrAssert(NULL != dstTex); | 2404 SkASSERT(NULL != dstTex); |
2405 // We modified the bound FBO | 2405 // We modified the bound FBO |
2406 fHWBoundRenderTarget = NULL; | 2406 fHWBoundRenderTarget = NULL; |
2407 GrGLIRect srcGLRect; | 2407 GrGLIRect srcGLRect; |
2408 srcGLRect.setRelativeTo(srcVP, | 2408 srcGLRect.setRelativeTo(srcVP, |
2409 srcRect.fLeft, | 2409 srcRect.fLeft, |
2410 srcRect.fTop, | 2410 srcRect.fTop, |
2411 srcRect.width(), | 2411 srcRect.width(), |
2412 srcRect.height(), | 2412 srcRect.height(), |
2413 src->origin()); | 2413 src->origin()); |
2414 | 2414 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 GL_CALL(DeleteFramebuffers(1, &dstFBO)); | 2491 GL_CALL(DeleteFramebuffers(1, &dstFBO)); |
2492 } | 2492 } |
2493 if (srcFBO) { | 2493 if (srcFBO) { |
2494 GL_CALL(DeleteFramebuffers(1, &srcFBO)); | 2494 GL_CALL(DeleteFramebuffers(1, &srcFBO)); |
2495 } | 2495 } |
2496 copied = true; | 2496 copied = true; |
2497 } | 2497 } |
2498 } | 2498 } |
2499 if (!copied && inheritedCouldCopy) { | 2499 if (!copied && inheritedCouldCopy) { |
2500 copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint); | 2500 copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint); |
2501 GrAssert(copied); | 2501 SkASSERT(copied); |
2502 } | 2502 } |
2503 return copied; | 2503 return copied; |
2504 } | 2504 } |
2505 | 2505 |
2506 bool GrGpuGL::onCanCopySurface(GrSurface* dst, | 2506 bool GrGpuGL::onCanCopySurface(GrSurface* dst, |
2507 GrSurface* src, | 2507 GrSurface* src, |
2508 const SkIRect& srcRect, | 2508 const SkIRect& srcRect, |
2509 const SkIPoint& dstPoint) { | 2509 const SkIPoint& dstPoint) { |
2510 // This mirrors the logic in onCopySurface. | 2510 // This mirrors the logic in onCopySurface. |
2511 if (can_copy_texsubimage(dst, src, this)) { | 2511 if (can_copy_texsubimage(dst, src, this)) { |
(...skipping 13 matching lines...) Expand all Loading... |
2525 return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); | 2525 return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); |
2526 } | 2526 } |
2527 | 2527 |
2528 | 2528 |
2529 /////////////////////////////////////////////////////////////////////////////// | 2529 /////////////////////////////////////////////////////////////////////////////// |
2530 | 2530 |
2531 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( | 2531 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( |
2532 GrGpuGL* gpu, | 2532 GrGpuGL* gpu, |
2533 const GrGLVertexBuffer* vbuffer, | 2533 const GrGLVertexBuffer* vbuffer, |
2534 const GrGLIndexBuffer* ibuffer)
{ | 2534 const GrGLIndexBuffer* ibuffer)
{ |
2535 GrAssert(NULL != vbuffer); | 2535 SkASSERT(NULL != vbuffer); |
2536 GrGLAttribArrayState* attribState; | 2536 GrGLAttribArrayState* attribState; |
2537 | 2537 |
2538 // We use a vertex array if we're on a core profile and the verts are in a V
BO. | 2538 // We use a vertex array if we're on a core profile and the verts are in a V
BO. |
2539 if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) { | 2539 if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) { |
2540 if (NULL == fVBOVertexArray || !fVBOVertexArray->isValid()) { | 2540 if (NULL == fVBOVertexArray || !fVBOVertexArray->isValid()) { |
2541 SkSafeUnref(fVBOVertexArray); | 2541 SkSafeUnref(fVBOVertexArray); |
2542 GrGLuint arrayID; | 2542 GrGLuint arrayID; |
2543 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); | 2543 GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
2544 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2544 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2545 fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (gpu, arrayID, attrCou
nt)); | 2545 fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (gpu, arrayID, attrCou
nt)); |
2546 } | 2546 } |
2547 attribState = fVBOVertexArray->bindWithIndexBuffer(ibuffer); | 2547 attribState = fVBOVertexArray->bindWithIndexBuffer(ibuffer); |
2548 } else { | 2548 } else { |
2549 if (NULL != ibuffer) { | 2549 if (NULL != ibuffer) { |
2550 this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID())
; | 2550 this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID())
; |
2551 } else { | 2551 } else { |
2552 this->setVertexArrayID(gpu, 0); | 2552 this->setVertexArrayID(gpu, 0); |
2553 } | 2553 } |
2554 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2554 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2555 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2555 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2556 fDefaultVertexArrayAttribState.resize(attrCount); | 2556 fDefaultVertexArrayAttribState.resize(attrCount); |
2557 } | 2557 } |
2558 attribState = &fDefaultVertexArrayAttribState; | 2558 attribState = &fDefaultVertexArrayAttribState; |
2559 } | 2559 } |
2560 return attribState; | 2560 return attribState; |
2561 } | 2561 } |
OLD | NEW |