OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
| 10 #include "gl/GrGLSLPrettyPrint.h" |
10 #include "gl/GrGLUniformHandle.h" | 11 #include "gl/GrGLUniformHandle.h" |
11 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
12 #include "GrDrawEffect.h" | 13 #include "GrDrawEffect.h" |
13 #include "GrGpuGL.h" | 14 #include "GrGpuGL.h" |
14 #include "GrTexture.h" | 15 #include "GrTexture.h" |
15 #include "SkRTConf.h" | 16 #include "SkRTConf.h" |
16 #include "SkTraceEvent.h" | 17 #include "SkTraceEvent.h" |
17 | 18 |
18 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) | 19 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
19 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) | 20 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 GrGLenum type, | 727 GrGLenum type, |
727 const SkString& shaderSrc) { | 728 const SkString& shaderSrc) { |
728 const GrGLInterface* gli = glCtx.interface(); | 729 const GrGLInterface* gli = glCtx.interface(); |
729 | 730 |
730 GrGLuint shaderId; | 731 GrGLuint shaderId; |
731 GR_GL_CALL_RET(gli, shaderId, CreateShader(type)); | 732 GR_GL_CALL_RET(gli, shaderId, CreateShader(type)); |
732 if (0 == shaderId) { | 733 if (0 == shaderId) { |
733 return 0; | 734 return 0; |
734 } | 735 } |
735 | 736 |
| 737 #ifdef SK_DEBUG |
| 738 SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, false)
; |
| 739 const GrGLchar* sourceStr = prettySource.c_str(); |
| 740 GrGLint sourceLength = static_cast<GrGLint>(prettySource.size()); |
| 741 #else |
| 742 GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size()); |
736 const GrGLchar* sourceStr = shaderSrc.c_str(); | 743 const GrGLchar* sourceStr = shaderSrc.c_str(); |
737 GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size()); | 744 #endif |
738 GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength)); | 745 GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength)); |
739 GR_GL_CALL(gli, CompileShader(shaderId)); | 746 GR_GL_CALL(gli, CompileShader(shaderId)); |
740 | 747 |
741 // Calling GetShaderiv in Chromium is quite expensive. Assume success in rel
ease builds. | 748 // Calling GetShaderiv in Chromium is quite expensive. Assume success in rel
ease builds. |
742 bool checkCompiled = !glCtx.isChromium(); | 749 bool checkCompiled = !glCtx.isChromium(); |
743 #ifdef SK_DEBUG | 750 #ifdef SK_DEBUG |
744 checkCompiled = true; | 751 checkCompiled = true; |
745 #endif | 752 #endif |
746 if (checkCompiled) { | 753 if (checkCompiled) { |
747 GrGLint compiled = GR_GL_INIT_ZERO; | 754 GrGLint compiled = GR_GL_INIT_ZERO; |
748 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled)); | 755 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled)); |
749 | 756 |
750 if (!compiled) { | 757 if (!compiled) { |
751 GrGLint infoLen = GR_GL_INIT_ZERO; | 758 GrGLint infoLen = GR_GL_INIT_ZERO; |
752 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLe
n)); | 759 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLe
n)); |
753 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugg
er | 760 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugg
er |
754 if (infoLen > 0) { | 761 if (infoLen > 0) { |
755 // retrieve length even though we don't need it to workaround bu
g in Chromium cmd | 762 // retrieve length even though we don't need it to workaround bu
g in Chromium cmd |
756 // buffer param validation. | 763 // buffer param validation. |
757 GrGLsizei length = GR_GL_INIT_ZERO; | 764 GrGLsizei length = GR_GL_INIT_ZERO; |
758 GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1, | 765 GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1, |
759 &length, (char*)log.get())); | 766 &length, (char*)log.get())); |
760 GrPrintf(shaderSrc.c_str()); | 767 GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_s
tr()); |
761 GrPrintf("\n%s", log.get()); | 768 GrPrintf("\n%s", log.get()); |
762 } | 769 } |
763 SkDEBUGFAIL("Shader compilation failed!"); | 770 SkDEBUGFAIL("Shader compilation failed!"); |
764 GR_GL_CALL(gli, DeleteShader(shaderId)); | 771 GR_GL_CALL(gli, DeleteShader(shaderId)); |
765 return 0; | 772 return 0; |
766 } | 773 } |
767 } | 774 } |
768 | 775 |
769 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::GLSha
der", | 776 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::GLSha
der", |
770 TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY(shad
erSrc.c_str())); | 777 TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY(shad
erSrc.c_str())); |
771 if (c_PrintShaders) { | 778 if (c_PrintShaders) { |
772 GrPrintf(shaderSrc.c_str()); | 779 GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str()); |
773 GrPrintf("\n"); | 780 GrPrintf("\n"); |
774 } | 781 } |
775 | 782 |
776 // Attach the shader, but defer deletion until after we have linked the prog
ram. | 783 // Attach the shader, but defer deletion until after we have linked the prog
ram. |
777 // This works around a bug in the Android emulator's GLES2 wrapper which | 784 // This works around a bug in the Android emulator's GLES2 wrapper which |
778 // will immediately delete the shader object and free its memory even though
it's | 785 // will immediately delete the shader object and free its memory even though
it's |
779 // attached to a program, which then causes glLinkProgram to fail. | 786 // attached to a program, which then causes glLinkProgram to fail. |
780 GR_GL_CALL(gli, AttachShader(programId, shaderId)); | 787 GR_GL_CALL(gli, AttachShader(programId, shaderId)); |
781 | 788 |
782 return shaderId; | 789 return shaderId; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 | 1104 |
1098 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, | 1105 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, |
1099 effectCnt); | 1106 effectCnt); |
1100 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, | 1107 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, |
1101 effectStages, | 1108 effectStages, |
1102 effectCnt, | 1109 effectCnt, |
1103 keyProvider, | 1110 keyProvider, |
1104 inOutFSColor); | 1111 inOutFSColor); |
1105 return pathTexGenEffectsBuilder.finish(); | 1112 return pathTexGenEffectsBuilder.finish(); |
1106 } | 1113 } |
OLD | NEW |